Merge pull request #7158 from opf/fix/boards-migration

Manually copy table from boards to forums to avoid index errors

[ci skip]
pull/7166/head
Oliver Günther 6 years ago committed by GitHub
commit c6ad680368
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      db/migrate/20190312083304_rename_boards_to_forums.rb
  2. 4
      db/migrate/tables/boards.rb
  3. 35
      db/migrate/tables/forums.rb

@ -1,9 +1,12 @@
require_relative './migration_utils/utils'
require_relative './tables/forums'
class RenameBoardsToForums < ActiveRecord::Migration[5.2]
def up
# Rename manually to ensure indexes need not be dropped
execute "ALTER TABLE boards RENAME TO forums;"
# Create the new table, then copy from the oldt table to ensure indexes are correct
::Tables::Forums.create(self)
execute "INSERT INTO forums SELECT * FROM boards";
rename_column :messages, :board_id, :forum_id
rename_column :message_journals, :board_id, :forum_id
@ -12,12 +15,13 @@ class RenameBoardsToForums < ActiveRecord::Migration[5.2]
EnabledModule.where(name: 'boards').update_all(name: 'forums')
RolePermission.where(permission: 'manage_boards').update_all(permission: 'manage_forums')
Watcher.where(watchable_type: 'Board').update_all(watchable_type: 'Forum')
end
# Finally, drop the old table
drop_table :boards
end
def down
# Rename manually to ensure indexes need not be dropped
execute "ALTER TABLE forums RENAME TO boards;"
rename_table :forums, :boards
rename_column :messages, :forum_id, :board_id
rename_column :message_journals, :forum_id, :board_id

@ -41,8 +41,8 @@ class Tables::Boards < Tables::Base
t.integer :messages_count, default: 0, null: false
t.integer :last_message_id
t.index :last_message_id, name: 'index_boards_on_last_message_id'
t.index :project_id, name: 'boards_project_id'
t.index :last_message_id, name: "index_#{table_name}_on_last_message_id"
t.index :project_id, name: "#{table_name}_project_id"
end
end
end

@ -0,0 +1,35 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See docs/COPYRIGHT.rdoc for more details.
#++
require_relative 'base'
require_relative 'boards'
class Tables::Forums < Tables::Boards
end
Loading…
Cancel
Save