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
Léo-Paul Géneau
gitlab-ce
Commits
8f84369a
Commit
8f84369a
authored
Nov 14, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delete orphaned fork networks in a migration
parent
8b426b63
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
1 deletion
+66
-1
changelogs/unreleased/bvl-delete-empty-fork-networks.yml
changelogs/unreleased/bvl-delete-empty-fork-networks.yml
+5
-0
db/post_migrate/20171114104051_remove_empty_fork_networks.rb
db/post_migrate/20171114104051_remove_empty_fork_networks.rb
+36
-0
db/schema.rb
db/schema.rb
+1
-1
spec/migrations/remove_empty_fork_networks_spec.rb
spec/migrations/remove_empty_fork_networks_spec.rb
+24
-0
No files found.
changelogs/unreleased/bvl-delete-empty-fork-networks.yml
0 → 100644
View file @
8f84369a
---
title
:
Clean up empty fork networks
merge_request
:
15373
author
:
type
:
other
db/post_migrate/20171114104051_remove_empty_fork_networks.rb
0 → 100644
View file @
8f84369a
class
RemoveEmptyForkNetworks
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
BATCH_SIZE
=
10_000
class
MigrationForkNetwork
<
ActiveRecord
::
Base
include
EachBatch
self
.
table_name
=
'fork_networks'
end
class
MigrationForkNetworkMembers
<
ActiveRecord
::
Base
self
.
table_name
=
'fork_network_members'
end
disable_ddl_transaction!
def
up
say
'Deleting empty ForkNetworks in batches'
has_members
=
MigrationForkNetworkMembers
.
where
(
'fork_network_members.fork_network_id = fork_networks.id'
)
.
select
(
1
)
MigrationForkNetwork
.
where
(
'NOT EXISTS (?)'
,
has_members
)
.
each_batch
(
of:
BATCH_SIZE
)
do
|
networks
|
deleted
=
networks
.
delete_all
say
"Deleted
#{
deleted
}
rows in batch"
end
end
def
down
# nothing
end
end
db/schema.rb
View file @
8f84369a
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
201711
0618064
1
)
do
ActiveRecord
::
Schema
.
define
(
version:
201711
1410405
1
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
...
...
spec/migrations/remove_empty_fork_networks_spec.rb
0 → 100644
View file @
8f84369a
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20171114104051_remove_empty_fork_networks.rb'
)
describe
RemoveEmptyForkNetworks
,
:migration
do
let!
(
:fork_networks
)
{
table
(
:fork_networks
)
}
let
(
:deleted_project
)
{
create
(
:project
)
}
let!
(
:empty_network
)
{
create
(
:fork_network
,
id:
1
,
root_project_id:
deleted_project
.
id
)
}
let!
(
:other_network
)
{
create
(
:fork_network
,
id:
2
,
root_project_id:
create
(
:project
).
id
)
}
before
do
deleted_project
.
destroy!
end
it
'deletes only the fork network without members'
do
expect
(
fork_networks
.
count
).
to
eq
(
2
)
migrate!
expect
(
fork_networks
.
find_by
(
id:
empty_network
.
id
)).
to
be_nil
expect
(
fork_networks
.
find_by
(
id:
other_network
.
id
)).
not_to
be_nil
expect
(
fork_networks
.
count
).
to
eq
(
1
)
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