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
Define custom migration classes for Project and Bim::IfcModels::IfcModel to avoid non existing enum type declaration errors.
Dombi Attila38b660aaa515
diff --git a/app/models/project.rb b/app/models/project.rbindex f6abac80621..111f9822832 100644--- a/app/models/project.rb+++ b/app/models/project.rb@@ -149,7 +149,6 @@ class Project < ApplicationRecordfriendly_id :identifier, use: :finders- include ::Scopes::Scopedscopes :allowed_to,:visiblediff --git a/db/migrate/20200220171133_rename_bim_module.rb b/db/migrate/20200220171133_rename_bim_module.rbindex 7451a9f6111..b0dfea0ae11 100644--- a/db/migrate/20200220171133_rename_bim_module.rb+++ b/db/migrate/20200220171133_rename_bim_module.rb@@ -27,6 +27,11 @@#++class RenameBimModule < ActiveRecord::Migration[6.0]+ # Note: rails 7.1 breaks the class' ancestor chain, when a class with an enum definition+ # without a database field is being referenced.+ # Re-defining the Project class without the enum to avoid the issue.+ class Project < ApplicationRecord; end+def upprojects_with_bcf = EnabledModule.where(name: 'bcf').pluck(:project_id)# Delete all bcf to avoid duplicatesdiff --git a/db/migrate/20210510193438_remove_project_setting.rb b/db/migrate/20210510193438_remove_project_setting.rbindex 6505e6bf664..99c4bb7c2d7 100644--- a/db/migrate/20210510193438_remove_project_setting.rb+++ b/db/migrate/20210510193438_remove_project_setting.rb@@ -27,6 +27,11 @@#++class RemoveProjectSetting < ActiveRecord::Migration[6.1]+ # 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 Project class without the enum to avoid the issue.+ class Project < ApplicationRecord; end+def upProject.where(name: 'sequential_project_identifiers').delete_allenddiff --git a/db/migrate/20220831073113_work_package_project_foreign_key.rb b/db/migrate/20220831073113_work_package_project_foreign_key.rbindex 3af792e12cd..4d7a16aea3a 100644--- a/db/migrate/20220831073113_work_package_project_foreign_key.rb+++ b/db/migrate/20220831073113_work_package_project_foreign_key.rb@@ -27,6 +27,11 @@#++class WorkPackageProjectForeignKey < ActiveRecord::Migration[7.0]+ # 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 Project class without the enum to avoid the issue.+ class Project < ApplicationRecord; end+def changereversible do |dir|dir.up dodiff --git a/modules/bim/app/models/bim/ifc_models/ifc_model.rb b/modules/bim/app/models/bim/ifc_models/ifc_model.rbindex 6669205c231..5c9b01f5f9f 100644--- a/modules/bim/app/models/bim/ifc_models/ifc_model.rb+++ b/modules/bim/app/models/bim/ifc_models/ifc_model.rb@@ -1,6 +1,13 @@module Bimmodule IfcModelsclass IfcModel < ApplicationRecord+ # Note: rails 7.1 breaks the class' ancestor chain, if it fails to infer the enum attribute's+ # type. We reference the Project class in migrations prior to the `conversion_status` column being added+ # to the database, which leads to rails failing to infer the enum's type.+ # The `conversion_status`'s type needs to be declared so rails will do the correct type inference and+ # not break the ancestor chain. Once this is fixed in rails, we can remove it.+ attribute :conversion_status, :integer+enum conversion_status: {pending: 0,processing: 1,diff --git a/modules/bim/db/migrate/20210521080035_update_xkt_to_version8.rb b/modules/bim/db/migrate/20210521080035_update_xkt_to_version8.rbindex 3ea28a0500e..7ce80e4a7bb 100644--- a/modules/bim/db/migrate/20210521080035_update_xkt_to_version8.rb+++ b/modules/bim/db/migrate/20210521080035_update_xkt_to_version8.rb@@ -31,11 +31,20 @@ class UpdateXktToVersion8 < ActiveRecord::Migration[6.1]'Hospital - Structural (cc-by-sa-3.0 Autodesk Inc.)' => 'hospital_structural','Hospital - Mechanical (cc-by-sa-3.0 Autodesk Inc.)' => 'hospital_mechanical' }.freeze+ # 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 Project class without the enum to avoid the issue.+ class IfcModel < ApplicationRecord+ has_many :attachments, -> { where(container_type: 'Bim::IfcModels::IfcModel') },+ foreign_key: :container_id,+ class_name: 'Attachment'+ end+def up# Queue every IFC model for a new transformation.Rails.logger.info "Migrate all IFC models to the latest XKT version"- if Bim::IfcModels::IfcModel.count.zero?+ if IfcModel.count.zero?Rails.logger.info("No IFC models to migrate")returnend@@ -59,7 +68,7 @@ class UpdateXktToVersion8 < ActiveRecord::Migration[6.1]privatedef migrate_all_ifc_models- ::Bim::IfcModels::IfcModel.find_each do |ifc_model|+ IfcModel.find_each do |ifc_model|cleanup_metadata_attachment(ifc_model)# We have seeded models that do not have an IFC attachment. They cannot get converted as an IFC file is# necessary.diff --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 c5dc2887a97..788b0edd5d0 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,15 +27,24 @@#++class AddColumnConversionStatusToIfcModel < ActiveRecord::Migration[6.1]+ # 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 Project class without the enum to avoid the issue.+ class IfcModel < ApplicationRecord+ has_many :attachments, -> { where(container_type: 'Bim::IfcModels::IfcModel') },+ foreign_key: :container_id,+ class_name: 'Attachment'+ end+def upadd_column(:ifc_models, :conversion_status, :integer, default: 0) # default "pending"add_column(:ifc_models, :conversion_error_message, :text)- converted_models = ::Bim::IfcModels::IfcModel+ converted_models = IfcModel.joins(:attachments).where("attachments.description = 'xkt'")- not_converted_models = ::Bim::IfcModels::IfcModel+ not_converted_models = IfcModel.where.not(id: converted_models)