OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Fix migration using attachments without enum
Oliver Güntherc4995e31217f
diff --git a/db/migrate/20180524084654_remove_non_null_container_on_attachments.rb b/db/migrate/20180524084654_remove_non_null_container_on_attachments.rbindex 3b01dad1b83..63e4498e355 100644--- a/db/migrate/20180524084654_remove_non_null_container_on_attachments.rb+++ b/db/migrate/20180524084654_remove_non_null_container_on_attachments.rb@@ -44,7 +44,11 @@ class RemoveNonNullContainerOnAttachments < ActiveRecord::Migration[5.1]rename_column :attachments, :created_on, :created_atreversible do |change|- change.up { Attachment.update_all("updated_at = created_at") }+ change.up do+ execute <<~SQL.squish+ Update attachments SET updated_at = created_at+ SQL+ endendendenddiff --git a/db/migrate/20200220171133_rename_bim_module.rb b/db/migrate/20200220171133_rename_bim_module.rbindex b0dfea0ae11..1536d7a1b53 100644--- a/db/migrate/20200220171133_rename_bim_module.rb+++ b/db/migrate/20200220171133_rename_bim_module.rb@@ -44,8 +44,8 @@ class RenameBimModule < ActiveRecord::Migration[6.0]end# Rename attachments container- Attachment.where(container_type: 'Bcf::Viewpoint').update_all(container_type: 'Bim::Bcf::Viewpoint')- Attachment.where(container_type: 'IFCModels::IFCModel').update_all(container_type: 'Bim::IfcModels::IfcModel')+ execute "UPDATE attachments SET container_type = 'Bim::Bcf::Viewpoint' WHERE container_type = 'Bcf::Viewpoint'"+ execute "UPDATE attachments SET container_type = 'Bim::IfcModels::IfcModel' WHERE container_type = 'IFCModels::IFCModel'"enddef down@@ -53,7 +53,7 @@ class RenameBimModule < ActiveRecord::Migration[6.0]EnabledModule.where(name: 'bim').update_all(name: 'bcf')# Rename attachments container- Attachment.where(container_type: 'Bim::Bcf::Viewpoint').update_all(container_type: 'Bcf::Viewpoint')- Attachment.where(container_type: 'Bim::IfcModel::IfcModel').update_all(container_type: 'IFCModels::IFCModel')+ execute "UPDATE attachments SET container_type = 'Bcf::Viewpoint' WHERE container_type = 'Bim::Bcf::Viewpoint'"+ execute "UPDATE attachments SET container_type = 'IfcModels::IfcModel' WHERE container_type = 'Bim::IFCModels::IFCModel'"endenddiff --git a/modules/bim/db/migrate/20211011204301_add_column_conversion_status_to_ifc_model.rb b/modules/bim/db/migrate/20211011204301_add_column_conversion_status_to_ifc_model.rbindex a40f2d1a840..ade6b02aa70 100644--- a/modules/bim/db/migrate/20211011204301_add_column_conversion_status_to_ifc_model.rb+++ b/modules/bim/db/migrate/20211011204301_add_column_conversion_status_to_ifc_model.rb@@ -27,13 +27,16 @@#++class AddColumnConversionStatusToIfcModel < ActiveRecord::Migration[6.1]+ class MigrationAttachment < ApplicationRecord+ self.table_name = 'attachments'+ end# Note: rails 7.1 breaks the class' ancestor chain, and raises an error, when a class# with an enum definition without a database field is being referenced.# Re-defining the IfcModel class without the enum to avoid the issue.class IfcModel < ApplicationRecordhas_many :attachments, -> { where(container_type: 'Bim::IfcModels::IfcModel') },foreign_key: :container_id,- class_name: 'Attachment'+ class_name: 'MigrationAttachment'enddef up