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
df5c3f36
Commit
df5c3f36
authored
May 18, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename users that had their namespace renamed
parent
e4eec191
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
1 deletion
+63
-1
db/post_migrate/20170518200835_rename_users_with_renamed_namespace.rb
...ate/20170518200835_rename_users_with_renamed_namespace.rb
+43
-0
db/schema.rb
db/schema.rb
+1
-1
spec/migrations/rename_users_with_renamed_namespace_spec.rb
spec/migrations/rename_users_with_renamed_namespace_spec.rb
+19
-0
No files found.
db/post_migrate/20170518200835_rename_users_with_renamed_namespace.rb
0 → 100644
View file @
df5c3f36
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class
RenameUsersWithRenamedNamespace
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
DISALLOWED_ROOT_PATHS
=
%w[
-
abuse_reports
api
autocomplete
explore
health_check
import
invites
jwt
koding
member
notification_settings
oauth
sent_notifications
unicorn_test
uploads
users
]
def
up
namespace_table
=
Arel
::
Table
.
new
(
'namespaces'
)
users_table
=
Arel
::
Table
.
new
(
'users'
)
matching_path
=
namespace_table
.
project
(
namespace_table
[
:path
])
.
join
(
users_table
).
on
(
users_table
[
:id
].
eq
(
namespace_table
[
:owner_id
]))
.
where
(
users_table
[
:username
].
not_eq
(
namespace_table
[
:path
]))
path_name
=
Arel
::
Nodes
::
SqlLiteral
.
new
(
"matching_path.path FROM (
#{
matching_path
.
to_sql
}
) as matching_path"
)
update_column_in_batches
(
:users
,
:username
,
path_name
)
do
|
table
,
query
|
query
.
where
(
table
[
:username
].
matches_any
(
DISALLOWED_ROOT_PATHS
))
end
end
def
down
end
end
db/schema.rb
View file @
df5c3f36
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
2017051
6183131
)
do
ActiveRecord
::
Schema
.
define
(
version:
2017051
8200835
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
...
...
spec/migrations/rename_users_with_renamed_namespace_spec.rb
0 → 100644
View file @
df5c3f36
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20170518200835_rename_users_with_renamed_namespace.rb'
)
describe
RenameUsersWithRenamedNamespace
,
truncate:
true
do
it
'renames a user that had his namespace renamed to the namespace path'
do
other_user
=
create
(
:user
,
username:
'kodingu'
)
user
=
create
(
:user
,
username:
"Users0"
)
user
.
update_attribute
(
:username
,
'Users'
)
user1
=
create
(
:user
,
username:
"import0"
)
user1
.
update_attribute
(
:username
,
'import'
)
described_class
.
new
.
up
expect
(
user
.
reload
.
username
).
to
eq
(
'Users0'
)
expect
(
user1
.
reload
.
username
).
to
eq
(
'import0'
)
expect
(
other_user
.
reload
.
username
).
to
eq
(
'kodingu'
)
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