-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug #524: Scripts in internal Grate migration tables are always regis…
…tered as "run" (#566) * Bug #524: Scripts in internal Grate migration tables are always registered as "run" The running of the scripts to create the grate tables ScriptsRun, ScriptsRunErrors and Version were always run in baseline mode, even after the scripts had been registered as run, so they were registered as run every time (even if they were only run once). * Check that the internal tables exist before trying to select from them * Improved silly test in unit test
- Loading branch information
Showing
10 changed files
with
134 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using MariaDB.TestInfrastructure; | ||
|
||
namespace MariaDB.Bootstrapping; | ||
|
||
[Collection(nameof(MariaDbGrateTestContext))] | ||
// ReSharper disable once InconsistentNaming | ||
// ReSharper disable once UnusedType.Global | ||
public class Grate_Internal_Scripts(MariaDbGrateTestContext testContext, ITestOutputHelper testOutput) | ||
: TestCommon.Generic.Bootstrapping.Grate_Internal_Scripts(testContext, testOutput); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Oracle.TestInfrastructure; | ||
|
||
namespace Oracle.Bootstrapping; | ||
|
||
[Collection(nameof(OracleGrateTestContext))] | ||
// ReSharper disable once InconsistentNaming | ||
// ReSharper disable once UnusedType.Global | ||
public class Grate_Internal_Scripts(OracleGrateTestContext testContext, ITestOutputHelper testOutput) | ||
: TestCommon.Generic.Bootstrapping.Grate_Internal_Scripts(testContext, testOutput); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using PostgreSQL.TestInfrastructure; | ||
|
||
namespace PostgreSQL.Bootstrapping; | ||
|
||
[Collection(nameof(PostgreSqlGrateTestContext))] | ||
// ReSharper disable once InconsistentNaming | ||
// ReSharper disable once UnusedType.Global | ||
public class Grate_Internal_Scripts(PostgreSqlGrateTestContext testContext, ITestOutputHelper testOutput) | ||
: TestCommon.Generic.Bootstrapping.Grate_Internal_Scripts(testContext, testOutput); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using SqlServer.TestInfrastructure; | ||
|
||
namespace SqlServer.Bootstrapping; | ||
|
||
[Collection(nameof(SqlServerGrateTestContext))] | ||
// ReSharper disable once InconsistentNaming | ||
// ReSharper disable once UnusedType.Global | ||
public class Grate_Internal_Scripts(SqlServerGrateTestContext testContext, ITestOutputHelper testOutput) | ||
: TestCommon.Generic.Bootstrapping.Grate_Internal_Scripts(testContext, testOutput); |
9 changes: 9 additions & 0 deletions
9
unittests/SqlServerCaseSensitive/Bootstrapping/Grate_Internal_Scripts.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using SqlServerCaseSensitive.TestInfrastructure; | ||
|
||
namespace SqlServerCaseSensitive.Bootstrapping; | ||
|
||
[Collection(nameof(SqlServerGrateTestContext))] | ||
// ReSharper disable once InconsistentNaming | ||
// ReSharper disable once UnusedType.Global | ||
public class Grate_Internal_Scripts(SqlServerGrateTestContext testContext, ITestOutputHelper testOutput) | ||
: TestCommon.Generic.Bootstrapping.Grate_Internal_Scripts(testContext, testOutput); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Sqlite.TestInfrastructure; | ||
using TestCommon.TestInfrastructure; | ||
|
||
namespace Sqlite.Bootstrapping; | ||
|
||
|
||
[Collection(nameof(SqliteTestDatabase))] | ||
// ReSharper disable once InconsistentNaming | ||
// ReSharper disable once UnusedType.Global | ||
public class Grate_Internal_Scripts(SqliteGrateTestContext testContext, ITestOutputHelper testOutput) | ||
: TestCommon.Generic.Bootstrapping.Grate_Internal_Scripts(testContext, testOutput); |
54 changes: 54 additions & 0 deletions
54
unittests/TestCommon/Generic/Bootstrapping/Grate_Internal_Scripts.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using Dapper; | ||
using FluentAssertions; | ||
using grate.Configuration; | ||
using TestCommon.Generic.Running_MigrationScripts; | ||
using TestCommon.TestInfrastructure; | ||
using Xunit.Abstractions; | ||
using static grate.Configuration.KnownFolderKeys; | ||
|
||
namespace TestCommon.Generic.Bootstrapping; | ||
|
||
//[TestFixture] | ||
// ReSharper disable once InconsistentNaming | ||
public abstract class Grate_Internal_Scripts(IGrateTestContext context, ITestOutputHelper testOutput) | ||
: MigrationsScriptsBase(context, testOutput) | ||
{ | ||
[Fact] | ||
public async Task Are_only_run_once() | ||
{ | ||
var db = TestConfig.RandomDatabase(); | ||
|
||
var parent = CreateRandomTempDirectory(); | ||
var knownFolders = Folders.Default; | ||
CreateDummySql(parent, knownFolders[Sprocs]); | ||
|
||
var config = GrateConfigurationBuilder.Create(Context.DefaultConfiguration) | ||
.WithConnectionString(Context.ConnectionString(db)) | ||
.WithFolders(knownFolders) | ||
.WithSqlFilesDirectory(parent) | ||
.Build(); | ||
|
||
await using (var migrator = Context.Migrator.WithConfiguration(config)) | ||
{ | ||
await migrator.Migrate(); | ||
} | ||
await using (var migrator = Context.Migrator.WithConfiguration(config)) | ||
{ | ||
await migrator.Migrate(); | ||
} | ||
|
||
string[] scripts; | ||
string sql = $""" | ||
SELECT script_name | ||
FROM {Context.Syntax.TableWithSchema("grate", "GrateScriptsRun")} | ||
WHERE script_name = '02_create_scripts_run_table.sql' | ||
"""; | ||
|
||
using (var conn = Context.External.CreateDbConnection(db)) | ||
{ | ||
scripts = (await conn.QueryAsync<string>(sql)).ToArray(); | ||
} | ||
|
||
scripts.Should().HaveCount(1); | ||
} | ||
} |