From 946ee9e47c4bed803e2f1cb24dfedaabf35975e5 Mon Sep 17 00:00:00 2001 From: tim-s-ccs Date: Tue, 9 Jul 2024 09:52:23 +0100 Subject: [PATCH] Update migration to avoid issue we have had on higher environments --- CHANGELOG.md | 4 ++++ ...031103327_rename_tables_with_long_names.rb | 21 +++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cb5332909..09960b8ecb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - FMFR-1399 - Use ccs frontend for the shared assets ([PR 4383](https://github.com/Crown-Commercial-Service/crown-marketplace/pull/4383)) - FMFR-1398 - Use propshaft to build assets ([PR 4363](https://github.com/Crown-Commercial-Service/crown-marketplace/pull/4363)) +### Fixed + +- Fix issue where higher environments would try to run old migration but could not ([PR 4452](https://github.com/Crown-Commercial-Service/crown-marketplace/pull/4452)) + ### Security - Various dependency updates diff --git a/db/migrate/20231031103327_rename_tables_with_long_names.rb b/db/migrate/20231031103327_rename_tables_with_long_names.rb index cf0df20705..ef30fcceff 100644 --- a/db/migrate/20231031103327_rename_tables_with_long_names.rb +++ b/db/migrate/20231031103327_rename_tables_with_long_names.rb @@ -1,7 +1,20 @@ class RenameTablesWithLongNames < ActiveRecord::Migration[7.1] - def change - rename_table :facilities_management_rm3830_procurement_building_service_lifts, :facilities_management_procurement_building_service_lifts - rename_table :facilities_management_rm3830_procurement_call_off_extensions, :facilities_management_rm3830_procurement_extensions - rename_table :facilities_management_rm6232_procurement_call_off_extensions, :facilities_management_rm6232_procurement_extensions + # We need to add this because we've had some issues on higher environments where it can't rename tables because of a primary key index name issue + # def change + # rename_table :facilities_management_rm3830_procurement_building_service_lifts, :facilities_management_procurement_building_service_lifts + # rename_table :facilities_management_rm3830_procurement_call_off_extensions, :facilities_management_rm3830_procurement_extensions + # rename_table :facilities_management_rm6232_procurement_call_off_extensions, :facilities_management_rm6232_procurement_extensions + # end + + def up + ActiveRecord::Base.connection.exec_query('ALTER TABLE facilities_management_rm3830_procurement_building_service_lifts RENAME TO facilities_management_procurement_building_service_lifts;') + ActiveRecord::Base.connection.exec_query('ALTER TABLE facilities_management_rm3830_procurement_call_off_extensions RENAME TO facilities_management_rm3830_procurement_extensions;') + ActiveRecord::Base.connection.exec_query('ALTER TABLE facilities_management_rm6232_procurement_call_off_extensions RENAME TO facilities_management_rm6232_procurement_extensions;') + end + + def down + ActiveRecord::Base.connection.exec_query('ALTER TABLE facilities_management_procurement_building_service_lifts RENAME TO facilities_management_rm3830_procurement_building_service_lifts;') + ActiveRecord::Base.connection.exec_query('ALTER TABLE facilities_management_rm3830_procurement_extensions RENAME TO facilities_management_rm3830_procurement_call_off_extensions;') + ActiveRecord::Base.connection.exec_query('ALTER TABLE facilities_management_rm6232_procurement_extensions RENAME TO facilities_management_rm6232_procurement_call_off_extensions;') end end