diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-02-06 09:32:18 +0100 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-02-06 09:32:18 +0100 |
commit | 066d4deaed3d8698a9d1decd138871528cecc4af (patch) | |
tree | aee535d5f19f0798ab155fdb2f65a4c743e54422 /db | |
parent | e011e291dadb00b260e74c25a64134f78d4d2177 (diff) | |
parent | 84bda43a3c0ce13a436748d0bc0ea943f6ebccb3 (diff) | |
download | gitlab-ce-066d4deaed3d8698a9d1decd138871528cecc4af.tar.gz |
Merge branch 'master' into fix/gb/fix-redundant-pipeline-stages
* master: (441 commits)
Conflicts:
db/schema.rb
Diffstat (limited to 'db')
11 files changed, 262 insertions, 4 deletions
diff --git a/db/migrate/20180115201419_add_index_updated_at_to_issues.rb b/db/migrate/20180115201419_add_index_updated_at_to_issues.rb new file mode 100644 index 00000000000..a5a48fc97be --- /dev/null +++ b/db/migrate/20180115201419_add_index_updated_at_to_issues.rb @@ -0,0 +1,15 @@ +class AddIndexUpdatedAtToIssues < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_index :issues, :updated_at + end + + def down + remove_concurrent_index :issues, :updated_at + end +end diff --git a/db/migrate/20180119135717_add_uploader_index_to_uploads.rb b/db/migrate/20180119135717_add_uploader_index_to_uploads.rb new file mode 100644 index 00000000000..a678c3d049f --- /dev/null +++ b/db/migrate/20180119135717_add_uploader_index_to_uploads.rb @@ -0,0 +1,20 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class AddUploaderIndexToUploads < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + remove_concurrent_index :uploads, :path + add_concurrent_index :uploads, [:uploader, :path], using: :btree + end + + def down + remove_concurrent_index :uploads, [:uploader, :path] + add_concurrent_index :uploads, :path, using: :btree + end +end diff --git a/db/migrate/20180125214301_create_user_callouts.rb b/db/migrate/20180125214301_create_user_callouts.rb new file mode 100644 index 00000000000..856eff36ae0 --- /dev/null +++ b/db/migrate/20180125214301_create_user_callouts.rb @@ -0,0 +1,16 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class CreateUserCallouts < ActiveRecord::Migration + # Set this constant to true if this migration requires downtime. + DOWNTIME = false + + def change + create_table :user_callouts do |t| + t.integer :feature_name, null: false + t.references :user, index: true, foreign_key: { on_delete: :cascade }, null: false + end + + add_index :user_callouts, [:user_id, :feature_name], unique: true + end +end diff --git a/db/migrate/20180129193323_add_uploads_builder_context.rb b/db/migrate/20180129193323_add_uploads_builder_context.rb new file mode 100644 index 00000000000..b3909a770ca --- /dev/null +++ b/db/migrate/20180129193323_add_uploads_builder_context.rb @@ -0,0 +1,14 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class AddUploadsBuilderContext < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + # Set this constant to true if this migration requires downtime. + DOWNTIME = false + + def change + add_column :uploads, :mount_point, :string + add_column :uploads, :secret, :string + end +end diff --git a/db/migrate/20180201102129_add_unique_constraint_to_trending_projects_project_id.rb b/db/migrate/20180201102129_add_unique_constraint_to_trending_projects_project_id.rb new file mode 100644 index 00000000000..02e53b8fa8a --- /dev/null +++ b/db/migrate/20180201102129_add_unique_constraint_to_trending_projects_project_id.rb @@ -0,0 +1,19 @@ +class AddUniqueConstraintToTrendingProjectsProjectId < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_index :trending_projects, :project_id, unique: true, name: 'index_trending_projects_on_project_id_unique' + remove_concurrent_index_by_name :trending_projects, 'index_trending_projects_on_project_id' + rename_index :trending_projects, 'index_trending_projects_on_project_id_unique', 'index_trending_projects_on_project_id' + end + + def down + rename_index :trending_projects, 'index_trending_projects_on_project_id', 'index_trending_projects_on_project_id_old' + add_concurrent_index :trending_projects, :project_id + remove_concurrent_index_by_name :trending_projects, 'index_trending_projects_on_project_id_old' + end +end diff --git a/db/migrate/20180201110056_add_foreign_keys_to_todos.rb b/db/migrate/20180201110056_add_foreign_keys_to_todos.rb new file mode 100644 index 00000000000..b7c40f8c01a --- /dev/null +++ b/db/migrate/20180201110056_add_foreign_keys_to_todos.rb @@ -0,0 +1,38 @@ +class AddForeignKeysToTodos < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + class Todo < ActiveRecord::Base + self.table_name = 'todos' + include EachBatch + end + + BATCH_SIZE = 1000 + + DOWNTIME = false + + disable_ddl_transaction! + + def up + Todo.where('NOT EXISTS ( SELECT true FROM users WHERE id=todos.user_id )').each_batch(of: BATCH_SIZE) do |batch| + batch.delete_all + end + + Todo.where('NOT EXISTS ( SELECT true FROM users WHERE id=todos.author_id )').each_batch(of: BATCH_SIZE) do |batch| + batch.delete_all + end + + Todo.where('note_id IS NOT NULL AND NOT EXISTS ( SELECT true FROM notes WHERE id=todos.note_id )').each_batch(of: BATCH_SIZE) do |batch| + batch.delete_all + end + + add_concurrent_foreign_key :todos, :users, column: :user_id, on_delete: :cascade + add_concurrent_foreign_key :todos, :users, column: :author_id, on_delete: :cascade + add_concurrent_foreign_key :todos, :notes, column: :note_id, on_delete: :cascade + end + + def down + remove_foreign_key :todos, :users + remove_foreign_key :todos, column: :author_id + remove_foreign_key :todos, :notes + end +end diff --git a/db/migrate/20180201145907_migrate_remaining_issues_closed_at.rb b/db/migrate/20180201145907_migrate_remaining_issues_closed_at.rb new file mode 100644 index 00000000000..5a36dec6a9a --- /dev/null +++ b/db/migrate/20180201145907_migrate_remaining_issues_closed_at.rb @@ -0,0 +1,55 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class MigrateRemainingIssuesClosedAt < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + # Set this constant to true if this migration requires downtime. + DOWNTIME = false + + disable_ddl_transaction! + + class Issue < ActiveRecord::Base + self.table_name = 'issues' + include EachBatch + end + + def up + Gitlab::BackgroundMigration.steal('CopyColumn') + Gitlab::BackgroundMigration.steal('CleanupConcurrentTypeChange') + + if migrate_column_type? + if closed_at_for_type_change_exists? + migrate_remaining_rows + else + # Due to some EE merge problems some environments may not have the + # "closed_at_for_type_change" column. If this is the case we have no + # other option than to migrate the data _right now_. + change_column_type_concurrently(:issues, :closed_at, :datetime_with_timezone) + cleanup_concurrent_column_type_change(:issues, :closed_at) + end + end + end + + def down + # Previous migrations already revert the changes made here. + end + + def migrate_remaining_rows + Issue.where('closed_at_for_type_change IS NULL AND closed_at IS NOT NULL').each_batch do |batch| + batch.update_all('closed_at_for_type_change = closed_at') + end + + cleanup_concurrent_column_type_change(:issues, :closed_at) + end + + def migrate_column_type? + # Some environments may have already executed the previous version of this + # migration, thus we don't need to migrate those environments again. + column_for('issues', 'closed_at').type == :datetime # rubocop:disable Migration/Datetime + end + + def closed_at_for_type_change_exists? + columns('issues').any? { |col| col.name == 'closed_at_for_type_change' } + end +end diff --git a/db/post_migrate/20171207150300_remove_project_labels_group_id_copy.rb b/db/post_migrate/20171207150300_remove_project_labels_group_id_copy.rb new file mode 100644 index 00000000000..2f339172eeb --- /dev/null +++ b/db/post_migrate/20171207150300_remove_project_labels_group_id_copy.rb @@ -0,0 +1,21 @@ +# Copy of 20180202111106 - this one should run before 20171207150343 to fix issues related to +# the removal of groups with labels. + +class RemoveProjectLabelsGroupIdCopy < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + # rubocop:disable Migration/UpdateColumnInBatches + update_column_in_batches(:labels, :group_id, nil) do |table, query| + query.where(table[:type].eq('ProjectLabel').and(table[:group_id].not_eq(nil))) + end + # rubocop:enable Migration/UpdateColumnInBatches + end + + def down + end +end diff --git a/db/post_migrate/20180202111106_remove_project_labels_group_id.rb b/db/post_migrate/20180202111106_remove_project_labels_group_id.rb new file mode 100644 index 00000000000..db7fd0d167d --- /dev/null +++ b/db/post_migrate/20180202111106_remove_project_labels_group_id.rb @@ -0,0 +1,19 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class RemoveProjectLabelsGroupId < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + update_column_in_batches(:labels, :group_id, nil) do |table, query| + query.where(table[:type].eq('ProjectLabel').and(table[:group_id].not_eq(nil))) + end + end + + def down + end +end diff --git a/db/post_migrate/20180204200836_change_author_id_to_not_null_in_todos.rb b/db/post_migrate/20180204200836_change_author_id_to_not_null_in_todos.rb new file mode 100644 index 00000000000..92c32feebf7 --- /dev/null +++ b/db/post_migrate/20180204200836_change_author_id_to_not_null_in_todos.rb @@ -0,0 +1,26 @@ +class ChangeAuthorIdToNotNullInTodos < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + class Todo < ActiveRecord::Base + self.table_name = 'todos' + include EachBatch + end + + BATCH_SIZE = 1000 + + DOWNTIME = false + + disable_ddl_transaction! + + def up + Todo.where(author_id: nil).each_batch(of: BATCH_SIZE) do |batch| + batch.delete_all + end + + change_column_null :todos, :author_id, false + end + + def down + change_column_null :todos, :author_id, true + end +end diff --git a/db/schema.rb b/db/schema.rb index 08af208e652..82ebe4369dd 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: 20180119121225) do +ActiveRecord::Schema.define(version: 20180204200836) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -886,6 +886,7 @@ ActiveRecord::Schema.define(version: 20180119121225) do add_index "issues", ["relative_position"], name: "index_issues_on_relative_position", using: :btree add_index "issues", ["state"], name: "index_issues_on_state", using: :btree add_index "issues", ["title"], name: "index_issues_on_title_trigram", using: :gin, opclasses: {"title"=>"gin_trgm_ops"} + add_index "issues", ["updated_at"], name: "index_issues_on_updated_at", using: :btree add_index "issues", ["updated_by_id"], name: "index_issues_on_updated_by_id", where: "(updated_by_id IS NOT NULL)", using: :btree create_table "keys", force: :cascade do |t| @@ -1706,7 +1707,7 @@ ActiveRecord::Schema.define(version: 20180119121225) do t.integer "project_id", null: false t.integer "target_id" t.string "target_type", null: false - t.integer "author_id" + t.integer "author_id", null: false t.integer "action", null: false t.string "state", null: false t.datetime "created_at" @@ -1726,7 +1727,7 @@ ActiveRecord::Schema.define(version: 20180119121225) do t.integer "project_id", null: false end - add_index "trending_projects", ["project_id"], name: "index_trending_projects_on_project_id", using: :btree + add_index "trending_projects", ["project_id"], name: "index_trending_projects_on_project_id", unique: true, using: :btree create_table "u2f_registrations", force: :cascade do |t| t.text "certificate" @@ -1750,11 +1751,13 @@ ActiveRecord::Schema.define(version: 20180119121225) do t.string "model_type" t.string "uploader", null: false t.datetime "created_at", null: false + t.string "mount_point" + t.string "secret" end add_index "uploads", ["checksum"], name: "index_uploads_on_checksum", using: :btree add_index "uploads", ["model_id", "model_type"], name: "index_uploads_on_model_id_and_model_type", using: :btree - add_index "uploads", ["path"], name: "index_uploads_on_path", using: :btree + add_index "uploads", ["uploader", "path"], name: "index_uploads_on_uploader_and_path", using: :btree create_table "user_agent_details", force: :cascade do |t| t.string "user_agent", null: false @@ -1768,6 +1771,14 @@ ActiveRecord::Schema.define(version: 20180119121225) do add_index "user_agent_details", ["subject_id", "subject_type"], name: "index_user_agent_details_on_subject_id_and_subject_type", using: :btree + create_table "user_callouts", force: :cascade do |t| + t.integer "feature_name", null: false + t.integer "user_id", null: false + end + + add_index "user_callouts", ["user_id", "feature_name"], name: "index_user_callouts_on_user_id_and_feature_name", unique: true, using: :btree + add_index "user_callouts", ["user_id"], name: "index_user_callouts_on_user_id", using: :btree + create_table "user_custom_attributes", force: :cascade do |t| t.datetime_with_timezone "created_at", null: false t.datetime_with_timezone "updated_at", null: false @@ -2036,9 +2047,13 @@ ActiveRecord::Schema.define(version: 20180119121225) do add_foreign_key "system_note_metadata", "notes", name: "fk_d83a918cb1", on_delete: :cascade add_foreign_key "timelogs", "issues", name: "fk_timelogs_issues_issue_id", on_delete: :cascade add_foreign_key "timelogs", "merge_requests", name: "fk_timelogs_merge_requests_merge_request_id", on_delete: :cascade + add_foreign_key "todos", "notes", name: "fk_91d1f47b13", on_delete: :cascade add_foreign_key "todos", "projects", name: "fk_45054f9c45", on_delete: :cascade + add_foreign_key "todos", "users", column: "author_id", name: "fk_ccf0373936", on_delete: :cascade + add_foreign_key "todos", "users", name: "fk_d94154aa95", on_delete: :cascade add_foreign_key "trending_projects", "projects", on_delete: :cascade add_foreign_key "u2f_registrations", "users" + add_foreign_key "user_callouts", "users", on_delete: :cascade add_foreign_key "user_custom_attributes", "users", on_delete: :cascade add_foreign_key "user_synced_attributes_metadata", "users", on_delete: :cascade add_foreign_key "users_star_projects", "projects", name: "fk_22cd27ddfc", on_delete: :cascade |