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

Add a test which would rollback db and migrate again

Closes #29106
parent 32da7602
......@@ -222,6 +222,13 @@ rake db:migrate:reset:
script:
- 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:
stage: test
<<: *use-db
......
......@@ -12,8 +12,8 @@ class AddGroupIdToLabels < ActiveRecord::Migration
end
def down
remove_foreign_key :labels, column: :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
end
end
......@@ -32,8 +32,8 @@ class AddPipelineIdToMergeRequestMetrics < ActiveRecord::Migration
end
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_foreign_key :merge_request_metrics, :ci_commits, column: :pipeline_id
remove_column :merge_request_metrics, :pipeline_id
end
end
......@@ -9,6 +9,7 @@ class AddProjectIdToSubscriptions < ActiveRecord::Migration
end
def down
remove_foreign_key :subscriptions, column: :project_id
remove_column :subscriptions, :project_id
end
end
......@@ -12,7 +12,7 @@ class CreateEnvironmentNameUniqueIndex < ActiveRecord::Migration
end
def down
remove_index :environments, [:project_id, :name], unique: true
add_concurrent_index :environments, [:project_id, :name]
remove_index :environments, [:project_id, :name]
add_concurrent_index :environments, [:project_id, :name], unique: true
end
end
......@@ -14,6 +14,6 @@ class AddUniqueIndexForEnvironmentSlug < ActiveRecord::Migration
end
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
......@@ -49,6 +49,16 @@ class AddForeignKeysToTimelogs < ActiveRecord::Migration
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'")
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
end
end
......@@ -3,6 +3,6 @@ class DropIndexForBuildsProjectStatus < ActiveRecord::Migration
DOWNTIME = false
def change
remove_index(:ci_commits, [:gl_project_id, :status])
remove_index(:ci_commits, column: [:gl_project_id, :status])
end
end
......@@ -18,6 +18,7 @@ class RemoveTrackableColumnsFromTimelogs < ActiveRecord::Migration
# disable_ddl_transaction!
def change
remove_columns :timelogs, :trackable_id, :trackable_type
remove_column :timelogs, :trackable_id, :integer
remove_column :timelogs, :trackable_type, :string
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