From a0c2a7b0cbb4567a1f09c4cbc400bf75df47a072 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Mon, 14 Dec 2015 11:04:47 +0100 Subject: Fix migrations [ci skip] --- db/migrate/20151209144329_migrate_ci_web_hooks.rb | 5 +++-- db/migrate/20151209145909_migrate_ci_emails.rb | 4 ++-- db/migrate/20151210125232_migrate_ci_slack_service.rb | 10 +++++++--- db/migrate/20151210125927_migrate_ci_hip_chat_service.rb | 10 +++++++--- 4 files changed, 19 insertions(+), 10 deletions(-) (limited to 'db/migrate') diff --git a/db/migrate/20151209144329_migrate_ci_web_hooks.rb b/db/migrate/20151209144329_migrate_ci_web_hooks.rb index 0293be3f6ce..825ba1973ff 100644 --- a/db/migrate/20151209144329_migrate_ci_web_hooks.rb +++ b/db/migrate/20151209144329_migrate_ci_web_hooks.rb @@ -3,8 +3,9 @@ class MigrateCiWebHooks < ActiveRecord::Migration def up execute( - 'INSERT INTO web_hooks (url, project_id, type, created_at, updated_at, push_events, build_events) ' \ - "SELECT ci_web_hooks.url, projects.id, 'ProjectHook', ci_web_hooks.created_at, ci_web_hooks.updated_at, #{false_value}, #{true_value} FROM ci_web_hooks " \ + 'INSERT INTO web_hooks (url, project_id, type, created_at, updated_at, push_events, issues_events, merge_requests_events, tag_push_events, note_events, build_events) ' \ + "SELECT ci_web_hooks.url, projects.id, 'ProjectHook', ci_web_hooks.created_at, ci_web_hooks.updated_at, " \ + "#{false_value}, #{false_value}, #{false_value}, #{false_value}, #{false_value}, #{true_value} FROM ci_web_hooks " \ 'JOIN ci_projects ON ci_web_hooks.project_id = ci_projects.id ' \ 'JOIN projects ON ci_projects.gitlab_id = projects.id' ) diff --git a/db/migrate/20151209145909_migrate_ci_emails.rb b/db/migrate/20151209145909_migrate_ci_emails.rb index 5ee11893582..202fac8e3fc 100644 --- a/db/migrate/20151209145909_migrate_ci_emails.rb +++ b/db/migrate/20151209145909_migrate_ci_emails.rb @@ -30,9 +30,9 @@ class MigrateCiEmails < ActiveRecord::Migration # This function returns 0 or 1 for column def convert_bool(name) - if self.postgresql? + if Gitlab::Database.postgresql? # PostgreSQL uses BOOLEAN type - "CASE WHEN #{name} IS TRUE THEN '1' ELSE '0' END;" + "CASE WHEN #{name} IS TRUE THEN '1' ELSE '0' END" else # MySQL uses TINYINT "#{name}" diff --git a/db/migrate/20151210125232_migrate_ci_slack_service.rb b/db/migrate/20151210125232_migrate_ci_slack_service.rb index 4a5dfe866a5..f14efa3e95d 100644 --- a/db/migrate/20151210125232_migrate_ci_slack_service.rb +++ b/db/migrate/20151210125232_migrate_ci_slack_service.rb @@ -4,16 +4,20 @@ class MigrateCiSlackService < ActiveRecord::Migration def up properties_query = 'SELECT properties FROM ci_services ' \ 'JOIN ci_projects ON ci_services.project_id=ci_projects.id ' \ - 'WHERE ci_projects.gitlab_id=services.project_id' + "WHERE ci_projects.gitlab_id=services.project_id AND ci_services.type='Ci::SlackService' AND ci_services.active " \ + 'LIMIT 1' active_query = 'SELECT 1 FROM ci_services ' \ 'JOIN ci_projects ON ci_services.project_id=ci_projects.id ' \ - "WHERE ci_projects.gitlab_id=services.project_id AND ci_services.type='Ci::SlackService' AND ci_services.active" + "WHERE ci_projects.gitlab_id=services.project_id AND ci_services.type='Ci::SlackService' AND ci_services.active " \ + 'LIMIT 1' # We update the service since services are always generated for project, even if they are inactive # Activate service and migrate properties if currently the service is not active execute( - "UPDATE services SET properties=(#{properties_query}), build_events=#{true_value}, active=#{true_value} " \ + "UPDATE services SET properties=(#{properties_query}), active=#{true_value}, " \ + "push_events=#{false_value}, issues_events=#{false_value}, merge_requests_events=#{false_value}, " \ + "tag_push_events=#{false_value}, note_events=#{false_value}, build_events=#{true_value} " \ "WHERE NOT services.active AND services.type='SlackService' AND (#{active_query}) IS NOT NULL" ) diff --git a/db/migrate/20151210125927_migrate_ci_hip_chat_service.rb b/db/migrate/20151210125927_migrate_ci_hip_chat_service.rb index 2fdaf5fb917..b9e04323576 100644 --- a/db/migrate/20151210125927_migrate_ci_hip_chat_service.rb +++ b/db/migrate/20151210125927_migrate_ci_hip_chat_service.rb @@ -5,16 +5,20 @@ class MigrateCiHipChatService < ActiveRecord::Migration # From properties strip `hipchat_` key properties_query = "SELECT REPLACE(properties, '\"hipchat_', '\"') FROM ci_services " \ 'JOIN ci_projects ON ci_services.project_id=ci_projects.id ' \ - 'WHERE ci_projects.gitlab_id=services.project_id' + "WHERE ci_projects.gitlab_id=services.project_id AND ci_services.type='Ci::HipChatService' AND ci_services.active " \ + 'LIMIT 1' active_query = 'SELECT 1 FROM ci_services ' \ 'JOIN ci_projects ON ci_services.project_id=ci_projects.id ' \ - "WHERE ci_projects.gitlab_id=services.project_id AND ci_services.type='Ci::HipchatService' AND ci_services.active" + "WHERE ci_projects.gitlab_id=services.project_id AND ci_services.type='Ci::HipChatService' AND ci_services.active " \ + 'LIMIT 1' # We update the service since services are always generated for project, even if they are inactive # Activate service and migrate properties if currently the service is not active execute( - "UPDATE services SET properties=(#{properties_query}), build_events=#{true_value}, active=#{true_value} " \ + "UPDATE services SET properties=(#{properties_query}), active=#{true_value}, " \ + "push_events=#{false_value}, issues_events=#{false_value}, merge_requests_events=#{false_value}, " \ + "tag_push_events=#{false_value}, note_events=#{false_value}, build_events=#{true_value} " \ "WHERE NOT services.active AND services.type='HipchatService' AND (#{active_query}) IS NOT NULL" ) -- cgit v1.2.3