2023-03-07 14:10:34 +01:00
|
|
|
|
using Bit.Migrator;
|
2023-09-28 16:29:52 +02:00
|
|
|
|
using CommandDotNet;
|
2023-03-07 14:10:34 +01:00
|
|
|
|
|
|
|
|
|
internal class Program
|
|
|
|
|
{
|
|
|
|
|
private static int Main(string[] args)
|
|
|
|
|
{
|
2023-09-28 16:29:52 +02:00
|
|
|
|
return new AppRunner<Program>().Run(args);
|
2023-03-07 14:10:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-28 16:29:52 +02:00
|
|
|
|
[DefaultCommand]
|
|
|
|
|
public void Execute(
|
|
|
|
|
[Operand(Description = "Database connection string")]
|
|
|
|
|
string databaseConnectionString,
|
|
|
|
|
[Option('r', "repeatable", Description = "Mark scripts as repeatable")]
|
|
|
|
|
bool repeatable = false,
|
|
|
|
|
[Option('f', "folder", Description = "Folder name of database scripts")]
|
2024-03-25 15:22:02 +01:00
|
|
|
|
string folderName = MigratorConstants.DefaultMigrationsFolderName,
|
|
|
|
|
[Option('d', "dry-run", Description = "Print the scripts that will be applied without actually executing them")]
|
|
|
|
|
bool dryRun = false
|
|
|
|
|
) => MigrateDatabase(databaseConnectionString, repeatable, folderName, dryRun);
|
2023-03-07 14:10:34 +01:00
|
|
|
|
|
2024-03-22 15:54:13 +01:00
|
|
|
|
private static bool MigrateDatabase(string databaseConnectionString,
|
2024-03-25 15:22:02 +01:00
|
|
|
|
bool repeatable = false, string folderName = "", bool dryRun = false)
|
2023-03-07 14:10:34 +01:00
|
|
|
|
{
|
2024-03-22 15:54:13 +01:00
|
|
|
|
var migrator = new DbMigrator(databaseConnectionString);
|
|
|
|
|
bool success;
|
2023-09-28 16:29:52 +02:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(folderName))
|
|
|
|
|
{
|
2024-03-25 15:22:02 +01:00
|
|
|
|
success = migrator.MigrateMsSqlDatabaseWithRetries(true, repeatable, folderName, dryRun);
|
2023-09-28 16:29:52 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-03-25 15:22:02 +01:00
|
|
|
|
success = migrator.MigrateMsSqlDatabaseWithRetries(true, repeatable, dryRun: dryRun);
|
2023-09-28 16:29:52 +02:00
|
|
|
|
}
|
2023-03-07 14:10:34 +01:00
|
|
|
|
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
}
|