private static int Execute(CommonOptions commonOptions,
                                   string from,
                                   string to,
                                   string output,
                                   bool idempotent,
                                   string context,
                                   string environment)
        {
            var sql = new OperationExecutor(commonOptions, environment)
                      .ScriptMigration(from, to, idempotent, context);

            if (string.IsNullOrEmpty(output))
            {
                ConsoleCommandLogger.Output(sql);
            }
            else
            {
                ConsoleCommandLogger.Verbose("Writing SQL script to '" + output + "'".Bold().Black());
                File.WriteAllText(output, sql, Encoding.UTF8);

                ConsoleCommandLogger.Output("Done");
            }

            return(0);
        }
Example #2
0
        private static async Task <int> ExecuteAsync(CommonOptions commonOptions,
                                                     string connection,
                                                     string provider,
                                                     bool dataAnnotations,
                                                     string context,
                                                     bool force,
                                                     string outputDir,
                                                     IEnumerable <string> schemas,
                                                     IEnumerable <string> tables,
                                                     string environment)
        {
            await new OperationExecutor(commonOptions, environment)
            .ReverseEngineerAsync(
                provider,
                connection,
                outputDir,
                context,
                schemas,
                tables,
                dataAnnotations,
                force);

            ConsoleCommandLogger.Output("Done");

            return(0);
        }
Example #3
0
        private static void ReportJson(MigrationFiles files)
        {
            var sb = new StringBuilder();

            sb.AppendLine("//BEGIN");
            sb.AppendLine("{");
            sb.AppendLine("  \"MigrationFile\": \"" + SerializePath(files.MigrationFile) + "\",");
            sb.AppendLine("  \"MetadataFile\": \"" + SerializePath(files.MetadataFile) + "\",");
            sb.AppendLine("  \"SnapshotFile\": \"" + SerializePath(files.SnapshotFile) + "\"");
            sb.AppendLine("}");
            sb.AppendLine("//END");
            ConsoleCommandLogger.Output(sb.ToString());
        }
Example #4
0
        private static void ReportResults(IEnumerable <Type> contextTypes)
        {
            var any = false;

            foreach (var contextType in contextTypes)
            {
                ConsoleCommandLogger.Output(contextType.FullName as string);
                any = true;
            }

            if (!any)
            {
                ConsoleCommandLogger.Error("No DbContext was found");
            }
        }
Example #5
0
        private static void ReportResults(IEnumerable <MigrationInfo> migrations)
        {
            var any = false;

            foreach (var migration in migrations)
            {
                ConsoleCommandLogger.Output(migration.Id as string);
                any = true;
            }

            if (!any)
            {
                ConsoleCommandLogger.Error("No migrations were found");
            }
        }
        private static int Execute(CommonOptions commonOptions,
                                   string name,
                                   string outputDir,
                                   string context,
                                   string environment,
                                   Action <MigrationFiles> reporter)
        {
            var files = new OperationExecutor(commonOptions, environment)
                        .AddMigration(name, outputDir, context);

            reporter?.Invoke(files);

            ConsoleCommandLogger.Output("Done. To undo this action, use 'dotnet ef migrations remove'");

            return(0);
        }
Example #7
0
        private static void WriteLogo()
        {
            const string Bold    = "\x1b[1m";
            const string Normal  = "\x1b[22m";
            const string Magenta = "\x1b[35m";
            const string White   = "\x1b[37m";
            const string Default = "\x1b[39m";

            ConsoleCommandLogger.Output("");
            ConsoleCommandLogger.Output(@"                     _/\__       ".Insert(21, Bold + White));
            ConsoleCommandLogger.Output(@"               ---==/    \\      ".Insert(20, Bold + White));
            ConsoleCommandLogger.Output(@"         ___  ___   |.    \|\    ".Insert(26, Bold).Insert(21, Normal).Insert(20, Bold + White).Insert(9, Normal + Magenta));
            ConsoleCommandLogger.Output(@"        | __|| __|  |  )   \\\   ".Insert(20, Bold + White).Insert(8, Normal + Magenta));
            ConsoleCommandLogger.Output(@"        | _| | _|   \_/ |  //|\\ ".Insert(20, Bold + White).Insert(8, Normal + Magenta));
            ConsoleCommandLogger.Output(@"        |___||_|       /   \\\/\\".Insert(33, Normal + Default).Insert(23, Bold + White).Insert(8, Normal + Magenta));
            ConsoleCommandLogger.Output("");
        }
Example #8
0
        private static void ReportJsonResults(IEnumerable <Type> contextTypes)
        {
            var nameGroups     = contextTypes.GroupBy(t => t.Name).ToList();
            var fullNameGroups = contextTypes.GroupBy(t => t.FullName).ToList();

            var output = new StringBuilder();

            output.AppendLine("//BEGIN");
            output.Append("[");

            var first = true;

            foreach (var contextType in contextTypes)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    output.Append(",");
                }
                var safeName = nameGroups.Count(g => g.Key == contextType.Name) == 1
                    ? contextType.Name
                    : fullNameGroups.Count(g => g.Key == contextType.FullName) == 1
                        ? contextType.FullName
                        : contextType.AssemblyQualifiedName;

                output.AppendLine();
                output.AppendLine("  {");
                output.AppendLine("     \"fullName\": \"" + contextType.FullName + "\",");
                output.AppendLine("     \"safeName\": \"" + safeName + "\",");
                output.AppendLine("     \"name\": \"" + contextType.Name + "\",");
                output.AppendLine("     \"assemblyQualifiedName\": \"" + contextType.AssemblyQualifiedName + "\"");
                output.AppendLine("  }");
            }

            output.AppendLine();
            output.AppendLine("]");
            output.AppendLine("//END");

            ConsoleCommandLogger.Output(output.ToString());
        }
Example #9
0
        private static void ReportJsonResults(IEnumerable <MigrationInfo> migrations)
        {
            var nameGroups = migrations.GroupBy(m => m.Name).ToList();
            var output     = new StringBuilder();

            output.AppendLine("//BEGIN");
            output.Append("[");

            var first = true;

            foreach (var m in migrations)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    output.Append(",");
                }

                var safeName = nameGroups.Count(g => g.Key == m.Name) == 1
                    ? m.Name
                    : m.Id;

                output.AppendLine();
                output.AppendLine("  {");
                output.AppendLine("    \"id\": \"" + m.Id + "\",");
                output.AppendLine("    \"name\": \"" + m.Name + "\",");
                output.AppendLine("    \"safeName\": \"" + safeName + "\"");
                output.Append("  }");
            }

            output.AppendLine();
            output.AppendLine("]");
            output.AppendLine("//END");

            ConsoleCommandLogger.Output(output.ToString());
        }
Example #10
0
        private static int Execute(CommonOptions commonOptions,
                                   string context,
                                   string environment,
                                   bool isForced)
        {
            new OperationExecutor(commonOptions, environment)
            .DropDatabase(
                context,
                (database, dataSource) =>
            {
                if (isForced)
                {
                    return(true);
                }

                ConsoleCommandLogger.Output(
                    $"Are you sure you want to drop the database '{database}' on server '{dataSource}'? (y/N)");
                var readedKey = Console.ReadKey().KeyChar;

                return((readedKey == 'y') || (readedKey == 'Y'));
            });

            return(0);
        }