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
33b0821b
Commit
33b0821b
authored
Dec 14, 2021
by
Adam Hegyi
Committed by
Steve Abrams
Dec 14, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delete merge_request_metrics -> ci_pipelines FK
parent
aad2d3f5
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
56 additions
and
3 deletions
+56
-3
db/post_migrate/20211213102111_drop_ci_pipelines_mr_metrics_fk.rb
...migrate/20211213102111_drop_ci_pipelines_mr_metrics_fk.rb
+15
-0
db/schema_migrations/20211213102111
db/schema_migrations/20211213102111
+1
-0
db/structure.sql
db/structure.sql
+0
-3
lib/gitlab/database/gitlab_loose_foreign_keys.yml
lib/gitlab/database/gitlab_loose_foreign_keys.yml
+4
-0
spec/models/merge_request/metrics_spec.rb
spec/models/merge_request/metrics_spec.rb
+6
-0
spec/models/terraform/state_version_spec.rb
spec/models/terraform/state_version_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
+25
-0
No files found.
db/post_migrate/20211213102111_drop_ci_pipelines_mr_metrics_fk.rb
0 → 100644
View file @
33b0821b
# frozen_string_literal: true
class
DropCiPipelinesMrMetricsFk
<
Gitlab
::
Database
::
Migration
[
1.0
]
disable_ddl_transaction!
def
up
with_lock_retries
do
remove_foreign_key_if_exists
(
:merge_request_metrics
,
:ci_pipelines
,
name:
"fk_rails_33ae169d48"
)
end
end
def
down
add_concurrent_foreign_key
(
:merge_request_metrics
,
:ci_pipelines
,
name:
"fk_rails_33ae169d48"
,
column: :pipeline_id
,
target_column: :id
,
on_delete:
"cascade"
)
end
end
db/schema_migrations/20211213102111
0 → 100644
View file @
33b0821b
3d011cc67fc6ac661788f2d0e3766e51d624a4248ac9dbd861a4db810d396091
\ No newline at end of file
db/structure.sql
View file @
33b0821b
...
@@ -30328,9 +30328,6 @@ ALTER TABLE ONLY container_repositories
...
@@ -30328,9 +30328,6 @@ ALTER TABLE ONLY container_repositories
ALTER TABLE ONLY clusters_applications_jupyter
ALTER TABLE ONLY clusters_applications_jupyter
ADD CONSTRAINT fk_rails_331f0aff78 FOREIGN KEY (oauth_application_id) REFERENCES oauth_applications(id) ON DELETE SET NULL;
ADD CONSTRAINT fk_rails_331f0aff78 FOREIGN KEY (oauth_application_id) REFERENCES oauth_applications(id) ON DELETE SET NULL;
ALTER TABLE ONLY merge_request_metrics
ADD CONSTRAINT fk_rails_33ae169d48 FOREIGN KEY (pipeline_id) REFERENCES ci_pipelines(id) ON DELETE CASCADE;
ALTER TABLE ONLY suggestions
ALTER TABLE ONLY suggestions
ADD CONSTRAINT fk_rails_33b03a535c FOREIGN KEY (note_id) REFERENCES notes(id) ON DELETE CASCADE;
ADD CONSTRAINT fk_rails_33b03a535c FOREIGN KEY (note_id) REFERENCES notes(id) ON DELETE CASCADE;
lib/gitlab/database/gitlab_loose_foreign_keys.yml
View file @
33b0821b
...
@@ -45,3 +45,7 @@ terraform_state_versions:
...
@@ -45,3 +45,7 @@ terraform_state_versions:
-
table
:
ci_builds
-
table
:
ci_builds
column
:
ci_build_id
column
:
ci_build_id
on_delete
:
async_nullify
on_delete
:
async_nullify
merge_request_metrics
:
-
table
:
ci_pipelines
column
:
pipeline_id
on_delete
:
async_delete
spec/models/merge_request/metrics_spec.rb
View file @
33b0821b
...
@@ -48,4 +48,10 @@ RSpec.describe MergeRequest::Metrics do
...
@@ -48,4 +48,10 @@ RSpec.describe MergeRequest::Metrics do
end
end
end
end
end
end
it_behaves_like
'cleanup by a loose foreign key'
do
let!
(
:merge_request
)
{
create
(
:merge_request
)
}
let!
(
:parent
)
{
create
(
:ci_pipeline
,
project:
merge_request
.
target_project
)
}
let!
(
:model
)
{
merge_request
.
metrics
.
tap
{
|
metrics
|
metrics
.
update!
(
pipeline:
parent
)
}
}
end
end
end
spec/models/terraform/state_version_spec.rb
View file @
33b0821b
...
@@ -92,4 +92,9 @@ RSpec.describe Terraform::StateVersion do
...
@@ -92,4 +92,9 @@ RSpec.describe Terraform::StateVersion do
end
end
end
end
end
end
it_behaves_like
'cleanup by a loose foreign key'
do
let!
(
:model
)
{
create
(
:terraform_state_version
)
}
let!
(
:parent
)
{
model
.
build
}
end
end
end
spec/support/shared_examples/loose_foreign_keys/have_loose_foreign_key.rb
View file @
33b0821b
...
@@ -47,3 +47,28 @@ RSpec.shared_examples 'it has loose foreign keys' do
...
@@ -47,3 +47,28 @@ RSpec.shared_examples 'it has loose foreign keys' do
expect
(
deleted_records
.
status_processed
.
count
).
to
be
(
1
)
expect
(
deleted_records
.
status_processed
.
count
).
to
be
(
1
)
end
end
end
end
RSpec
.
shared_examples
'cleanup by a loose foreign key'
do
let
(
:foreign_key_definition
)
do
foreign_keys_for_parent
=
Gitlab
::
Database
::
LooseForeignKeys
.
definitions_by_table
[
parent
.
class
.
table_name
]
foreign_keys_for_parent
.
find
{
|
definition
|
definition
.
from_table
==
model
.
class
.
table_name
}
end
def
find_model
model
.
class
.
find_by
(
id:
model
.
id
)
end
it
'deletes the model'
do
parent
.
delete
expect
(
find_model
).
to
be_present
LooseForeignKeys
::
ProcessDeletedRecordsService
.
new
(
connection:
model
.
connection
).
execute
if
foreign_key_definition
.
on_delete
.
eql?
(
:async_delete
)
expect
(
find_model
).
not_to
be_present
else
expect
(
find_model
[
foreign_key_definition
.
column
]).
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