Skip to content
This repository was archived by the owner on May 4, 2026. It is now read-only.

Commit 027df67

Browse files
Added the template tutorial files (#13)
2 parents 8ccbc00 + e2f9a29 commit 027df67

10 files changed

Lines changed: 152 additions & 0 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"Name": "SaasProduct",
3+
"ValidationScript": "SELECT CAST(CASE WHEN EXISTS(SELECT * FROM master.sys.databases WHERE [Name] = '{{RegistryDb}}') THEN 1 ELSE 0 END AS BIT)",
4+
"TemplateOrder": [
5+
"Registry",
6+
"Client"
7+
],
8+
"ScriptTokens": {
9+
"RegistryDb": "Registry",
10+
"MigrationVersion": "1.0.1"
11+
}
12+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"Schema": "[dbo]",
3+
"Name": "[Client]",
4+
"Columns": [
5+
{
6+
"Name": "[ClientName]",
7+
"DataType": "VARCHAR(50)",
8+
"Nullable": false
9+
},
10+
{
11+
"Name": "[Url]",
12+
"DataType": "VARCHAR(50)",
13+
"Nullable": false
14+
},
15+
{
16+
"Name": "[ModifiedDate]",
17+
"DataType": "DATETIME",
18+
"Nullable": false,
19+
"Default": "getdate()"
20+
}
21+
]
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"Schema": "[dbo]",
3+
"Name": "[ProductVersion]",
4+
"Columns": [
5+
{
6+
"Name": "[Product]",
7+
"DataType": "VARCHAR(50)",
8+
"Nullable": false
9+
},
10+
{
11+
"Name": "[Version]",
12+
"DataType": "VARCHAR(50)",
13+
"Nullable": false
14+
},
15+
{
16+
"Name": "[ModifiedDate]",
17+
"DataType": "DATETIME",
18+
"Nullable": false,
19+
"Default": "getdate()"
20+
}
21+
]
22+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"Name": "Client",
3+
"DatabaseIdentificationScript": "SELECT [DatabaseName] FROM {{RegistryDB}}.dbo.ClientDBs WHERE [IsEnabled] = 1",
4+
"VersionStampScript": "IF NOT EXISTS(SELECT * FROM dbo.ProductVersion WHERE Product = '{{ProductName}}' AND Version = '{{MigrationVersion}}') INSERT dbo.ProductVersion(Product, Version) VALUES('{{ProductName}}', '{{MigrationVersion}}')"
5+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
MERGE INTO Registry.dbo.ClientDBs AS Target
2+
USING (
3+
VALUES
4+
('First client', 'Client1'),
5+
('Second client', 'Client2')
6+
) AS Source (ClientName, DatabaseName)
7+
ON Target.DatabaseName = Source.DatabaseName
8+
9+
-- When a row exists, update its ClientName
10+
WHEN MATCHED THEN
11+
UPDATE
12+
SET ClientName = Source.ClientName
13+
14+
-- When no matching row, insert a new one
15+
WHEN NOT MATCHED BY TARGET THEN
16+
INSERT (ClientName, DatabaseName)
17+
VALUES (Source.ClientName, Source.DatabaseName)
18+
;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"Schema": "[dbo]",
3+
"Name": "[ClientDBs]",
4+
"Columns": [
5+
{
6+
"Name": "[ClientName]",
7+
"DataType": "VARCHAR(50)",
8+
"Nullable": false
9+
},
10+
{
11+
"Name": "[DatabaseName]",
12+
"DataType": "sysname",
13+
"Nullable": false
14+
},
15+
{
16+
"Name": "[IsEnabled]",
17+
"DataType": "BIT",
18+
"Nullable": false,
19+
"Default": "1"
20+
}
21+
],
22+
"Indexes": [
23+
{
24+
"Name": "[PK_ClientDBs]",
25+
"PrimaryKey": true,
26+
"Unique": true,
27+
"Clustered": true,
28+
"IndexColumns": "[DatabaseName]"
29+
}
30+
]
31+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"Name": "Registry",
3+
"DatabaseIdentificationScript": "SELECT [Name] FROM master.sys.databases WHERE [Name] = '{{RegistryDb}}'",
4+
"VersionStampScript": ""
5+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"Name": "ValidProduct",
3+
"ValidationScript": "SELECT CAST(CASE WHEN EXISTS(SELECT * FROM master.sys.databases WHERE [Name] LIKE '{{ClientDb}}%') THEN 1 ELSE 0 END AS BIT)",
4+
"TemplateOrder": [
5+
"Client"
6+
],
7+
"ScriptTokens": {
8+
"ClientDb": "Client"
9+
}
10+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"Schema": "[dbo]",
3+
"Name": "[Info]",
4+
"Columns": [
5+
{
6+
"Name": "[ClientName]",
7+
"DataType": "VARCHAR(50)",
8+
"Nullable": false
9+
},
10+
{
11+
"Name": "[Url]",
12+
"DataType": "VARCHAR(50)",
13+
"Nullable": false
14+
},
15+
{
16+
"Name": "[ModifiedDate]",
17+
"DataType": "DATETIME",
18+
"Nullable": false,
19+
"Default": "getdate()"
20+
}
21+
]
22+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"Name": "Client",
3+
"DatabaseIdentificationScript": "SELECT [Name] FROM master.sys.databases WHERE [Name] LIKE '{{ClientDb}}%'",
4+
"VersionStampScript": ""
5+
}

0 commit comments

Comments
 (0)