From f0ee72ce2f8859b55cba606f4a1cc19b1c666bdb Mon Sep 17 00:00:00 2001 From: Erik Darling <2136037+erikdarlingdata@users.noreply.github.com> Date: Fri, 27 Feb 2026 12:30:20 -0500 Subject: [PATCH] =?UTF-8?q?Move=20collect=5Fquery/collect=5Fplan=20upgrade?= =?UTF-8?q?=20to=20proper=20upgrade=20path=20(2.0.0=E2=86=922.1.0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove ALTER TABLE blocks from 01_install_database.sql — upgrade logic belongs in upgrades/ folder, not install scripts. CREATE TABLE already has the columns for fresh installs. (#337) Co-Authored-By: Claude Opus 4.6 --- install/01_install_database.sql | 41 ------------ .../01_collection_schedule_optional_text.sql | 65 +++++++++++++++++++ upgrades/2.0.0-to-2.1.0/upgrade.txt | 1 + 3 files changed, 66 insertions(+), 41 deletions(-) create mode 100644 upgrades/2.0.0-to-2.1.0/01_collection_schedule_optional_text.sql create mode 100644 upgrades/2.0.0-to-2.1.0/upgrade.txt diff --git a/install/01_install_database.sql b/install/01_install_database.sql index a435add..2d71820 100644 --- a/install/01_install_database.sql +++ b/install/01_install_database.sql @@ -321,47 +321,6 @@ BEGIN PRINT 'Created config.collection_schedule table'; END; -/* -Add collect_query and collect_plan columns for existing installations -Controls whether collectors store query text and execution plans -Both default to enabled (1) for backwards compatibility -*/ -IF NOT EXISTS -( - SELECT - 1/0 - FROM sys.columns - WHERE object_id = OBJECT_ID(N'config.collection_schedule') - AND name = N'collect_query' -) -BEGIN - ALTER TABLE - config.collection_schedule - ADD collect_query bit NOT NULL - CONSTRAINT DF_collection_schedule_collect_query - DEFAULT CONVERT(bit, 'true'); - - PRINT 'Added collect_query column to config.collection_schedule'; -END; - -IF NOT EXISTS -( - SELECT - 1/0 - FROM sys.columns - WHERE object_id = OBJECT_ID(N'config.collection_schedule') - AND name = N'collect_plan' -) -BEGIN - ALTER TABLE - config.collection_schedule - ADD collect_plan bit NOT NULL - CONSTRAINT DF_collection_schedule_collect_plan - DEFAULT CONVERT(bit, 'true'); - - PRINT 'Added collect_plan column to config.collection_schedule'; -END; - /* Critical issues table Logs significant performance problems detected by collectors and analysis procedures diff --git a/upgrades/2.0.0-to-2.1.0/01_collection_schedule_optional_text.sql b/upgrades/2.0.0-to-2.1.0/01_collection_schedule_optional_text.sql new file mode 100644 index 0000000..57164df --- /dev/null +++ b/upgrades/2.0.0-to-2.1.0/01_collection_schedule_optional_text.sql @@ -0,0 +1,65 @@ +/* +Copyright 2026 Darling Data, LLC +https://www.erikdarling.com/ + +Upgrade from 2.0.0 to 2.1.0 +Adds collect_query and collect_plan columns to config.collection_schedule +for optional query text and execution plan collection (#337). +Both default to 1 (enabled) to preserve existing behavior. +*/ + +SET ANSI_NULLS ON; +SET ANSI_PADDING ON; +SET ANSI_WARNINGS ON; +SET ARITHABORT ON; +SET CONCAT_NULL_YIELDS_NULL ON; +SET QUOTED_IDENTIFIER ON; +SET NUMERIC_ROUNDABORT OFF; +SET IMPLICIT_TRANSACTIONS OFF; +SET STATISTICS TIME, IO OFF; +GO + +USE PerformanceMonitor; +GO + +/* Add collect_query column for optional query text collection */ +IF NOT EXISTS +( + SELECT + 1/0 + FROM sys.columns + WHERE object_id = OBJECT_ID(N'config.collection_schedule') + AND name = N'collect_query' +) +BEGIN + ALTER TABLE + config.collection_schedule + ADD + collect_query bit NOT NULL + CONSTRAINT DF_collection_schedule_collect_query + DEFAULT CONVERT(bit, 'true'); + + PRINT 'Added collect_query to config.collection_schedule'; +END; +GO + +/* Add collect_plan column for optional execution plan collection */ +IF NOT EXISTS +( + SELECT + 1/0 + FROM sys.columns + WHERE object_id = OBJECT_ID(N'config.collection_schedule') + AND name = N'collect_plan' +) +BEGIN + ALTER TABLE + config.collection_schedule + ADD + collect_plan bit NOT NULL + CONSTRAINT DF_collection_schedule_collect_plan + DEFAULT CONVERT(bit, 'true'); + + PRINT 'Added collect_plan to config.collection_schedule'; +END; +GO diff --git a/upgrades/2.0.0-to-2.1.0/upgrade.txt b/upgrades/2.0.0-to-2.1.0/upgrade.txt new file mode 100644 index 0000000..cffb776 --- /dev/null +++ b/upgrades/2.0.0-to-2.1.0/upgrade.txt @@ -0,0 +1 @@ +01_collection_schedule_optional_text.sql