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
8c4879e7
Commit
8c4879e7
authored
Aug 25, 2021
by
Pavel Shutsin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup used membership invites
Changelog: other
parent
9ee6c875
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
0 deletions
+65
-0
db/post_migrate/20210825150212_cleanup_remaining_orphan_invites.rb
...igrate/20210825150212_cleanup_remaining_orphan_invites.rb
+27
-0
db/schema_migrations/20210825150212
db/schema_migrations/20210825150212
+1
-0
spec/migrations/cleanup_remaining_orphan_invites_spec.rb
spec/migrations/cleanup_remaining_orphan_invites_spec.rb
+37
-0
No files found.
db/post_migrate/20210825150212_cleanup_remaining_orphan_invites.rb
0 → 100644
View file @
8c4879e7
# frozen_string_literal: true
class
CleanupRemainingOrphanInvites
<
ActiveRecord
::
Migration
[
6.1
]
include
Gitlab
::
Database
::
MigrationHelpers
disable_ddl_transaction!
TMP_INDEX_NAME
=
'tmp_idx_members_with_orphaned_invites'
QUERY_CONDITION
=
"invite_token IS NOT NULL AND user_id IS NOT NULL"
def
up
membership
=
define_batchable_model
(
'members'
)
add_concurrent_index
:members
,
:id
,
where:
QUERY_CONDITION
,
name:
TMP_INDEX_NAME
membership
.
where
(
QUERY_CONDITION
).
pluck
(
:id
).
each_slice
(
10
)
do
|
group
|
membership
.
where
(
id:
group
).
where
(
QUERY_CONDITION
).
update_all
(
invite_token:
nil
)
end
remove_concurrent_index_by_name
:members
,
TMP_INDEX_NAME
end
def
down
remove_concurrent_index_by_name
:members
,
TMP_INDEX_NAME
if
index_exists_by_name?
(
:members
,
TMP_INDEX_NAME
)
end
end
db/schema_migrations/20210825150212
0 → 100644
View file @
8c4879e7
5dc6a4f9ecbd705bf8361c65b29931cde94968084e8ae7945a27acdcbd6475c8
\ No newline at end of file
spec/migrations/cleanup_remaining_orphan_invites_spec.rb
0 → 100644
View file @
8c4879e7
# frozen_string_literal: true
require
'spec_helper'
require_migration!
'cleanup_remaining_orphan_invites'
RSpec
.
describe
CleanupRemainingOrphanInvites
,
:migration
do
def
create_member
(
**
extra_attributes
)
defaults
=
{
access_level:
10
,
source_id:
1
,
source_type:
"Project"
,
notification_level:
0
,
type:
'ProjectMember'
}
table
(
:members
).
create!
(
defaults
.
merge
(
extra_attributes
))
end
def
create_user
(
**
extra_attributes
)
defaults
=
{
projects_limit:
0
}
table
(
:users
).
create!
(
defaults
.
merge
(
extra_attributes
))
end
describe
'#up'
,
:aggregate_failures
do
it
'removes invite tokens for accepted records'
do
record1
=
create_member
(
invite_token:
'foo'
,
user_id:
nil
)
record2
=
create_member
(
invite_token:
'foo2'
,
user_id:
create_user
(
username:
'foo'
,
email:
'foo@example.com'
).
id
)
record3
=
create_member
(
invite_token:
nil
,
user_id:
create_user
(
username:
'bar'
,
email:
'bar@example.com'
).
id
)
migrate!
expect
(
table
(
:members
).
find
(
record1
.
id
).
invite_token
).
to
eq
'foo'
expect
(
table
(
:members
).
find
(
record2
.
id
).
invite_token
).
to
eq
nil
expect
(
table
(
:members
).
find
(
record3
.
id
).
invite_token
).
to
eq
nil
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