diff --git a/grate/Commands/MigrateCommand.cs b/grate/Commands/MigrateCommand.cs index ad18e3d5..cad17a33 100644 --- a/grate/Commands/MigrateCommand.cs +++ b/grate/Commands/MigrateCommand.cs @@ -46,13 +46,7 @@ public MigrateCommand(GrateMigrator mi) : base("Migrates the database") }); } - - private static Option Database() => - new Option( - new[] { "--database" }, - "OBSOLETE: Please specify the connection string instead") - { IsRequired = false }; - + //REQUIRED OPTIONS private static Option ConnectionString() => new Option( new[] { "--connectionstring", "-c", "-cs", "--connstring" }, @@ -60,6 +54,8 @@ private static Option ConnectionString() => ) { IsRequired = true }; + + //CONNECTIONSTRING OPTIONS private static Option AdminConnectionString() => new Option( new[] { "-csa", "-a", "--adminconnectionstring", "-acs", "--adminconnstring" }, @@ -67,6 +63,8 @@ private static Option AdminConnectionString() => ) { IsRequired = false }; + + //DIRECTORY OPTIONS private static Option SqlFilesDirectory() => new Option( new[] { "--sqlfilesdirectory", "-f", "--files" }, @@ -81,19 +79,16 @@ private static Option OutputPath() => "This is where everything related to the migration is stored. This includes any backups, all items that ran, permission dumps, logs, etc." ).ExistingOnly(); - private static Option ServerName() => - new Option( - new[] { "--instance", "--server", "--servername", "-s" }, - //() => DefaultServerName, - "OBSOLETE: Please specify the connection string instead." - ); + //SECURITY OPTIONS private static Option AccessToken() => new Option( new[] { "--accesstoken" }, "Access token to be used for logging in to SQL Server / Azure SQL Database." ); + + //TIMEOUT OPTIONS private static Option CommandTimeout() => new Option( new[] { "--commandtimeout", "-ct" }, @@ -108,6 +103,8 @@ private static Option CommandTimeoutAdmin() => "This is the timeout when administration commands are run (except for restore, which has its own)." ); + + //DATABASE OPTIONS private static Option DatabaseType() => new Option( new[] { "--databasetype", "--dt", "--dbt" }, @@ -120,14 +117,6 @@ private static Option DatabaseType() => new[] { "--transaction", "--trx", "-t" }, "Run the migration in a transaction" ); - - private static Option Environment() => - new ( - aliases: new[] { "--env", "--environment" }, // we'll only support a single environment initially - parseArgument: ArgumentParsers.ParseEnvironment, // Needed in System.CommandLine beta3: https://github.com/dotnet/command-line-api/issues/1664 - description: "Environment Name - This allows grate to be environment aware and only run scripts that are in a particular environment based on the name of the script. 'something.ENV.LOCAL.sql' would only be run if --env=LOCAL was set." - ); - private static Option SchemaName() => new( new[] { "--sc", "--schema", "--schemaname" }, @@ -135,29 +124,22 @@ private static Option SchemaName() => "The schema to use for the migration tables" ); - private static Option Silent() => - new( - new[] { "--noninteractive", "-ni", "--ni", "--silent" }, - "Silent - tells grate not to ask for any input when it runs." - ); - - private static Option Version() => - new( - new[] { "--version" }, // we can't use --version as it conflicts with the standard option - "Database Version - specify the version of the current migration directly on the command line." - ); - private static Option Drop() => new(new[] { "--drop" }, "Drop - This instructs grate to remove the target database. Unlike RoundhousE grate will continue to run the migration scripts after the drop." ); - private static Option Tokens() => - new( - new[] { "--disabletokenreplacement", "--disabletokens" }, - "Tokens - This instructs grate to not perform token replacement ({{somename}}). Defaults to false." + + //ENVIRONMENT OPTIONS + private static Option Environment() => + new ( + aliases: new[] { "--env", "--environment" }, + parseArgument: ArgumentParsers.ParseEnvironment, // Needed in System.CommandLine beta3: https://github.com/dotnet/command-line-api/issues/1664 + description: "Environment Name - This allows grate to be environment aware and only run scripts that are in a particular environment based on the name of the script. 'something.ENV.LOCAL.sql' would only be run if --env=LOCAL was set." ); + + //WARNING OPTIONS private static Option WarnAndRunOnScriptChange() => new( new[] { "-w", "--warnononetimescriptchanges" }, @@ -170,12 +152,22 @@ private static Option WarnAndIgnoreOnScriptChange() => "WarnAndIgnoreOnOneTimeScriptChanges - Instructs grate to ignore and update the hash of changed one time scripts (DDL/DML in Up folder) that have previously been run against the database instead of failing. A warning is logged for each one time scripts that is rerun. Defaults to false." ); + + //TOKEN OPTIONS + private static Option Tokens() => + new( + new[] { "--disabletokenreplacement", "--disabletokens" }, + "Tokens - This instructs grate to not perform token replacement ({{somename}}). Defaults to false." + ); + private static Option> UserTokens() => new( new[] { "--ut", "--usertokens" }, "User Tokens - Allows grate to perform token replacement on custom tokens ({{my_token}}). Set as a key=value pair, eg '--ut=my_token=myvalue'. Can be specified multiple times." ); + + //SCRIPT OPTIONS private static Option DoNotStoreScriptText() => new( new[] { "--donotstorescriptsruntext" }, @@ -188,6 +180,8 @@ private static Option RunAllAnyTimeScripts() => "RunAllAnyTimeScripts - This instructs grate to run any time scripts every time it is run even if they haven't changed. Defaults to false." ); + + //MISC OPTIONS private static Option Baseline() => new( new[] { "--baseline" }, @@ -205,4 +199,31 @@ private static Option Restore() => new[] { "--restore" }, " Restore - This instructs grate where to get the backed up database file. Defaults to NULL." ); + + private static Option Silent() => + new( + new[] { "--noninteractive", "-ni", "--ni", "--silent" }, + "Silent - tells grate not to ask for any input when it runs." + ); + + private static Option Version() => + new( + new[] { "--version" }, // we can't use --version as it conflicts with the standard option + "Database Version - specify the version of the current migration directly on the command line." + ); + + + //OBSOLETE OPTIONS + private static Option Database() => + new Option( + new[] { "--database" }, + "OBSOLETE: Please specify the connection string instead") + { IsRequired = false }; + + private static Option ServerName() => + new Option( + new[] { "--instance", "--server", "--servername", "-s" }, + //() => DefaultServerName, + "OBSOLETE: Please specify the connection string instead." + ); }