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
e5c49b57
Commit
e5c49b57
authored
Jan 10, 2018
by
Yorick Peterse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added tests for removing soft removed objects
parent
d0b8f536
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
12 deletions
+87
-12
db/post_migrate/20171207150343_remove_soft_removed_objects.rb
...ost_migrate/20171207150343_remove_soft_removed_objects.rb
+10
-12
spec/migrations/remove_soft_removed_objects_spec.rb
spec/migrations/remove_soft_removed_objects_spec.rb
+77
-0
No files found.
db/post_migrate/20171207150343_remove_soft_removed_objects.rb
View file @
e5c49b57
...
...
@@ -156,6 +156,15 @@ class RemoveSoftRemovedObjects < ActiveRecord::Migration
end
def
remove_group_namespaces
admin_id
=
id_for_admin_user
unless
admin_id
say
'Not scheduling soft removed groups for removal as no admin user '
\
'could be found. You will need to remove any such groups manually.'
return
end
# Left over groups can't be easily removed because we may also need to
# remove memberships, repositories, and other associated data. As a result
# we'll just schedule a Sidekiq job to remove these.
...
...
@@ -163,10 +172,6 @@ class RemoveSoftRemovedObjects < ActiveRecord::Migration
# As of January 5th, 2018 there are 36 groups that will be removed using
# this code.
Namespace
.
select
(
:id
).
soft_removed_group
.
each_batch
(
of:
10
)
do
|
batch
,
index
|
# We need the ID of an admin user as the owners of the group may no longer
# exist (or might not even be set in `namespaces.owner_id`).
admin_id
=
id_for_admin_user
batch
.
each
do
|
ns
|
schedule_group_removal
(
index
*
5
.
minutes
,
ns
.
id
,
admin_id
)
end
...
...
@@ -194,14 +199,7 @@ class RemoveSoftRemovedObjects < ActiveRecord::Migration
end
def
id_for_admin_user
return
@id_for_admin_user
if
@id_for_admin_user
if
(
admin_id
=
User
.
where
(
admin:
true
).
limit
(
1
).
pluck
(
:id
).
first
)
@id_for_admin_user
=
admin_id
else
raise
'Can not remove soft removed groups as no admin user exists. '
\
'Please make sure at least one user with `admin` set to TRUE exists before proceeding.'
end
User
.
where
(
admin:
true
).
limit
(
1
).
pluck
(
:id
).
first
end
def
migrate_inline?
...
...
spec/migrations/remove_soft_removed_objects_spec.rb
0 → 100644
View file @
e5c49b57
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20171207150343_remove_soft_removed_objects.rb'
)
describe
RemoveSoftRemovedObjects
,
:migration
do
describe
'#up'
do
it
'removes various soft removed objects'
do
5
.
times
do
create_with_deleted_at
(
:issue
)
end
regular_issue
=
create
(
:issue
)
run_migration
expect
(
Issue
.
count
).
to
eq
(
1
)
expect
(
Issue
.
first
).
to
eq
(
regular_issue
)
end
it
'removes the temporary indexes once soft removed data has been removed'
do
migration
=
described_class
.
new
run_migration
disable_migrations_output
do
expect
(
migration
.
temporary_index_exists?
(
Issue
)).
to
eq
(
false
)
end
end
it
'removes routes of soft removed personal namespaces'
do
namespace
=
create_with_deleted_at
(
:namespace
)
group
=
create
(
:group
)
expect
(
Route
.
where
(
source:
namespace
).
exists?
).
to
eq
(
true
)
expect
(
Route
.
where
(
source:
group
).
exists?
).
to
eq
(
true
)
run_migration
expect
(
Route
.
where
(
source:
namespace
).
exists?
).
to
eq
(
false
)
expect
(
Route
.
where
(
source:
group
).
exists?
).
to
eq
(
true
)
end
it
'schedules the removal of soft removed groups'
do
group
=
create_with_deleted_at
(
:group
)
admin
=
create
(
:user
,
admin:
true
)
expect_any_instance_of
(
GroupDestroyWorker
)
.
to
receive
(
:perform
)
.
with
(
group
.
id
,
admin
.
id
)
run_migration
end
it
'does not remove soft removed groups when no admin user could be found'
do
create_with_deleted_at
(
:group
)
expect_any_instance_of
(
GroupDestroyWorker
)
.
not_to
receive
(
:perform
)
run_migration
end
end
def
run_migration
disable_migrations_output
do
migrate!
end
end
def
create_with_deleted_at
(
*
args
)
row
=
create
(
*
args
)
# We set "deleted_at" this way so we don't run into any column cache issues.
row
.
class
.
where
(
id:
row
.
id
).
update_all
(
deleted_at:
1
.
year
.
ago
)
row
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