示例#1
0
        public static void Configure([NotNull] CommandLineApplication command, [NotNull] CommonCommandOptions commonOptions)
        {
            command.Description = "List the migrations";

            var context = command.Option(
                "-c|--context <context>",
                "The DbContext to use. If omitted, the default DbContext is used");
            var startupProject = command.Option(
                "-s|--startup-project <project>",
                "The startup project to use. If omitted, the current project is used.");
            var environment = command.Option(
                "-e|--environment <environment>",
                "The environment to use. If omitted, \"Development\" is used.");
            var json = command.JsonOption();

            command.HelpOption();
            command.VerboseOption();

            command.OnExecute(
                () => Execute(commonOptions.Value(),
                              context.Value(),
                              startupProject.Value(),
                              environment.Value(),
                              json.HasValue()
                        ? (Action <IEnumerable <MigrationInfo> >)ReportJsonResults
                        : ReportResults));
        }
示例#2
0
        public static void Configure([NotNull] CommandLineApplication command, [NotNull] CommonCommandOptions commonOptions)
        {
            command.Description = "Updates the database to a specified migration";

            var migration = command.Argument(
                "[migration]",
                "The target migration. If '0', all migrations will be reverted. If omitted, all pending migrations will be applied");

            var context = command.Option(
                "-c|--context <context>",
                "The DbContext to use. If omitted, the default DbContext is used");
            var startupProject = command.Option(
                "-s|--startup-project <project>",
                "The startup project to use. If omitted, the current project is used.");
            var environment = command.Option(
                "-e|--environment <environment>",
                "The environment to use. If omitted, \"Development\" is used.");

            command.HelpOption();
            command.VerboseOption();

            command.OnExecute(
                () => Execute(commonOptions.Value(),
                              migration.Value,
                              context.Value(),
                              startupProject.Value(),
                              environment.Value()));
        }
示例#3
0
        public static void Configure([NotNull] CommandLineApplication command, [NotNull] CommonCommandOptions commonOptions)
        {
            command.Description = "Remove the last migration";

            var context = command.Option(
                "-c|--context <context>",
                "The DbContext to use. If omitted, the default DbContext is used");
            var startupProject = command.Option(
                "-s|--startup-project <project>",
                "The startup project to use. If omitted, the current project is used.");
            var environment = command.Option(
                "-e|--environment <environment>",
                "The environment to use. If omitted, \"Development\" is used.");
            var force = command.Option(
                "-f|--force",
                "Removes the last migration without checking the database. If the last migration has been applied to the database, you will need to manually reverse the changes it made.",
                CommandOptionType.NoValue);

            command.HelpOption();
            command.VerboseOption();

            command.OnExecute(
                () => Execute(commonOptions.Value(),
                              context.Value(),
                              startupProject.Value(),
                              environment.Value(),
                              force.HasValue()));
        }
        public static void Configure([NotNull] CommandLineApplication command, [NotNull] CommonCommandOptions commonOptions)
        {
            command.Description = "Drop the database for specific environment";

            var startupProject = command.Option(
                "-s|--startup-project <project>",
                "The startup project to use. If omitted, the current project is used.");
            var environment = command.Option(
                "-e|--environment <environment>",
                "The environment to use. If omitted, \"Development\" is used.");
            var context = command.Option(
                "-c|--context <context>",
                "The DbContext to use. If omitted, the default DbContext is used");
            var force = command.Option(
                "-f|--force",
                "Drop without confirmation");

            command.HelpOption();
            command.VerboseOption();

            command.OnExecute(
                () => Execute(commonOptions.Value(),
                              context.Value(),
                              startupProject.Value(),
                              environment.Value(),
                              force.HasValue()));
        }
        public static void Configure([NotNull] CommandLineApplication command, [NotNull] CommonCommandOptions commonOptions)
        {
            command.Description = "Add a new migration";

            var name = command.Argument("[name]", "The name of the migration");

            var outputDir = command.Option(
                "-o|--output-dir <path>",
                "The directory (and sub-namespace) to use. If omitted, \"Migrations\" is used.");
            var context = command.Option(
                "-c|--context <context>",
                "The DbContext to use. If omitted, the default DbContext is used");
            var startupProject = command.Option(
                "-s|--startup-project <project>",
                "The startup project to use. If omitted, the current project is used.");
            var environment = command.Option(
                "-e|--environment <environment>",
                "The environment to use. If omitted, \"Development\" is used.");
            var json = command.JsonOption();

            command.HelpOption();
            command.VerboseOption();

            command.OnExecute(
                () =>
            {
                if (string.IsNullOrEmpty(name.Value))
                {
                    Reporter.Error.WriteLine(("Missing required argument '" + name.Name + "'").Bold().Red());
                    command.ShowHelp();

                    return(1);
                }

                return(Execute(commonOptions.Value(),
                               name.Value,
                               outputDir.Value(),
                               context.Value(),
                               startupProject.Value(),
                               environment.Value(),
                               json.HasValue()
                            ? (Action <MigrationFiles>)ReportJson
                            : null));
            });
        }
示例#6
0
        public static void Configure([NotNull] CommandLineApplication command, [NotNull] CommonCommandOptions commonOptions)
        {
            command.Description = "List your DbContext types";

            var environment = command.Option(
                "-e|--environment <environment>",
                "The environment to use. If omitted, \"Development\" is used.");
            var json = command.JsonOption();

            command.HelpOption();
            command.VerboseOption();

            command.OnExecute(
                () => Execute(commonOptions.Value(),
                              environment.Value(),
                              json.HasValue()
                        ? (Action <IEnumerable <Type> >)ReportJsonResults
                        : ReportResults)
                );
        }
示例#7
0
        public static void Configure([NotNull] CommandLineApplication command, [NotNull] CommonCommandOptions commonOptions)
        {
            command.Description = "Generate a SQL script from migrations";

            var from = command.Argument(
                "[from]",
                "The starting migration. If omitted, '0' (the initial database) is used");
            var to = command.Argument(
                "[to]",
                "The ending migration. If omitted, the last migration is used");

            var output = command.Option(
                "-o|--output <file>",
                "The file to write the script to instead of stdout");
            var idempotent = command.Option(
                "-i|--idempotent",
                "Generates an idempotent script that can used on a database at any migration");
            var context = command.Option(
                "-c|--context <context>",
                "The DbContext to use. If omitted, the default DbContext is used");
            var startupProject = command.Option(
                "-s|--startup-project <project>",
                "The startup project to use. If omitted, the current project is used.");
            var environment = command.Option(
                "-e|--environment <environment>",
                "The environment to use. If omitted, \"Development\" is used.");

            command.HelpOption();
            command.VerboseOption();

            command.OnExecute(
                () => Execute(commonOptions.Value(),
                              from.Value,
                              to.Value,
                              output.Value(),
                              idempotent.HasValue(),
                              context.Value(),
                              startupProject.Value(),
                              environment.Value()));
        }
        public static void Configure([NotNull] CommandLineApplication command, [NotNull] CommonCommandOptions commonOptions)
        {
            command.Description = "Scaffolds a DbContext and entity type classes for a specified database";

            var connection = command.Argument(
                "[connection]",
                "The connection string of the database");
            var provider = command.Argument(
                "[provider]",
                "The provider to use. For example, EntityFramework.MicrosoftSqlServer");

            var dataAnnotations = command.Option(
                "-a|--data-annotations",
                "Use DataAnnotation attributes to configure the model where possible. If omitted, the output code will use only the fluent API.",
                CommandOptionType.NoValue);
            var context = command.Option(
                "-c|--context <name>",
                "Name of the generated DbContext class.");
            var force = command.Option(
                "-f|--force",
                "Force scaffolding to overwrite existing files. Otherwise, the code will only proceed if no output files would be overwritten.",
                CommandOptionType.NoValue);
            var outputDir = command.Option(
                "-o|--output-dir <path>",
                "Directory of the project where the classes should be output. If omitted, the top-level project directory is used.");
            var schemas = command.Option(
                "--schema <schema>",
                "Selects a schema for which to generate classes.",
                CommandOptionType.MultipleValue);
            var tables = command.Option(
                "-t|--table <schema.table>",
                "Selects a table for which to generate classes.",
                CommandOptionType.MultipleValue);
            var environment = command.Option(
                "-e|--environment <environment>",
                "The environment to use. If omitted, \"Development\" is used.");

            command.HelpOption();
            command.VerboseOption();

            command.OnExecute(
                () =>
            {
                if (string.IsNullOrEmpty(connection.Value))
                {
                    Reporter.Error.WriteLine(("Missing required argument '" + connection.Name + "'").Bold().Red());
                    command.ShowHelp();

                    return(Task.FromResult(1));
                }
                if (string.IsNullOrEmpty(provider.Value))
                {
                    Reporter.Error.WriteLine(("Missing required argument '" + provider.Name + "'").Bold().Red());
                    command.ShowHelp();

                    return(Task.FromResult(1));
                }

                return(ExecuteAsync(commonOptions.Value(),
                                    connection.Value,
                                    provider.Value,
                                    dataAnnotations.HasValue(),
                                    context.Value(),
                                    force.HasValue(),
                                    outputDir.Value(),
                                    schemas.Values,
                                    tables.Values,
                                    environment.Value()));
            });
        }