Skip to content

Commit

Permalink
Add reassuring info message when running in baseline mode (#542)
Browse files Browse the repository at this point in the history
Co-authored-by: Arve Systad <[email protected]>
  • Loading branch information
ArveSystad and Arve Systad authored Jun 24, 2024
1 parent 538ad81 commit ec0256e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/grate.core/Migration/GrateMigrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ public async Task Migrate()
database.ServerName,
database.DatabaseName
);

if(config.Baseline)
_logger.LogInformation("Running a baseline run. No scripts will be actually be run, but the scripts will be marked as run.");

_logger.LogInformation("Looking in {UpFolder} for scripts to run.", config.SqlFilesDirectory);

Expand Down
18 changes: 14 additions & 4 deletions unittests/Basic_tests/Migration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public Migration()
[Fact]
public async Task Does_not_output_qny_sql_run_in_dryrun_mode()
{
var dbMigrator = GetDbMigrator(true);
var dbMigrator = GetDbMigrator(true, baseline: false);
var migrator = new GrateMigrator(_loggerFactory, dbMigrator);
await migrator.Migrate();
_logger.LoggedMessages.Should().NotContain(" No sql run, either an empty folder, or all files run against destination previously.");
Expand All @@ -29,16 +29,25 @@ public async Task Does_not_output_qny_sql_run_in_dryrun_mode()
[Fact]
public async Task Outputs_no_sql_run_in_live_mode()
{
var dbMigrator = GetDbMigrator(false);
var dbMigrator = GetDbMigrator(false, baseline: false);
var migrator = new GrateMigrator(_loggerFactory, dbMigrator);
await migrator.Migrate();
_logger.LoggedMessages.Should().Contain(" No sql run, either an empty folder, or all files run against destination previously.");
}

[Fact]
public async Task Outputs_baseline_info_in_baseline_mode()
{
var dbMigrator = GetDbMigrator(false, baseline: true);
var migrator = new GrateMigrator(_loggerFactory, dbMigrator);
await migrator.Migrate();
_logger.LoggedMessages.Should().Contain("Running a baseline run. No scripts will be actually be run, but the scripts will be marked as run.");
}

private static DirectoryInfo Wrap(DirectoryInfo root, string? subFolder) =>
new(Path.Combine(root.ToString(), subFolder ?? ""));

private static IDbMigrator GetDbMigrator(bool dryRun)
private static IDbMigrator GetDbMigrator(bool dryRun, bool baseline)
{
var parent = TestConfig.CreateRandomTempDirectory();
var knownFolders = FoldersConfiguration.Default();
Expand All @@ -53,7 +62,8 @@ private static IDbMigrator GetDbMigrator(bool dryRun)
{
NonInteractive = true,
SqlFilesDirectory = parent,
DryRun = dryRun
DryRun = dryRun,
Baseline = baseline
};
var dbMigrator = new MockDbMigrator() { Configuration = configuration };

Expand Down

0 comments on commit ec0256e

Please sign in to comment.