Commit a0c2a7b0 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Fix migrations [ci skip]

parent 8b4cdc50
...@@ -3,8 +3,9 @@ class MigrateCiWebHooks < ActiveRecord::Migration ...@@ -3,8 +3,9 @@ class MigrateCiWebHooks < ActiveRecord::Migration
def up def up
execute( execute(
'INSERT INTO web_hooks (url, project_id, type, created_at, updated_at, push_events, build_events) ' \ '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}, #{true_value} FROM ci_web_hooks " \ "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 ci_projects ON ci_web_hooks.project_id = ci_projects.id ' \
'JOIN projects ON ci_projects.gitlab_id = projects.id' 'JOIN projects ON ci_projects.gitlab_id = projects.id'
) )
......
...@@ -30,9 +30,9 @@ class MigrateCiEmails < ActiveRecord::Migration ...@@ -30,9 +30,9 @@ class MigrateCiEmails < ActiveRecord::Migration
# This function returns 0 or 1 for column # This function returns 0 or 1 for column
def convert_bool(name) def convert_bool(name)
if self.postgresql? if Gitlab::Database.postgresql?
# PostgreSQL uses BOOLEAN type # 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 else
# MySQL uses TINYINT # MySQL uses TINYINT
"#{name}" "#{name}"
......
...@@ -4,16 +4,20 @@ class MigrateCiSlackService < ActiveRecord::Migration ...@@ -4,16 +4,20 @@ class MigrateCiSlackService < ActiveRecord::Migration
def up def up
properties_query = 'SELECT properties FROM ci_services ' \ properties_query = 'SELECT properties FROM ci_services ' \
'JOIN ci_projects ON ci_services.project_id=ci_projects.id ' \ '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 ' \ active_query = 'SELECT 1 FROM ci_services ' \
'JOIN ci_projects ON ci_services.project_id=ci_projects.id ' \ '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 # 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 # Activate service and migrate properties if currently the service is not active
execute( 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" "WHERE NOT services.active AND services.type='SlackService' AND (#{active_query}) IS NOT NULL"
) )
......
...@@ -5,16 +5,20 @@ class MigrateCiHipChatService < ActiveRecord::Migration ...@@ -5,16 +5,20 @@ class MigrateCiHipChatService < ActiveRecord::Migration
# From properties strip `hipchat_` key # From properties strip `hipchat_` key
properties_query = "SELECT REPLACE(properties, '\"hipchat_', '\"') FROM ci_services " \ properties_query = "SELECT REPLACE(properties, '\"hipchat_', '\"') FROM ci_services " \
'JOIN ci_projects ON ci_services.project_id=ci_projects.id ' \ '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 ' \ active_query = 'SELECT 1 FROM ci_services ' \
'JOIN ci_projects ON ci_services.project_id=ci_projects.id ' \ '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 # 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 # Activate service and migrate properties if currently the service is not active
execute( 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" "WHERE NOT services.active AND services.type='HipchatService' AND (#{active_query}) IS NOT NULL"
) )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment