Skip to content

Commit

Permalink
v2.5.8 (#57)
Browse files Browse the repository at this point in the history
- *Fixed:* SQL Server `data` merge statement fixed to include the `TenantIdColumn` where applicable to avoid possible duplicate key.
  • Loading branch information
chullybun committed Jul 1, 2024
1 parent f35f808 commit 96c09e5
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

Represents the **NuGet** versions.

## v2.5.8
- *Fixed:* SQL Server `data` merge statement fixed to include the `TenantIdColumn` where applicable to avoid possible duplicate key.

## v2.5.7
- *Fixed:* Corrected issue introduced in version `2.5.5` where some strings were being incorrectly converted to a guid.

Expand Down
2 changes: 1 addition & 1 deletion Common.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>2.5.7</Version>
<Version>2.5.8</Version>
<LangVersion>preview</LangVersion>
<Authors>Avanade</Authors>
<Company>Avanade</Company>
Expand Down
2 changes: 1 addition & 1 deletion src/DbEx.SqlServer/Resources/DatabaseData_sql.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ INSERT INTO #temp ({{#each Columns}}[{{Name}}]{{#unless @last}}, {{/unless}}{{/e

MERGE INTO [{{Schema}}].[{{Name}}] WITH (HOLDLOCK) as [t]
USING (SELECT {{#each Columns}}[{{Name}}]{{#unless @last}}, {{/unless}}{{/each}} FROM #temp) AS [s]
ON ({{#if IsRefData}}[s].[{{DbTable.RefDataCodeColumn.Name}}] = [t].[{{DbTable.RefDataCodeColumn.Name}}]{{else}}{{#each PrimaryKeyColumns}}{{#unless @first}} ON {{/unless}}[s].[{{Name}}] = [t].[{{Name}}]{{/each}}{{/if}})
ON ({{#if IsRefData}}[s].[{{DbTable.RefDataCodeColumn.Name}}] = [t].[{{DbTable.RefDataCodeColumn.Name}}]{{else}}{{#each PrimaryKeyColumns}}{{#unless @first}} ON {{/unless}}[s].[{{Name}}] = [t].[{{Name}}]{{/each}}{{/if}}{{#ifval DbTable.TenantIdColumn}} AND [s].[{{DbTable.TenantIdColumn.Name}}] = [t].[{{DbTable.TenantIdColumn.Name}}]{{/ifval}})
WHEN MATCHED AND EXISTS (
SELECT {{#each MergeMatchColumns}}[s].[{{Name}}]{{#unless @last}}, {{/unless}}{{/each}}
EXCEPT
Expand Down
7 changes: 6 additions & 1 deletion tests/DbEx.Test.Console/Data/Data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@
- { 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
- X: Not specified
- $Status:
- { Code: A, Text: Active, TenantId: ^88 }
- { Code: I, Text: Inactive, TenantId: ^88 }
- { Code: A, Text: Active, TenantId: ^99 }
- { Code: I, Text: Inactive, TenantId: ^99 }
7 changes: 7 additions & 0 deletions tests/DbEx.Test.Console/Data/Data2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Test:
# Specified again, merge should not result in duplicate error
- $Status:
- { Code: A, Text: Active, TenantId: ^88 }
- { Code: I, Text: Inactive, TenantId: ^88 }
- { Code: A, Text: Active, TenantId: ^99 }
- { Code: I, Text: Inactive, TenantId: ^99 }
2 changes: 2 additions & 0 deletions tests/DbEx.Test.Console/DbEx.Test.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

<ItemGroup>
<None Remove="Data\ContactType.json" />
<None Remove="Data\Data2.yaml" />
<None Remove="Migrations\004a-create-test-contact-address-table.sql" />
<None Remove="Migrations\007-create-test-status-table.sql" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CREATE TABLE [Test].[Status] (
[StatusId] UNIQUEIDENTIFIER NOT NULL DEFAULT (NEWSEQUENTIALID()) PRIMARY KEY,
[Code] NVARCHAR (50) NOT NULL,
[Text] VARCHAR (256) NOT NULL,
[CreatedBy] NVARCHAR (50) NULL,
[CreatedDate] DATETIME2 NULL,
[UpdatedBy] NVARCHAR (50) NULL,
[UpdatedDate] DATETIME2 NULL,
[TenantId] NVARCHAR(50) NOT NULL,
UNIQUE ([TenantId], [Code])
)

0 comments on commit 96c09e5

Please sign in to comment.