diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2017-06-23 08:23:27 +0000 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2017-06-23 18:09:22 +0800 |
commit | d34e87818c217a1a7368852e4cba384914afedd0 (patch) | |
tree | 3a5fbd0400f2b3f5c7addf897f0ff18f15302e5a | |
parent | 5eb4a47204931ebf5e5f40a3653f1ba9557af2ce (diff) | |
download | gitlab-ce-d34e87818c217a1a7368852e4cba384914afedd0.tar.gz |
Remove old project_id index and make sure mysql work
-rw-r--r-- | db/migrate/20170622135728_add_unique_constraint_to_ci_variables.rb | 18 | ||||
-rw-r--r-- | db/migrate/20170623080805_remove_ci_variables_project_id_index.rb | 19 | ||||
-rw-r--r-- | db/schema.rb | 2 |
3 files changed, 34 insertions, 5 deletions
diff --git a/db/migrate/20170622135728_add_unique_constraint_to_ci_variables.rb b/db/migrate/20170622135728_add_unique_constraint_to_ci_variables.rb index 69729a17054..f7fca511e9b 100644 --- a/db/migrate/20170622135728_add_unique_constraint_to_ci_variables.rb +++ b/db/migrate/20170622135728_add_unique_constraint_to_ci_variables.rb @@ -6,18 +6,28 @@ class AddUniqueConstraintToCiVariables < ActiveRecord::Migration disable_ddl_transaction! def up - unless index_exists?(:ci_variables, columns) - add_concurrent_index(:ci_variables, columns, unique: true) + unless this_index_exists? + add_concurrent_index(:ci_variables, columns, name: index_name, unique: true) end end def down - if index_exists?(:ci_variables, columns) && Gitlab::Database.postgresql? - remove_concurrent_index(:ci_variables, columns) + if this_index_exists? && Gitlab::Database.postgresql? + remove_concurrent_index(:ci_variables, columns, name: index_name) end end + private + + def this_index_exists? + index_exists?(:ci_variables, name: index_name) + end + def columns @columns ||= [:project_id, :key, :environment_scope] end + + def index_name + 'index_ci_variables_on_project_id_and_key_and_environment_scope' + end end diff --git a/db/migrate/20170623080805_remove_ci_variables_project_id_index.rb b/db/migrate/20170623080805_remove_ci_variables_project_id_index.rb new file mode 100644 index 00000000000..ddcc0292b9d --- /dev/null +++ b/db/migrate/20170623080805_remove_ci_variables_project_id_index.rb @@ -0,0 +1,19 @@ +class RemoveCiVariablesProjectIdIndex < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + if index_exists?(:ci_variables, :project_id) + remove_concurrent_index(:ci_variables, :project_id) + end + end + + def down + unless index_exists?(:ci_variables, :project_id) + add_concurrent_index(:ci_variables, :project_id) + end + end +end diff --git a/db/schema.rb b/db/schema.rb index fa66d515a0d..94b03219b21 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170622135728) do +ActiveRecord::Schema.define(version: 20170623080805) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" |