-
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.
Added Restore from path option for Sql Server only migrations (#136)
* Adding options for restore * Added not implemented exception for remaining ansi databases * Update docs to mention new configuration option * Remove not used tokens and uncommented out restore so it can be used
- Loading branch information
Showing
17 changed files
with
168 additions
and
7 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
61 changes: 61 additions & 0 deletions
61
grate.unittests/SqlServer/Running_MigrationScripts/RestoreDatabase.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,61 @@ | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using Dapper; | ||
using FluentAssertions; | ||
using grate.Configuration; | ||
using grate.unittests.TestInfrastructure; | ||
using NUnit.Framework; | ||
|
||
namespace grate.unittests.SqlServer.Running_MigrationScripts | ||
{ | ||
[TestFixture] | ||
[Category("SqlServer")] | ||
public class RestoreDatabase : SqlServerScriptsBase | ||
{ | ||
protected override IGrateTestContext Context => GrateTestContext.SqlServer; | ||
private readonly string _backupPath = "/var/opt/mssql/backup/test.bak"; | ||
|
||
[OneTimeSetUp] | ||
public async Task RunBeforeTest() | ||
{ | ||
await using (var conn = Context.CreateDbConnection("master")) | ||
{ | ||
await conn.ExecuteAsync("use [master] CREATE DATABASE [test]"); | ||
await conn.ExecuteAsync("use [test] CREATE TABLE dbo.Table_1 (column1 int NULL)"); | ||
await conn.ExecuteAsync($"BACKUP DATABASE [test] TO DISK = '{_backupPath}'"); | ||
await conn.ExecuteAsync("use [master] DROP DATABASE [test]"); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task Ensure_database_gets_restored() | ||
{ | ||
var db = TestConfig.RandomDatabase(); | ||
|
||
var knownFolders = KnownFolders.In(CreateRandomTempDirectory()); | ||
CreateDummySql(knownFolders.Sprocs); | ||
|
||
var restoreConfig = Context.GetConfiguration(db, knownFolders) with | ||
{ | ||
Restore = _backupPath | ||
}; | ||
|
||
await using (var migrator = Context.GetMigrator(restoreConfig)) | ||
{ | ||
await migrator.Migrate(); | ||
} | ||
|
||
int[] results; | ||
string sql = $"select count(1) from sys.tables where [name]='Table_1'"; | ||
|
||
await using (var conn = Context.CreateDbConnection(db)) | ||
{ | ||
results = (await conn.QueryAsync<int>(sql)).ToArray(); | ||
} | ||
|
||
results.First().Should().Be(1); | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
grate.unittests/SqlServer/Running_MigrationScripts/SqlServerScriptsBase.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,8 @@ | ||
using grate.unittests.Generic.Running_MigrationScripts; | ||
|
||
namespace grate.unittests.SqlServer.Running_MigrationScripts | ||
{ | ||
public abstract class SqlServerScriptsBase : MigrationsScriptsBase | ||
{ | ||
} | ||
} |
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 |
---|---|---|
|
@@ -27,5 +27,4 @@ | |
<ItemGroup> | ||
<ProjectReference Include="..\grate\grate.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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
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
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
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