mirror of
https://github.com/discourse/discourse.git
synced 2025-09-08 12:06:51 +08:00
FIX: DROP NOT NULL instead of changing all the rows in the table.
``` change_column :topic_views, :ip_address, :inet, null: true ``` translates to ``` "ALTER TABLE \"topic_views\" ALTER COLUMN \"ip_address\" TYPE inet" ``` which locks the whole table while the migration is taking place.
This commit is contained in:
parent
818bc10107
commit
a6e9f4f44b
2 changed files with 10 additions and 7 deletions
|
@ -1,12 +1,5 @@
|
||||||
class ChangeIndexesTopicViewItem < ActiveRecord::Migration[5.1]
|
class ChangeIndexesTopicViewItem < ActiveRecord::Migration[5.1]
|
||||||
def up
|
def up
|
||||||
begin
|
|
||||||
Migration::SafeMigrate.disable!
|
|
||||||
change_column :topic_views, :ip_address, :inet, null: true
|
|
||||||
ensure
|
|
||||||
Migration::SafeMigrate.enable!
|
|
||||||
end
|
|
||||||
|
|
||||||
remove_index :topic_views,
|
remove_index :topic_views,
|
||||||
column: [:ip_address, :topic_id],
|
column: [:ip_address, :topic_id],
|
||||||
name: :ip_address_topic_id_topic_views,
|
name: :ip_address_topic_id_topic_views,
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
class DropNotNullIpAddressOnTopicViews < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
begin
|
||||||
|
Migration::SafeMigrate.disable!
|
||||||
|
change_column_null :topic_views, :ip_address, true
|
||||||
|
ensure
|
||||||
|
Migration::SafeMigrate.enable!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue