Skip to content

Commit 96c09e5

Browse files
authored
v2.5.8 (#57)
- *Fixed:* SQL Server `data` merge statement fixed to include the `TenantIdColumn` where applicable to avoid possible duplicate key.
1 parent f35f808 commit 96c09e5

File tree

7 files changed

+31
-3
lines changed

7 files changed

+31
-3
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
Represents the **NuGet** versions.
44

5+
## v2.5.8
6+
- *Fixed:* SQL Server `data` merge statement fixed to include the `TenantIdColumn` where applicable to avoid possible duplicate key.
7+
58
## v2.5.7
69
- *Fixed:* Corrected issue introduced in version `2.5.5` where some strings were being incorrectly converted to a guid.
710

Common.targets

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>2.5.7</Version>
3+
<Version>2.5.8</Version>
44
<LangVersion>preview</LangVersion>
55
<Authors>Avanade</Authors>
66
<Company>Avanade</Company>

src/DbEx.SqlServer/Resources/DatabaseData_sql.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ INSERT INTO #temp ({{#each Columns}}[{{Name}}]{{#unless @last}}, {{/unless}}{{/e
1515

1616
MERGE INTO [{{Schema}}].[{{Name}}] WITH (HOLDLOCK) as [t]
1717
USING (SELECT {{#each Columns}}[{{Name}}]{{#unless @last}}, {{/unless}}{{/each}} FROM #temp) AS [s]
18-
ON ({{#if IsRefData}}[s].[{{DbTable.RefDataCodeColumn.Name}}] = [t].[{{DbTable.RefDataCodeColumn.Name}}]{{else}}{{#each PrimaryKeyColumns}}{{#unless @first}} ON {{/unless}}[s].[{{Name}}] = [t].[{{Name}}]{{/each}}{{/if}})
18+
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}})
1919
WHEN MATCHED AND EXISTS (
2020
SELECT {{#each MergeMatchColumns}}[s].[{{Name}}]{{#unless @last}}, {{/unless}}{{/each}}
2121
EXCEPT

tests/DbEx.Test.Console/Data/Data.yaml

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,9 @@
1010
- { PersonId: ^88, Name: '^(DbEx.Test.Console.RuntimeValues.Name, DbEx.Test.Console)' }
1111
- { Name: '^(DefaultName)', AddressJson: { Street: "Main St", City: "Maine" }, NicknamesJson: ["Gaz", "Baz"] }
1212
- $Gender:
13-
- X: Not specified
13+
- X: Not specified
14+
- $Status:
15+
- { Code: A, Text: Active, TenantId: ^88 }
16+
- { Code: I, Text: Inactive, TenantId: ^88 }
17+
- { Code: A, Text: Active, TenantId: ^99 }
18+
- { Code: I, Text: Inactive, TenantId: ^99 }
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Test:
2+
# Specified again, merge should not result in duplicate error
3+
- $Status:
4+
- { Code: A, Text: Active, TenantId: ^88 }
5+
- { Code: I, Text: Inactive, TenantId: ^88 }
6+
- { Code: A, Text: Active, TenantId: ^99 }
7+
- { Code: I, Text: Inactive, TenantId: ^99 }

tests/DbEx.Test.Console/DbEx.Test.Console.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
<ItemGroup>
1515
<None Remove="Data\ContactType.json" />
16+
<None Remove="Data\Data2.yaml" />
1617
<None Remove="Migrations\004a-create-test-contact-address-table.sql" />
18+
<None Remove="Migrations\007-create-test-status-table.sql" />
1719
</ItemGroup>
1820

1921
<ItemGroup>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CREATE TABLE [Test].[Status] (
2+
[StatusId] UNIQUEIDENTIFIER NOT NULL DEFAULT (NEWSEQUENTIALID()) PRIMARY KEY,
3+
[Code] NVARCHAR (50) NOT NULL,
4+
[Text] VARCHAR (256) NOT NULL,
5+
[CreatedBy] NVARCHAR (50) NULL,
6+
[CreatedDate] DATETIME2 NULL,
7+
[UpdatedBy] NVARCHAR (50) NULL,
8+
[UpdatedDate] DATETIME2 NULL,
9+
[TenantId] NVARCHAR(50) NOT NULL,
10+
UNIQUE ([TenantId], [Code])
11+
)

0 commit comments

Comments
 (0)