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
Boxiang Sun
gitlab-ce
Commits
537b45b7
Commit
537b45b7
authored
May 19, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename users on mysql
parent
bc58f51d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
4 deletions
+15
-4
db/post_migrate/20170518200835_rename_users_with_renamed_namespace.rb
...ate/20170518200835_rename_users_with_renamed_namespace.rb
+15
-4
No files found.
db/post_migrate/20170518200835_rename_users_with_renamed_namespace.rb
View file @
537b45b7
...
...
@@ -26,10 +26,21 @@ class RenameUsersWithRenamedNamespace < ActiveRecord::Migration
def
up
DISALLOWED_ROOT_PATHS
.
each
do
|
path
|
update_sql
=
"UPDATE users SET username = namespaces.path "
\
"FROM namespaces WHERE namespaces.owner_id = users.id "
\
"AND namespaces.type IS NULL "
\
"AND users.username ILIKE '
#{
path
}
'"
users
=
Arel
::
Table
.
new
(
:users
)
namespaces
=
Arel
::
Table
.
new
(
:namespaces
)
predicate
=
namespaces
[
:owner_id
].
eq
(
users
[
:id
])
.
and
(
namespaces
[
:type
].
eq
(
nil
))
.
and
(
users
[
:username
].
matches
(
path
))
update_sql
=
if
Gitlab
::
Database
.
postgresql?
"UPDATE users SET username = namespaces.path "
\
"FROM namespaces WHERE
#{
predicate
.
to_sql
}
"
else
"UPDATE users INNER JOIN namespaces "
\
"ON namespaces.owner_id = users.id "
\
"SET username = namespaces.path "
\
"WHERE
#{
predicate
.
to_sql
}
"
end
connection
.
execute
(
update_sql
)
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