From a1aff1f811e4bc501d730a246bb0514917670e28 Mon Sep 17 00:00:00 2001 From: "Eric Sibly [chullybun]" Date: Sat, 19 Aug 2023 09:25:13 -0700 Subject: [PATCH] V2.3.8 (#42) * Fix MAX length. * Fix typo. --- CHANGELOG.md | 3 ++ Common.targets | 2 +- src/DbEx.MySql/DbEx.MySql.csproj | 2 +- src/DbEx.SqlServer/DbEx.SqlServer.csproj | 2 +- src/DbEx.SqlServer/SqlServerSchemaConfig.cs | 2 +- src/DbEx/DbEx.csproj | 2 +- .../004-create-test-contact-table.sql | 1 + .../004-create-test-contact-table.sql | 1 + tests/DbEx.Test/DatabaseSchemaTest.cs | 40 ++++++++++++++++++- tests/DbEx.Test/DbEx.Test.csproj | 2 +- 10 files changed, 49 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8430b98..4c03250 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ Represents the **NuGet** versions. +## v2.3.8 +- *Fixed:* `SqlServerMigration` has been fixed to handle column size of `MAX` correctly. + ## v2.3.7 - *Fixed:* `SqlServerMigration` updated to correct the `DataResetFilterPredicate` to exclude all tables within schema `cdc`, and exclude all tables within the `dbo` schema where the table name starts with `sys`. This is to ensure that the internal Change Data tables are not reset, and that any SQL Server system tables are not inadvertently reset. diff --git a/Common.targets b/Common.targets index 39a4e91..ead0a5c 100644 --- a/Common.targets +++ b/Common.targets @@ -1,6 +1,6 @@ - 2.3.7 + 2.3.8 preview Avanade Avanade diff --git a/src/DbEx.MySql/DbEx.MySql.csproj b/src/DbEx.MySql/DbEx.MySql.csproj index 757d8a4..96d391c 100644 --- a/src/DbEx.MySql/DbEx.MySql.csproj +++ b/src/DbEx.MySql/DbEx.MySql.csproj @@ -41,7 +41,7 @@ - + diff --git a/src/DbEx.SqlServer/DbEx.SqlServer.csproj b/src/DbEx.SqlServer/DbEx.SqlServer.csproj index e0aeb3f..17518d3 100644 --- a/src/DbEx.SqlServer/DbEx.SqlServer.csproj +++ b/src/DbEx.SqlServer/DbEx.SqlServer.csproj @@ -32,7 +32,7 @@ - + diff --git a/src/DbEx.SqlServer/SqlServerSchemaConfig.cs b/src/DbEx.SqlServer/SqlServerSchemaConfig.cs index 258bd21..b67edda 100644 --- a/src/DbEx.SqlServer/SqlServerSchemaConfig.cs +++ b/src/DbEx.SqlServer/SqlServerSchemaConfig.cs @@ -73,7 +73,7 @@ public override void PrepareDataParserArgs(DataParserArgs dataParserArgs) public override DbColumnSchema CreateColumnFromInformationSchema(DbTableSchema table, DatabaseRecord dr) => new(table, dr.GetValue("COLUMN_NAME"), dr.GetValue("DATA_TYPE")) { IsNullable = dr.GetValue("IS_NULLABLE").ToUpperInvariant() == "YES", - Length = (ulong?)dr.GetValue("CHARACTER_MAXIMUM_LENGTH"), + Length = (ulong?)(dr.GetValue("CHARACTER_MAXIMUM_LENGTH") <= 0 ? null : dr.GetValue("CHARACTER_MAXIMUM_LENGTH")), Precision = (ulong?)(dr.GetValue("NUMERIC_PRECISION") ?? dr.GetValue("DATETIME_PRECISION")), Scale = (ulong?)dr.GetValue("NUMERIC_SCALE"), DefaultValue = dr.GetValue("COLUMN_DEFAULT") diff --git a/src/DbEx/DbEx.csproj b/src/DbEx/DbEx.csproj index 0cf444b..6d452d4 100644 --- a/src/DbEx/DbEx.csproj +++ b/src/DbEx/DbEx.csproj @@ -23,7 +23,7 @@ - + diff --git a/tests/DbEx.Test.Console/Migrations/004-create-test-contact-table.sql b/tests/DbEx.Test.Console/Migrations/004-create-test-contact-table.sql index f91fb2a..2bfa38b 100644 --- a/tests/DbEx.Test.Console/Migrations/004-create-test-contact-table.sql +++ b/tests/DbEx.Test.Console/Migrations/004-create-test-contact-table.sql @@ -6,5 +6,6 @@ [ContactTypeId] INT NOT NULL DEFAULT 1, [GenderId] INT NULL, [TenantId] NVARCHAR(50), + [Notes] NVARCHAR(MAX) NULL, CONSTRAINT [FK_Test_Contact_ContactType] FOREIGN KEY ([ContactTypeId]) REFERENCES [Test].[ContactType] ([ContactTypeId]) ) \ No newline at end of file diff --git a/tests/DbEx.Test.MySqlConsole/Migrations/004-create-test-contact-table.sql b/tests/DbEx.Test.MySqlConsole/Migrations/004-create-test-contact-table.sql index 69158b4..932cb2b 100644 --- a/tests/DbEx.Test.MySqlConsole/Migrations/004-create-test-contact-table.sql +++ b/tests/DbEx.Test.MySqlConsole/Migrations/004-create-test-contact-table.sql @@ -5,5 +5,6 @@ `date_of_birth` DATE NULL, `contact_type_id` INT NOT NULL DEFAULT 1, `gender_id` INT NULL, + `notes` TEXT NULL, CONSTRAINT `FK_Test_Contact_ContactType` FOREIGN KEY (`contact_type_id`) REFERENCES `contact_type` (`contact_type_id`) ) \ No newline at end of file diff --git a/tests/DbEx.Test/DatabaseSchemaTest.cs b/tests/DbEx.Test/DatabaseSchemaTest.cs index 01b5cf9..d4e450e 100644 --- a/tests/DbEx.Test/DatabaseSchemaTest.cs +++ b/tests/DbEx.Test/DatabaseSchemaTest.cs @@ -101,7 +101,7 @@ public async Task SqlServerSelectSchema() Assert.AreEqual("[Test].[Contact]", tab.QualifiedName); Assert.IsFalse(tab.IsAView); Assert.IsFalse(tab.IsRefData); - Assert.AreEqual(7, tab.Columns.Count); + Assert.AreEqual(8, tab.Columns.Count); Assert.AreEqual(1, tab.PrimaryKeyColumns.Count); col = tab.Columns[0]; @@ -192,6 +192,24 @@ public async Task SqlServerSelectSchema() col = tab.Columns[6]; Assert.AreEqual("TenantId", col.Name); + col = tab.Columns[7]; + Assert.AreEqual("Notes", col.Name); + Assert.AreEqual("nvarchar", col.Type); + Assert.AreEqual("NVARCHAR(MAX) NULL", col.SqlType); + Assert.IsNull(col.Length); + Assert.IsNull(col.Scale); + Assert.IsNull(col.Precision); + Assert.AreEqual("string", col.DotNetType); + Assert.IsTrue(col.IsNullable); + Assert.IsFalse(col.IsPrimaryKey); + Assert.IsFalse(col.IsIdentity); + Assert.IsNull(col.IdentitySeed); + Assert.IsNull(col.IdentityIncrement); + Assert.IsFalse(col.IsUnique); + Assert.IsFalse(col.IsComputed); + Assert.IsFalse(col.IsForeignRefData); + Assert.IsNull(col.DefaultValue); + // [Test].[MultiPk] tab = tables.Where(x => x.Name == "MultiPk").SingleOrDefault(); Assert.IsNotNull(tab); @@ -405,7 +423,7 @@ public async Task MySqlSelectSchema() Assert.AreEqual("`contact`", tab.QualifiedName); Assert.IsFalse(tab.IsAView); Assert.IsFalse(tab.IsRefData); - Assert.AreEqual(6, tab.Columns.Count); + Assert.AreEqual(7, tab.Columns.Count); Assert.AreEqual(1, tab.PrimaryKeyColumns.Count); col = tab.Columns[0]; @@ -493,6 +511,24 @@ public async Task MySqlSelectSchema() Assert.AreEqual("gender_id", col.ForeignColumn); Assert.IsNull(col.DefaultValue); + col = tab.Columns[6]; + Assert.AreEqual("notes", col.Name); + Assert.AreEqual("text", col.Type); + Assert.AreEqual("TEXT NULL", col.SqlType); + Assert.AreEqual(65535, col.Length); + Assert.IsNull(col.Scale); + Assert.IsNull(col.Precision); + Assert.AreEqual("string", col.DotNetType); + Assert.IsTrue(col.IsNullable); + Assert.IsFalse(col.IsPrimaryKey); + Assert.IsFalse(col.IsIdentity); + Assert.IsNull(col.IdentitySeed); + Assert.IsNull(col.IdentityIncrement); + Assert.IsFalse(col.IsUnique); + Assert.IsFalse(col.IsComputed); + Assert.IsFalse(col.IsForeignRefData); + Assert.IsNull(col.DefaultValue); + // [Test].[MultiPk] tab = tables.Where(x => x.Name == "multi_pk").SingleOrDefault(); Assert.IsNotNull(tab); diff --git a/tests/DbEx.Test/DbEx.Test.csproj b/tests/DbEx.Test/DbEx.Test.csproj index 222ddae..ad50df6 100644 --- a/tests/DbEx.Test/DbEx.Test.csproj +++ b/tests/DbEx.Test/DbEx.Test.csproj @@ -11,7 +11,7 @@ - +