mirror of
https://github.com/discourse/discourse.git
synced 2025-05-29 21:27:58 +08:00
Merge pull request #8736 from gschlager/rename_reply_id_column
REFACTOR: Rename `post_replies.reply_id` column to `post_replies.reply_post_id`
This commit is contained in:
18
db/migrate/20200116140132_rename_reply_id_column.rb
Normal file
18
db/migrate/20200116140132_rename_reply_id_column.rb
Normal file
@ -0,0 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class RenameReplyIdColumn < ActiveRecord::Migration[6.0]
|
||||
def up
|
||||
Migration::ColumnDropper.mark_readonly(:post_replies, :reply_id)
|
||||
|
||||
add_column :post_replies, :reply_post_id, :integer
|
||||
|
||||
execute <<~SQL
|
||||
UPDATE post_replies
|
||||
SET reply_post_id = reply_id
|
||||
SQL
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
29
db/migrate/20200117141138_update_post_reply_indexes.rb
Normal file
29
db/migrate/20200117141138_update_post_reply_indexes.rb
Normal file
@ -0,0 +1,29 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class UpdatePostReplyIndexes < ActiveRecord::Migration[6.0]
|
||||
# Adding and removing indexes concurrently doesn't work within transaction.
|
||||
# It also needs existence checks for indexes in case the migration fails and needs to run again.
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
if !index_exists?(:post_replies, [:post_id, :reply_post_id])
|
||||
add_index :post_replies, [:post_id, :reply_post_id], unique: true, algorithm: :concurrently
|
||||
end
|
||||
|
||||
if !index_exists?(:post_replies, [:reply_post_id])
|
||||
add_index :post_replies, [:reply_post_id], algorithm: :concurrently
|
||||
end
|
||||
|
||||
if index_exists?(:post_replies, [:post_id, :reply_id])
|
||||
remove_index :post_replies, column: [:post_id, :reply_id], algorithm: :concurrently
|
||||
end
|
||||
|
||||
if index_exists?(:post_replies, [:reply_id])
|
||||
remove_index :post_replies, column: [:reply_id], algorithm: :concurrently
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user