diff options
author | Rémy Coutable <remy@rymai.me> | 2017-03-17 17:24:33 +0100 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-04-11 11:38:30 +0200 |
commit | 1637de85f7edd185d4035d91e0e72e621f9cbeae (patch) | |
tree | c0468f6237243eb608613573b072c7b4d12f2a8f | |
parent | b071bf979af5acdc5248f0f7a53e13697331910e (diff) | |
download | gitlab-ce-29656-fix-rollback-job.tar.gz |
Make many migrations rollbackable29656-fix-rollback-job
Don't try to create the index if it already exist. It's possible that a
previous rollback did not remove the index since the index is not
dropped on MySQL because MySQL would also drop the foreign key in that
case, see f67d8eb1da.
Signed-off-by: Rémy Coutable <remy@rymai.me>
41 files changed, 292 insertions, 71 deletions
diff --git a/db/migrate/20140914113604_add_members_table.rb b/db/migrate/20140914113604_add_members_table.rb index 0f76bb0ef79..e03c5b0af39 100644 --- a/db/migrate/20140914113604_add_members_table.rb +++ b/db/migrate/20140914113604_add_members_table.rb @@ -2,7 +2,7 @@ class AddMembersTable < ActiveRecord::Migration DOWNTIME = false - def change + def up create_table :members do |t| t.integer :access_level, null: false t.integer :source_id, null: false @@ -19,4 +19,8 @@ class AddMembersTable < ActiveRecord::Migration add_index :members, :access_level add_index :members, [:source_id, :source_type] end + + def down + drop_table :members + end end diff --git a/db/migrate/20141118150935_add_audit_event.rb b/db/migrate/20141118150935_add_audit_event.rb index 52d70b4a0ac..4be4d835e28 100644 --- a/db/migrate/20141118150935_add_audit_event.rb +++ b/db/migrate/20141118150935_add_audit_event.rb @@ -2,7 +2,7 @@ class AddAuditEvent < ActiveRecord::Migration DOWNTIME = false - def change + def up create_table :audit_events do |t| t.integer :author_id, null: false t.string :type, null: false @@ -22,4 +22,8 @@ class AddAuditEvent < ActiveRecord::Migration add_index :audit_events, :type add_index :audit_events, [:entity_id, :entity_type] end + + def down + drop_table :audit_events + end end diff --git a/db/migrate/20150206181414_add_index_to_created_at.rb b/db/migrate/20150206181414_add_index_to_created_at.rb index a161fad79dc..3f40062e0f8 100644 --- a/db/migrate/20150206181414_add_index_to_created_at.rb +++ b/db/migrate/20150206181414_add_index_to_created_at.rb @@ -1,6 +1,8 @@ # rubocop:disable all class AddIndexToCreatedAt < ActiveRecord::Migration - def change + DOWNTIME = false + + def up add_index "users", [:created_at, :id] add_index "members", [:created_at, :id] add_index "projects", [:created_at, :id] @@ -14,4 +16,20 @@ class AddIndexToCreatedAt < ActiveRecord::Migration add_index "web_hooks", [:created_at, :id] add_index "snippets", [:created_at, :id] end + + def down + # These one is removed by RemoveRedundantIndexes + remove_index :snippets, column: [:created_at, :id] if index_exists?(:snippets, [:created_at, :id]) + remove_index :web_hooks, column: [:created_at, :id] if index_exists?(:web_hooks, [:created_at, :id]) + remove_index :keys, column: [:created_at, :id] if index_exists?(:keys, [:created_at, :id]) + remove_index :identities, column: [:created_at, :id] if index_exists?(:identities, [:created_at, :id]) + remove_index :notes, column: [:created_at, :id] if index_exists?(:notes, [:created_at, :id]) + remove_index :namespaces, column: [:created_at, :id] if index_exists?(:namespaces, [:created_at, :id]) + remove_index :milestones, column: [:created_at, :id] if index_exists?(:milestones, [:created_at, :id]) + remove_index :merge_requests, column: [:created_at, :id] if index_exists?(:merge_requests, [:created_at, :id]) + remove_index :issues, column: [:created_at, :id] if index_exists?(:issues, [:created_at, :id]) + remove_index :projects, column: [:created_at, :id] if index_exists?(:projects, [:created_at, :id]) + remove_index :members, column: [:created_at, :id] if index_exists?(:members, [:created_at, :id]) + remove_index :users, column: [:created_at, :id] if index_exists?(:users, [:created_at, :id]) + end end diff --git a/db/migrate/20150209222013_add_missing_index.rb b/db/migrate/20150209222013_add_missing_index.rb index 18e3ac2cbbb..84a5716edcc 100644 --- a/db/migrate/20150209222013_add_missing_index.rb +++ b/db/migrate/20150209222013_add_missing_index.rb @@ -1,6 +1,13 @@ # rubocop:disable all class AddMissingIndex < ActiveRecord::Migration - def change + DOWNTIME = false + + def up add_index "services", [:created_at, :id] end + + def down + # This one is removed by RemoveRedundantIndexes + remove_index :services, column: [:created_at, :id] if index_exists?(:services, [:created_at, :id]) + end end diff --git a/db/migrate/20150211174341_allow_null_in_services_project_id.rb b/db/migrate/20150211174341_allow_null_in_services_project_id.rb index fea95c79adf..6cad14ff104 100644 --- a/db/migrate/20150211174341_allow_null_in_services_project_id.rb +++ b/db/migrate/20150211174341_allow_null_in_services_project_id.rb @@ -1,6 +1,12 @@ # rubocop:disable all class AllowNullInServicesProjectId < ActiveRecord::Migration - def change + DOWNTIME = false + + def up change_column :services, :project_id, :integer, null: true end + + def down + change_column :services, :project_id, :integer, null: false + end end diff --git a/db/migrate/20150425164649_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb b/db/migrate/20150425164649_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb index 1568d2dd4ce..a5d43577982 100644 --- a/db/migrate/20150425164649_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb +++ b/db/migrate/20150425164649_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb @@ -1,16 +1,20 @@ # rubocop:disable all # This migration comes from acts_as_taggable_on_engine (originally 3) class AddTaggingsCounterCacheToTags < ActiveRecord::Migration - def self.up + DOWNTIME = false + + def up add_column :tags, :taggings_count, :integer, default: 0 + return unless ActsAsTaggableOn.tags_counter + ActsAsTaggableOn::Tag.reset_column_information ActsAsTaggableOn::Tag.find_each do |tag| ActsAsTaggableOn::Tag.reset_counters(tag.id, :taggings) end end - def self.down + def down remove_column :tags, :taggings_count end end diff --git a/db/migrate/20150817163600_deduplicate_user_identities.rb b/db/migrate/20150817163600_deduplicate_user_identities.rb index b0cfad7d20f..6f4cc549cac 100644 --- a/db/migrate/20150817163600_deduplicate_user_identities.rb +++ b/db/migrate/20150817163600_deduplicate_user_identities.rb @@ -1,6 +1,8 @@ # rubocop:disable all class DeduplicateUserIdentities < ActiveRecord::Migration - def change + DOWNTIME = false + + def up execute 'DROP TABLE IF EXISTS tt_migration_DeduplicateUserIdentities;' execute 'CREATE TABLE tt_migration_DeduplicateUserIdentities AS SELECT id,provider,user_id FROM identities;' execute 'DELETE FROM identities WHERE id NOT IN ( SELECT MIN(id) FROM tt_migration_DeduplicateUserIdentities GROUP BY user_id, provider);' @@ -9,7 +11,5 @@ class DeduplicateUserIdentities < ActiveRecord::Migration def down # This is an irreversible migration; - # If someone is trying to rollback for other reasons, we should not throw an Exception. - # raise ActiveRecord::IrreversibleMigration end end diff --git a/db/migrate/20150826001931_add_ci_tables.rb b/db/migrate/20150826001931_add_ci_tables.rb index d1f8506d1fe..0ce39843ae8 100644 --- a/db/migrate/20150826001931_add_ci_tables.rb +++ b/db/migrate/20150826001931_add_ci_tables.rb @@ -1,6 +1,8 @@ # rubocop:disable all class AddCiTables < ActiveRecord::Migration - def change + DOWNTIME = false + + def up create_table "ci_application_settings", force: true do |t| t.boolean "all_broken_builds" t.boolean "add_pusher" @@ -188,4 +190,21 @@ class AddCiTables < ActiveRecord::Migration t.datetime "updated_at" end end + + def down + drop_table :ci_application_settings + drop_table :ci_builds + drop_table :ci_commits + drop_table :ci_events + drop_table :ci_jobs + drop_table :ci_projects + drop_table :ci_runner_projects + drop_table :ci_runners + drop_table :ci_services + drop_table :ci_sessions + drop_table :ci_trigger_requests + drop_table :ci_triggers + drop_table :ci_variables + drop_table :ci_web_hooks + end end diff --git a/db/migrate/20150914215247_add_ci_tags.rb b/db/migrate/20150914215247_add_ci_tags.rb index b647bc9c8a2..a69252f2530 100644 --- a/db/migrate/20150914215247_add_ci_tags.rb +++ b/db/migrate/20150914215247_add_ci_tags.rb @@ -1,6 +1,8 @@ # rubocop:disable all class AddCiTags < ActiveRecord::Migration - def change + DOWNTIME = false + + def up create_table "ci_taggings", force: true do |t| t.integer "tag_id" t.integer "taggable_id" @@ -21,4 +23,9 @@ class AddCiTags < ActiveRecord::Migration add_index "ci_tags", ["name"], name: "index_ci_tags_on_name", unique: true, using: :btree end + + def down + drop_table :ci_tags + drop_table :ci_taggings + end end diff --git a/db/migrate/20150915001905_enable_ssl_verification_by_default.rb b/db/migrate/20150915001905_enable_ssl_verification_by_default.rb index 3f070139418..1bd46069f01 100644 --- a/db/migrate/20150915001905_enable_ssl_verification_by_default.rb +++ b/db/migrate/20150915001905_enable_ssl_verification_by_default.rb @@ -1,6 +1,12 @@ # rubocop:disable all class EnableSslVerificationByDefault < ActiveRecord::Migration - def change + DOWNTIME = false + + def up change_column :web_hooks, :enable_ssl_verification, :boolean, default: true end + + def down + change_column :web_hooks, :enable_ssl_verification, :boolean, default: false + end end diff --git a/db/migrate/20150916145038_add_index_for_committed_at_and_id.rb b/db/migrate/20150916145038_add_index_for_committed_at_and_id.rb index a18ed93cf37..8c0a136753b 100644 --- a/db/migrate/20150916145038_add_index_for_committed_at_and_id.rb +++ b/db/migrate/20150916145038_add_index_for_committed_at_and_id.rb @@ -1,6 +1,15 @@ # rubocop:disable all class AddIndexForCommittedAtAndId < ActiveRecord::Migration - def change + DOWNTIME = false + + def up add_index :ci_commits, [:project_id, :committed_at, :id] end + + def down + # This one is removed by RemoveRedundantIndexes + if index_exists?(:ci_commits, [:project_id, :committed_at, :id]) + remove_index :ci_commits, column: [:project_id, :committed_at, :id] + end + end end diff --git a/db/migrate/20150924125150_add_project_id_to_ci_commit.rb b/db/migrate/20150924125150_add_project_id_to_ci_commit.rb index 905332b7dc7..908768c7608 100644 --- a/db/migrate/20150924125150_add_project_id_to_ci_commit.rb +++ b/db/migrate/20150924125150_add_project_id_to_ci_commit.rb @@ -1,6 +1,8 @@ # rubocop:disable all class AddProjectIdToCiCommit < ActiveRecord::Migration - def up + DOWNTIME = false + + def change add_column :ci_commits, :gl_project_id, :integer end end diff --git a/db/migrate/20150930001110_merge_request_error_field.rb b/db/migrate/20150930001110_merge_request_error_field.rb index 71a8ae3938a..a05169c8e18 100644 --- a/db/migrate/20150930001110_merge_request_error_field.rb +++ b/db/migrate/20150930001110_merge_request_error_field.rb @@ -1,6 +1,8 @@ # rubocop:disable all class MergeRequestErrorField < ActiveRecord::Migration - def up + DOWNTIME = false + + def change add_column :merge_requests, :merge_error, :string end end diff --git a/db/migrate/20151002122943_migrate_ref_and_tag_to_build.rb b/db/migrate/20151002122943_migrate_ref_and_tag_to_build.rb index 52217ce5af2..1a8ffe20977 100644 --- a/db/migrate/20151002122943_migrate_ref_and_tag_to_build.rb +++ b/db/migrate/20151002122943_migrate_ref_and_tag_to_build.rb @@ -1,7 +1,13 @@ # rubocop:disable all class MigrateRefAndTagToBuild < ActiveRecord::Migration - def change + DOWNTIME = false + + def up execute('UPDATE ci_builds SET ref=(SELECT ref FROM ci_commits WHERE ci_commits.id = ci_builds.commit_id) WHERE ref IS NULL') execute('UPDATE ci_builds SET tag=(SELECT tag FROM ci_commits WHERE ci_commits.id = ci_builds.commit_id) WHERE tag IS NULL') end + + def down + # no-op + end end diff --git a/db/migrate/20151008110232_add_users_lower_username_email_indexes.rb b/db/migrate/20151008110232_add_users_lower_username_email_indexes.rb index 6080d2a0fcf..f1659e1d7b3 100644 --- a/db/migrate/20151008110232_add_users_lower_username_email_indexes.rb +++ b/db/migrate/20151008110232_add_users_lower_username_email_indexes.rb @@ -12,7 +12,7 @@ class AddUsersLowerUsernameEmailIndexes < ActiveRecord::Migration def down return unless Gitlab::Database.postgresql? - remove_index :users, :index_on_users_lower_username - remove_index :users, :index_on_users_lower_email + remove_index :users, name: :index_on_users_lower_username + remove_index :users, name: :index_on_users_lower_email end end diff --git a/db/migrate/20151008130321_migrate_name_to_description_for_builds.rb b/db/migrate/20151008130321_migrate_name_to_description_for_builds.rb index 306fa7092ea..8818ef8188a 100644 --- a/db/migrate/20151008130321_migrate_name_to_description_for_builds.rb +++ b/db/migrate/20151008130321_migrate_name_to_description_for_builds.rb @@ -1,6 +1,12 @@ # rubocop:disable all class MigrateNameToDescriptionForBuilds < ActiveRecord::Migration - def change + DOWNTIME = false + + def up execute("UPDATE ci_builds SET type='Ci::Build' WHERE type IS NULL") end + + def down + # no-op + end end diff --git a/db/migrate/20151016195451_add_ci_builds_and_projects_indexes.rb b/db/migrate/20151016195451_add_ci_builds_and_projects_indexes.rb index 899e004d610..b76548b348f 100644 --- a/db/migrate/20151016195451_add_ci_builds_and_projects_indexes.rb +++ b/db/migrate/20151016195451_add_ci_builds_and_projects_indexes.rb @@ -1,10 +1,22 @@ # rubocop:disable all class AddCiBuildsAndProjectsIndexes < ActiveRecord::Migration - def change + DOWNTIME = false + + def up add_index :ci_projects, :gitlab_id add_index :ci_projects, :shared_runners_enabled add_index :ci_builds, :type add_index :ci_builds, :status end + + def down + # This one is removed by RemoveRedundantIndexes + remove_index :ci_projects, column: :gitlab_id if index_exists?(:ci_projects, :gitlab_id) + # This one is removed by RemoveRedundantIndexes + remove_index :ci_projects, column: :shared_runners_enabled if index_exists?(:ci_projects, :shared_runners_enabled) + # This one is removed by RemoveRedundantIndexes + remove_index :ci_builds, column: :type if index_exists?(:ci_builds, :type) + remove_index :ci_builds, column: :status + end end diff --git a/db/migrate/20151020173516_ci_limits_to_mysql.rb b/db/migrate/20151020173516_ci_limits_to_mysql.rb index 5314611cbcd..1222009d4ba 100644 --- a/db/migrate/20151020173516_ci_limits_to_mysql.rb +++ b/db/migrate/20151020173516_ci_limits_to_mysql.rb @@ -1,10 +1,18 @@ # rubocop:disable all class CiLimitsToMysql < ActiveRecord::Migration - def change - return unless ActiveRecord::Base.configurations[Rails.env]['adapter'] =~ /^mysql/ + DOWNTIME = false + + def up + return unless Gitlab::Database.mysql? # CI change_column :ci_builds, :trace, :text, limit: 1073741823 change_column :ci_commits, :push_data, :text, limit: 16777215 end + + def down + return unless Gitlab::Database.mysql? + + # no-op, keep the new limit to prevent data loss + end end diff --git a/db/migrate/20151103133339_add_shared_runners_setting.rb b/db/migrate/20151103133339_add_shared_runners_setting.rb index b5b34d4ca61..5afd0f19ebe 100644 --- a/db/migrate/20151103133339_add_shared_runners_setting.rb +++ b/db/migrate/20151103133339_add_shared_runners_setting.rb @@ -1,6 +1,8 @@ # rubocop:disable all class AddSharedRunnersSetting < ActiveRecord::Migration - def up + DOWNTIME = false + + def change add_column :application_settings, :shared_runners_enabled, :boolean, default: true, null: false end end diff --git a/db/migrate/20151106000015_add_is_award_to_notes.rb b/db/migrate/20151106000015_add_is_award_to_notes.rb index b463d939b78..81497c79414 100644 --- a/db/migrate/20151106000015_add_is_award_to_notes.rb +++ b/db/migrate/20151106000015_add_is_award_to_notes.rb @@ -1,7 +1,15 @@ # rubocop:disable all class AddIsAwardToNotes < ActiveRecord::Migration - def change + DOWNTIME = false + + def up add_column :notes, :is_award, :boolean, default: false, null: false add_index :notes, :is_award end + + def down + remove_column :notes, :is_award + # This one is removed in ConvertAwardNoteToEmojiAward + remove_index :notes, column: :is_award if index_exists?(:notes, :is_award) + end end diff --git a/db/migrate/20151116144118_add_unique_for_lfs_oid_index.rb b/db/migrate/20151116144118_add_unique_for_lfs_oid_index.rb index 1f192544ea1..b0706846bed 100644 --- a/db/migrate/20151116144118_add_unique_for_lfs_oid_index.rb +++ b/db/migrate/20151116144118_add_unique_for_lfs_oid_index.rb @@ -1,8 +1,10 @@ # rubocop:disable all class AddUniqueForLfsOidIndex < ActiveRecord::Migration + DOWNTIME = false + def change - remove_index :lfs_objects, :oid - remove_index :lfs_objects, [:oid, :size] + remove_index :lfs_objects, column: :oid + remove_index :lfs_objects, column: [:oid, :size] add_index :lfs_objects, :oid, unique: true end end diff --git a/db/migrate/20151118162244_add_projects_public_index.rb b/db/migrate/20151118162244_add_projects_public_index.rb index 589f124c21e..61c43c416e9 100644 --- a/db/migrate/20151118162244_add_projects_public_index.rb +++ b/db/migrate/20151118162244_add_projects_public_index.rb @@ -1,6 +1,13 @@ # rubocop:disable all class AddProjectsPublicIndex < ActiveRecord::Migration - def change + DOWNTIME = false + + def up add_index :namespaces, :public end + + def down + # This one is removed in RemovePublicFromNamespace + remove_index :namespaces, :public if index_exists?(:namespaces, :public) + end end diff --git a/db/migrate/20151201203948_raise_hook_url_limit.rb b/db/migrate/20151201203948_raise_hook_url_limit.rb index c490b7ace0f..3b614654e02 100644 --- a/db/migrate/20151201203948_raise_hook_url_limit.rb +++ b/db/migrate/20151201203948_raise_hook_url_limit.rb @@ -1,6 +1,12 @@ # rubocop:disable all class RaiseHookUrlLimit < ActiveRecord::Migration - def change + DOWNTIME = false + + def up change_column :web_hooks, :url, :string, limit: 2000 end + + def down + # no-op, keep the new limit to prevent data loss + end end diff --git a/db/migrate/20151210125931_add_index_to_ci_tables.rb b/db/migrate/20151210125931_add_index_to_ci_tables.rb index d87d335cf6b..7e38a38d751 100644 --- a/db/migrate/20151210125931_add_index_to_ci_tables.rb +++ b/db/migrate/20151210125931_add_index_to_ci_tables.rb @@ -1,6 +1,8 @@ # rubocop:disable all class AddIndexToCiTables < ActiveRecord::Migration - def change + DOWNTIME = false + + def up add_index :ci_builds, :gl_project_id add_index :ci_runner_projects, :gl_project_id add_index :ci_triggers, :gl_project_id @@ -10,4 +12,15 @@ class AddIndexToCiTables < ActiveRecord::Migration add_index :projects, [:builds_enabled, :shared_runners_enabled] add_index :projects, [:ci_id] end + + def down + remove_index :ci_builds, :gl_project_id if index_exists?(:ci_builds, :gl_project_id) + remove_index :ci_runner_projects, :gl_project_id if index_exists?(:ci_runner_projects, :gl_project_id) + remove_index :ci_triggers, :gl_project_id if index_exists?(:ci_triggers, :gl_project_id) + remove_index :ci_variables, :gl_project_id if index_exists?(:ci_variables, :gl_project_id) + remove_index :projects, :runners_token if index_exists?(:projects, :runners_token) + remove_index :projects, :builds_enabled if index_exists?(:projects, :builds_enabled) + remove_index :projects, [:builds_enabled, :shared_runners_enabled] if index_exists?(:projects, [:builds_enabled, :shared_runners_enabled]) + remove_index :projects, [:ci_id] if index_exists?(:projects, [:ci_id]) + end end diff --git a/db/migrate/20151210125932_drop_null_for_ci_tables.rb b/db/migrate/20151210125932_drop_null_for_ci_tables.rb index e1a0a964589..6b6b56b0a54 100644 --- a/db/migrate/20151210125932_drop_null_for_ci_tables.rb +++ b/db/migrate/20151210125932_drop_null_for_ci_tables.rb @@ -1,8 +1,10 @@ # rubocop:disable all class DropNullForCiTables < ActiveRecord::Migration + DOWNTIME = false + def change - remove_index :ci_variables, :project_id - remove_index :ci_runner_projects, :project_id + remove_index :ci_variables, column: :project_id + remove_index :ci_runner_projects, column: :project_id change_column_null :ci_triggers, :project_id, true change_column_null :ci_variables, :project_id, true change_column_null :ci_runner_projects, :project_id, true diff --git a/db/migrate/20151229112614_influxdb_remote_database_setting.rb b/db/migrate/20151229112614_influxdb_remote_database_setting.rb index d2ac906ead3..57abe3b1ea4 100644 --- a/db/migrate/20151229112614_influxdb_remote_database_setting.rb +++ b/db/migrate/20151229112614_influxdb_remote_database_setting.rb @@ -1,6 +1,8 @@ # rubocop:disable all class InfluxdbRemoteDatabaseSetting < ActiveRecord::Migration + DOWNTIME = false + def change - remove_column :application_settings, :metrics_database + remove_column :application_settings, :metrics_database, :string end end diff --git a/db/migrate/20160128233227_change_lfs_objects_size_column.rb b/db/migrate/20160128233227_change_lfs_objects_size_column.rb index 645c0cdb192..b7f61484eca 100644 --- a/db/migrate/20160128233227_change_lfs_objects_size_column.rb +++ b/db/migrate/20160128233227_change_lfs_objects_size_column.rb @@ -1,6 +1,12 @@ # rubocop:disable all class ChangeLfsObjectsSizeColumn < ActiveRecord::Migration - def change + DOWNTIME = false + + def up change_column :lfs_objects, :size, :integer, limit: 8 end + + def down + # no-op, keep the new limit to prevent data loss + end end diff --git a/db/migrate/20160320204112_index_namespaces_on_visibility_level.rb b/db/migrate/20160320204112_index_namespaces_on_visibility_level.rb index 07ae7c95477..1452aa65ada 100644 --- a/db/migrate/20160320204112_index_namespaces_on_visibility_level.rb +++ b/db/migrate/20160320204112_index_namespaces_on_visibility_level.rb @@ -1,8 +1,16 @@ # rubocop:disable all class IndexNamespacesOnVisibilityLevel < ActiveRecord::Migration - def change + DOWNTIME = false + + def up unless index_exists?(:namespaces, :visibility_level) add_index :namespaces, :visibility_level end end + + def down + if index_exists?(:namespaces, :visibility_level) + add_index :namespaces, :visibility_level + end + end end diff --git a/db/migrate/20160412173417_update_ci_commit.rb b/db/migrate/20160412173417_update_ci_commit.rb index 858faeb060e..c0da9f1087b 100644 --- a/db/migrate/20160412173417_update_ci_commit.rb +++ b/db/migrate/20160412173417_update_ci_commit.rb @@ -2,10 +2,16 @@ class UpdateCiCommit < ActiveRecord::Migration # This migration can be run online, but needs to be executed for the second time after restarting Unicorn workers # Otherwise Offline migration should be used. - def change + DOWNTIME = false + + def up execute("UPDATE ci_commits SET status=#{status}, ref=#{ref}, tag=#{tag} WHERE status IS NULL") end + def down + # no-op + end + private def status diff --git a/db/migrate/20160508221410_set_type_on_legacy_diff_notes.rb b/db/migrate/20160508221410_set_type_on_legacy_diff_notes.rb index 6dd958ff4a0..2b4e4d398dd 100644 --- a/db/migrate/20160508221410_set_type_on_legacy_diff_notes.rb +++ b/db/migrate/20160508221410_set_type_on_legacy_diff_notes.rb @@ -1,6 +1,12 @@ # rubocop:disable all class SetTypeOnLegacyDiffNotes < ActiveRecord::Migration - def change + DOWNTIME = false + + def up execute "UPDATE notes SET type = 'LegacyDiffNote' WHERE line_code IS NOT NULL" end + + def down + # no-op + end end diff --git a/db/migrate/20160525205328_remove_main_language_from_projects.rb b/db/migrate/20160525205328_remove_main_language_from_projects.rb index dc4ceacddb1..1af143991ef 100644 --- a/db/migrate/20160525205328_remove_main_language_from_projects.rb +++ b/db/migrate/20160525205328_remove_main_language_from_projects.rb @@ -1,22 +1,10 @@ # rubocop:disable all -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - class RemoveMainLanguageFromProjects < ActiveRecord::Migration include Gitlab::Database::MigrationHelpers - # When using the methods "add_concurrent_index" or "add_column_with_default" - # you must disable the use of transactions as these methods can not run in an - # existing transaction. When using "add_concurrent_index" make sure that this - # method is the _only_ method called in the migration, any other changes - # should go in a separate migration. This ensures that upon failure _only_ the - # index creation fails and can be retried or reverted easily. - # - # To disable transactions uncomment the following line and remove these - # comments: - # disable_ddl_transaction! + DOWNTIME = false def change - remove_column :projects, :main_language + remove_column :projects, :main_language, :string end end diff --git a/db/migrate/20160528043124_add_users_state_index.rb b/db/migrate/20160528043124_add_users_state_index.rb index 6419d2ae71d..53b009ff0e7 100644 --- a/db/migrate/20160528043124_add_users_state_index.rb +++ b/db/migrate/20160528043124_add_users_state_index.rb @@ -1,10 +1,15 @@ # rubocop:disable all class AddUsersStateIndex < ActiveRecord::Migration include Gitlab::Database::MigrationHelpers - disable_ddl_transaction! - def change + DOWNTIME = false + + def up add_concurrent_index :users, :state end + + def down + remove_index :users, :state + end end diff --git a/db/migrate/20160603182247_add_index_to_notification_settings.rb b/db/migrate/20160603182247_add_index_to_notification_settings.rb index f6ae26d555f..6463e346582 100644 --- a/db/migrate/20160603182247_add_index_to_notification_settings.rb +++ b/db/migrate/20160603182247_add_index_to_notification_settings.rb @@ -1,10 +1,15 @@ # rubocop:disable all class AddIndexToNotificationSettings < ActiveRecord::Migration include Gitlab::Database::MigrationHelpers - disable_ddl_transaction! - def change + DOWNTIME = false + + def up add_concurrent_index :notification_settings, [:user_id, :source_id, :source_type], { unique: true, name: "index_notifications_on_user_id_and_source_id_and_source_type" } end + + def down + remove_index :notification_settings, column: [:user_id, :source_id, :source_type], unique: true, name: "index_notifications_on_user_id_and_source_id_and_source_type" + end end diff --git a/db/migrate/20160610140403_remove_notification_setting_not_null_constraints.rb b/db/migrate/20160610140403_remove_notification_setting_not_null_constraints.rb index 259abb08e47..09463dae3b5 100644 --- a/db/migrate/20160610140403_remove_notification_setting_not_null_constraints.rb +++ b/db/migrate/20160610140403_remove_notification_setting_not_null_constraints.rb @@ -1,11 +1,14 @@ class RemoveNotificationSettingNotNullConstraints < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + def up change_column :notification_settings, :source_type, :string, null: true change_column :notification_settings, :source_id, :integer, null: true end def down - change_column :notification_settings, :source_type, :string, null: false - change_column :notification_settings, :source_id, :integer, null: false + # no-op since the data would prevent the change of the null constraint end end diff --git a/db/migrate/20160703180340_add_index_on_award_emoji_user_and_name.rb b/db/migrate/20160703180340_add_index_on_award_emoji_user_and_name.rb index 0c25f87dfb4..1670fe19c5e 100644 --- a/db/migrate/20160703180340_add_index_on_award_emoji_user_and_name.rb +++ b/db/migrate/20160703180340_add_index_on_award_emoji_user_and_name.rb @@ -5,7 +5,13 @@ class AddIndexOnAwardEmojiUserAndName < ActiveRecord::Migration include Gitlab::Database::MigrationHelpers disable_ddl_transaction! - def change + DOWNTIME = false + + def up add_concurrent_index(:award_emoji, [:user_id, :name]) end + + def down + remove_index :award_emoji, [:user_id, :name] + end end diff --git a/db/migrate/20160725104020_merge_request_diff_remove_uniq.rb b/db/migrate/20160725104020_merge_request_diff_remove_uniq.rb index 12e11bc3fbe..85bc7d867c2 100644 --- a/db/migrate/20160725104020_merge_request_diff_remove_uniq.rb +++ b/db/migrate/20160725104020_merge_request_diff_remove_uniq.rb @@ -1,6 +1,3 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - # rubocop:disable RemoveIndex class MergeRequestDiffRemoveUniq < ActiveRecord::Migration include Gitlab::Database::MigrationHelpers @@ -25,9 +22,7 @@ class MergeRequestDiffRemoveUniq < ActiveRecord::Migration end def down - unless index_exists?(:merge_request_diffs, :merge_request_id) - add_concurrent_index(:merge_request_diffs, :merge_request_id, unique: true) - end + # no-op since the data would prevent the creation of a unique index end def constraint_exists?(name) diff --git a/db/migrate/20160802010328_remove_builds_enable_index_on_projects.rb b/db/migrate/20160802010328_remove_builds_enable_index_on_projects.rb index 6d7733762c8..7d382edab38 100644 --- a/db/migrate/20160802010328_remove_builds_enable_index_on_projects.rb +++ b/db/migrate/20160802010328_remove_builds_enable_index_on_projects.rb @@ -1,10 +1,15 @@ # rubocop:disable RemoveIndex +# rubocop:disable AddIndex class RemoveBuildsEnableIndexOnProjects < ActiveRecord::Migration include Gitlab::Database::MigrationHelpers DOWNTIME = false - def change - remove_index :projects, column: :builds_enabled if index_exists?(:projects, :builds_enabled) + def up + remove_index :projects, :builds_enabled if index_exists?(:projects, :builds_enabled) + end + + def down + add_index :projects, :builds_enabled unless index_exists?(:projects, :builds_enabled) end end diff --git a/db/migrate/20160808085602_add_index_for_build_token.rb b/db/migrate/20160808085602_add_index_for_build_token.rb index 0446b2f2e15..d6771688dae 100644 --- a/db/migrate/20160808085602_add_index_for_build_token.rb +++ b/db/migrate/20160808085602_add_index_for_build_token.rb @@ -2,7 +2,6 @@ class AddIndexForBuildToken < ActiveRecord::Migration include Gitlab::Database::MigrationHelpers - # Set this constant to true if this migration requires downtime. DOWNTIME = false disable_ddl_transaction! @@ -12,6 +11,6 @@ class AddIndexForBuildToken < ActiveRecord::Migration end def down - remove_index :ci_builds, :token, unique: true if index_exists? :ci_builds, :token, unique: true + remove_index :ci_builds, :token if index_exists? :ci_builds, :token, unique: true end end diff --git a/db/migrate/20160823081327_change_merge_error_to_text.rb b/db/migrate/20160823081327_change_merge_error_to_text.rb index 7920389cd83..be244993de5 100644 --- a/db/migrate/20160823081327_change_merge_error_to_text.rb +++ b/db/migrate/20160823081327_change_merge_error_to_text.rb @@ -4,7 +4,11 @@ class ChangeMergeErrorToText < ActiveRecord::Migration DOWNTIME = true DOWNTIME_REASON = 'This migration requires downtime because it alters a column from varchar(255) to text.' - def change + def up change_column :merge_requests, :merge_error, :text, limit: 65535 end + + def down + change_column :merge_requests, :merge_error, :string + end end diff --git a/db/migrate/20160824103857_drop_unused_ci_tables.rb b/db/migrate/20160824103857_drop_unused_ci_tables.rb index 65cf46308d9..33bb56208d2 100644 --- a/db/migrate/20160824103857_drop_unused_ci_tables.rb +++ b/db/migrate/20160824103857_drop_unused_ci_tables.rb @@ -4,8 +4,27 @@ class DropUnusedCiTables < ActiveRecord::Migration # Set this constant to true if this migration requires downtime. DOWNTIME = false - def change + def up drop_table(:ci_services) drop_table(:ci_web_hooks) end + + def down + create_table "ci_web_hooks", force: true do |t| + t.string "url", null: false + t.integer "project_id", null: false + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "ci_services", force: true do |t| + t.string "type" + t.string "title" + t.integer "project_id", null: false + t.datetime "created_at" + t.datetime "updated_at" + t.boolean "active", default: false, null: false + t.text "properties" + end + end end diff --git a/db/migrate/20160919144305_add_type_to_labels.rb b/db/migrate/20160919144305_add_type_to_labels.rb index 66172bda6ff..96d72d24184 100644 --- a/db/migrate/20160919144305_add_type_to_labels.rb +++ b/db/migrate/20160919144305_add_type_to_labels.rb @@ -4,11 +4,15 @@ class AddTypeToLabels < ActiveRecord::Migration DOWNTIME = true DOWNTIME_REASON = 'Labels will not work as expected until this migration is complete.' - def change + def up add_column :labels, :type, :string update_column_in_batches(:labels, :type, 'ProjectLabel') do |table, query| query.where(table[:project_id].not_eq(nil)) end end + + def down + remove_column :labels, :type + end end |