From a2a2389c3f7341239e952a93f9b1d1bd590e6ab2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CF=81=CE=B9=D1=82=D1=94=D1=8F=20=D0=BC=CE=B1=D1=8F=CF=87?= Date: Tue, 15 Dec 2020 13:49:15 +0000 Subject: [PATCH 01/13] Update MigrationEngine.cs --- src/MigrationEngine/MigrationEngine.cs | 29 ++++++++++++++------------ 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/MigrationEngine/MigrationEngine.cs b/src/MigrationEngine/MigrationEngine.cs index 17f1fa8..f104898 100644 --- a/src/MigrationEngine/MigrationEngine.cs +++ b/src/MigrationEngine/MigrationEngine.cs @@ -26,19 +26,22 @@ public MigrationEngine(IDatabase database, ILogger log) this.log = log ?? NullLogger.Instance; } - public async Task EnsureDatabase(CancellationToken ct = default) + public async Task DryRun(IEnumerable> migrations, IJournal journal = null, CancellationToken ct = default) + where T : IJournalEntry { - if (!await database.Exists(ct)) + using (var connection = await database.OpenConnection(true)) { - await database.Create(ct); + return await MigrateInternal(new DryRunDatabase(database.Name, connection), migrations, journal, ct); } } - public Task Migrate(IEnumerable> migrations, CancellationToken token = default) + public async Task Migrate(IEnumerable> migrations, IJournal journal = null, CancellationToken ct = default) where T : IJournalEntry - => Migrate(migrations, new NullJournal(), token); + { + return await MigrateInternal(database, migrations, journal, ct); + } - public async Task Migrate(IEnumerable> migrations, IJournal journal = null, CancellationToken token = default) + private async Task MigrateInternal(IDatabase db, IEnumerable> migrations, IJournal journal, CancellationToken ct) where T : IJournalEntry { journal = journal ?? new NullJournal(); @@ -52,17 +55,17 @@ public async Task Migrate(IEnumerable> migrations, IJ try { sw.Start(); - await mig.Run(database, journal, token); + await mig.Run(db, journal, ct); sw.Stop(); times[mig.Name] = sw.Elapsed; - log.LogDebug("{0} ({1}) {2}", database.Name, sw.Elapsed, mig.Name); + log.DebugFormat("{0} ({1}) {2}", db.Name, sw.Elapsed, mig.Name); sw.Reset(); } catch { - log.LogError("Failed migration on script {0}", mig.Name); + log.ErrorFormat("Failed migration on script {0}", mig.Name); throw; } } @@ -71,12 +74,12 @@ public async Task Migrate(IEnumerable> migrations, IJ async Task> EnsureJournal() { - using (var con = await database.OpenConnection()) + using (var con = await db.OpenConnection()) { - log.LogInformation("{0} -> Getting journal entries", database.Name); - return await journal.EnsureJournal(con, token); + log.InfoFormat("{0} -> Getting journal entries", db.Name); + return await journal.EnsureJournal(con, ct); } } } } -} \ No newline at end of file +} From c61ad959c1a381536913c6ad384aea39f012febf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CF=81=CE=B9=D1=82=D1=94=D1=8F=20=D0=BC=CE=B1=D1=8F=CF=87?= Date: Tue, 15 Dec 2020 13:51:32 +0000 Subject: [PATCH 02/13] Create DryRunDatabase.cs --- .../Implementations/DryRun/DryRunDatabase.cs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/MigrationEngine/Implementations/DryRun/DryRunDatabase.cs diff --git a/src/MigrationEngine/Implementations/DryRun/DryRunDatabase.cs b/src/MigrationEngine/Implementations/DryRun/DryRunDatabase.cs new file mode 100644 index 0000000..880fb9c --- /dev/null +++ b/src/MigrationEngine/Implementations/DryRun/DryRunDatabase.cs @@ -0,0 +1,28 @@ +using System; +using System.Threading; +using System.Threading.Tasks; +using MigrationEngine.Interfaces; + +namespace MigrationEngine.Implementations.DryRun +{ + public class DryRunDatabase : IDatabase + { + public string Name { get; } + + private readonly IConnectionManager connection; + + public DryRunDatabase(string name, IConnectionManager connection) + { + Name = name; + this.connection = new DryRunConnectionManager(connection); + } + + public Task Drop(CancellationToken token = default) => throw new Exception("Cannot drop in a dry run"); + + public Task Exists(CancellationToken token = default) => Task.FromResult(true); + + public Task Create(CancellationToken token = default) => throw new Exception("Cannot create databases in a dry run"); + + public Task OpenConnection(bool withTransaction = false) => Task.FromResult(connection); + } +} From 3f2d7f460da0681f5a62fe82e821543e5b480b52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CF=81=CE=B9=D1=82=D1=94=D1=8F=20=D0=BC=CE=B1=D1=8F=CF=87?= Date: Tue, 15 Dec 2020 13:52:16 +0000 Subject: [PATCH 03/13] Create DryRunConnectionManager.cs --- .../DryRun/DryRunConnectionManager.cs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/MigrationEngine/Implementations/DryRun/DryRunConnectionManager.cs diff --git a/src/MigrationEngine/Implementations/DryRun/DryRunConnectionManager.cs b/src/MigrationEngine/Implementations/DryRun/DryRunConnectionManager.cs new file mode 100644 index 0000000..5f28435 --- /dev/null +++ b/src/MigrationEngine/Implementations/DryRun/DryRunConnectionManager.cs @@ -0,0 +1,28 @@ +using System; +using System.Data.Common; +using System.Threading.Tasks; +using MigrationEngine.Interfaces; + +namespace MigrationEngine.Implementations.DryRun +{ + public class DryRunConnectionManager : IConnectionManager + { + private readonly IConnectionManager manager; + + public DryRunConnectionManager(IConnectionManager manager) + { + this.manager = manager; + } + + public Task RunCommand(Func> action) => manager.RunCommand(action); + + public void Commit() + { + // NEVER COMMIT IN A DRY RUN + } + + public void Dispose() + { + } + } +} From 6dfbfd56fddd19890a54fb01e74a6a0d12095d29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CF=81=CE=B9=D1=82=D1=94=D1=8F=20=D0=BC=CE=B1=D1=8F=CF=87?= Date: Tue, 15 Dec 2020 13:52:36 +0000 Subject: [PATCH 04/13] Update MigrationEngine.cs --- src/MigrationEngine/MigrationEngine.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/MigrationEngine/MigrationEngine.cs b/src/MigrationEngine/MigrationEngine.cs index f104898..76bac99 100644 --- a/src/MigrationEngine/MigrationEngine.cs +++ b/src/MigrationEngine/MigrationEngine.cs @@ -26,7 +26,7 @@ public MigrationEngine(IDatabase database, ILogger log) this.log = log ?? NullLogger.Instance; } - public async Task DryRun(IEnumerable> migrations, IJournal journal = null, CancellationToken ct = default) + public async Task DryRun(IEnumerable> migrations, IJournal journal = null, CancellationToken ct = default) where T : IJournalEntry { using (var connection = await database.OpenConnection(true)) @@ -35,10 +35,10 @@ public async Task DryRun(IEnumerable> migrations, IJo } } - public async Task Migrate(IEnumerable> migrations, IJournal journal = null, CancellationToken ct = default) + public Task Migrate(IEnumerable> migrations, IJournal journal = null, CancellationToken ct = default) where T : IJournalEntry { - return await MigrateInternal(database, migrations, journal, ct); + return MigrateInternal(database, migrations, journal, ct); } private async Task MigrateInternal(IDatabase db, IEnumerable> migrations, IJournal journal, CancellationToken ct) From 846be70612354745bbb264efd13b8f77bf0164bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CF=81=CE=B9=D1=82=D1=94=D1=8F=20=D0=BC=CE=B1=D1=8F=CF=87?= Date: Tue, 15 Dec 2020 13:54:22 +0000 Subject: [PATCH 05/13] Update MigrationEngine.cs --- src/MigrationEngine/MigrationEngine.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/MigrationEngine/MigrationEngine.cs b/src/MigrationEngine/MigrationEngine.cs index 76bac99..4d2e78f 100644 --- a/src/MigrationEngine/MigrationEngine.cs +++ b/src/MigrationEngine/MigrationEngine.cs @@ -59,13 +59,13 @@ private async Task MigrateInternal(IDatabase db, IEnumerable> EnsureJournal() { using (var con = await db.OpenConnection()) { - log.InfoFormat("{0} -> Getting journal entries", db.Name); + log.LogInformation("{0} -> Getting journal entries", db.Name); return await journal.EnsureJournal(con, ct); } } From 455f342fa1650e75c9976d4e644abdfd5771c656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CF=81=CE=B9=D1=82=D1=94=D1=8F=20=D0=BC=CE=B1=D1=8F=CF=87?= Date: Tue, 15 Dec 2020 13:57:23 +0000 Subject: [PATCH 06/13] Create dotnet.yml --- .github/workflows/dotnet.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/dotnet.yml diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml new file mode 100644 index 0000000..e15fed7 --- /dev/null +++ b/.github/workflows/dotnet.yml @@ -0,0 +1,25 @@ +name: .NET + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Setup .NET + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 3.1.301 + - name: Restore dependencies + run: dotnet restore + - name: Build + run: dotnet build --no-restore + - name: Test + run: dotnet test --no-build --verbosity normal From 9357085229e4c055f4648a9e6884544019d54815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CF=81=CE=B9=D1=82=D1=94=D1=8F=20=D0=BC=CE=B1=D1=8F=CF=87?= Date: Tue, 15 Dec 2020 13:59:48 +0000 Subject: [PATCH 07/13] Update dotnet.yml --- .github/workflows/dotnet.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index e15fed7..9a54a40 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -10,6 +10,8 @@ jobs: build: runs-on: ubuntu-latest + env: + working-directory: src steps: - uses: actions/checkout@v2 From 1c1e502891f35fc3a508c561615de51f8d68efcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CF=81=CE=B9=D1=82=D1=94=D1=8F=20=D0=BC=CE=B1=D1=8F=CF=87?= Date: Tue, 15 Dec 2020 14:03:28 +0000 Subject: [PATCH 08/13] Update dotnet.yml --- .github/workflows/dotnet.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 6c9b27c..09d560c 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -11,15 +11,13 @@ jobs: runs-on: ubuntu-latest - env: - working-directory: src - steps: - uses: actions/checkout@v2 - name: Setup .NET uses: actions/setup-dotnet@v1 with: dotnet-version: 3.1.301 + working-directory: src - name: Restore dependencies run: dotnet restore - name: Build From 686a8bcae255710b1ec4f241c0389fee8e0af463 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CF=81=CE=B9=D1=82=D1=94=D1=8F=20=D0=BC=CE=B1=D1=8F=CF=87?= Date: Tue, 15 Dec 2020 14:08:29 +0000 Subject: [PATCH 09/13] Update dotnet.yml --- .github/workflows/dotnet.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 09d560c..a84d298 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -17,10 +17,12 @@ jobs: uses: actions/setup-dotnet@v1 with: dotnet-version: 3.1.301 - working-directory: src - name: Restore dependencies + working-directory: src run: dotnet restore - name: Build + working-directory: src run: dotnet build --no-restore - name: Test + working-directory: src run: dotnet test --no-build --verbosity normal From fd9c250d01266ee427be9a1cbadd56aa97da4a53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CF=81=CE=B9=D1=82=D1=94=D1=8F=20=D0=BC=CE=B1=D1=8F=CF=87?= Date: Tue, 15 Dec 2020 14:25:00 +0000 Subject: [PATCH 10/13] Update MigrationEngine.csproj --- src/MigrationEngine/MigrationEngine.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MigrationEngine/MigrationEngine.csproj b/src/MigrationEngine/MigrationEngine.csproj index 6f96232..0afa184 100644 --- a/src/MigrationEngine/MigrationEngine.csproj +++ b/src/MigrationEngine/MigrationEngine.csproj @@ -4,7 +4,7 @@ MigrationEngine pitermarx - net472 + net50 MigrationEngine MigrationEngine MigrationEngine From 7807782bfb5c4a07614c66808db30aaa94e0b0e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CF=81=CE=B9=D1=82=D1=94=D1=8F=20=D0=BC=CE=B1=D1=8F=CF=87?= Date: Tue, 15 Dec 2020 14:25:08 +0000 Subject: [PATCH 11/13] Update MigrationEngine.Tests.csproj --- src/MigrationEngine.Tests/MigrationEngine.Tests.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MigrationEngine.Tests/MigrationEngine.Tests.csproj b/src/MigrationEngine.Tests/MigrationEngine.Tests.csproj index aae5613..559d4e2 100644 --- a/src/MigrationEngine.Tests/MigrationEngine.Tests.csproj +++ b/src/MigrationEngine.Tests/MigrationEngine.Tests.csproj @@ -1,7 +1,7 @@ - net472 + net50 false @@ -15,4 +15,4 @@ - \ No newline at end of file + From aff685e0e3ab6b6f58028795d6b53a1071b26463 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CF=81=CE=B9=D1=82=D1=94=D1=8F=20=D0=BC=CE=B1=D1=8F=CF=87?= Date: Tue, 15 Dec 2020 14:26:54 +0000 Subject: [PATCH 12/13] Update MigrationEngine.csproj --- src/MigrationEngine/MigrationEngine.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MigrationEngine/MigrationEngine.csproj b/src/MigrationEngine/MigrationEngine.csproj index 0afa184..c7a7342 100644 --- a/src/MigrationEngine/MigrationEngine.csproj +++ b/src/MigrationEngine/MigrationEngine.csproj @@ -4,7 +4,7 @@ MigrationEngine pitermarx - net50 + netstandard21 MigrationEngine MigrationEngine MigrationEngine From 059320083adec6bd674417483abc848f762c3445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CF=81=CE=B9=D1=82=D1=94=D1=8F=20=D0=BC=CE=B1=D1=8F=CF=87?= Date: Tue, 15 Dec 2020 14:27:18 +0000 Subject: [PATCH 13/13] Update MigrationEngine.Tests.csproj --- src/MigrationEngine.Tests/MigrationEngine.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MigrationEngine.Tests/MigrationEngine.Tests.csproj b/src/MigrationEngine.Tests/MigrationEngine.Tests.csproj index 559d4e2..4762c8e 100644 --- a/src/MigrationEngine.Tests/MigrationEngine.Tests.csproj +++ b/src/MigrationEngine.Tests/MigrationEngine.Tests.csproj @@ -1,7 +1,7 @@ - net50 + netstandard21 false