Commit 9226ce9e authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'test-db-rollback' into 'master'

Add a test which would rollback db and migrate again

Closes #29106

See merge request !9908
parents 5694d9e5 83e36064
...@@ -224,6 +224,14 @@ rake db:migrate:reset: ...@@ -224,6 +224,14 @@ 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 STEP=120
- bundle exec rake db:migrate
rake db:seed_fu: rake db:seed_fu:
stage: test stage: test
<<: *use-db <<: *use-db
......
...@@ -12,8 +12,8 @@ class AddGroupIdToLabels < ActiveRecord::Migration ...@@ -12,8 +12,8 @@ class AddGroupIdToLabels < ActiveRecord::Migration
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 @@ class AddPipelineIdToMergeRequestMetrics < ActiveRecord::Migration ...@@ -32,8 +32,8 @@ class AddPipelineIdToMergeRequestMetrics < ActiveRecord::Migration
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 @@ class AddProjectIdToSubscriptions < ActiveRecord::Migration ...@@ -9,6 +9,7 @@ class AddProjectIdToSubscriptions < ActiveRecord::Migration
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
...@@ -16,8 +16,9 @@ class MigrateProjectStatistics < ActiveRecord::Migration ...@@ -16,8 +16,9 @@ class MigrateProjectStatistics < ActiveRecord::Migration
remove_column :projects, :commit_count remove_column :projects, :commit_count
end end
# rubocop: disable Migration/AddColumn
def down def down
add_column_with_default :projects, :repository_size, :float, default: 0.0 add_column :projects, :repository_size, :float, default: 0.0
add_column_with_default :projects, :commit_count, :integer, default: 0 add_column :projects, :commit_count, :integer, default: 0
end end
end end
...@@ -12,7 +12,7 @@ class CreateEnvironmentNameUniqueIndex < ActiveRecord::Migration ...@@ -12,7 +12,7 @@ class CreateEnvironmentNameUniqueIndex < ActiveRecord::Migration
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 @@ class AddUniqueIndexForEnvironmentSlug < ActiveRecord::Migration ...@@ -14,6 +14,6 @@ class AddUniqueIndexForEnvironmentSlug < ActiveRecord::Migration
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
...@@ -17,6 +17,6 @@ class AddLowerPathIndexToRoutes < ActiveRecord::Migration ...@@ -17,6 +17,6 @@ class AddLowerPathIndexToRoutes < ActiveRecord::Migration
def down def down
return unless Gitlab::Database.postgresql? return unless Gitlab::Database.postgresql?
remove_index :routes, name: :index_on_routes_lower_path remove_index :routes, name: :index_on_routes_lower_path if index_exists?(:routes, name: :index_on_routes_lower_path)
end end
end end
...@@ -49,6 +49,9 @@ class AddForeignKeysToTimelogs < ActiveRecord::Migration ...@@ -49,6 +49,9 @@ class AddForeignKeysToTimelogs < ActiveRecord::Migration
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'")
remove_foreign_key :timelogs, name: 'fk_timelogs_issues_issue_id'
remove_foreign_key :timelogs, name: '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
...@@ -8,4 +8,9 @@ class AddIndexToProjectAuthorizations < ActiveRecord::Migration ...@@ -8,4 +8,9 @@ class AddIndexToProjectAuthorizations < ActiveRecord::Migration
def up def up
add_concurrent_index(:project_authorizations, :project_id) add_concurrent_index(:project_authorizations, :project_id)
end end
def down
remove_index(:project_authorizations, :project_id) if
Gitlab::Database.postgresql?
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