Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tatuya Kamada
gitlab-ce
Commits
e3657501
Commit
e3657501
authored
Dec 11, 2015
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enhance migrate CI emails
parent
dc4e2744
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
4 deletions
+23
-4
db/migrate/20151209145909_migrate_ci_emails.rb
db/migrate/20151209145909_migrate_ci_emails.rb
+23
-4
No files found.
db/migrate/20151209145909_migrate_ci_emails.rb
View file @
e3657501
...
...
@@ -3,13 +3,16 @@ class MigrateCiEmails < ActiveRecord::Migration
def
up
# This inserts a new service: BuildsEmailService
# It
also
"manually" constructs the properties (JSON-encoded)
# It "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
}
, "
\
"CONCAT('{
\"
notify_only_broken_builds
\"
:
\"
', ci_projects.email_only_broken_builds, "
\
"'
\"
,
\"
add_pusher
\"
:
\"
', ci_projects.email_add_pusher, '
\"
,
\"
recipients
\"
:
\"
', ci_projects.email_recipients, '
\"
}') "
\
"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
}
, "
\
"CONCAT('{
\"
notify_only_broken_builds
\"
:
\"
',
#{
convert_bool
(
'ci_projects.email_only_broken_builds'
)
}
, "
\
"'
\"
,
\"
add_pusher
\"
:
\"
',
#{
convert_bool
(
'ci_projects.email_add_pusher'
)
}
, "
\
"'
\"
,
\"
recipients
\"
:
\"
',
#{
escape_text
(
'ci_projects.email_recipients'
)
}
, "
\
"'
\"
}') "
\
'FROM ci_services '
\
'JOIN ci_projects ON ci_services.project_id = ci_projects.id '
\
'JOIN projects ON ci_projects.gitlab_id = projects.id '
\
...
...
@@ -19,4 +22,20 @@ class MigrateCiEmails < ActiveRecord::Migration
def
down
end
# This function escapes double-quotes and slash
def
escape_text
(
name
)
"REPLACE(REPLACE(
#{
name
}
, '
\\
', '
\\\\
'), '
\"
', '
\\\"
')"
end
# This function returns 0 or 1 for column
def
convert_bool
(
name
)
if
self
.
postgresql?
# PostgreSQL uses BOOLEAN type
"CASE WHEN
#{
name
}
IS TRUE THEN '1' ELSE '0' END;"
else
# MySQL uses TINYINT
"
#{
name
}
"
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment