Make wrong migrations idempotent

This commit is contained in:
Felipe Artur 2017-07-07 15:01:30 -03:00
parent 4e07305b27
commit b24ef9ce2a
3 changed files with 11 additions and 3 deletions

View file

@ -2,6 +2,8 @@ class AddGroupIdToMilestones < ActiveRecord::Migration
DOWNTIME = false DOWNTIME = false
def up def up
return if column_exists? :milestones, :group_id
change_column_null :milestones, :project_id, true change_column_null :milestones, :project_id, true
add_column :milestones, :group_id, :integer add_column :milestones, :group_id, :integer

View file

@ -6,6 +6,8 @@ class AddGroupMilestoneIdIndexes < ActiveRecord::Migration
DOWNTIME = false DOWNTIME = false
def up def up
return if index_exists?(:milestones, :group_id)
add_concurrent_foreign_key :milestones, :namespaces, column: :group_id, on_delete: :cascade add_concurrent_foreign_key :milestones, :namespaces, column: :group_id, on_delete: :cascade
add_concurrent_index :milestones, :group_id add_concurrent_index :milestones, :group_id

View file

@ -1,6 +1,10 @@
class RemoveWrongVersionsFromSchemaVersions < ActiveRecord::Migration class RemoveWrongVersionsFromSchemaVersions < ActiveRecord::Migration
def change DOWNTIME = false
execute "UPDATE schema_migrations SET version = '20170707183807' WHERE version = '20170723183807'"
execute "UPDATE schema_migrations SET version = '20170707184243' WHERE version = '20170724184243'" def up
execute("DELETE FROM schema_migrations WHERE version IN ('20170723183807', '20170724184243')")
end
def down
end end
end end