Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2015-12-14 13:35:40 +0300
committerKamil Trzciński <ayufan@ayufan.eu>2015-12-14 13:35:40 +0300
commitc81023435795766411c5954a4676ebb215af40a6 (patch)
tree4b71817f8c5d6986c28b70353459a544fe444519 /db
parente81ae1e68c03de4442265e4699710421e2f2755c (diff)
parentbaa38f0dc1a0e1af84cd06a35450d772eee2d1c4 (diff)
Merge branch 'ci-project-migrate' into 'master'
Ci Project migrate - This doesn't migrate: allow_git_fetch, coverage_regex, timeout. Since this are project configuration settings I would propose to migrate them to `.gitlab-ci.yml`. - This requires offline migrations. - It simplifies database models making all CI objects to be attached to: Project. - It removes Ci::Project, but makes /ci/projects working by adding method: Project.find_by_ci_id for backward compatibility (badges, triggers). - We should add default `timeout` to Application Settings. - It misses specs. - It is based on ci-services-migrate for now. - It removes CI events. - It removes administrator CI projects overview. - It removes CI application settings. In 8.4 or 8.5 we can remove redundant tables and columns. See merge request !1987
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20151210125928_add_ci_to_project.rb11
-rw-r--r--db/migrate/20151210125929_add_project_id_to_ci.rb8
-rw-r--r--db/migrate/20151210125930_migrate_ci_to_project.rb37
-rw-r--r--db/migrate/20151210125931_add_index_to_ci_tables.rb12
-rw-r--r--db/migrate/20151210125932_drop_null_for_ci_tables.rb9
-rw-r--r--db/schema.rb35
6 files changed, 103 insertions, 9 deletions
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 6ccd4404219..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: 20151210125927) do
+ActiveRecord::Schema.define(version: 20151210125932) 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,13 +655,24 @@ ActiveRecord::Schema.define(version: 20151210125927) do
t.string "import_source"
t.integer "commit_count", default: 0
t.text "import_error"
- end
-
+ t.integer "ci_id"
+ t.boolean "builds_enabled", default: true, null: false
+ t.boolean "shared_runners_enabled", default: true, null: false
+ 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
+ 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", ["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", ["visibility_level"], name: "index_projects_on_visibility_level", using: :btree