diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-05-17 15:51:33 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-05-17 15:51:33 +0900 |
commit | 1c636b8080bad4f9ea8fb6992277e421816271ce (patch) | |
tree | a1d562ea97ef2c1829a752906f9ee0ef27cb4682 /db | |
parent | 82a49d0fea1ace87b5619fbc4ed728f43fdef7bd (diff) | |
parent | 60b14e52963238bb2401004350d963eda1fabef6 (diff) | |
download | gitlab-ce-1c636b8080bad4f9ea8fb6992277e421816271ce.tar.gz |
Merge branch 'master' into per-project-pipeline-iid
Diffstat (limited to 'db')
4 files changed, 83 insertions, 3 deletions
diff --git a/db/migrate/20180511090724_add_index_on_ci_runners_runner_type.rb b/db/migrate/20180511090724_add_index_on_ci_runners_runner_type.rb new file mode 100644 index 00000000000..580f56007c7 --- /dev/null +++ b/db/migrate/20180511090724_add_index_on_ci_runners_runner_type.rb @@ -0,0 +1,15 @@ +class AddIndexOnCiRunnersRunnerType < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_index :ci_runners, :runner_type + end + + def down + remove_index :ci_runners, :runner_type + end +end diff --git a/db/post_migrate/20180511174224_add_unique_constraint_to_project_features_project_id.rb b/db/post_migrate/20180511174224_add_unique_constraint_to_project_features_project_id.rb new file mode 100644 index 00000000000..88a9f5f8256 --- /dev/null +++ b/db/post_migrate/20180511174224_add_unique_constraint_to_project_features_project_id.rb @@ -0,0 +1,43 @@ +class AddUniqueConstraintToProjectFeaturesProjectId < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + class ProjectFeature < ActiveRecord::Base + self.table_name = 'project_features' + + include EachBatch + end + + def up + remove_duplicates + + add_concurrent_index :project_features, :project_id, unique: true, name: 'index_project_features_on_project_id_unique' + remove_concurrent_index_by_name :project_features, 'index_project_features_on_project_id' + rename_index :project_features, 'index_project_features_on_project_id_unique', 'index_project_features_on_project_id' + end + + def down + rename_index :project_features, 'index_project_features_on_project_id', 'index_project_features_on_project_id_old' + add_concurrent_index :project_features, :project_id + remove_concurrent_index_by_name :project_features, 'index_project_features_on_project_id_old' + end + + private + + def remove_duplicates + features = ProjectFeature + .select('MAX(id) AS max, COUNT(id), project_id') + .group(:project_id) + .having('COUNT(id) > 1') + + features.each do |feature| + ProjectFeature + .where(project_id: feature['project_id']) + .where('id <> ?', feature['max']) + .each_batch { |batch| batch.delete_all } + end + end +end diff --git a/db/post_migrate/20180512061621_add_not_null_constraint_to_project_features_project_id.rb b/db/post_migrate/20180512061621_add_not_null_constraint_to_project_features_project_id.rb new file mode 100644 index 00000000000..5a6d6ff4a10 --- /dev/null +++ b/db/post_migrate/20180512061621_add_not_null_constraint_to_project_features_project_id.rb @@ -0,0 +1,21 @@ +class AddNotNullConstraintToProjectFeaturesProjectId < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + class ProjectFeature < ActiveRecord::Base + include EachBatch + + self.table_name = 'project_features' + end + + def up + ProjectFeature.where(project_id: nil).delete_all + + change_column_null :project_features, :project_id, false + end + + def down + change_column_null :project_features, :project_id, true + end +end diff --git a/db/schema.rb b/db/schema.rb index 77492236f72..27bdb7701c1 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: 20180508135515) do +ActiveRecord::Schema.define(version: 20180512061621) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -505,6 +505,7 @@ ActiveRecord::Schema.define(version: 20180508135515) do add_index "ci_runners", ["contacted_at"], name: "index_ci_runners_on_contacted_at", using: :btree add_index "ci_runners", ["is_shared"], name: "index_ci_runners_on_is_shared", using: :btree add_index "ci_runners", ["locked"], name: "index_ci_runners_on_locked", using: :btree + add_index "ci_runners", ["runner_type"], name: "index_ci_runners_on_runner_type", using: :btree add_index "ci_runners", ["token"], name: "index_ci_runners_on_token", using: :btree create_table "ci_stages", force: :cascade do |t| @@ -1495,7 +1496,7 @@ ActiveRecord::Schema.define(version: 20180508135515) do add_index "project_deploy_tokens", ["project_id", "deploy_token_id"], name: "index_project_deploy_tokens_on_project_id_and_deploy_token_id", unique: true, using: :btree create_table "project_features", force: :cascade do |t| - t.integer "project_id" + t.integer "project_id", null: false t.integer "merge_requests_access_level" t.integer "issues_access_level" t.integer "wiki_access_level" @@ -1506,7 +1507,7 @@ ActiveRecord::Schema.define(version: 20180508135515) do t.integer "repository_access_level", default: 20, null: false end - add_index "project_features", ["project_id"], name: "index_project_features_on_project_id", using: :btree + add_index "project_features", ["project_id"], name: "index_project_features_on_project_id", unique: true, using: :btree create_table "project_group_links", force: :cascade do |t| t.integer "project_id", null: false |