Skip to content

Commit

Permalink
Merge pull request #197 from DjKillerMemeStar/Re-order_MigrateCommand…
Browse files Browse the repository at this point in the history
…_options

Fixes #67
  • Loading branch information
wokket authored Jun 3, 2022
2 parents 00c0f35 + a1b1831 commit 87f1193
Showing 1 changed file with 58 additions and 37 deletions.
95 changes: 58 additions & 37 deletions grate/Commands/MigrateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,25 @@ public MigrateCommand(GrateMigrator mi) : base("Migrates the database")
});
}


private static Option Database() =>
new Option<string>(
new[] { "--database" },
"OBSOLETE: Please specify the connection string instead")
{ IsRequired = false };

//REQUIRED OPTIONS
private static Option ConnectionString() =>
new Option<string>(
new[] { "--connectionstring", "-c", "-cs", "--connstring" },
"You now provide an entire connection string. ServerName and Database are obsolete."
)
{ IsRequired = true };


//CONNECTIONSTRING OPTIONS
private static Option AdminConnectionString() =>
new Option<string>(
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 };


//DIRECTORY OPTIONS
private static Option SqlFilesDirectory() =>
new Option<DirectoryInfo>(
new[] { "--sqlfilesdirectory", "-f", "--files" },
Expand All @@ -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<string>(
new[] { "--instance", "--server", "--servername", "-s" },
//() => DefaultServerName,
"OBSOLETE: Please specify the connection string instead."
);

//SECURITY OPTIONS
private static Option AccessToken() =>
new Option<string>(
new[] { "--accesstoken" },
"Access token to be used for logging in to SQL Server / Azure SQL Database."
);


//TIMEOUT OPTIONS
private static Option CommandTimeout() =>
new Option<int>(
new[] { "--commandtimeout", "-ct" },
Expand All @@ -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<DatabaseType>(
new[] { "--databasetype", "--dt", "--dbt" },
Expand All @@ -120,44 +117,29 @@ private static Option DatabaseType() =>
new[] { "--transaction", "--trx", "-t" },
"Run the migration in a transaction"
);

private static Option<GrateEnvironment?> 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<string> SchemaName() =>
new(
new[] { "--sc", "--schema", "--schemaname" },
() => "grate",
"The schema to use for the migration tables"
);

private static Option<bool> Silent() =>
new(
new[] { "--noninteractive", "-ni", "--ni", "--silent" },
"Silent - tells grate not to ask for any input when it runs."
);

private static Option<string> 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<bool> 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<bool> Tokens() =>
new(
new[] { "--disabletokenreplacement", "--disabletokens" },
"Tokens - This instructs grate to not perform token replacement ({{somename}}). Defaults to false."

//ENVIRONMENT OPTIONS
private static Option<GrateEnvironment?> 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<bool> WarnAndRunOnScriptChange() =>
new(
new[] { "-w", "--warnononetimescriptchanges" },
Expand All @@ -170,12 +152,22 @@ private static Option<bool> 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<bool> Tokens() =>
new(
new[] { "--disabletokenreplacement", "--disabletokens" },
"Tokens - This instructs grate to not perform token replacement ({{somename}}). Defaults to false."
);

private static Option<IEnumerable<string>> 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<bool> DoNotStoreScriptText() =>
new(
new[] { "--donotstorescriptsruntext" },
Expand All @@ -188,6 +180,8 @@ private static Option<bool> 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<bool> Baseline() =>
new(
new[] { "--baseline" },
Expand All @@ -205,4 +199,31 @@ private static Option<string> Restore() =>
new[] { "--restore" },
" Restore - This instructs grate where to get the backed up database file. Defaults to NULL."
);

private static Option<bool> Silent() =>
new(
new[] { "--noninteractive", "-ni", "--ni", "--silent" },
"Silent - tells grate not to ask for any input when it runs."
);

private static Option<string> 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<string>(
new[] { "--database" },
"OBSOLETE: Please specify the connection string instead")
{ IsRequired = false };

private static Option ServerName() =>
new Option<string>(
new[] { "--instance", "--server", "--servername", "-s" },
//() => DefaultServerName,
"OBSOLETE: Please specify the connection string instead."
);
}

0 comments on commit 87f1193

Please sign in to comment.