summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorValery Sizov <vsv2711@gmail.com>2015-06-02 14:10:07 +0300
committerValery Sizov <vsv2711@gmail.com>2015-06-03 16:36:54 +0300
commitd61d6eea995bf4e87513124c9c2ccd1251ca6f3f (patch)
tree679712d7b17730ba72d6ec30e8e7ad2bca0eb1a9 /db
parent9d89ea49948ecb6bf6cf2df5d4bff6980616b295 (diff)
downloadgitlab-ci-d61d6eea995bf4e87513124c9c2ccd1251ca6f3f.tar.gz
Add migrator for deprecated jobs
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20150601043220_add_yaml_to_projects.rb9
-rw-r--r--db/migrate/20150601043222_migrate_jobs_to_yaml.rb61
-rw-r--r--db/schema.rb3
3 files changed, 72 insertions, 1 deletions
diff --git a/db/migrate/20150601043220_add_yaml_to_projects.rb b/db/migrate/20150601043220_add_yaml_to_projects.rb
new file mode 100644
index 0000000..f741842
--- /dev/null
+++ b/db/migrate/20150601043220_add_yaml_to_projects.rb
@@ -0,0 +1,9 @@
+class AddYamlToProjects < ActiveRecord::Migration
+ def up
+ add_column :projects, :generated_yaml_config, :text
+ end
+
+ def down
+ remove_column :projects, :generated_yaml_config
+ end
+end
diff --git a/db/migrate/20150601043222_migrate_jobs_to_yaml.rb b/db/migrate/20150601043222_migrate_jobs_to_yaml.rb
new file mode 100644
index 0000000..926863c
--- /dev/null
+++ b/db/migrate/20150601043222_migrate_jobs_to_yaml.rb
@@ -0,0 +1,61 @@
+class MigrateJobsToYaml < ActiveRecord::Migration
+ def up
+ select_all("SELECT * FROM projects").each do |project|
+ config = {jobs: [], deploy_jobs: []}
+
+ concatenate_expression = if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
+ "string_agg(tags.name, ',')"
+ else
+ "GROUP_CONCAT(string SEPARATOR ' ')"
+ end
+
+ sql = "SELECT j.*, #{concatenate_expression} tags
+ FROM jobs j
+ LEFT JOIN taggings tgs ON j.id = tgs.taggable_id AND tgs.taggable_type = 'Job'
+ LEFT JOIN tags ON tgs.tag_id = tags.id
+ WHERE project_id = #{project['id']}
+ AND active = true
+ AND job_type = 'parallel'
+ GROUP BY j.id"
+
+ # Create Jobs
+ select_all(sql).each do |job|
+ config[:jobs] << {
+ script: job["commands"],
+ name: job["name"],
+ branches: parse_boolean_value(job["build_branches"]),
+ tags: parse_boolean_value(job["build_tags"]),
+ runner: job["tags"]
+ }
+ end
+
+ # Create Deploy Jobs
+ select_all(sql.sub("parallel", 'deploy')).each do |job|
+ config[:deploy_jobs] << {
+ script: job["commands"],
+ name: job["name"],
+ refs: job["refs"],
+ runner: job["tags"]
+ }
+ end
+
+ config[:skip_refs] = project["skip_refs"]
+
+ yaml_config = YAML.dump(config.deep_stringify_keys)
+
+ yaml_config.sub!("---", "# This file is generated by GitLab CI")
+
+ execute("UPDATE projects SET generated_yaml_config = '#{quote_string(yaml_config)}' WHERE projects.id = #{project["id"]}")
+ end
+ end
+
+ def down
+
+ end
+
+ private
+
+ def parse_boolean_value(value)
+ [ true, 1, '1', 't', 'T', 'true', 'TRUE', 'on', 'ON' ].include?(value)
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index edfcb6d..6b40fc8 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: 20150529012113) do
+ActiveRecord::Schema.define(version: 20150601043222) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -102,6 +102,7 @@ ActiveRecord::Schema.define(version: 20150529012113) do
t.string "skip_refs"
t.string "coverage_regex"
t.boolean "shared_runners_enabled", default: false
+ t.text "generated_yaml_config"
end
create_table "runner_projects", force: true do |t|