Skip to content

Commit 0914b0e

Browse files
Add upgrade script template and update README guidelines
Adds _template.sql with the required SET options and USE PerformanceMonitor preamble so future upgrade scripts don't repeat the #828 mistake. Updates the README example to match the actual pattern used by all upgrade scripts. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1ca4a57 commit 0914b0e

2 files changed

Lines changed: 53 additions & 11 deletions

File tree

upgrades/README.md

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,49 @@ The installer:
3636

3737
## Upgrade Script Guidelines
3838

39-
1. **Always check before altering**: Use `IF NOT EXISTS` checks before adding columns/indexes
40-
2. **Be idempotent**: Scripts should be safe to run multiple times
41-
3. **Preserve data**: Never DROP tables with data (use ALTER/UPDATE instead)
42-
4. **Add comments**: Document why each change is being made
43-
5. **Test upgrade paths**: Test upgrading from each previous version
39+
1. **Start from `_template.sql`**: Copy the template for every new upgrade script — it has the required SET options and `USE PerformanceMonitor` that the installer depends on
40+
2. **Always check before altering**: Use `IF NOT EXISTS` / `IF EXISTS` checks before adding or modifying columns/indexes
41+
3. **Be idempotent**: Scripts should be safe to run multiple times
42+
4. **Preserve data**: Never DROP tables with data (use ALTER/UPDATE instead)
43+
5. **Add comments**: Document why each change is being made
44+
6. **Test upgrade paths**: Test upgrading from each previous version
4445

4546
## Example Upgrade Script
4647

4748
```sql
4849
/*
50+
Copyright 2026 Darling Data, LLC
51+
https://www.erikdarling.com/
52+
4953
Upgrade from 1.0.0 to 1.1.0
5054
Adds execution context tracking to query_stats
5155
*/
5256

53-
-- Add new column if it doesn't exist
54-
IF NOT EXISTS (
55-
SELECT 1/0
57+
SET ANSI_NULLS ON;
58+
SET ANSI_PADDING ON;
59+
SET ANSI_WARNINGS ON;
60+
SET ARITHABORT ON;
61+
SET CONCAT_NULL_YIELDS_NULL ON;
62+
SET QUOTED_IDENTIFIER ON;
63+
SET NUMERIC_ROUNDABORT OFF;
64+
SET IMPLICIT_TRANSACTIONS OFF;
65+
SET STATISTICS TIME, IO OFF;
66+
GO
67+
68+
USE PerformanceMonitor;
69+
GO
70+
71+
IF NOT EXISTS
72+
(
73+
SELECT
74+
1/0
5675
FROM sys.columns
57-
WHERE object_id = OBJECT_ID('collect.query_stats')
58-
AND name = 'execution_context'
76+
WHERE object_id = OBJECT_ID(N'collect.query_stats')
77+
AND name = N'execution_context'
5978
)
6079
BEGIN
6180
ALTER TABLE collect.query_stats
62-
ADD execution_context nvarchar(128) NULL;
81+
ADD execution_context nvarchar(128) NULL;
6382

6483
PRINT 'Added execution_context column to collect.query_stats';
6584
END;

upgrades/_template.sql

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
Copyright 2026 Darling Data, LLC
3+
https://www.erikdarling.com/
4+
5+
Upgrade from X.Y.Z to X.Y.Z
6+
<describe what this upgrade does and why>
7+
*/
8+
9+
SET ANSI_NULLS ON;
10+
SET ANSI_PADDING ON;
11+
SET ANSI_WARNINGS ON;
12+
SET ARITHABORT ON;
13+
SET CONCAT_NULL_YIELDS_NULL ON;
14+
SET QUOTED_IDENTIFIER ON;
15+
SET NUMERIC_ROUNDABORT OFF;
16+
SET IMPLICIT_TRANSACTIONS OFF;
17+
SET STATISTICS TIME, IO OFF;
18+
GO
19+
20+
USE PerformanceMonitor;
21+
GO
22+
23+
/* upgrade logic here — must be idempotent */

0 commit comments

Comments
 (0)