https://blog.bitwrangler.com/2016/11/30/performant-postgres-migrations.html
slow
class AddInfoColumnToCaseDocketReport < ActiveRecord::Migration
def change
add_column :case_docket_reports, :info, '{}'
end
end
faster
Add columns without default values
class AddInfoColumnToCaseDocketReport < ActiveRecord::Migration
def change
add_column :case_docket_reports, :info, :jsonb
change_column_default :case_docket_reports, :info, '{}'
end
end
并行往postgres添加index的问题解决,快且不阻塞
class AddIndexToAsksActive < ActiveRecord::Migration
disable_ddl_transaction!
def change
add_index :asks, :active, algorithm: :concurrently
end
end
网友评论