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
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/migrate
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/migrate')
-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
5 files changed, 77 insertions, 0 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