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
17896b3b
Commit
17896b3b
authored
May 11, 2021
by
Igor Drozdov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add foreign keys to lfs_objects_projects
It's added without a validation until the data is cleaned up
parent
15448f95
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
45 additions
and
2 deletions
+45
-2
app/models/lfs_object.rb
app/models/lfs_object.rb
+1
-1
app/models/project.rb
app/models/project.rb
+1
-1
db/migrate/20210511165250_add_foreign_key_to_lfs_objects_projects.rb
...20210511165250_add_foreign_key_to_lfs_objects_projects.rb
+19
-0
db/schema_migrations/20210511165250
db/schema_migrations/20210511165250
+1
-0
db/structure.sql
db/structure.sql
+6
-0
spec/models/lfs_object_spec.rb
spec/models/lfs_object_spec.rb
+13
-0
spec/models/project_spec.rb
spec/models/project_spec.rb
+4
-0
No files found.
app/models/lfs_object.rb
View file @
17896b3b
...
...
@@ -7,7 +7,7 @@ class LfsObject < ApplicationRecord
include
ObjectStorage
::
BackgroundMove
include
FileStoreMounter
has_many
:lfs_objects_projects
,
dependent: :destroy
# rubocop:disable Cop/ActiveRecordDependent
has_many
:lfs_objects_projects
has_many
:projects
,
->
{
distinct
},
through: :lfs_objects_projects
scope
:with_files_stored_locally
,
->
{
where
(
file_store:
LfsObjectUploader
::
Store
::
LOCAL
)
}
...
...
app/models/project.rb
View file @
17896b3b
...
...
@@ -286,7 +286,7 @@ class Project < ApplicationRecord
has_many
:users_star_projects
has_many
:starrers
,
through: :users_star_projects
,
source: :user
has_many
:releases
has_many
:lfs_objects_projects
,
dependent: :destroy
# rubocop:disable Cop/ActiveRecordDependent
has_many
:lfs_objects_projects
has_many
:lfs_objects
,
->
{
distinct
},
through: :lfs_objects_projects
has_many
:lfs_file_locks
has_many
:project_group_links
...
...
db/migrate/20210511165250_add_foreign_key_to_lfs_objects_projects.rb
0 → 100644
View file @
17896b3b
# frozen_string_literal: true
class
AddForeignKeyToLfsObjectsProjects
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
disable_ddl_transaction!
def
up
add_concurrent_foreign_key
:lfs_objects_projects
,
:lfs_objects
,
column: :lfs_object_id
,
on_delete: :restrict
,
validate:
false
add_concurrent_foreign_key
:lfs_objects_projects
,
:projects
,
column: :project_id
,
on_delete: :cascade
,
validate:
false
end
def
down
with_lock_retries
do
remove_foreign_key
:lfs_objects_projects
,
column: :lfs_object_id
remove_foreign_key
:lfs_objects_projects
,
column: :project_id
end
end
end
db/schema_migrations/20210511165250
0 → 100644
View file @
17896b3b
8f746d7eb604ae31a5941840d6a078eae2e4fa59b7185bf8cc0db9c55b463c33
\ No newline at end of file
db/structure.sql
View file @
17896b3b
...
...
@@ -25401,6 +25401,9 @@ ALTER TABLE ONLY notes
ALTER TABLE ONLY members
ADD CONSTRAINT fk_2e88fb7ce9 FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
ALTER TABLE ONLY lfs_objects_projects
ADD CONSTRAINT fk_2eb33f7a78 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE NOT VALID;
ALTER TABLE ONLY lists
ADD CONSTRAINT fk_30f2a831f4 FOREIGN KEY (iteration_id) REFERENCES sprints(id) ON DELETE CASCADE;
...
...
@@ -25713,6 +25716,9 @@ ALTER TABLE ONLY bulk_import_entities
ALTER TABLE ONLY users
ADD CONSTRAINT fk_a4b8fefe3e FOREIGN KEY (managing_group_id) REFERENCES namespaces(id) ON DELETE SET NULL;
ALTER TABLE ONLY lfs_objects_projects
ADD CONSTRAINT fk_a56e02279c FOREIGN KEY (lfs_object_id) REFERENCES lfs_objects(id) ON DELETE RESTRICT NOT VALID;
ALTER TABLE ONLY dast_profiles_pipelines
ADD CONSTRAINT fk_a60cad829d FOREIGN KEY (ci_pipeline_id) REFERENCES ci_pipelines(id) ON DELETE CASCADE;
spec/models/lfs_object_spec.rb
View file @
17896b3b
...
...
@@ -178,4 +178,17 @@ RSpec.describe LfsObject do
expect
(
described_class
.
calculate_oid
(
path
)).
to
eq
expected
end
end
context
'when an lfs object is associated with a project'
do
let!
(
:lfs_object
)
{
create
(
:lfs_object
)
}
let!
(
:lfs_object_project
)
{
create
(
:lfs_objects_project
,
lfs_object:
lfs_object
)
}
it
'cannot be deleted'
do
expect
{
lfs_object
.
destroy!
}.
to
raise_error
(
ActiveRecord
::
InvalidForeignKey
)
lfs_object_project
.
destroy!
expect
{
lfs_object
.
destroy!
}.
not_to
raise_error
end
end
end
spec/models/project_spec.rb
View file @
17896b3b
...
...
@@ -6452,6 +6452,10 @@ RSpec.describe Project, factory_default: :keep do
expect
(
subject
).
to
eq
([
lfs_object
.
oid
])
end
end
it
'lfs_objects_projects associations are deleted along with project'
do
expect
{
project
.
delete
}.
to
change
(
LfsObjectsProject
,
:count
).
by
(
-
2
)
end
end
context
'when project has no associated LFS objects'
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