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
88a66287
Commit
88a66287
authored
Apr 09, 2021
by
Arturo Herrero
Committed by
Adam Hegyi
Apr 09, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove records without group from webhooks
parent
3916d605
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
63 additions
and
0 deletions
+63
-0
changelogs/unreleased/202423-remove-records-without-group-from-webhooks.yml
...sed/202423-remove-records-without-group-from-webhooks.yml
+5
-0
db/post_migrate/20210330091751_remove_records_without_group_from_webhooks_table.rb
...91751_remove_records_without_group_from_webhooks_table.rb
+30
-0
db/schema_migrations/20210330091751
db/schema_migrations/20210330091751
+1
-0
spec/migrations/remove_records_without_group_from_webhooks_table_spec.rb
.../remove_records_without_group_from_webhooks_table_spec.rb
+27
-0
No files found.
changelogs/unreleased/202423-remove-records-without-group-from-webhooks.yml
0 → 100644
View file @
88a66287
---
title
:
Remove records without group from webhooks table
merge_request
:
57863
author
:
type
:
other
db/post_migrate/20210330091751_remove_records_without_group_from_webhooks_table.rb
0 → 100644
View file @
88a66287
# frozen_string_literal: true
class
RemoveRecordsWithoutGroupFromWebhooksTable
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
class
WebHook
<
ActiveRecord
::
Base
include
EachBatch
self
.
table_name
=
'web_hooks'
end
class
Group
<
ActiveRecord
::
Base
self
.
inheritance_column
=
:_type_disabled
self
.
table_name
=
'namespaces'
end
def
up
subquery
=
Group
.
select
(
1
).
where
(
Group
.
arel_table
[
:id
].
eq
(
WebHook
.
arel_table
[
:group_id
]))
WebHook
.
each_batch
(
of:
500
,
column: :id
)
do
|
relation
|
relation
.
where
(
type:
'GroupHook'
).
where
.
not
(
'EXISTS (?)'
,
subquery
).
delete_all
end
end
def
down
# no-op
end
end
db/schema_migrations/20210330091751
0 → 100644
View file @
88a66287
3a195b9671846409cf6665b13caad9713541d9cdd95c9f246c22b7db225ab02c
\ No newline at end of file
spec/migrations/remove_records_without_group_from_webhooks_table_spec.rb
0 → 100644
View file @
88a66287
# frozen_string_literal: true
require
'spec_helper'
require_migration!
require
Rails
.
root
.
join
(
'db'
,
'migrate'
,
'20210325092215_add_not_valid_foreign_key_to_group_hooks.rb'
)
RSpec
.
describe
RemoveRecordsWithoutGroupFromWebhooksTable
,
schema:
20210330091751
do
let
(
:web_hooks
)
{
table
(
:web_hooks
)
}
let
(
:groups
)
{
table
(
:namespaces
)
}
before
do
group
=
groups
.
create!
(
name:
'gitlab'
,
path:
'gitlab-org'
)
web_hooks
.
create!
(
group_id:
group
.
id
,
type:
'GroupHook'
)
web_hooks
.
create!
(
group_id:
nil
)
AddNotValidForeignKeyToGroupHooks
.
new
.
down
web_hooks
.
create!
(
group_id:
non_existing_record_id
,
type:
'GroupHook'
)
AddNotValidForeignKeyToGroupHooks
.
new
.
up
end
it
'removes group hooks where the referenced group does not exist'
,
:aggregate_failures
do
expect
{
RemoveRecordsWithoutGroupFromWebhooksTable
.
new
.
up
}.
to
change
{
web_hooks
.
count
}.
by
(
-
1
)
expect
(
web_hooks
.
where
.
not
(
group_id:
groups
.
select
(
:id
)).
count
).
to
eq
(
0
)
expect
(
web_hooks
.
where
.
not
(
group_id:
nil
).
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