diff --git a/database/migrations/V023__refactor_chargeable_char_config_to_product_type.sql b/database/migrations/V023__refactor_chargeable_char_config_to_product_type.sql index 5724118..acef49f 100644 --- a/database/migrations/V023__refactor_chargeable_char_config_to_product_type.sql +++ b/database/migrations/V023__refactor_chargeable_char_config_to_product_type.sql @@ -38,9 +38,17 @@ IF EXISTS (SELECT 1 FROM sys.tables WHERE name = 'ChargeableCharConfig' AND sche BEGIN PRINT 'V023: MedioId column found — proceeding with refactor.'; - -- ─── 1. Turn OFF SYSTEM_VERSIONING ───────────────────────────────── - ALTER TABLE dbo.ChargeableCharConfig SET (SYSTEM_VERSIONING = OFF); - PRINT 'V023: SYSTEM_VERSIONING = OFF.'; + -- ─── 1. Turn OFF SYSTEM_VERSIONING (idempotent — skip if already OFF) ─── + IF EXISTS (SELECT 1 FROM sys.tables + WHERE name = 'ChargeableCharConfig' + AND schema_id = SCHEMA_ID('dbo') + AND temporal_type = 2) -- 2 = SYSTEM_VERSIONED_TEMPORAL_TABLE + BEGIN + ALTER TABLE dbo.ChargeableCharConfig SET (SYSTEM_VERSIONING = OFF); + PRINT 'V023: SYSTEM_VERSIONING = OFF.'; + END + ELSE + PRINT 'V023: SYSTEM_VERSIONING already OFF — skipping.'; -- ─── 2. Drop indexes that reference MedioId ──────────────────────── IF EXISTS (SELECT 1 FROM sys.indexes WHERE name = 'UX_ChargeableCharConfig_Vigente'