From 270d49ffcca150e7483e7785c86701b2f7e31be2 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Thu, 2 Mar 2017 05:07:41 +0800 Subject: [PATCH 1/6] Remove various unused CI tables and column --- app/services/ci/retry_build_service.rb | 2 +- .../unreleased/remove-unused-ci-tables.yml | 4 ++ ...639_remove_unused_ci_tables_and_columns.rb | 20 +++++++ db/schema.rb | 59 +------------------ 4 files changed, 26 insertions(+), 59 deletions(-) create mode 100644 changelogs/unreleased/remove-unused-ci-tables.yml create mode 100644 db/migrate/20170301205639_remove_unused_ci_tables_and_columns.rb diff --git a/app/services/ci/retry_build_service.rb b/app/services/ci/retry_build_service.rb index 38ef323f6e5b..595125765dc4 100644 --- a/app/services/ci/retry_build_service.rb +++ b/app/services/ci/retry_build_service.rb @@ -12,7 +12,7 @@ class RetryBuildService < ::BaseService queued_at erased_by erased_at].freeze IGNORE_ATTRIBUTES = %i[type lock_version gl_project_id target_url - deploy job_id description].freeze + description].freeze def execute(build) reprocess(build).tap do |new_build| diff --git a/changelogs/unreleased/remove-unused-ci-tables.yml b/changelogs/unreleased/remove-unused-ci-tables.yml new file mode 100644 index 000000000000..fccfb882bd93 --- /dev/null +++ b/changelogs/unreleased/remove-unused-ci-tables.yml @@ -0,0 +1,4 @@ +--- +title: Remove various unused CI tables and columns +merge_request: 9639 +author: diff --git a/db/migrate/20170301205639_remove_unused_ci_tables_and_columns.rb b/db/migrate/20170301205639_remove_unused_ci_tables_and_columns.rb new file mode 100644 index 000000000000..cf738652b691 --- /dev/null +++ b/db/migrate/20170301205639_remove_unused_ci_tables_and_columns.rb @@ -0,0 +1,20 @@ +class RemoveUnusedCiTablesAndColumns < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def change + %w[ci_application_settings + ci_events + ci_jobs + ci_sessions + ci_taggings + ci_tags].each do |table| + drop_table(table) + end + + remove_column :ci_commits, :push_data + remove_column :ci_builds, :job_id + remove_column :ci_builds, :deploy + end +end diff --git a/db/schema.rb b/db/schema.rb index cd5aa3392692..2c592ec7af4f 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: 20170217151947) do +ActiveRecord::Schema.define(version: 20170301205639) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -172,13 +172,6 @@ add_index "chat_names", ["service_id", "team_id", "chat_id"], name: "index_chat_names_on_service_id_and_team_id_and_chat_id", unique: true, using: :btree add_index "chat_names", ["user_id", "service_id"], name: "index_chat_names_on_user_id_and_service_id", unique: true, using: :btree - create_table "ci_application_settings", force: :cascade do |t| - t.boolean "all_broken_builds" - t.boolean "add_pusher" - t.datetime "created_at" - t.datetime "updated_at" - end - create_table "ci_builds", force: :cascade do |t| t.integer "project_id" t.string "status" @@ -191,9 +184,7 @@ t.float "coverage" t.integer "commit_id" t.text "commands" - t.integer "job_id" t.string "name" - t.boolean "deploy", default: false t.text "options" t.boolean "allow_failure", default: false, null: false t.string "stage" @@ -237,7 +228,6 @@ t.string "ref" t.string "sha" t.string "before_sha" - t.text "push_data" t.datetime "created_at" t.datetime "updated_at" t.boolean "tag", default: false @@ -258,29 +248,6 @@ add_index "ci_commits", ["status"], name: "index_ci_commits_on_status", using: :btree add_index "ci_commits", ["user_id"], name: "index_ci_commits_on_user_id", using: :btree - create_table "ci_events", force: :cascade do |t| - t.integer "project_id" - t.integer "user_id" - t.integer "is_admin" - t.text "description" - t.datetime "created_at" - t.datetime "updated_at" - end - - create_table "ci_jobs", force: :cascade do |t| - t.integer "project_id", null: false - t.text "commands" - t.boolean "active", default: true, null: false - t.datetime "created_at" - t.datetime "updated_at" - t.string "name" - t.boolean "build_branches", default: true, null: false - t.boolean "build_tags", default: false, null: false - t.string "job_type", default: "parallel" - t.string "refs" - t.datetime "deleted_at" - end - create_table "ci_projects", force: :cascade do |t| t.string "name" t.integer "timeout", default: 3600, null: false @@ -336,30 +303,6 @@ add_index "ci_runners", ["locked"], name: "index_ci_runners_on_locked", using: :btree add_index "ci_runners", ["token"], name: "index_ci_runners_on_token", using: :btree - create_table "ci_sessions", force: :cascade do |t| - t.string "session_id", null: false - t.text "data" - t.datetime "created_at" - t.datetime "updated_at" - end - - create_table "ci_taggings", force: :cascade do |t| - t.integer "tag_id" - t.integer "taggable_id" - t.string "taggable_type" - t.integer "tagger_id" - t.string "tagger_type" - t.string "context", limit: 128 - t.datetime "created_at" - end - - add_index "ci_taggings", ["taggable_id", "taggable_type", "context"], name: "index_ci_taggings_on_taggable_id_and_taggable_type_and_context", using: :btree - - create_table "ci_tags", force: :cascade do |t| - t.string "name" - t.integer "taggings_count", default: 0 - end - create_table "ci_trigger_requests", force: :cascade do |t| t.integer "trigger_id", null: false t.text "variables" -- GitLab From 2a523b455cff23339fcd202f652850b33c5a2876 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Fri, 3 Mar 2017 17:32:04 +0800 Subject: [PATCH 2/6] Require downtime, feedback: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/9639/diffs#note_24610182 --- .../20170301205639_remove_unused_ci_tables_and_columns.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/db/migrate/20170301205639_remove_unused_ci_tables_and_columns.rb b/db/migrate/20170301205639_remove_unused_ci_tables_and_columns.rb index cf738652b691..b22446d68279 100644 --- a/db/migrate/20170301205639_remove_unused_ci_tables_and_columns.rb +++ b/db/migrate/20170301205639_remove_unused_ci_tables_and_columns.rb @@ -1,7 +1,10 @@ class RemoveUnusedCiTablesAndColumns < ActiveRecord::Migration include Gitlab::Database::MigrationHelpers - DOWNTIME = false + DOWNTIME = true + DOWNTIME_REASON = + 'Remove unused columns in used tables.' \ + ' Downtime required in case Rails caches them' def change %w[ci_application_settings -- GitLab From 192f037cffa64b405ae35c8bb26dc04068c74efc Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Fri, 3 Mar 2017 17:35:58 +0800 Subject: [PATCH 3/6] Make reversing removal of columns work by specifying datatype --- .../20170301205639_remove_unused_ci_tables_and_columns.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/db/migrate/20170301205639_remove_unused_ci_tables_and_columns.rb b/db/migrate/20170301205639_remove_unused_ci_tables_and_columns.rb index b22446d68279..4e18af7f9176 100644 --- a/db/migrate/20170301205639_remove_unused_ci_tables_and_columns.rb +++ b/db/migrate/20170301205639_remove_unused_ci_tables_and_columns.rb @@ -16,8 +16,8 @@ def change drop_table(table) end - remove_column :ci_commits, :push_data - remove_column :ci_builds, :job_id - remove_column :ci_builds, :deploy + remove_column :ci_commits, :push_data, :text + remove_column :ci_builds, :job_id, :integer + remove_column :ci_builds, :deploy, :boolean end end -- GitLab From c9acdd071c8b535dfc71bdcfb871825218e99c04 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Fri, 3 Mar 2017 18:32:04 +0800 Subject: [PATCH 4/6] Make the migration reversible properly --- ...639_remove_unused_ci_tables_and_columns.rb | 62 ++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/db/migrate/20170301205639_remove_unused_ci_tables_and_columns.rb b/db/migrate/20170301205639_remove_unused_ci_tables_and_columns.rb index 4e18af7f9176..1784cc92e953 100644 --- a/db/migrate/20170301205639_remove_unused_ci_tables_and_columns.rb +++ b/db/migrate/20170301205639_remove_unused_ci_tables_and_columns.rb @@ -6,7 +6,7 @@ class RemoveUnusedCiTablesAndColumns < ActiveRecord::Migration 'Remove unused columns in used tables.' \ ' Downtime required in case Rails caches them' - def change + def up %w[ci_application_settings ci_events ci_jobs @@ -20,4 +20,64 @@ def change remove_column :ci_builds, :job_id, :integer remove_column :ci_builds, :deploy, :boolean end + + def down + add_column :ci_builds, :deploy, :boolean + add_column :ci_builds, :job_id, :integer + add_column :ci_commits, :push_data, :text + + create_table "ci_tags", force: :cascade do |t| + t.string "name" + t.integer "taggings_count", default: 0 + end + + create_table "ci_taggings", force: :cascade do |t| + t.integer "tag_id" + t.integer "taggable_id" + t.string "taggable_type" + t.integer "tagger_id" + t.string "tagger_type" + t.string "context", limit: 128 + t.datetime "created_at" + end + + add_index "ci_taggings", ["taggable_id", "taggable_type", "context"] + + create_table "ci_sessions", force: :cascade do |t| + t.string "session_id", null: false + t.text "data" + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "ci_jobs", force: :cascade do |t| + t.integer "project_id", null: false + t.text "commands" + t.boolean "active", default: true, null: false + t.datetime "created_at" + t.datetime "updated_at" + t.string "name" + t.boolean "build_branches", default: true, null: false + t.boolean "build_tags", default: false, null: false + t.string "job_type", default: "parallel" + t.string "refs" + t.datetime "deleted_at" + end + + create_table "ci_events", force: :cascade do |t| + t.integer "project_id" + t.integer "user_id" + t.integer "is_admin" + t.text "description" + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "ci_application_settings", force: :cascade do |t| + t.boolean "all_broken_builds" + t.boolean "add_pusher" + t.datetime "created_at" + t.datetime "updated_at" + end + end end -- GitLab From 9f98472b99be9a0e5e5b66972e9963fd333c1446 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Fri, 3 Mar 2017 19:34:39 +0800 Subject: [PATCH 5/6] Use %w[] for rubocop --- .../20170301205639_remove_unused_ci_tables_and_columns.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20170301205639_remove_unused_ci_tables_and_columns.rb b/db/migrate/20170301205639_remove_unused_ci_tables_and_columns.rb index 1784cc92e953..bc7753a9190e 100644 --- a/db/migrate/20170301205639_remove_unused_ci_tables_and_columns.rb +++ b/db/migrate/20170301205639_remove_unused_ci_tables_and_columns.rb @@ -41,7 +41,7 @@ def down t.datetime "created_at" end - add_index "ci_taggings", ["taggable_id", "taggable_type", "context"] + add_index "ci_taggings", %w[taggable_id taggable_type context] create_table "ci_sessions", force: :cascade do |t| t.string "session_id", null: false -- GitLab From 253ad1982d7cb897e418c0891b698b38b2997121 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Fri, 3 Mar 2017 20:09:42 +0800 Subject: [PATCH 6/6] Remove removed columns from expectation --- spec/services/ci/retry_build_service_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/services/ci/retry_build_service_spec.rb b/spec/services/ci/retry_build_service_spec.rb index 65af4e13118e..f29e2cdd10ca 100644 --- a/spec/services/ci/retry_build_service_spec.rb +++ b/spec/services/ci/retry_build_service_spec.rb @@ -19,7 +19,7 @@ erased_at].freeze IGNORE_ACCESSORS = - %i[type lock_version target_url gl_project_id deploy job_id base_tags + %i[type lock_version target_url gl_project_id base_tags commit_id deployments erased_by_id last_deployment project_id runner_id tag_taggings taggings tags trigger_request_id user_id].freeze -- GitLab