diff --git a/src/grate.core/Configuration/GrateConfiguration.cs b/src/grate.core/Configuration/GrateConfiguration.cs index 01e677de..1d7a4fb6 100644 --- a/src/grate.core/Configuration/GrateConfiguration.cs +++ b/src/grate.core/Configuration/GrateConfiguration.cs @@ -173,5 +173,5 @@ public record GrateConfiguration /// internal bool DeferWritingToRunTables { get; set; } - public bool IsUpToDateCheck { get; set; } + public bool UpToDateCheck { get; set; } } diff --git a/src/grate.core/Migration/GrateMigrator.cs b/src/grate.core/Migration/GrateMigrator.cs index e35e6bc1..4d581b93 100644 --- a/src/grate.core/Migration/GrateMigrator.cs +++ b/src/grate.core/Migration/GrateMigrator.cs @@ -229,11 +229,11 @@ public async Task Migrate() } // If it's an up-to-date check, we output on the console if it's up-to-date or not. - if (config.IsUpToDateCheck) + if (config.UpToDateCheck) { var logger = _loggerFactory.CreateLogger(LogCategory + ".IsUpToDate"); - logger.LogInformation("Database is up to date: {IsUpToDate}", MigrationResult.IsUpToDate); + logger.LogInformation("Up to date: {IsUpToDate}", MigrationResult.IsUpToDate); foreach (var script in MigrationResult.ScriptsRun) { logger.LogDebug("Changed script: {ScriptName}", script); diff --git a/src/grate/Commands/MigrateCommand.cs b/src/grate/Commands/MigrateCommand.cs index 21839c85..cf3a87f4 100644 --- a/src/grate/Commands/MigrateCommand.cs +++ b/src/grate/Commands/MigrateCommand.cs @@ -40,6 +40,7 @@ public MigrateCommand(IGrateMigrator mi) : base("Migrates the database") Add(DryRun()); Add(Restore()); Add(IgnoreDirectoryNames()); + Add(UpToDateCheck()); Handler = CommandHandler.Create( async () => @@ -334,4 +335,8 @@ private static Option IgnoreDirectoryNames() => new[] { "--ignoredirectorynames", "--searchallinsteadoftraverse", "--searchallsubdirectoriesinsteadoftraverse" }, "IgnoreDirectoryNames - By default, scripts are ordered by relative path including subdirectories. This option searches subdirectories, but order is based on filename alone." ); + + internal static Option UpToDateCheck() => new( + ["--uptodatecheck", "--isuptodate"], + "Outputs whether the database is up to date or not (whether any non-everytime scripts would be run)"); } diff --git a/src/grate/Program.cs b/src/grate/Program.cs index 3dba4542..accfdd04 100644 --- a/src/grate/Program.cs +++ b/src/grate/Program.cs @@ -29,7 +29,7 @@ public static async Task Main(string[] args) // Temporarily parse the configuration, to get the verbosity level, and potentially set parameters // to support the "IsUpToDate" check. var cfg = await ParseGrateConfiguration(args); - if (cfg.IsUpToDateCheck) + if (cfg.UpToDateCheck) { cfg = cfg with { Verbosity = LogLevel.Critical, DryRun = true }; } @@ -88,7 +88,6 @@ private static async Task ParseGrateConfiguration var cmd = new MigrateCommand(null!) { Verbosity(), - IsUpToDateCheck(), }; ParseResult p = @@ -158,11 +157,6 @@ private static ServiceProvider BuildServiceProvider(CommandLineGrateConfiguratio internal static Option Verbosity() => new( ["-v", "--verbosity"], "Verbosity level (as defined here: https://docs.microsoft.com/dotnet/api/Microsoft.Extensions.Logging.LogLevel)"); - - internal static Option IsUpToDateCheck() => new( - ["--isuptodate"], - "Outputs whether the database is up to date or not (whether any non-everytime scripts would be run)"); - private static T Create() where T : notnull => _serviceProvider.GetRequiredService(); } diff --git a/unittests/Basic_tests/CommandLineParsing/Basic_CommandLineParsing.cs b/unittests/Basic_tests/CommandLineParsing/Basic_CommandLineParsing.cs index 28631374..85085ba7 100644 --- a/unittests/Basic_tests/CommandLineParsing/Basic_CommandLineParsing.cs +++ b/unittests/Basic_tests/CommandLineParsing/Basic_CommandLineParsing.cs @@ -378,6 +378,18 @@ public async Task IgnoreDirectoryNames(string args, bool expected) var cfg = await ParseGrateConfiguration(args); cfg?.IgnoreDirectoryNames.Should().Be(expected); } + + [Theory] + [InlineData("", false)] + [InlineData("--isuptodate", true)] + [InlineData("--isuptodate false", false)] + [InlineData("--uptodatecheck", true)] + [InlineData("--uptodatecheck false", false)] + public async Task UpToDateCheck(string args, bool expected) + { + var cfg = await ParseGrateConfiguration(args); + cfg?.UpToDateCheck.Should().Be(expected); + } private static async Task ParseGrateConfiguration(string commandline) { diff --git a/unittests/Basic_tests/GrateMigrator_MigrationStatus/IsUpToDate_.cs b/unittests/Basic_tests/GrateMigrator_MigrationStatus/IsUpToDate_.cs index a10dfc38..9efc977b 100644 --- a/unittests/Basic_tests/GrateMigrator_MigrationStatus/IsUpToDate_.cs +++ b/unittests/Basic_tests/GrateMigrator_MigrationStatus/IsUpToDate_.cs @@ -33,7 +33,7 @@ public async Task False_if_scripts_run(bool dryRun) grateMigrator.MigrationResult.Should().NotBeNull(); grateMigrator.MigrationResult.IsUpToDate.Should().BeFalse(); - _logger.LoggedMessages.Should().Contain("Database is up to date: False"); + _logger.LoggedMessages.Should().Contain("Up to date: False"); _logger.LoggedMessages.Should().Contain("Changed script: script_that_is_run.sql"); } @@ -106,7 +106,7 @@ private GrateMigrator CreateMigrator(Dictionary> SqlFilesDirectory = SqlFilesDirectory, NonInteractive = true, DryRun = dryRun, - IsUpToDateCheck = true + UpToDateCheck = true }; var dbMigrator = Substitute.ForPartsOf();