From fef0f726cb69c3dea7eade0818e23fe9fd2d283a Mon Sep 17 00:00:00 2001 From: "Eric Sibly [chullybun]" Date: Thu, 27 Jun 2024 11:27:47 -0700 Subject: [PATCH] v2.5.5 (#56) - *Fixed:* Updated `DataParser` to set column with a guid representation of an integer where specified using shorthand notation; i.e. replace `^n` values where `n` is an integer with a guid equivalent; e.g. `^1` will be converted to `00000001-0000-0000-0000-000000000000`. A new `DataParserArgs.ReplaceShorthandGuids` had been added to control this behavior (defaults to `true`). --- CHANGELOG.md | 3 +++ Common.targets | 2 +- src/DbEx/Migration/Data/DataParser.cs | 2 ++ src/DbEx/Migration/Data/DataParserArgs.cs | 6 ++++++ tests/DbEx.Test.Console/Data/Data.yaml | 2 +- 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d3031f4..b56d86b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ Represents the **NuGet** versions. +## v2.5.5 +- *Fixed:* Updated `DataParser` to set column with a guid representation of an integer where specified using shorthand notation; i.e. replace `^n` values where `n` is an integer with a guid equivalent; e.g. `^1` will be converted to `00000001-0000-0000-0000-000000000000`. A new `DataParserArgs.ReplaceShorthandGuids` had been added to control this behavior (defaults to `true`). + ## 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. diff --git a/Common.targets b/Common.targets index 1f6e1ed..3a5090b 100644 --- a/Common.targets +++ b/Common.targets @@ -1,6 +1,6 @@ - 2.5.4 + 2.5.5 preview Avanade Avanade diff --git a/src/DbEx/Migration/Data/DataParser.cs b/src/DbEx/Migration/Data/DataParser.cs index daa5be4..8323328 100644 --- a/src/DbEx/Migration/Data/DataParser.cs +++ b/src/DbEx/Migration/Data/DataParser.cs @@ -317,6 +317,8 @@ private async Task ParseTableJsonAsync(List tables, DataRow? parent, throw new DataParserException(msg); } + else if (ParserArgs.ReplaceShorthandGuids && int.TryParse(value[1..], out var i)) + return new Guid(i, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); else return value; } diff --git a/src/DbEx/Migration/Data/DataParserArgs.cs b/src/DbEx/Migration/Data/DataParserArgs.cs index 676f411..ff9b287 100644 --- a/src/DbEx/Migration/Data/DataParserArgs.cs +++ b/src/DbEx/Migration/Data/DataParserArgs.cs @@ -131,6 +131,11 @@ public DataParserArgs Parameter(string key, object? value, bool overrideExisting /// public DataParserTableNameMappings TableNameMappings { get; } = []; + /// + /// Indiates whether to replace '^n' values where 'n' is an integer with a equivalent; e.g. '^1' will be '00000001-0000-0000-0000-000000000000' + /// + public bool ReplaceShorthandGuids { get; set; } = true; + /// /// Copy and replace from . /// @@ -152,6 +157,7 @@ public void CopyFrom(DataParserArgs args) args.Parameters.ForEach(x => Parameters.Add(x.Key, x.Value)); TableNameMappings.Clear(); args.TableNameMappings.ForEach(x => TableNameMappings.Add(x.Key.ParsedSchema, x.Key.ParsedTable, x.Value.Schema, x.Value.Table, x.Value.ColumnMappings)); + ReplaceShorthandGuids = args.ReplaceShorthandGuids; } } } \ No newline at end of file diff --git a/tests/DbEx.Test.Console/Data/Data.yaml b/tests/DbEx.Test.Console/Data/Data.yaml index 68ab660..2650701 100644 --- a/tests/DbEx.Test.Console/Data/Data.yaml +++ b/tests/DbEx.Test.Console/Data/Data.yaml @@ -7,7 +7,7 @@ - { ContactId: 1, ContactType: E, Gender: M, Name: Bob, DateOfBirth: 2001-10-22, Addresses: [ { ContactAddressId: 10, Street: "1 Main Street" } ] } - { 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)' } + - { PersonId: ^88, Name: '^(DbEx.Test.Console.RuntimeValues.Name, DbEx.Test.Console)' } - { Name: '^(DefaultName)', AddressJson: { Street: "Main St", City: "Maine" }, NicknamesJson: ["Gaz", "Baz"] } - $Gender: - X: Not specified \ No newline at end of file