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
def up
return if column_exists? :milestones, :group_id
change_column_null :milestones, :project_id, true
add_column :milestones, :group_id, :integer

View file

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

View file

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