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
f7e3cb79
Commit
f7e3cb79
authored
Jan 18, 2022
by
Adam Hegyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add locking and test case
parent
ac5eacab
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
2 deletions
+13
-2
db/post_migrate/20220110224913_remove_dast_scanner_profiles_builds_ci_build_id_fk.rb
...913_remove_dast_scanner_profiles_builds_ci_build_id_fk.rb
+1
-0
ee/spec/models/dast/scanner_profiles_build_spec.rb
ee/spec/models/dast/scanner_profiles_build_spec.rb
+5
-0
spec/support/shared_examples/loose_foreign_keys/have_loose_foreign_key.rb
...red_examples/loose_foreign_keys/have_loose_foreign_key.rb
+7
-2
No files found.
db/post_migrate/20220110224913_remove_dast_scanner_profiles_builds_ci_build_id_fk.rb
View file @
f7e3cb79
...
...
@@ -7,6 +7,7 @@ class RemoveDastScannerProfilesBuildsCiBuildIdFk < Gitlab::Database::Migration[1
def
up
with_lock_retries
do
execute
(
'LOCK ci_builds, dast_scanner_profiles_builds IN ACCESS EXCLUSIVE MODE'
)
remove_foreign_key_if_exists
(
:dast_scanner_profiles_builds
,
:ci_builds
,
name:
CONSTRAINT_NAME
)
end
end
...
...
ee/spec/models/dast/scanner_profiles_build_spec.rb
View file @
f7e3cb79
...
...
@@ -27,4 +27,9 @@ RSpec.describe Dast::ScannerProfilesBuild, type: :model do
end
end
end
it_behaves_like
'cleanup by a loose foreign key'
do
let!
(
:model
)
{
create
(
:dast_scanner_profiles_build
)
}
let
(
:parent
)
{
model
.
ci_build
}
end
end
spec/support/shared_examples/loose_foreign_keys/have_loose_foreign_key.rb
View file @
f7e3cb79
...
...
@@ -55,8 +55,13 @@ RSpec.shared_examples 'cleanup by a loose foreign key' do
end
def
find_model
primary_key
=
model
.
class
.
primary_key
.
to_sym
model
.
class
.
find_by
(
primary_key
=>
model
.
public_send
(
primary_key
))
query
=
model
.
class
# handle composite primary keys
connection
=
model
.
class
.
connection
connection
.
primary_keys
(
model
.
class
.
table_name
).
each
do
|
primary_key
|
query
=
query
.
where
(
primary_key
=>
model
.
public_send
(
primary_key
))
end
query
.
first
end
it
'cleans up (delete or nullify) the model'
do
...
...
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