From 1c71fe615c301320784aa23a32d6c5ebb01cdcfc Mon Sep 17 00:00:00 2001 From: Erik Darling <2136037+erikdarlingdata@users.noreply.github.com> Date: Thu, 26 Mar 2026 18:13:14 -0400 Subject: [PATCH] Widen installation_history version columns to nvarchar(512) (#712) @@VERSION can exceed 255 characters on some SQL Server editions. This caused installation_history inserts to fail, making the installer think it was always a fresh install. - Fresh installs: column defined as nvarchar(512) - Upgrades: ALTER COLUMN in 2.4.0-to-2.5.0 upgrade script - Idempotent: checks current max_length before altering Co-Authored-By: Claude Opus 4.6 (1M context) --- install/01_install_database.sql | 4 +-- .../01_widen_version_columns.sql | 36 +++++++++++++++++++ upgrades/2.4.0-to-2.5.0/upgrade.txt | 1 + 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 upgrades/2.4.0-to-2.5.0/01_widen_version_columns.sql create mode 100644 upgrades/2.4.0-to-2.5.0/upgrade.txt diff --git a/install/01_install_database.sql b/install/01_install_database.sql index 32e845a..0559e3a 100644 --- a/install/01_install_database.sql +++ b/install/01_install_database.sql @@ -746,8 +746,8 @@ BEGIN installation_date datetime2(7) NOT NULL DEFAULT SYSDATETIME(), installer_version nvarchar(50) NOT NULL, installer_info_version nvarchar(100) NULL, - sql_server_version nvarchar(255) NOT NULL, - sql_server_edition nvarchar(255) NOT NULL, + sql_server_version nvarchar(512) NOT NULL, + sql_server_edition nvarchar(512) NOT NULL, installation_type nvarchar(20) NOT NULL, /*INSTALL, UPGRADE, REINSTALL*/ previous_version nvarchar(50) NULL, installation_status nvarchar(20) NOT NULL, /*SUCCESS, FAILED, PARTIAL*/ diff --git a/upgrades/2.4.0-to-2.5.0/01_widen_version_columns.sql b/upgrades/2.4.0-to-2.5.0/01_widen_version_columns.sql new file mode 100644 index 0000000..dcb1afb --- /dev/null +++ b/upgrades/2.4.0-to-2.5.0/01_widen_version_columns.sql @@ -0,0 +1,36 @@ +/* +Widen sql_server_version and sql_server_edition columns in config.installation_history +Some @@VERSION strings exceed 255 characters (#712) +*/ + +IF EXISTS +( + SELECT + 1/0 + FROM sys.columns AS c + WHERE c.object_id = OBJECT_ID(N'config.installation_history') + AND c.name = N'sql_server_version' + AND c.max_length = 510 /* nvarchar(255) = 510 bytes */ +) +BEGIN + ALTER TABLE config.installation_history + ALTER COLUMN sql_server_version nvarchar(512) NOT NULL; + + PRINT 'Widened config.installation_history.sql_server_version to nvarchar(512)'; +END; + +IF EXISTS +( + SELECT + 1/0 + FROM sys.columns AS c + WHERE c.object_id = OBJECT_ID(N'config.installation_history') + AND c.name = N'sql_server_edition' + AND c.max_length = 510 +) +BEGIN + ALTER TABLE config.installation_history + ALTER COLUMN sql_server_edition nvarchar(512) NOT NULL; + + PRINT 'Widened config.installation_history.sql_server_edition to nvarchar(512)'; +END; diff --git a/upgrades/2.4.0-to-2.5.0/upgrade.txt b/upgrades/2.4.0-to-2.5.0/upgrade.txt new file mode 100644 index 0000000..6614123 --- /dev/null +++ b/upgrades/2.4.0-to-2.5.0/upgrade.txt @@ -0,0 +1 @@ +01_widen_version_columns.sql