diff options
Diffstat (limited to 'db')
| -rw-r--r-- | db/migrate/20151012173029_set_jira_service_api_url.rb | 50 | ||||
| -rw-r--r-- | db/migrate/20151203162134_add_build_events_to_services.rb | 2 | ||||
| -rw-r--r-- | db/migrate/20151209144329_migrate_ci_web_hooks.rb | 3 | ||||
| -rw-r--r-- | db/migrate/20151210030143_add_unlock_token_to_user.rb | 5 | ||||
| -rw-r--r-- | db/migrate/20151210125928_add_ci_to_project.rb | 2 | ||||
| -rw-r--r-- | db/migrate/20151210125929_add_project_id_to_ci.rb | 2 | ||||
| -rw-r--r-- | db/migrate/20151210125930_migrate_ci_to_project.rb | 4 | ||||
| -rw-r--r-- | db/migrate/20151210125931_add_index_to_ci_tables.rb | 2 | ||||
| -rw-r--r-- | db/migrate/20151210125932_drop_null_for_ci_tables.rb | 2 | ||||
| -rw-r--r-- | db/schema.rb | 1 |
10 files changed, 68 insertions, 5 deletions
diff --git a/db/migrate/20151012173029_set_jira_service_api_url.rb b/db/migrate/20151012173029_set_jira_service_api_url.rb new file mode 100644 index 00000000000..2af99e0db0b --- /dev/null +++ b/db/migrate/20151012173029_set_jira_service_api_url.rb @@ -0,0 +1,50 @@ +class SetJiraServiceApiUrl < ActiveRecord::Migration + # This migration can be performed online without errors, but some Jira API calls may be missed + # when doing so because api_url is not yet available. + + def build_api_url_from_project_url(project_url, api_version) + # this is the exact logic previously used to build the Jira API URL from project_url + server = URI(project_url) + default_ports = [80, 443].include?(server.port) + server_url = "#{server.scheme}://#{server.host}" + server_url.concat(":#{server.port}") unless default_ports + "#{server_url}/rest/api/#{api_version}" + end + + def get_api_version_from_api_url(api_url) + match = /\/rest\/api\/(?<api_version>\w+)$/.match(api_url) + match && match['api_version'] + end + + def change + reversible do |dir| + select_all("SELECT id, properties FROM services WHERE services.type IN ('JiraService')").each do |jira_service| + id = jira_service["id"] + properties = JSON.parse(jira_service["properties"]) + properties_was = properties.clone + + dir.up do + # remove api_version and set api_url + if properties['api_version'].present? && properties['project_url'].present? + begin + properties['api_url'] ||= build_api_url_from_project_url(properties['project_url'], properties['api_version']) + rescue + # looks like project_url was not a valid URL. Do nothing. + end + end + properties.delete('api_version') if properties.include?('api_version') + end + + dir.down do + # remove api_url and set api_version (default to '2') + properties['api_version'] ||= get_api_version_from_api_url(properties['api_url']) || '2' + properties.delete('api_url') if properties.include?('api_url') + end + + if properties != properties_was + execute("UPDATE services SET properties = '#{quote_string(properties.to_json)}' WHERE id = #{id}") + end + end + end + end +end diff --git a/db/migrate/20151203162134_add_build_events_to_services.rb b/db/migrate/20151203162134_add_build_events_to_services.rb index a84be7db3f1..c5542cb864d 100644 --- a/db/migrate/20151203162134_add_build_events_to_services.rb +++ b/db/migrate/20151203162134_add_build_events_to_services.rb @@ -1,5 +1,5 @@ class AddBuildEventsToServices < ActiveRecord::Migration - def up + def change add_column :services, :build_events, :boolean, default: false, null: false add_column :web_hooks, :build_events, :boolean, default: false, null: false end diff --git a/db/migrate/20151209144329_migrate_ci_web_hooks.rb b/db/migrate/20151209144329_migrate_ci_web_hooks.rb index 825ba1973ff..d7e196e6763 100644 --- a/db/migrate/20151209144329_migrate_ci_web_hooks.rb +++ b/db/migrate/20151209144329_migrate_ci_web_hooks.rb @@ -10,4 +10,7 @@ class MigrateCiWebHooks < ActiveRecord::Migration 'JOIN projects ON ci_projects.gitlab_id = projects.id' ) end + + def down + end end diff --git a/db/migrate/20151210030143_add_unlock_token_to_user.rb b/db/migrate/20151210030143_add_unlock_token_to_user.rb new file mode 100644 index 00000000000..0ea66ba65df --- /dev/null +++ b/db/migrate/20151210030143_add_unlock_token_to_user.rb @@ -0,0 +1,5 @@ +class AddUnlockTokenToUser < ActiveRecord::Migration + def change + add_column :users, :unlock_token, :string + end +end diff --git a/db/migrate/20151210125928_add_ci_to_project.rb b/db/migrate/20151210125928_add_ci_to_project.rb index 8a65abab636..8c167f64a2b 100644 --- a/db/migrate/20151210125928_add_ci_to_project.rb +++ b/db/migrate/20151210125928_add_ci_to_project.rb @@ -1,5 +1,5 @@ class AddCiToProject < ActiveRecord::Migration - def up + def change 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 diff --git a/db/migrate/20151210125929_add_project_id_to_ci.rb b/db/migrate/20151210125929_add_project_id_to_ci.rb index 5d1cf543576..84273591fa2 100644 --- a/db/migrate/20151210125929_add_project_id_to_ci.rb +++ b/db/migrate/20151210125929_add_project_id_to_ci.rb @@ -1,5 +1,5 @@ class AddProjectIdToCi < ActiveRecord::Migration - def up + def change 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 diff --git a/db/migrate/20151210125930_migrate_ci_to_project.rb b/db/migrate/20151210125930_migrate_ci_to_project.rb index 75278997862..c32c7feb193 100644 --- a/db/migrate/20151210125930_migrate_ci_to_project.rb +++ b/db/migrate/20151210125930_migrate_ci_to_project.rb @@ -14,6 +14,10 @@ class MigrateCiToProject < ActiveRecord::Migration migrate_ci_service end + def down + # We can't reverse the data + 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") diff --git a/db/migrate/20151210125931_add_index_to_ci_tables.rb b/db/migrate/20151210125931_add_index_to_ci_tables.rb index 9fedb5d612c..5e129c9303d 100644 --- a/db/migrate/20151210125931_add_index_to_ci_tables.rb +++ b/db/migrate/20151210125931_add_index_to_ci_tables.rb @@ -1,5 +1,5 @@ class AddIndexToCiTables < ActiveRecord::Migration - def up + def change add_index :ci_builds, :gl_project_id add_index :ci_runner_projects, :gl_project_id add_index :ci_triggers, :gl_project_id diff --git a/db/migrate/20151210125932_drop_null_for_ci_tables.rb b/db/migrate/20151210125932_drop_null_for_ci_tables.rb index 0b007430b0c..c520c2ed56f 100644 --- a/db/migrate/20151210125932_drop_null_for_ci_tables.rb +++ b/db/migrate/20151210125932_drop_null_for_ci_tables.rb @@ -1,5 +1,5 @@ class DropNullForCiTables < ActiveRecord::Migration - def up + def change remove_index :ci_variables, :project_id remove_index :ci_runner_projects, :project_id change_column_null :ci_triggers, :project_id, true diff --git a/db/schema.rb b/db/schema.rb index 0167e30ff8b..60b42f7a473 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -837,6 +837,7 @@ ActiveRecord::Schema.define(version: 20151210125932) do t.integer "consumed_timestep" t.integer "layout", default: 0 t.boolean "hide_project_limit", default: false + t.string "unlock_token" end add_index "users", ["admin"], name: "index_users_on_admin", using: :btree |
