From 91cdb08d5fa83a86f5f18088bf148e832732bed9 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Thu, 10 Dec 2015 18:08:59 +0100 Subject: Rename columns and rename migrations --- db/migrate/20151203162135_add_ci_to_project.rb | 11 ------- db/migrate/20151204110124_add_project_id_to_ci.rb | 8 ----- db/migrate/20151204110613_migrate_ci_to_project.rb | 37 ---------------------- .../20151204110832_add_index_to_ci_tables.rb | 12 ------- .../20151204123933_drop_null_for_ci_tables.rb | 9 ------ db/migrate/20151210125928_add_ci_to_project.rb | 11 +++++++ db/migrate/20151210125929_add_project_id_to_ci.rb | 8 +++++ db/migrate/20151210125930_migrate_ci_to_project.rb | 37 ++++++++++++++++++++++ .../20151210125931_add_index_to_ci_tables.rb | 12 +++++++ .../20151210125932_drop_null_for_ci_tables.rb | 9 ++++++ db/schema.rb | 8 +++-- 11 files changed, 82 insertions(+), 80 deletions(-) delete mode 100644 db/migrate/20151203162135_add_ci_to_project.rb delete mode 100644 db/migrate/20151204110124_add_project_id_to_ci.rb delete mode 100644 db/migrate/20151204110613_migrate_ci_to_project.rb delete mode 100644 db/migrate/20151204110832_add_index_to_ci_tables.rb delete mode 100644 db/migrate/20151204123933_drop_null_for_ci_tables.rb create mode 100644 db/migrate/20151210125928_add_ci_to_project.rb create mode 100644 db/migrate/20151210125929_add_project_id_to_ci.rb create mode 100644 db/migrate/20151210125930_migrate_ci_to_project.rb create mode 100644 db/migrate/20151210125931_add_index_to_ci_tables.rb create mode 100644 db/migrate/20151210125932_drop_null_for_ci_tables.rb diff --git a/db/migrate/20151203162135_add_ci_to_project.rb b/db/migrate/20151203162135_add_ci_to_project.rb deleted file mode 100644 index 8a65abab636..00000000000 --- a/db/migrate/20151203162135_add_ci_to_project.rb +++ /dev/null @@ -1,11 +0,0 @@ -class AddCiToProject < ActiveRecord::Migration - def up - add_column :projects, :ci_id, :integer - add_column :projects, :builds_enabled, :boolean, default: true, null: false - add_column :projects, :shared_runners_enabled, :boolean, default: true, null: false - add_column :projects, :runners_token, :string - add_column :projects, :build_coverage_regex, :string - add_column :projects, :build_allow_git_fetch, :boolean, default: true, null: false - add_column :projects, :build_timeout, :integer, default: 3600, null: false - end -end diff --git a/db/migrate/20151204110124_add_project_id_to_ci.rb b/db/migrate/20151204110124_add_project_id_to_ci.rb deleted file mode 100644 index 5d1cf543576..00000000000 --- a/db/migrate/20151204110124_add_project_id_to_ci.rb +++ /dev/null @@ -1,8 +0,0 @@ -class AddProjectIdToCi < ActiveRecord::Migration - def up - add_column :ci_builds, :gl_project_id, :integer - add_column :ci_runner_projects, :gl_project_id, :integer - add_column :ci_triggers, :gl_project_id, :integer - add_column :ci_variables, :gl_project_id, :integer - end -end diff --git a/db/migrate/20151204110613_migrate_ci_to_project.rb b/db/migrate/20151204110613_migrate_ci_to_project.rb deleted file mode 100644 index d17b2a425f8..00000000000 --- a/db/migrate/20151204110613_migrate_ci_to_project.rb +++ /dev/null @@ -1,37 +0,0 @@ -class MigrateCiToProject < ActiveRecord::Migration - def up - migrate_project_id_for_table('ci_runner_projects') - migrate_project_id_for_table('ci_triggers') - migrate_project_id_for_table('ci_variables') - migrate_project_id_for_builds - - migrate_project_column('id', 'ci_id') - migrate_project_column('shared_runners_enabled', 'shared_runners_enabled') - migrate_project_column('token', 'runners_token') - migrate_project_column('coverage_regex', 'build_coverage_regex') - migrate_project_column('allow_git_fetch', 'build_allow_git_fetch') - migrate_project_column('timeout', 'build_timeout') - migrate_ci_service - end - - def migrate_project_id_for_table(table) - subquery = "SELECT gitlab_id FROM ci_projects WHERE ci_projects.id = #{table}.project_id" - execute("UPDATE #{table} SET gl_project_id=(#{subquery}) WHERE gl_project_id IS NULL") - end - - def migrate_project_id_for_builds - subquery = 'SELECT gl_project_id FROM ci_commits WHERE ci_commits.id = ci_builds.commit_id' - execute("UPDATE ci_builds SET gl_project_id=(#{subquery}) WHERE gl_project_id IS NULL") - end - - def migrate_project_column(column, new_column = nil) - new_column ||= column - subquery = "SELECT ci_projects.#{column} FROM ci_projects WHERE projects.id = ci_projects.gitlab_id" - execute("UPDATE projects SET #{new_column}=(#{subquery}) WHERE #{new_column} IS NULL AND (#{subquery}) IS NOT NULL") - end - - def migrate_ci_service - subquery = "SELECT active FROM services WHERE projects.id = services.project_id AND type='GitlabCiService'" - execute("UPDATE projects SET builds_enabled=(#{subquery}) WHERE builds_enabled IS NULL AND (#{subquery}) IS NOT NULL") - end -end diff --git a/db/migrate/20151204110832_add_index_to_ci_tables.rb b/db/migrate/20151204110832_add_index_to_ci_tables.rb deleted file mode 100644 index 9fedb5d612c..00000000000 --- a/db/migrate/20151204110832_add_index_to_ci_tables.rb +++ /dev/null @@ -1,12 +0,0 @@ -class AddIndexToCiTables < ActiveRecord::Migration - def up - add_index :ci_builds, :gl_project_id - add_index :ci_runner_projects, :gl_project_id - add_index :ci_triggers, :gl_project_id - add_index :ci_variables, :gl_project_id - add_index :projects, :runners_token - add_index :projects, :builds_enabled - add_index :projects, [:builds_enabled, :shared_runners_enabled] - add_index :projects, [:ci_id] - end -end diff --git a/db/migrate/20151204123933_drop_null_for_ci_tables.rb b/db/migrate/20151204123933_drop_null_for_ci_tables.rb deleted file mode 100644 index 0b007430b0c..00000000000 --- a/db/migrate/20151204123933_drop_null_for_ci_tables.rb +++ /dev/null @@ -1,9 +0,0 @@ -class DropNullForCiTables < ActiveRecord::Migration - def up - remove_index :ci_variables, :project_id - remove_index :ci_runner_projects, :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 - end -end diff --git a/db/migrate/20151210125928_add_ci_to_project.rb b/db/migrate/20151210125928_add_ci_to_project.rb new file mode 100644 index 00000000000..8a65abab636 --- /dev/null +++ b/db/migrate/20151210125928_add_ci_to_project.rb @@ -0,0 +1,11 @@ +class AddCiToProject < ActiveRecord::Migration + def up + add_column :projects, :ci_id, :integer + add_column :projects, :builds_enabled, :boolean, default: true, null: false + add_column :projects, :shared_runners_enabled, :boolean, default: true, null: false + add_column :projects, :runners_token, :string + add_column :projects, :build_coverage_regex, :string + add_column :projects, :build_allow_git_fetch, :boolean, default: true, null: false + add_column :projects, :build_timeout, :integer, default: 3600, null: false + end +end diff --git a/db/migrate/20151210125929_add_project_id_to_ci.rb b/db/migrate/20151210125929_add_project_id_to_ci.rb new file mode 100644 index 00000000000..5d1cf543576 --- /dev/null +++ b/db/migrate/20151210125929_add_project_id_to_ci.rb @@ -0,0 +1,8 @@ +class AddProjectIdToCi < ActiveRecord::Migration + def up + add_column :ci_builds, :gl_project_id, :integer + add_column :ci_runner_projects, :gl_project_id, :integer + add_column :ci_triggers, :gl_project_id, :integer + add_column :ci_variables, :gl_project_id, :integer + end +end diff --git a/db/migrate/20151210125930_migrate_ci_to_project.rb b/db/migrate/20151210125930_migrate_ci_to_project.rb new file mode 100644 index 00000000000..d17b2a425f8 --- /dev/null +++ b/db/migrate/20151210125930_migrate_ci_to_project.rb @@ -0,0 +1,37 @@ +class MigrateCiToProject < ActiveRecord::Migration + def up + migrate_project_id_for_table('ci_runner_projects') + migrate_project_id_for_table('ci_triggers') + migrate_project_id_for_table('ci_variables') + migrate_project_id_for_builds + + migrate_project_column('id', 'ci_id') + migrate_project_column('shared_runners_enabled', 'shared_runners_enabled') + migrate_project_column('token', 'runners_token') + migrate_project_column('coverage_regex', 'build_coverage_regex') + migrate_project_column('allow_git_fetch', 'build_allow_git_fetch') + migrate_project_column('timeout', 'build_timeout') + migrate_ci_service + end + + def migrate_project_id_for_table(table) + subquery = "SELECT gitlab_id FROM ci_projects WHERE ci_projects.id = #{table}.project_id" + execute("UPDATE #{table} SET gl_project_id=(#{subquery}) WHERE gl_project_id IS NULL") + end + + def migrate_project_id_for_builds + subquery = 'SELECT gl_project_id FROM ci_commits WHERE ci_commits.id = ci_builds.commit_id' + execute("UPDATE ci_builds SET gl_project_id=(#{subquery}) WHERE gl_project_id IS NULL") + end + + def migrate_project_column(column, new_column = nil) + new_column ||= column + subquery = "SELECT ci_projects.#{column} FROM ci_projects WHERE projects.id = ci_projects.gitlab_id" + execute("UPDATE projects SET #{new_column}=(#{subquery}) WHERE #{new_column} IS NULL AND (#{subquery}) IS NOT NULL") + end + + def migrate_ci_service + subquery = "SELECT active FROM services WHERE projects.id = services.project_id AND type='GitlabCiService'" + execute("UPDATE projects SET builds_enabled=(#{subquery}) WHERE builds_enabled IS NULL AND (#{subquery}) IS NOT NULL") + end +end diff --git a/db/migrate/20151210125931_add_index_to_ci_tables.rb b/db/migrate/20151210125931_add_index_to_ci_tables.rb new file mode 100644 index 00000000000..9fedb5d612c --- /dev/null +++ b/db/migrate/20151210125931_add_index_to_ci_tables.rb @@ -0,0 +1,12 @@ +class AddIndexToCiTables < ActiveRecord::Migration + def up + add_index :ci_builds, :gl_project_id + add_index :ci_runner_projects, :gl_project_id + add_index :ci_triggers, :gl_project_id + add_index :ci_variables, :gl_project_id + add_index :projects, :runners_token + add_index :projects, :builds_enabled + add_index :projects, [:builds_enabled, :shared_runners_enabled] + add_index :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 new file mode 100644 index 00000000000..0b007430b0c --- /dev/null +++ b/db/migrate/20151210125932_drop_null_for_ci_tables.rb @@ -0,0 +1,9 @@ +class DropNullForCiTables < ActiveRecord::Migration + def up + remove_index :ci_variables, :project_id + remove_index :ci_runner_projects, :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 + end +end diff --git a/db/schema.rb b/db/schema.rb index fd9004faa29..d17930b84b0 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: 20151204123933) do +ActiveRecord::Schema.define(version: 20151210125932) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -655,9 +655,10 @@ ActiveRecord::Schema.define(version: 20151204123933) do t.string "import_source" t.integer "commit_count", default: 0 t.text "import_error" + t.integer "ci_id" t.boolean "builds_enabled", default: true, null: false t.boolean "shared_runners_enabled", default: true, null: false - t.string "token" + t.string "runners_token" t.string "build_coverage_regex" t.boolean "build_allow_git_fetch", default: true, null: false t.integer "build_timeout", default: 3600, null: false @@ -665,13 +666,14 @@ ActiveRecord::Schema.define(version: 20151204123933) do add_index "projects", ["builds_enabled", "shared_runners_enabled"], name: "index_projects_on_builds_enabled_and_shared_runners_enabled", using: :btree add_index "projects", ["builds_enabled"], name: "index_projects_on_builds_enabled", using: :btree + add_index "projects", ["ci_id"], name: "index_projects_on_ci_id", using: :btree add_index "projects", ["created_at", "id"], name: "index_projects_on_created_at_and_id", using: :btree add_index "projects", ["creator_id"], name: "index_projects_on_creator_id", using: :btree add_index "projects", ["last_activity_at"], name: "index_projects_on_last_activity_at", using: :btree add_index "projects", ["namespace_id"], name: "index_projects_on_namespace_id", using: :btree add_index "projects", ["path"], name: "index_projects_on_path", using: :btree + add_index "projects", ["runners_token"], name: "index_projects_on_runners_token", using: :btree add_index "projects", ["star_count"], name: "index_projects_on_star_count", using: :btree - add_index "projects", ["token"], name: "index_projects_on_token", using: :btree add_index "projects", ["visibility_level"], name: "index_projects_on_visibility_level", using: :btree create_table "protected_branches", force: :cascade do |t| -- cgit v1.2.1