-- Preserve the repaired schema-14 tables for current installations and restore -- the retained early schema-14 table only when it can be renamed without loss. SET @schema = DATABASE(); SET @sql = ( SELECT IF( EXISTS (SELECT 1 FROM information_schema.table_constraints WHERE constraint_schema=@schema AND table_name='payment_orders' AND constraint_name='fk_payment_order_config_version'), 'ALTER TABLE payment_orders DROP FOREIGN KEY fk_payment_order_config_version', 'SELECT 1' ) ); PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt; SET @sql = ( SELECT IF( EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema=@schema AND table_name='payment_orders' AND column_name='provider_config_version'), 'ALTER TABLE payment_orders DROP COLUMN provider_config_version', 'SELECT 1' ) ); PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt; SET @sql = ( SELECT IF( EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema=@schema AND table_name='payment_channel_configs_legacy_v14') AND EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema=@schema AND table_name='payment_channel_configs'), 'DROP TABLE payment_channel_configs', 'SELECT 1' ) ); PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt; SET @sql = ( SELECT IF( EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema=@schema AND table_name='payment_channel_configs_legacy_v14') AND NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema=@schema AND table_name='payment_channel_configs'), 'RENAME TABLE payment_channel_configs_legacy_v14 TO payment_channel_configs', 'SELECT 1' ) ); PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt; -- Never drop immutable configuration history during this repair rollback.