Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2015-12-10 16:08:09 +0300
committerKamil Trzcinski <ayufan@ayufan.eu>2015-12-10 18:04:08 +0300
commit80f8074d01a310141984dad9dfe01a27b533e78a (patch)
tree7572628ea97b47ca3a2ff613bbfc8e2564256978 /db/migrate
parentd5c91bb9a601a1a344d94763654f0b0996857497 (diff)
Migrate SlackService and HipChat service
Diffstat (limited to 'db/migrate')
-rw-r--r--db/migrate/20151209145909_migrate_ci_emails.rb6
-rw-r--r--db/migrate/20151210125232_migrate_ci_slack_service.rb29
-rw-r--r--db/migrate/20151210125927_migrate_ci_hip_chat_service.rb30
3 files changed, 65 insertions, 0 deletions
diff --git a/db/migrate/20151209145909_migrate_ci_emails.rb b/db/migrate/20151209145909_migrate_ci_emails.rb
index ebf0e7d264f..964dde841ad 100644
--- a/db/migrate/20151209145909_migrate_ci_emails.rb
+++ b/db/migrate/20151209145909_migrate_ci_emails.rb
@@ -2,6 +2,9 @@ class MigrateCiEmails < ActiveRecord::Migration
include Gitlab::Database
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(
'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}, " \
@@ -13,4 +16,7 @@ class MigrateCiEmails < ActiveRecord::Migration
"WHERE ci_services.type = 'Ci::MailService' AND ci_services.active"
)
end
+
+ def down
+ end
end
diff --git a/db/migrate/20151210125232_migrate_ci_slack_service.rb b/db/migrate/20151210125232_migrate_ci_slack_service.rb
new file mode 100644
index 00000000000..4a5dfe866a5
--- /dev/null
+++ b/db/migrate/20151210125232_migrate_ci_slack_service.rb
@@ -0,0 +1,29 @@
+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
diff --git a/db/migrate/20151210125927_migrate_ci_hip_chat_service.rb b/db/migrate/20151210125927_migrate_ci_hip_chat_service.rb
new file mode 100644
index 00000000000..2fdaf5fb917
--- /dev/null
+++ b/db/migrate/20151210125927_migrate_ci_hip_chat_service.rb
@@ -0,0 +1,30 @@
+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