diff --git a/db/migrate/20240131081040_rename_hal_publications.rb b/db/migrate/20240131081040_rename_hal_publications.rb index 93e5f2fb3a21eab2b8272a533195c1f41b30617c..2ef098867e8b131bd11ff4ac4e53113b3745890f 100644 --- a/db/migrate/20240131081040_rename_hal_publications.rb +++ b/db/migrate/20240131081040_rename_hal_publications.rb @@ -5,9 +5,17 @@ class RenameHalPublications < ActiveRecord::Migration[7.1] rename_table :research_hal_publications_university_people, :research_publications_university_people rename_column :research_publications_university_people, :research_hal_publication_id, :research_publication_id - # Vieil index problématique - # https://stackoverflow.com/questions/32395126/rename-table-relation-table-pkey-does-not-exist - execute "ALTER INDEX research_documents_pkey RENAME TO research_hal_publications_pkey;" + reversible do |dir| + # Vieil index problématique + # Pas évident à intégrer dans une migration : + # 1. la première fois qu'on migre on répare l'index + # 2. mais on ne peut pas reverse la migration, d'où l'usage de reversible + # 3. et quand on remet après revert, il ne veut plus passer parce que l'index à réparer est déjà réparé + # 4. en ajoutant IF EXISTS, on peut le repasser + # Bingo ! + # https://stackoverflow.com/questions/32395126/rename-table-relation-table-pkey-does-not-exist + dir.up { execute "ALTER INDEX IF EXISTS research_documents_pkey RENAME TO research_hal_publications_pkey" } + end rename_table :research_hal_publications, :research_publications rename_column :research_publications, :docid, :hal_docid add_column :research_publications, :source, :integer, default: 0