diff --git a/CHANGELOG.md b/CHANGELOG.md index f9c3722..d3031f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ Represents the **NuGet** versions. +## v2.5.4 +- *Fixed:* Updated `CoreEx` to version `3.21.0`. +- *Fixed:* Updated `DataParser` to set column with JSON (`JsonElement.GetRawText`) value versus throwing an exception when the JSON is an object or an array. + ## v2.5.3 - *Fixed:* Updated `CoreEx` to version `3.20.0`. - *Fixed:* Fixed logging of SQL statements to include the source: `FILE`, `RES` (embedded resource) or `SQL` (specified statement). diff --git a/Common.targets b/Common.targets index 14e8a61..1f6e1ed 100644 --- a/Common.targets +++ b/Common.targets @@ -1,6 +1,6 @@ - 2.5.3 + 2.5.4 preview Avanade Avanade diff --git a/src/DbEx.MySql/DbEx.MySql.csproj b/src/DbEx.MySql/DbEx.MySql.csproj index cb835e1..d76a5f8 100644 --- a/src/DbEx.MySql/DbEx.MySql.csproj +++ b/src/DbEx.MySql/DbEx.MySql.csproj @@ -41,7 +41,7 @@ - + diff --git a/src/DbEx.Postgres/DbEx.Postgres.csproj b/src/DbEx.Postgres/DbEx.Postgres.csproj index 342d035..115b113 100644 --- a/src/DbEx.Postgres/DbEx.Postgres.csproj +++ b/src/DbEx.Postgres/DbEx.Postgres.csproj @@ -42,7 +42,7 @@ - + diff --git a/src/DbEx.SqlServer/DbEx.SqlServer.csproj b/src/DbEx.SqlServer/DbEx.SqlServer.csproj index 6165ae0..82c0992 100644 --- a/src/DbEx.SqlServer/DbEx.SqlServer.csproj +++ b/src/DbEx.SqlServer/DbEx.SqlServer.csproj @@ -32,7 +32,7 @@ - + diff --git a/src/DbEx/DbEx.csproj b/src/DbEx/DbEx.csproj index 90e4725..7635191 100644 --- a/src/DbEx/DbEx.csproj +++ b/src/DbEx/DbEx.csproj @@ -20,7 +20,7 @@ - + diff --git a/src/DbEx/Migration/Data/DataParser.cs b/src/DbEx/Migration/Data/DataParser.cs index 1d50d81..daa5be4 100644 --- a/src/DbEx/Migration/Data/DataParser.cs +++ b/src/DbEx/Migration/Data/DataParser.cs @@ -220,11 +220,16 @@ private async Task ParseTableJsonAsync(List tables, DataRow? parent, switch (jr.Value.ValueKind) { case JsonValueKind.Object: - throw new DataParserException($"Table '{sdt.Schema}.{sdt.Name}' has unsupported '{jr.Name}' column value; must not be an object: {jr.Value}."); + row.AddColumn(jr.Name, jr.Value.GetRawText()); + break; case JsonValueKind.Array: - // Try parsing as a further described nested table configuration; i.e. representing a relationship. - await ParseTableJsonAsync(tables, row, sdt.Schema, jr, cancellationToken).ConfigureAwait(false); + // Try parsing as a further described nested table configuration (i.e. representing a relationship) or update column with JSON string. + if (sdt.DbTable.Columns.SingleOrDefault(x => x.Name == jr.Name) is null) + await ParseTableJsonAsync(tables, row, sdt.Schema, jr, cancellationToken).ConfigureAwait(false); + else + row.AddColumn(jr.Name, jr.Value.GetRawText()); + break; default: diff --git a/tests/DbEx.Test.Console/Data/Data.yaml b/tests/DbEx.Test.Console/Data/Data.yaml index 4a085f2..68ab660 100644 --- a/tests/DbEx.Test.Console/Data/Data.yaml +++ b/tests/DbEx.Test.Console/Data/Data.yaml @@ -8,6 +8,6 @@ - { ContactId: 2, ContactType: I, Name: Jane, Phone: 1234, Addresses: [ { ContactAddressId: 20, ContactId: 2, Street: "1 Main Street" } ] } - ^Person: - { PersonId: 88, Name: '^(DbEx.Test.Console.RuntimeValues.Name, DbEx.Test.Console)' } - - { Name: '^(DefaultName)' } + - { Name: '^(DefaultName)', AddressJson: { Street: "Main St", City: "Maine" }, NicknamesJson: ["Gaz", "Baz"] } - $Gender: - X: Not specified \ No newline at end of file diff --git a/tests/DbEx.Test.Console/Migrations/006-create-test-person-table.sql b/tests/DbEx.Test.Console/Migrations/006-create-test-person-table.sql index ecae200..cd9e6c6 100644 --- a/tests/DbEx.Test.Console/Migrations/006-create-test-person-table.sql +++ b/tests/DbEx.Test.Console/Migrations/006-create-test-person-table.sql @@ -1,6 +1,8 @@  CREATE TABLE [Test].[Person] ( [PersonId] UNIQUEIDENTIFIER NOT NULL DEFAULT (NEWSEQUENTIALID()) PRIMARY KEY, [Name] NVARCHAR (200) NOT NULL, + [NicknamesJson] NVARCHAR (500) NULL, + [AddressJson] NVARCHAR (500) NULL, [CreatedBy] NVARCHAR (200) NULL, [CreatedDate] DATETIME2 NULL, [UpdatedBy] NVARCHAR (200) NULL, diff --git a/tests/DbEx.Test/DatabaseSchemaTest.cs b/tests/DbEx.Test/DatabaseSchemaTest.cs index be61dc8..30d8e4c 100644 --- a/tests/DbEx.Test/DatabaseSchemaTest.cs +++ b/tests/DbEx.Test/DatabaseSchemaTest.cs @@ -331,7 +331,7 @@ public async Task SqlServerSelectSchema() Assert.AreEqual("[Test].[Person]", tab.QualifiedName); Assert.IsFalse(tab.IsAView); Assert.IsFalse(tab.IsRefData); - Assert.AreEqual(6, tab.Columns.Count); + Assert.AreEqual(8, tab.Columns.Count); Assert.AreEqual(1, tab.PrimaryKeyColumns.Count); Assert.AreEqual("Person", tab.DotNetName); Assert.AreEqual("People", tab.PluralName); diff --git a/tests/DbEx.Test/DbEx.Test.csproj b/tests/DbEx.Test/DbEx.Test.csproj index 226e114..daac799 100644 --- a/tests/DbEx.Test/DbEx.Test.csproj +++ b/tests/DbEx.Test/DbEx.Test.csproj @@ -11,7 +11,7 @@ - + diff --git a/tests/DbEx.Test/SqlServerMigrationTest.cs b/tests/DbEx.Test/SqlServerMigrationTest.cs index 0412e9c..fba130b 100644 --- a/tests/DbEx.Test/SqlServerMigrationTest.cs +++ b/tests/DbEx.Test/SqlServerMigrationTest.cs @@ -124,6 +124,8 @@ public async Task A130_MigrateAll_Console() Name = dr.GetValue("Name"), CreatedBy = dr.GetValue("CreatedBy"), CreatedDate = dr.GetValue("CreatedDate"), + AddressJson = dr.GetValue("AddressJson"), + NicknamesJson = dr.GetValue("NicknamesJson") }).ConfigureAwait(false)).ToList(); Assert.AreEqual(3, res.Count); @@ -138,6 +140,8 @@ public async Task A130_MigrateAll_Console() Assert.AreEqual("Bazza", row2.Name); Assert.AreEqual(m.Args.DataParserArgs.UserName, row2.CreatedBy); Assert.AreEqual(m.Args.DataParserArgs.DateTimeNow, row2.CreatedDate); + Assert.AreEqual("{\"Street\": \"Main St\", \"City\": \"Maine\"}", row2.AddressJson); + Assert.AreEqual("[\"Gaz\", \"Baz\"]", row2.NicknamesJson); // Check that the stored procedure script was migrated and works! res = (await db.StoredProcedure("[Test].[spGetContact]").Param("@ContactId", 2).SelectQueryAsync(dr => new