Commit 67729cec authored by Lin Jen-Shin's avatar Lin Jen-Shin
Browse files

Add a test which would rollback db and migrate again

Closes #29106
parent 32da7602
...@@ -222,6 +222,13 @@ rake db:migrate:reset: ...@@ -222,6 +222,13 @@ rake db:migrate:reset:
script: script:
- bundle exec rake db:migrate:reset - bundle exec rake db:migrate:reset
rake db:rollback:
stage: test
<<: *use-db
<<: *dedicated-runner
script:
- bundle exec rake db:rollback db:migrate STEP=120
rake db:seed_fu: rake db:seed_fu:
stage: test stage: test
<<: *use-db <<: *use-db
......
...@@ -12,8 +12,8 @@ def up ...@@ -12,8 +12,8 @@ def up
end end
def down def down
remove_foreign_key :labels, column: :group_id
remove_index :labels, :group_id if index_exists? :labels, :group_id remove_index :labels, :group_id if index_exists? :labels, :group_id
remove_foreign_key :labels, :namespaces, column: :group_id
remove_column :labels, :group_id remove_column :labels, :group_id
end end
end end
...@@ -32,8 +32,8 @@ def up ...@@ -32,8 +32,8 @@ def up
end end
def down def down
remove_foreign_key :merge_request_metrics, column: :pipeline_id
remove_index :merge_request_metrics, :pipeline_id if index_exists? :merge_request_metrics, :pipeline_id remove_index :merge_request_metrics, :pipeline_id if index_exists? :merge_request_metrics, :pipeline_id
remove_foreign_key :merge_request_metrics, :ci_commits, column: :pipeline_id
remove_column :merge_request_metrics, :pipeline_id remove_column :merge_request_metrics, :pipeline_id
end end
end end
...@@ -9,6 +9,7 @@ def up ...@@ -9,6 +9,7 @@ def up
end end
def down def down
remove_foreign_key :subscriptions, column: :project_id
remove_column :subscriptions, :project_id remove_column :subscriptions, :project_id
end end
end end
...@@ -12,7 +12,7 @@ def up ...@@ -12,7 +12,7 @@ def up
end end
def down def down
remove_index :environments, [:project_id, :name], unique: true remove_index :environments, [:project_id, :name]
add_concurrent_index :environments, [:project_id, :name] add_concurrent_index :environments, [:project_id, :name], unique: true
end end
end end
...@@ -14,6 +14,6 @@ def up ...@@ -14,6 +14,6 @@ def up
end end
def down def down
remove_index :environments, [:project_id, :slug], unique: true if index_exists? :environments, [:project_id, :slug] remove_index :environments, [:project_id, :slug] if index_exists? :environments, [:project_id, :slug]
end end
end end
...@@ -49,6 +49,16 @@ def down ...@@ -49,6 +49,16 @@ def down
Timelog.where('issue_id IS NOT NULL').update_all("trackable_id = issue_id, trackable_type = 'Issue'") Timelog.where('issue_id IS NOT NULL').update_all("trackable_id = issue_id, trackable_type = 'Issue'")
Timelog.where('merge_request_id IS NOT NULL').update_all("trackable_id = merge_request_id, trackable_type = 'MergeRequest'") Timelog.where('merge_request_id IS NOT NULL').update_all("trackable_id = merge_request_id, trackable_type = 'MergeRequest'")
constraint =
if Gitlab::Database.postgresql?
'CONSTRAINT'
else
'FOREIGN KEY'
end
execute "ALTER TABLE timelogs DROP #{constraint} fk_timelogs_issues_issue_id"
execute "ALTER TABLE timelogs DROP #{constraint} fk_timelogs_merge_requests_merge_request_id"
remove_columns :timelogs, :issue_id, :merge_request_id remove_columns :timelogs, :issue_id, :merge_request_id
end end
end end
...@@ -3,6 +3,6 @@ class DropIndexForBuildsProjectStatus < ActiveRecord::Migration ...@@ -3,6 +3,6 @@ class DropIndexForBuildsProjectStatus < ActiveRecord::Migration
DOWNTIME = false DOWNTIME = false
def change def change
remove_index(:ci_commits, [:gl_project_id, :status]) remove_index(:ci_commits, column: [:gl_project_id, :status])
end end
end end
...@@ -18,6 +18,7 @@ class RemoveTrackableColumnsFromTimelogs < ActiveRecord::Migration ...@@ -18,6 +18,7 @@ class RemoveTrackableColumnsFromTimelogs < ActiveRecord::Migration
# disable_ddl_transaction! # disable_ddl_transaction!
def change def change
remove_columns :timelogs, :trackable_id, :trackable_type remove_column :timelogs, :trackable_id, :integer
remove_column :timelogs, :trackable_type, :string
end end
end end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment