From abd5014eb0a3a4a6ed8efa7c3569019a6a382612 Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 22 Feb 2026 03:35:56 +0100 Subject: [PATCH] Release v2.2.3: migration 138 integer compatibility hotfix --- RELEASE_NOTES_v2.2.3.md | 15 ++++++++ VERSION | 2 +- ...8_customers_economic_unique_constraint.sql | 34 ++++++++++++++----- 3 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 RELEASE_NOTES_v2.2.3.md diff --git a/RELEASE_NOTES_v2.2.3.md b/RELEASE_NOTES_v2.2.3.md new file mode 100644 index 0000000..4323464 --- /dev/null +++ b/RELEASE_NOTES_v2.2.3.md @@ -0,0 +1,15 @@ +# BMC Hub v2.2.3 - Migration Hotfix + +**Release Date:** 22. februar 2026 + +## 🛠️ Hotfix + +### Migration 138 compatibility fix +- Fixed `migrations/138_customers_economic_unique_constraint.sql` for environments where `customers.economic_customer_number` is numeric (`integer`). +- Removed unconditional `btrim(...)` usage on non-text columns. +- Added type-aware normalization logic that only applies trimming for text-like column types. + +## ✅ Impact + +- Migration `138_customers_economic_unique_constraint.sql` now runs on both numeric and text column variants without `function btrim(integer) does not exist` errors. +- Unique index safety behavior and duplicate detection are unchanged. diff --git a/VERSION b/VERSION index b1b25a5..5859406 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.2.2 +2.2.3 diff --git a/migrations/138_customers_economic_unique_constraint.sql b/migrations/138_customers_economic_unique_constraint.sql index 71642c3..b3785b3 100644 --- a/migrations/138_customers_economic_unique_constraint.sql +++ b/migrations/138_customers_economic_unique_constraint.sql @@ -1,15 +1,33 @@ -- Migration: Enforce unique economic customer number on customers -- Prevents ambiguous mapping during e-conomic sync --- Normalize values before uniqueness check -UPDATE customers -SET economic_customer_number = NULL -WHERE economic_customer_number IS NOT NULL - AND btrim(economic_customer_number) = ''; +-- Normalize values before uniqueness check (only for text-like columns) +DO $$ +DECLARE + column_data_type TEXT; +BEGIN + SELECT data_type + INTO column_data_type + FROM information_schema.columns + WHERE table_schema = 'public' + AND table_name = 'customers' + AND column_name = 'economic_customer_number'; -UPDATE customers -SET economic_customer_number = btrim(economic_customer_number) -WHERE economic_customer_number IS NOT NULL; + IF column_data_type IN ('character varying', 'character', 'text') THEN + EXECUTE $$ + UPDATE customers + SET economic_customer_number = NULL + WHERE economic_customer_number IS NOT NULL + AND btrim(economic_customer_number) = '' + $$; + + EXECUTE $$ + UPDATE customers + SET economic_customer_number = btrim(economic_customer_number) + WHERE economic_customer_number IS NOT NULL + $$; + END IF; +END $$; -- Abort migration if duplicates exist (must be manually resolved first) DO $$