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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
3e0b81c7
Commit
3e0b81c7
authored
Sep 22, 2020
by
George Koltsov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix CleanupGroupImportStatesWithNullUserId post deploy migration
parent
9ab4328f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
1 deletion
+30
-1
db/post_migrate/20200909161624_cleanup_group_import_states_with_null_user_id.rb
...09161624_cleanup_group_import_states_with_null_user_id.rb
+4
-1
spec/migrations/cleanup_group_import_states_with_null_user_id_spec.rb
...ons/cleanup_group_import_states_with_null_user_id_spec.rb
+26
-0
No files found.
db/post_migrate/20200909161624_cleanup_group_import_states_with_null_user_id.rb
View file @
3e0b81c7
...
...
@@ -19,7 +19,6 @@ class CleanupGroupImportStatesWithNullUserId < ActiveRecord::Migration[6.0]
class
Namespace
<
ActiveRecord
::
Base
self
.
table_name
=
'namespaces'
belongs_to
:parent
,
class_name:
'CleanupGroupImportStatesWithNullUserId::Namespace'
belongs_to
:owner
,
class_name:
'CleanupGroupImportStatesWithNullUserId::User'
end
...
...
@@ -39,6 +38,10 @@ class CleanupGroupImportStatesWithNullUserId < ActiveRecord::Migration[6.0]
owners
.
first
||
parent
&
.
default_owner
||
owner
end
def
parent
Group
.
find_by_id
(
parent_id
)
end
def
owners
Member
.
where
(
type:
'GroupMember'
,
source_type:
'Namespace'
,
source_id:
id
,
requested_at:
nil
,
access_level:
OWNER
).
map
(
&
:user
)
end
...
...
spec/migrations/cleanup_group_import_states_with_null_user_id_spec.rb
View file @
3e0b81c7
...
...
@@ -61,6 +61,32 @@ RSpec.describe CleanupGroupImportStatesWithNullUserId, :migration,
expect
{
group_import_state_3
.
reload
}.
to
raise_error
(
ActiveRecord
::
RecordNotFound
)
end
end
context
'when group has parent'
do
it
'updates user_id with parent group default owner id'
do
user
=
users_table
.
create!
(
name:
'user4'
,
email:
'user4@example.com'
,
projects_limit:
1
)
group_1
=
namespaces_table
.
create!
(
name:
'group_1'
,
path:
'group_1'
,
type:
'Group'
)
create_member
(
user_id:
user
.
id
,
type:
'GroupMember'
,
source_type:
'Namespace'
,
source_id:
group_1
.
id
,
access_level:
described_class
::
Group
::
OWNER
)
group_2
=
namespaces_table
.
create!
(
name:
'group_2'
,
path:
'group_2'
,
type:
'Group'
,
parent_id:
group_1
.
id
)
group_import_state
=
group_import_states_table
.
create!
(
group_id:
group_2
.
id
,
user_id:
nil
,
status:
0
)
disable_migrations_output
{
migrate!
}
expect
(
group_import_state
.
reload
.
user_id
).
to
eq
(
user
.
id
)
end
end
context
'when group has owner_id'
do
it
'updates user_id with owner_id'
do
user
=
users_table
.
create!
(
name:
'user'
,
email:
'user@example.com'
,
projects_limit:
1
)
group
=
namespaces_table
.
create!
(
name:
'group'
,
path:
'group'
,
type:
'Group'
,
owner_id:
user
.
id
)
group_import_state
=
group_import_states_table
.
create!
(
group_id:
group
.
id
,
user_id:
nil
,
status:
0
)
disable_migrations_output
{
migrate!
}
expect
(
group_import_state
.
reload
.
user_id
).
to
eq
(
user
.
id
)
end
end
end
def
create_member
(
options
)
...
...
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