better migrations for unread count field on group accounts table

This commit is contained in:
2458773093 2019-07-22 02:50:01 +03:00
parent 06e1c47ff4
commit 7bd832c9bd
3 changed files with 18 additions and 3 deletions

View File

@ -1,5 +1,10 @@
class AddUnreadCountToGroupAccounts < ActiveRecord::Migration[5.2]
def change
add_column :group_accounts, :unread_count, :integer, default: 0
def up
add_column :group_accounts, :unread_count, :integer
change_column_default :group_accounts, :unread_count, 0
end
def down
remove_column :group_accounts, :unread_count
end
end

View File

@ -0,0 +1,10 @@
class BackfillAddUnreadCountToGroupAccounts < ActiveRecord::Migration[5.2]
disable_ddl_transaction!
def change
GroupAccount.in_batches do |relation|
relation.update_all unread_count: 0
sleep(0.1)
end
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2019_07_21_214831) do
ActiveRecord::Schema.define(version: 2019_07_21_234917) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"