From e80e3f5372d6bcad1fbe04a85b3086bb66794828 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Fri, 4 Dec 2015 12:55:23 +0100 Subject: Migrate CI::Project to Project --- db/migrate/20151203162135_add_ci_to_project.rb | 10 ++++++ db/migrate/20151204110124_add_project_id_to_ci.rb | 8 +++++ db/migrate/20151204110613_migrate_ci_to_project.rb | 36 ++++++++++++++++++++++ .../20151204110832_add_index_to_ci_tables.rb | 11 +++++++ .../20151204123933_drop_null_for_ci_tables.rb | 9 ++++++ db/schema.rb | 29 ++++++++++++----- 6 files changed, 96 insertions(+), 7 deletions(-) create mode 100644 db/migrate/20151203162135_add_ci_to_project.rb create mode 100644 db/migrate/20151204110124_add_project_id_to_ci.rb create mode 100644 db/migrate/20151204110613_migrate_ci_to_project.rb create mode 100644 db/migrate/20151204110832_add_index_to_ci_tables.rb create mode 100644 db/migrate/20151204123933_drop_null_for_ci_tables.rb (limited to 'db') diff --git a/db/migrate/20151203162135_add_ci_to_project.rb b/db/migrate/20151203162135_add_ci_to_project.rb new file mode 100644 index 00000000000..e95942666c3 --- /dev/null +++ b/db/migrate/20151203162135_add_ci_to_project.rb @@ -0,0 +1,10 @@ +class AddCiToProject < ActiveRecord::Migration + def up + add_column :projects, :builds_enabled, :boolean, default: true, null: false + add_column :projects, :shared_runners_enabled, :boolean, default: true, null: false + add_column :projects, :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 new file mode 100644 index 00000000000..5d1cf543576 --- /dev/null +++ b/db/migrate/20151204110124_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/20151204110613_migrate_ci_to_project.rb b/db/migrate/20151204110613_migrate_ci_to_project.rb new file mode 100644 index 00000000000..1777b6170b4 --- /dev/null +++ b/db/migrate/20151204110613_migrate_ci_to_project.rb @@ -0,0 +1,36 @@ +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('shared_runners_enabled') + migrate_project_column('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 #{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 new file mode 100644 index 00000000000..b95931334c6 --- /dev/null +++ b/db/migrate/20151204110832_add_index_to_ci_tables.rb @@ -0,0 +1,11 @@ +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, :token + add_index :projects, :builds_enabled + add_index :projects, [:builds_enabled, :shared_runners_enabled] + end +end diff --git a/db/migrate/20151204123933_drop_null_for_ci_tables.rb b/db/migrate/20151204123933_drop_null_for_ci_tables.rb new file mode 100644 index 00000000000..0b007430b0c --- /dev/null +++ b/db/migrate/20151204123933_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 6ccd4404219..fd9004faa29 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: 20151210125927) do +ActiveRecord::Schema.define(version: 20151204123933) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -110,6 +110,7 @@ ActiveRecord::Schema.define(version: 20151210125927) do t.string "target_url" t.string "description" t.text "artifacts_file" + t.integer "gl_project_id" end add_index "ci_builds", ["commit_id", "stage_idx", "created_at"], name: "index_ci_builds_on_commit_id_and_stage_idx_and_created_at", using: :btree @@ -117,6 +118,7 @@ ActiveRecord::Schema.define(version: 20151210125927) do add_index "ci_builds", ["commit_id", "type", "name", "ref"], name: "index_ci_builds_on_commit_id_and_type_and_name_and_ref", using: :btree add_index "ci_builds", ["commit_id", "type", "ref"], name: "index_ci_builds_on_commit_id_and_type_and_ref", using: :btree add_index "ci_builds", ["commit_id"], name: "index_ci_builds_on_commit_id", using: :btree + add_index "ci_builds", ["gl_project_id"], name: "index_ci_builds_on_gl_project_id", using: :btree add_index "ci_builds", ["project_id", "commit_id"], name: "index_ci_builds_on_project_id_and_commit_id", using: :btree add_index "ci_builds", ["project_id"], name: "index_ci_builds_on_project_id", using: :btree add_index "ci_builds", ["runner_id"], name: "index_ci_builds_on_runner_id", using: :btree @@ -201,13 +203,14 @@ ActiveRecord::Schema.define(version: 20151210125927) do add_index "ci_projects", ["shared_runners_enabled"], name: "index_ci_projects_on_shared_runners_enabled", using: :btree create_table "ci_runner_projects", force: :cascade do |t| - t.integer "runner_id", null: false - t.integer "project_id", null: false + t.integer "runner_id", null: false + t.integer "project_id" t.datetime "created_at" t.datetime "updated_at" + t.integer "gl_project_id" end - add_index "ci_runner_projects", ["project_id"], name: "index_ci_runner_projects_on_project_id", using: :btree + add_index "ci_runner_projects", ["gl_project_id"], name: "index_ci_runner_projects_on_gl_project_id", using: :btree add_index "ci_runner_projects", ["runner_id"], name: "index_ci_runner_projects_on_runner_id", using: :btree create_table "ci_runners", force: :cascade do |t| @@ -277,24 +280,27 @@ ActiveRecord::Schema.define(version: 20151210125927) do create_table "ci_triggers", force: :cascade do |t| t.string "token" - t.integer "project_id", null: false + t.integer "project_id" t.datetime "deleted_at" t.datetime "created_at" t.datetime "updated_at" + t.integer "gl_project_id" end add_index "ci_triggers", ["deleted_at"], name: "index_ci_triggers_on_deleted_at", using: :btree + add_index "ci_triggers", ["gl_project_id"], name: "index_ci_triggers_on_gl_project_id", using: :btree create_table "ci_variables", force: :cascade do |t| - t.integer "project_id", null: false + t.integer "project_id" t.string "key" t.text "value" t.text "encrypted_value" t.string "encrypted_value_salt" t.string "encrypted_value_iv" + t.integer "gl_project_id" end - add_index "ci_variables", ["project_id"], name: "index_ci_variables_on_project_id", using: :btree + add_index "ci_variables", ["gl_project_id"], name: "index_ci_variables_on_gl_project_id", using: :btree create_table "ci_web_hooks", force: :cascade do |t| t.string "url", null: false @@ -649,14 +655,23 @@ ActiveRecord::Schema.define(version: 20151210125927) do t.string "import_source" t.integer "commit_count", default: 0 t.text "import_error" + t.boolean "builds_enabled", default: true, null: false + t.boolean "shared_runners_enabled", default: true, null: false + t.string "token" + t.string "build_coverage_regex" + t.boolean "build_allow_git_fetch", default: true, null: false + t.integer "build_timeout", default: 3600, null: false end + 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", ["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", ["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 From 8cdd54cc0696b76daa2baf463d02d944b50bac6a Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Thu, 10 Dec 2015 17:29:44 +0100 Subject: Add runners token --- db/migrate/20151203162135_add_ci_to_project.rb | 3 ++- db/migrate/20151204110613_migrate_ci_to_project.rb | 7 ++++--- db/migrate/20151204110832_add_index_to_ci_tables.rb | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) (limited to 'db') diff --git a/db/migrate/20151203162135_add_ci_to_project.rb b/db/migrate/20151203162135_add_ci_to_project.rb index e95942666c3..8a65abab636 100644 --- a/db/migrate/20151203162135_add_ci_to_project.rb +++ b/db/migrate/20151203162135_add_ci_to_project.rb @@ -1,8 +1,9 @@ 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, :token, :string + 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 diff --git a/db/migrate/20151204110613_migrate_ci_to_project.rb b/db/migrate/20151204110613_migrate_ci_to_project.rb index 1777b6170b4..d17b2a425f8 100644 --- a/db/migrate/20151204110613_migrate_ci_to_project.rb +++ b/db/migrate/20151204110613_migrate_ci_to_project.rb @@ -5,8 +5,9 @@ class MigrateCiToProject < ActiveRecord::Migration migrate_project_id_for_table('ci_variables') migrate_project_id_for_builds - migrate_project_column('shared_runners_enabled') - migrate_project_column('token') + 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') @@ -25,7 +26,7 @@ class MigrateCiToProject < ActiveRecord::Migration def migrate_project_column(column, new_column = nil) new_column ||= column - subquery = "SELECT #{column} FROM ci_projects WHERE projects.id = ci_projects.gitlab_id" + 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 diff --git a/db/migrate/20151204110832_add_index_to_ci_tables.rb b/db/migrate/20151204110832_add_index_to_ci_tables.rb index b95931334c6..9fedb5d612c 100644 --- a/db/migrate/20151204110832_add_index_to_ci_tables.rb +++ b/db/migrate/20151204110832_add_index_to_ci_tables.rb @@ -4,8 +4,9 @@ class AddIndexToCiTables < ActiveRecord::Migration 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, :token + 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 -- cgit v1.2.1 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 (limited to 'db') 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