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 orphaned tokens migration for some MySQL imported schemas
Markus Kahldb7f2a7c4809
diff --git a/db/migrate/20221017073431_remove_orphaned_tokens.rb b/db/migrate/20221017073431_remove_orphaned_tokens.rbindex 61c804451ae..71c37cc42d6 100644--- a/db/migrate/20221017073431_remove_orphaned_tokens.rb+++ b/db/migrate/20221017073431_remove_orphaned_tokens.rb@@ -1,10 +1,30 @@class RemoveOrphanedTokens < ActiveRecord::Migration[7.0]def upToken::Base.where.not(user_id: User.select(:id)).delete_all++ # Make sure we have bigint columns on both sides so the foreign key can be added.+ # It could be that they are of type numeric if the data was migrated from MySQL once.+ make_bigint! :users, :id+ make_bigint! :tokens, :user_id+add_foreign_key :tokens, :usersenddef down# Nothing to doend++ def make_bigint!(table, field)+ return if bigint? table, field++ change_column table, field, :bigint+ end++ def bigint?(table, field)+ get_column_type(table, field).to_s == "bigint"+ end++ def get_column_type(table, field)+ ActiveRecord::Base.connection.columns(table.to_s).find { |col| col.name == field.to_s }&.sql_type+ endend