BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
35273121
Commit
35273121
authored
Sep 13, 2017
by
Stan Hu
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'revert-
373ff978
' into 'master'
Revert "Merge branch 'rs-remove-bad-foreground-migration' into 'master'" See merge request !14253
parents
4879e438
652a9324
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
0 deletions
+57
-0
20170828135939_migrate_user_external_mail_data.rb
db/migrate/20170828135939_migrate_user_external_mail_data.rb
+57
-0
No files found.
db/migrate/20170828135939_migrate_user_external_mail_data.rb
0 → 100644
View file @
35273121
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class
MigrateUserExternalMailData
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
class
User
<
ActiveRecord
::
Base
self
.
table_name
=
'users'
include
EachBatch
end
class
UserSyncedAttributesMetadata
<
ActiveRecord
::
Base
self
.
table_name
=
'user_synced_attributes_metadata'
include
EachBatch
end
def
up
User
.
each_batch
do
|
batch
|
start_id
,
end_id
=
batch
.
pluck
(
'MIN(id), MAX(id)'
).
first
execute
<<-
EOF
INSERT INTO user_synced_attributes_metadata (user_id, provider, email_synced)
SELECT id, email_provider, external_email
FROM users
WHERE external_email = TRUE
AND NOT EXISTS (
SELECT true
FROM user_synced_attributes_metadata
WHERE user_id = users.id
AND provider = users.email_provider
)
AND id BETWEEN
#{
start_id
}
AND
#{
end_id
}
EOF
end
end
def
down
UserSyncedAttributesMetadata
.
each_batch
do
|
batch
|
start_id
,
end_id
=
batch
.
pluck
(
'MIN(id), MAX(id)'
).
first
execute
<<-
EOF
UPDATE users
SET users.email_provider = metadata.provider, users.external_email = metadata.email_synced
FROM user_synced_attributes_metadata as metadata, users
WHERE metadata.email_synced = TRUE
AND metadata.user_id = users.id
AND id BETWEEN
#{
start_id
}
AND
#{
end_id
}
EOF
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