Commit 80f8074d authored by Kamil Trzcinski's avatar Kamil Trzcinski

Migrate SlackService and HipChat service

parent d5c91bb9
...@@ -24,6 +24,8 @@ class BuildsEmailService < Service ...@@ -24,6 +24,8 @@ class BuildsEmailService < Service
boolean_accessor :notify_only_broken_builds boolean_accessor :notify_only_broken_builds
validates :recipients, presence: true, if: :activated? validates :recipients, presence: true, if: :activated?
default_value_for :notify_only_broken_builds, true
def title def title
'Builds emails' 'Builds emails'
end end
......
...@@ -25,6 +25,8 @@ class HipchatService < Service ...@@ -25,6 +25,8 @@ class HipchatService < Service
boolean_accessor :notify_only_broken_builds boolean_accessor :notify_only_broken_builds
validates :token, presence: true, if: :activated? validates :token, presence: true, if: :activated?
default_value_for :notify_only_broken_builds, true
def title def title
'HipChat' 'HipChat'
end end
......
...@@ -23,6 +23,8 @@ class SlackService < Service ...@@ -23,6 +23,8 @@ class SlackService < Service
boolean_accessor :notify_only_broken_builds boolean_accessor :notify_only_broken_builds
validates :webhook, presence: true, if: :activated? validates :webhook, presence: true, if: :activated?
default_value_for :notify_only_broken_builds, true
def title def title
'Slack' 'Slack'
end end
......
...@@ -2,6 +2,9 @@ class MigrateCiEmails < ActiveRecord::Migration ...@@ -2,6 +2,9 @@ class MigrateCiEmails < ActiveRecord::Migration
include Gitlab::Database include Gitlab::Database
def up def up
# This inserts a new service: BuildsEmailService
# It also "manually" constructs the properties (JSON-encoded)
# Migrating all ci_projects e-mail related columns
execute( execute(
'INSERT INTO services (project_id, type, created_at, updated_at, active, push_events, issues_events, merge_requests_events, tag_push_events, note_events, build_events, properties) ' \ 'INSERT INTO services (project_id, type, created_at, updated_at, active, push_events, issues_events, merge_requests_events, tag_push_events, note_events, build_events, properties) ' \
"SELECT projects.id, 'BuildsEmailService', ci_services.created_at, ci_services.updated_at, #{true_value}, #{false_value}, #{false_value}, #{false_value}, #{false_value}, #{false_value}, #{true_value}, " \ "SELECT projects.id, 'BuildsEmailService', ci_services.created_at, ci_services.updated_at, #{true_value}, #{false_value}, #{false_value}, #{false_value}, #{false_value}, #{false_value}, #{true_value}, " \
...@@ -13,4 +16,7 @@ class MigrateCiEmails < ActiveRecord::Migration ...@@ -13,4 +16,7 @@ class MigrateCiEmails < ActiveRecord::Migration
"WHERE ci_services.type = 'Ci::MailService' AND ci_services.active" "WHERE ci_services.type = 'Ci::MailService' AND ci_services.active"
) )
end end
def down
end
end end
class MigrateCiSlackService < ActiveRecord::Migration
include Gitlab::Database
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'
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"
# 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} " \
"WHERE NOT services.active AND services.type='SlackService' AND (#{active_query}) IS NOT NULL"
)
# Tick only build_events if the service is already active
execute(
"UPDATE services SET build_events=#{true_value} " \
"WHERE services.active AND services.type='SlackService' AND (#{active_query}) IS NOT NULL"
)
end
def down
end
end
class MigrateCiHipChatService < ActiveRecord::Migration
include Gitlab::Database
def up
# 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'
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"
# 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} " \
"WHERE NOT services.active AND services.type='HipchatService' AND (#{active_query}) IS NOT NULL"
)
# Tick only build_events if the service is already active
execute(
"UPDATE services SET build_events=#{true_value} " \
"WHERE services.active AND services.type='HipchatService' AND (#{active_query}) IS NOT NULL"
)
end
def down
end
end
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20151209145909) do ActiveRecord::Schema.define(version: 20151210125927) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
......
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