Fixes #10721 This PR addresses an issue where the data migration in the CE edition was failing due to missing models. The change ensures that the migration process runs only when the deployment is using the EE image.
36 lines
1.3 KiB
Ruby
36 lines
1.3 KiB
Ruby
class ConvertDocumentToPolymorphicAssociation < ActiveRecord::Migration[7.0]
|
|
def up
|
|
add_column :captain_assistant_responses, :documentable_type, :string
|
|
|
|
# rubocop:disable Rails/SkipsModelValidations
|
|
if ChatwootApp.enterprise?
|
|
Captain::AssistantResponse
|
|
.where
|
|
.not(document_id: nil)
|
|
.update_all(documentable_type: 'Captain::Document')
|
|
end
|
|
# rubocop:enable Rails/SkipsModelValidations
|
|
remove_index :captain_assistant_responses, :document_id if index_exists?(
|
|
:captain_assistant_responses, :document_id
|
|
)
|
|
|
|
rename_column :captain_assistant_responses, :document_id, :documentable_id
|
|
add_index :captain_assistant_responses, [:documentable_id, :documentable_type],
|
|
name: 'idx_cap_asst_resp_on_documentable'
|
|
end
|
|
|
|
def down
|
|
if index_exists?(
|
|
:captain_assistant_responses, [:documentable_id, :documentable_type], name: 'idx_cap_asst_resp_on_documentable'
|
|
)
|
|
remove_index :captain_assistant_responses, name: 'idx_cap_asst_resp_on_documentable'
|
|
end
|
|
|
|
rename_column :captain_assistant_responses, :documentable_id, :document_id
|
|
remove_column :captain_assistant_responses, :documentable_type
|
|
add_index :captain_assistant_responses, :document_id unless index_exists?(
|
|
:captain_assistant_responses, :document_id
|
|
)
|
|
end
|
|
end
|