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
Jérome Perrin
gitlab-ce
Commits
7d8dfccf
Commit
7d8dfccf
authored
Dec 08, 2014
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
speed up migration to identities
parent
bbf9953b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
9 deletions
+15
-9
db/migrate/20141121161704_add_identity_table.rb
db/migrate/20141121161704_add_identity_table.rb
+15
-9
No files found.
db/migrate/20141121161704_add_identity_table.rb
View file @
7d8dfccf
...
@@ -8,9 +8,11 @@ class AddIdentityTable < ActiveRecord::Migration
...
@@ -8,9 +8,11 @@ class AddIdentityTable < ActiveRecord::Migration
add_index
:identities
,
:user_id
add_index
:identities
,
:user_id
User
.
where
(
"provider IS NOT NULL"
).
find_each
do
|
user
|
execute
<<
eos
execute
"INSERT INTO identities(provider, extern_uid, user_id) VALUES('
#{
user
.
provider
}
', '
#{
user
.
extern_uid
}
', '
#{
user
.
id
}
')"
INSERT INTO identities (provider, extern_uid, user_id)
end
SELECT provider, extern_uid, id FROM users
WHERE provider IS NOT NULL
eos
remove_column
:users
,
:extern_uid
remove_column
:users
,
:extern_uid
remove_column
:users
,
:provider
remove_column
:users
,
:provider
...
@@ -20,12 +22,16 @@ class AddIdentityTable < ActiveRecord::Migration
...
@@ -20,12 +22,16 @@ class AddIdentityTable < ActiveRecord::Migration
add_column
:users
,
:extern_uid
,
:string
add_column
:users
,
:extern_uid
,
:string
add_column
:users
,
:provider
,
:string
add_column
:users
,
:provider
,
:string
User
.
where
(
"id IN(SELECT user_id FROM identities)"
).
find_each
do
|
user
|
if
ActiveRecord
::
Base
.
connection
.
adapter_name
==
'PostgreSQL'
identity
=
user
.
identities
.
last
execute
<<
eos
user
.
extern_uid
=
identity
.
extern_uid
UPDATE users u
user
.
provider
=
identity
.
provider
SET provider = i.provider, extern_uid = i.extern_uid
user
.
save
FROM identities i
end
WHERE i.user_id = u.id
eos
else
execute
"UPDATE users u, identities i SET u.provider = i.provider, u.extern_uid = i.extern_uid WHERE u.id = i.user_id"
end
drop_table
:identities
drop_table
:identities
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