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 wiki_contents with missing user as author
Markus Kahl1a640c2417cb
diff --git a/db/migrate/20230322135932_merge_wiki_content_into_page.rb b/db/migrate/20230322135932_merge_wiki_content_into_page.rbindex 846b58159c6..ab583be17f0 100644--- a/db/migrate/20230322135932_merge_wiki_content_into_page.rb+++ b/db/migrate/20230322135932_merge_wiki_content_into_page.rb@@ -27,11 +27,14 @@#++class MergeWikiContentIntoPage < ActiveRecord::Migration[7.0]+ include ::Migration::Utils+def changeadd_contents_columns_to_pagesreversible do |dir|dir.up do+ change_null_values_on_contentsupdate_wiki_pages_from_contentsupdate_journals_to_pagesend@@ -76,13 +79,29 @@ class MergeWikiContentIntoPage < ActiveRecord::Migration[7.0]endend+ def change_null_values_on_contents+ execute_sql(+ "+ UPDATE wiki_contents SET author_id = :deleted_user_id+ WHERE author_id NOT IN (SELECT id from users)+ ",+ deleted_user_id:+ )+ end+def change_null_values_on_pageschange_column_null :wiki_pages, :lock_version, false- WikiPage.where(author_id: nil).update_all(author_id: DeletedUser.first.id)+ execute_sql("UPDATE wiki_pages SET author_id = :deleted_user_id WHERE author_id IS NULL", deleted_user_id:)+change_column_null :wiki_pages, :author_id, falseend+ def deleted_user_id+ # We use the model to make sure one is created in case it doesn't exist yet+ @deleted_user_id ||= DeletedUser.first.id+ end+def rename_and_adapt_journal_datarename_table :wiki_content_journals, :wiki_page_journalsremove_column :wiki_page_journals, :page_id, :bigintdiff --git a/db/migrate/migration_utils/utils.rb b/db/migrate/migration_utils/utils.rbindex 8a175764835..4a667f5bd00 100644--- a/db/migrate/migration_utils/utils.rb+++ b/db/migrate/migration_utils/utils.rb@@ -47,5 +47,24 @@ module Migrationremove_index table_name, name: index_nameendend++ ##+ # Executes the given SQL query while passing in sanitized parameters.+ #+ # @param query [String] SQL query including parameter references like `:param`+ # @param params [Hash] Hash containing values for referenced parameters+ #+ # @raise [ActiveRecord::ActiveRecordError] If the query fails+ # @return [PG::Result]+ #+ # Example:+ #+ # execute_sql "select id from users where mail = :email", email: params[:email]+ #+ def execute_sql(query, params = {})+ query = ActiveRecord::Base.sanitize_sql [query, params]++ ActiveRecord::Base.connection.execute query+ endendend