1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-13 00:58:13 -05:00
Matt Bishop 743465273c
[PM-6909] Centralize database migration logic ()
* Centralize database migration logic

* Clean up unused usings

* Prizatize

* Remove verbose flag from Docker invocation

* Allow argument passthrough still

Co-authored-by: Michał Chęciński <mchecinski@bitwarden.com>

* Allow DI logger

---------

Co-authored-by: Michał Chęciński <mchecinski@bitwarden.com>
2024-03-22 10:54:13 -04:00

38 lines
1.2 KiB
C#

using Bit.Migrator;
using CommandDotNet;
internal class Program
{
private static int Main(string[] args)
{
return new AppRunner<Program>().Run(args);
}
[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")]
string folderName = MigratorConstants.DefaultMigrationsFolderName)
=> MigrateDatabase(databaseConnectionString, repeatable, folderName);
private static bool MigrateDatabase(string databaseConnectionString,
bool repeatable = false, string folderName = "")
{
var migrator = new DbMigrator(databaseConnectionString);
bool success;
if (!string.IsNullOrWhiteSpace(folderName))
{
success = migrator.MigrateMsSqlDatabaseWithRetries(true, repeatable, folderName);
}
else
{
success = migrator.MigrateMsSqlDatabaseWithRetries(true, repeatable);
}
return success;
}
}