From 59dbc6fa031aa1acab11d910b85ea7cd00f7bf3b Mon Sep 17 00:00:00 2001 From: Jari Flederick Date: Wed, 1 Jun 2022 00:11:14 +0200 Subject: [PATCH 1/3] Add regions to the command options --- grate/Commands/MigrateCommand.cs | 98 +++++++++++++++++++------------- 1 file changed, 60 insertions(+), 38 deletions(-) diff --git a/grate/Commands/MigrateCommand.cs b/grate/Commands/MigrateCommand.cs index ad18e3d5..62e2eae8 100644 --- a/grate/Commands/MigrateCommand.cs +++ b/grate/Commands/MigrateCommand.cs @@ -46,27 +46,25 @@ 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 }; - + #region REQUIRED OPTIONS private static Option ConnectionString() => new Option( new[] { "--connectionstring", "-c", "-cs", "--connstring" }, "You now provide an entire connection string. ServerName and Database are obsolete." ) { IsRequired = true }; + #endregion + #region CONNECTIONSTRING OPTIONS private static Option AdminConnectionString() => new Option( new[] { "-csa", "-a", "--adminconnectionstring", "-acs", "--adminconnstring" }, "The connection string for connecting to master, if you want to create the database. Defaults to the same as --connstring." ) { IsRequired = false }; + #endregion + #region DIRECTORY OPTIONS private static Option SqlFilesDirectory() => new Option( new[] { "--sqlfilesdirectory", "-f", "--files" }, @@ -80,20 +78,17 @@ private static Option OutputPath() => () => new DirectoryInfo(DefaultOutputPath), "This is where everything related to the migration is stored. This includes any backups, all items that ran, permission dumps, logs, etc." ).ExistingOnly(); + #endregion - private static Option ServerName() => - new Option( - new[] { "--instance", "--server", "--servername", "-s" }, - //() => DefaultServerName, - "OBSOLETE: Please specify the connection string instead." - ); - + #region SECURITY OPTIONS private static Option AccessToken() => new Option( new[] { "--accesstoken" }, "Access token to be used for logging in to SQL Server / Azure SQL Database." ); + #endregion + #region TIMEOUT OPTIONS private static Option CommandTimeout() => new Option( new[] { "--commandtimeout", "-ct" }, @@ -107,7 +102,9 @@ private static Option CommandTimeoutAdmin() => () => DefaultAdminCommandTimeout, "This is the timeout when administration commands are run (except for restore, which has its own)." ); + #endregion + #region 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." ); + #endregion - private static Option Tokens() => - new( - new[] { "--disabletokenreplacement", "--disabletokens" }, - "Tokens - This instructs grate to not perform token replacement ({{somename}}). Defaults to false." + #region 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." ); + #endregion + #region WARNING OPTIONS private static Option WarnAndRunOnScriptChange() => new( new[] { "-w", "--warnononetimescriptchanges" }, @@ -169,13 +151,23 @@ private static Option WarnAndIgnoreOnScriptChange() => new[] { "--warnandignoreononetimescriptchanges" }, "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." ); + #endregion + + #region 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." ); + #endregion + #region SCRIPT OPTIONS private static Option DoNotStoreScriptText() => new( new[] { "--donotstorescriptsruntext" }, @@ -187,7 +179,9 @@ private static Option RunAllAnyTimeScripts() => new[] { "--runallanytimescripts", "--forceanytimescripts" }, "RunAllAnyTimeScripts - This instructs grate to run any time scripts every time it is run even if they haven't changed. Defaults to false." ); + #endregion + #region MISC OPTIONS private static Option Baseline() => new( new[] { "--baseline" }, @@ -205,4 +199,32 @@ 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." + ); + #endregion + + #region 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." + ); + #endregion } From 63877c273c6f8e30390c4f352d35fb7a512db273 Mon Sep 17 00:00:00 2001 From: Jari Flederick Date: Wed, 1 Jun 2022 00:35:11 +0200 Subject: [PATCH 2/3] change regions to comments --- grate/Commands/MigrateCommand.cs | 48 ++++++++++++++++---------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/grate/Commands/MigrateCommand.cs b/grate/Commands/MigrateCommand.cs index 62e2eae8..567b80a4 100644 --- a/grate/Commands/MigrateCommand.cs +++ b/grate/Commands/MigrateCommand.cs @@ -46,25 +46,25 @@ public MigrateCommand(GrateMigrator mi) : base("Migrates the database") }); } - #region REQUIRED OPTIONS + //REQUIRED OPTIONS private static Option ConnectionString() => new Option( new[] { "--connectionstring", "-c", "-cs", "--connstring" }, "You now provide an entire connection string. ServerName and Database are obsolete." ) { IsRequired = true }; - #endregion - #region CONNECTIONSTRING OPTIONS + + //CONNECTIONSTRING OPTIONS private static Option AdminConnectionString() => new Option( new[] { "-csa", "-a", "--adminconnectionstring", "-acs", "--adminconnstring" }, "The connection string for connecting to master, if you want to create the database. Defaults to the same as --connstring." ) { IsRequired = false }; - #endregion - #region DIRECTORY OPTIONS + + //DIRECTORY OPTIONS private static Option SqlFilesDirectory() => new Option( new[] { "--sqlfilesdirectory", "-f", "--files" }, @@ -78,17 +78,17 @@ private static Option OutputPath() => () => new DirectoryInfo(DefaultOutputPath), "This is where everything related to the migration is stored. This includes any backups, all items that ran, permission dumps, logs, etc." ).ExistingOnly(); - #endregion - #region SECURITY OPTIONS + + //SECURITY OPTIONS private static Option AccessToken() => new Option( new[] { "--accesstoken" }, "Access token to be used for logging in to SQL Server / Azure SQL Database." ); - #endregion - #region TIMEOUT OPTIONS + + //TIMEOUT OPTIONS private static Option CommandTimeout() => new Option( new[] { "--commandtimeout", "-ct" }, @@ -102,9 +102,9 @@ private static Option CommandTimeoutAdmin() => () => DefaultAdminCommandTimeout, "This is the timeout when administration commands are run (except for restore, which has its own)." ); - #endregion - #region DATABASE OPTIONS + + //DATABASE OPTIONS private static Option DatabaseType() => new Option( new[] { "--databasetype", "--dt", "--dbt" }, @@ -128,18 +128,18 @@ 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." ); - #endregion - #region ENVIRONMENT OPTIONS + + //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." ); - #endregion - #region WARNING OPTIONS + + //WARNING OPTIONS private static Option WarnAndRunOnScriptChange() => new( new[] { "-w", "--warnononetimescriptchanges" }, @@ -151,9 +151,9 @@ private static Option WarnAndIgnoreOnScriptChange() => new[] { "--warnandignoreononetimescriptchanges" }, "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." ); - #endregion - #region TOKEN OPTIONS + + //TOKEN OPTIONS private static Option Tokens() => new( new[] { "--disabletokenreplacement", "--disabletokens" }, @@ -165,9 +165,9 @@ private static Option> UserTokens() => 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." ); - #endregion - #region SCRIPT OPTIONS + + //SCRIPT OPTIONS private static Option DoNotStoreScriptText() => new( new[] { "--donotstorescriptsruntext" }, @@ -179,9 +179,9 @@ private static Option RunAllAnyTimeScripts() => new[] { "--runallanytimescripts", "--forceanytimescripts" }, "RunAllAnyTimeScripts - This instructs grate to run any time scripts every time it is run even if they haven't changed. Defaults to false." ); - #endregion - #region MISC OPTIONS + + //MISC OPTIONS private static Option Baseline() => new( new[] { "--baseline" }, @@ -211,9 +211,9 @@ private static Option Version() => 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." ); - #endregion - #region OBSOLETE OPTIONS + + //OBSOLETE OPTIONS private static Option Database() => new Option( new[] { "--database" }, @@ -226,5 +226,5 @@ private static Option ServerName() => //() => DefaultServerName, "OBSOLETE: Please specify the connection string instead." ); - #endregion + } From a1b1831bdee5c071bb8cd65391c62a530b80e317 Mon Sep 17 00:00:00 2001 From: Jari Flederick Date: Wed, 1 Jun 2022 00:35:22 +0200 Subject: [PATCH 3/3] Remove whitespace --- grate/Commands/MigrateCommand.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/grate/Commands/MigrateCommand.cs b/grate/Commands/MigrateCommand.cs index 567b80a4..cad17a33 100644 --- a/grate/Commands/MigrateCommand.cs +++ b/grate/Commands/MigrateCommand.cs @@ -226,5 +226,4 @@ private static Option ServerName() => //() => DefaultServerName, "OBSOLETE: Please specify the connection string instead." ); - }