From d67895ea3bcf1c02d922e748ae033abe7a3e1c87 Mon Sep 17 00:00:00 2001 From: Frans van Dorsselaer <17404029+dorssel@users.noreply.github.com> Date: Fri, 1 Mar 2024 14:57:29 +0100 Subject: [PATCH] Fix migrations --- .config/dotnet-tools.json | 3 +- Directory.Packages.props | 6 +- Example/Example.csproj | 1 - SqliteTimestamp/SqliteTimestamp.csproj | 5 -- .../SqliteTimestampMigrationsSqlGenerator.cs | 21 +++-- ...teTimestampMigrationsSqlGenerator_Tests.cs | 90 ++++++++++++++++++- UnitTests/UnitTests.csproj | 1 - codecov.yml | 13 +++ dotnet-ef-sqlite-timestamp.sln | 1 + 9 files changed, 119 insertions(+), 22 deletions(-) create mode 100644 codecov.yml diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 752dc6c..749b034 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -1,4 +1,5 @@ { + "$schema": "https://json-schema.org/draft/2020-12/schema", "version": 1, "isRoot": true, "tools": { @@ -7,4 +8,4 @@ "commands": ["dotnet-ef"] } } -} \ No newline at end of file +} diff --git a/Directory.Packages.props b/Directory.Packages.props index 501b72f..f5817dd 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -9,15 +9,15 @@ SPDX-License-Identifier: MIT - - + - + + diff --git a/Example/Example.csproj b/Example/Example.csproj index 61f90e2..ee984a0 100644 --- a/Example/Example.csproj +++ b/Example/Example.csproj @@ -15,7 +15,6 @@ SPDX-License-Identifier: MIT all runtime; build; native; contentfiles; analyzers; buildtransitive - diff --git a/SqliteTimestamp/SqliteTimestamp.csproj b/SqliteTimestamp/SqliteTimestamp.csproj index 521c8d3..2bdf7a2 100644 --- a/SqliteTimestamp/SqliteTimestamp.csproj +++ b/SqliteTimestamp/SqliteTimestamp.csproj @@ -11,7 +11,6 @@ SPDX-License-Identifier: MIT Dorssel.EntityFrameworkCore.Sqlite.Timestamp true - false true Dorssel.EntityFrameworkCore.Sqlite.Timestamp true @@ -23,10 +22,6 @@ SPDX-License-Identifier: MIT - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - diff --git a/SqliteTimestamp/SqliteTimestampMigrationsSqlGenerator.cs b/SqliteTimestamp/SqliteTimestampMigrationsSqlGenerator.cs index 026c5c9..b812a49 100644 --- a/SqliteTimestamp/SqliteTimestampMigrationsSqlGenerator.cs +++ b/SqliteTimestamp/SqliteTimestampMigrationsSqlGenerator.cs @@ -32,16 +32,19 @@ public override IReadOnlyList Generate(IReadOnlyList(); + var designTimeModel = db.GetService(); + var operations = new List + { + new CreateTableOperation() { Name = MemoryDbContext.TestTableName } + }; + + var result = generator.Generate(operations, designTimeModel.Model); + + Assert.IsTrue(result.Any(c => c.CommandText.Contains("TRIGGER"))); + } + + [TestMethod] + public void SqliteTimestampMigrationsSqlGenerator_RenameTable() + { + using var db = new MemoryDbContext(); + var generator = db.GetService(); + var designTimeModel = db.GetService(); + var operations = new List + { + new RenameTableOperation() { Name = MemoryDbContext.TestTableName, NewName = "Renamed" } + }; + + var result = generator.Generate(operations, designTimeModel.Model); + + Assert.IsTrue(result.Any(c => c.CommandText.Contains("TRIGGER"))); + } + + [TestMethod] + public void SqliteTimestampMigrationsSqlGenerator_RenameSchema() + { + using var db = new MemoryDbContext(); + var generator = db.GetService(); + var designTimeModel = db.GetService(); + var operations = new List + { + new RenameTableOperation() { Name = MemoryDbContext.TestTableName, NewSchema = "Renamed" } + }; + + var result = generator.Generate(operations, designTimeModel.Model); + + Assert.IsTrue(result.Any(c => c.CommandText.Contains("TRIGGER"))); + } + + [TestMethod] + public void SqliteTimestampMigrationsSqlGenerator_AlterTable() + { + using var db = new MemoryDbContext(); + var generator = db.GetService(); + var designTimeModel = db.GetService(); + var operations = new List + { + new AlterTableOperation() { Name = MemoryDbContext.TestTableName } + }; + + var result = generator.Generate(operations, designTimeModel.Model); + + Assert.IsTrue(result.Any(c => c.CommandText.Contains("TRIGGER"))); + } + + [TestMethod] + public void SqliteTimestampMigrationsSqlGenerator_DropTable() + { + using var db = new MemoryDbContext(); + var generator = db.GetService(); + var designTimeModel = db.GetService(); + var operations = new List + { + new DropTableOperation() { Name = MemoryDbContext.TestTableName } + }; + + var result = generator.Generate(operations, designTimeModel.Model); + + Assert.IsTrue(result.Any(c => c.CommandText.Contains("TRIGGER"))); + } + + [TestMethod] + public void SqliteTimestampMigrationsSqlGenerator_NullModelNoThrow() { using var db = new MemoryDbContext(); + var generator = db.GetService(); - db.Database.EnsureCreated(); + _ = generator.Generate([]); } } diff --git a/UnitTests/UnitTests.csproj b/UnitTests/UnitTests.csproj index 3af2d5b..01698d9 100644 --- a/UnitTests/UnitTests.csproj +++ b/UnitTests/UnitTests.csproj @@ -14,7 +14,6 @@ SPDX-License-Identifier: MIT - diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..d1f4fa4 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,13 @@ +# SPDX-FileCopyrightText: 2024 Frans van Dorsselaer +# +# SPDX-License-Identifier: MIT + +--- +coverage: + status: + patch: + default: + informational: true + project: + default: + informational: true diff --git a/dotnet-ef-sqlite-timestamp.sln b/dotnet-ef-sqlite-timestamp.sln index f7cb470..5fb9a25 100644 --- a/dotnet-ef-sqlite-timestamp.sln +++ b/dotnet-ef-sqlite-timestamp.sln @@ -13,6 +13,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution .gitattributes = .gitattributes .gitignore = .gitignore .mega-linter.yml = .mega-linter.yml + codecov.yml = codecov.yml Directory.Build.props = Directory.Build.props Directory.Packages.props = Directory.Packages.props GitVersion.yml = GitVersion.yml