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
198fdc54
Commit
198fdc54
authored
Nov 29, 2018
by
Toon Claes
Committed by
Nick Thomas
Nov 29, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Store hashed storage paths in the database
parent
6775dafa
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
128 additions
and
10 deletions
+128
-10
app/models/concerns/shardable.rb
app/models/concerns/shardable.rb
+18
-0
app/models/pool_repository.rb
app/models/pool_repository.rb
+1
-10
app/models/project.rb
app/models/project.rb
+8
-0
app/models/project_repository.rb
app/models/project_repository.rb
+13
-0
app/services/projects/create_service.rb
app/services/projects/create_service.rb
+2
-0
app/services/projects/hashed_storage/migrate_repository_service.rb
...ces/projects/hashed_storage/migrate_repository_service.rb
+1
-0
changelogs/unreleased/tc-repo-full-path-in-db.yml
changelogs/unreleased/tc-repo-full-path-in-db.yml
+5
-0
db/migrate/20181122160027_create_project_repositories.rb
db/migrate/20181122160027_create_project_repositories.rb
+18
-0
db/schema.rb
db/schema.rb
+11
-0
spec/lib/gitlab/import_export/all_models.yml
spec/lib/gitlab/import_export/all_models.yml
+1
-0
spec/models/pool_repository_spec.rb
spec/models/pool_repository_spec.rb
+2
-0
spec/models/project_repository_spec.rb
spec/models/project_repository_spec.rb
+23
-0
spec/models/project_spec.rb
spec/models/project_spec.rb
+25
-0
No files found.
app/models/concerns/shardable.rb
0 → 100644
View file @
198fdc54
# frozen_string_literal: true
module
Shardable
extend
ActiveSupport
::
Concern
included
do
belongs_to
:shard
validates
:shard
,
presence:
true
end
def
shard_name
shard
&
.
name
end
def
shard_name
=
(
name
)
self
.
shard
=
Shard
.
by_name
(
name
)
end
end
app/models/pool_repository.rb
View file @
198fdc54
# frozen_string_literal: true
class
PoolRepository
<
ActiveRecord
::
Base
belongs_to
:shard
validates
:shard
,
presence:
true
include
Shardable
has_many
:member_projects
,
class_name:
'Project'
after_create
:correct_disk_path
def
shard_name
shard
&
.
name
end
def
shard_name
=
(
name
)
self
.
shard
=
Shard
.
by_name
(
name
)
end
private
def
correct_disk_path
...
...
app/models/project.rb
View file @
198fdc54
...
...
@@ -186,6 +186,7 @@ class Project < ActiveRecord::Base
has_one
:import_state
,
autosave:
true
,
class_name:
'ProjectImportState'
,
inverse_of: :project
has_one
:import_export_upload
,
dependent: :destroy
# rubocop:disable Cop/ActiveRecordDependent
has_one
:project_repository
,
inverse_of: :project
# Merge Requests for target project should be removed with it
has_many
:merge_requests
,
foreign_key:
'target_project_id'
,
inverse_of: :target_project
...
...
@@ -1206,6 +1207,13 @@ class Project < ActiveRecord::Base
false
end
def
track_project_repository
return
unless
hashed_storage?
(
:repository
)
project_repo
=
project_repository
||
build_project_repository
project_repo
.
update!
(
shard_name:
repository_storage
,
disk_path:
disk_path
)
end
def
create_repository
(
force:
false
)
# Forked import is handled asynchronously
return
if
forked?
&&
!
force
...
...
app/models/project_repository.rb
0 → 100644
View file @
198fdc54
# frozen_string_literal: true
class
ProjectRepository
<
ActiveRecord
::
Base
include
Shardable
belongs_to
:project
,
inverse_of: :project_repository
class
<<
self
def
find_project
(
disk_path
)
find_by
(
disk_path:
disk_path
)
&
.
project
end
end
end
app/services/projects/create_service.rb
View file @
198fdc54
...
...
@@ -86,6 +86,8 @@ module Projects
@project
.
create_wiki
unless
skip_wiki?
end
@project
.
track_project_repository
event_service
.
create_project
(
@project
,
current_user
)
system_hook_service
.
execute_hooks_for
(
@project
,
:create
)
...
...
app/services/projects/hashed_storage/migrate_repository_service.rb
View file @
198fdc54
...
...
@@ -30,6 +30,7 @@ module Projects
if
result
project
.
write_repository_config
project
.
track_project_repository
else
rollback_folder_move
project
.
storage_version
=
nil
...
...
changelogs/unreleased/tc-repo-full-path-in-db.yml
0 → 100644
View file @
198fdc54
---
title
:
Add model and relation to store repo full path in database
merge_request
:
23143
author
:
type
:
added
db/migrate/20181122160027_create_project_repositories.rb
0 → 100644
View file @
198fdc54
# frozen_string_literal: true
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class
CreateProjectRepositories
<
ActiveRecord
::
Migration
[
5.0
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
def
change
create_table
:project_repositories
,
id: :bigserial
do
|
t
|
t
.
references
:shard
,
null:
false
,
index:
true
,
foreign_key:
{
on_delete: :restrict
}
t
.
string
:disk_path
,
null:
false
,
index:
{
unique:
true
}
t
.
references
:project
,
null:
false
,
index:
{
unique:
true
},
foreign_key:
{
on_delete: :cascade
}
end
end
end
db/schema.rb
View file @
198fdc54
...
...
@@ -1601,6 +1601,15 @@ ActiveRecord::Schema.define(version: 20181126153547) do
t
.
index
[
"status"
],
name:
"index_project_mirror_data_on_status"
,
using: :btree
end
create_table
"project_repositories"
,
id: :bigserial
,
force: :cascade
do
|
t
|
t
.
integer
"shard_id"
,
null:
false
t
.
string
"disk_path"
,
null:
false
t
.
integer
"project_id"
,
null:
false
t
.
index
[
"disk_path"
],
name:
"index_project_repositories_on_disk_path"
,
unique:
true
,
using: :btree
t
.
index
[
"project_id"
],
name:
"index_project_repositories_on_project_id"
,
unique:
true
,
using: :btree
t
.
index
[
"shard_id"
],
name:
"index_project_repositories_on_shard_id"
,
using: :btree
end
create_table
"project_statistics"
,
force: :cascade
do
|
t
|
t
.
integer
"project_id"
,
null:
false
t
.
integer
"namespace_id"
,
null:
false
...
...
@@ -2385,6 +2394,8 @@ ActiveRecord::Schema.define(version: 20181126153547) do
add_foreign_key
"project_group_links"
,
"projects"
,
name:
"fk_daa8cee94c"
,
on_delete: :cascade
add_foreign_key
"project_import_data"
,
"projects"
,
name:
"fk_ffb9ee3a10"
,
on_delete: :cascade
add_foreign_key
"project_mirror_data"
,
"projects"
,
on_delete: :cascade
add_foreign_key
"project_repositories"
,
"projects"
,
on_delete: :cascade
add_foreign_key
"project_repositories"
,
"shards"
,
on_delete: :restrict
add_foreign_key
"project_statistics"
,
"projects"
,
on_delete: :cascade
add_foreign_key
"projects"
,
"pool_repositories"
,
name:
"fk_6e5c14658a"
,
on_delete: :nullify
add_foreign_key
"prometheus_metrics"
,
"projects"
,
on_delete: :cascade
...
...
spec/lib/gitlab/import_export/all_models.yml
View file @
198fdc54
...
...
@@ -245,6 +245,7 @@ project:
-
protected_branches
-
protected_tags
-
project_members
-
project_repository
-
users
-
requesters
-
deploy_keys_projects
...
...
spec/models/pool_repository_spec.rb
View file @
198fdc54
# frozen_string_literal: true
require
'spec_helper'
describe
PoolRepository
do
...
...
spec/models/project_repository_spec.rb
0 → 100644
View file @
198fdc54
# frozen_string_literal: true
require
'spec_helper'
describe
ProjectRepository
do
describe
'associations'
do
it
{
is_expected
.
to
belong_to
(
:shard
)
}
it
{
is_expected
.
to
belong_to
(
:project
)
}
end
describe
'.find_project'
do
it
'finds project by disk path'
do
project
=
create
(
:project
)
project
.
track_project_repository
expect
(
described_class
.
find_project
(
project
.
disk_path
)).
to
eq
(
project
)
end
it
'returns nil when it does not find the project'
do
expect
(
described_class
.
find_project
(
'@@unexisting/path/to/project'
)).
to
be_nil
end
end
end
spec/models/project_spec.rb
View file @
198fdc54
...
...
@@ -54,6 +54,7 @@ describe Project do
it
{
is_expected
.
to
have_one
(
:gitlab_issue_tracker_service
)
}
it
{
is_expected
.
to
have_one
(
:external_wiki_service
)
}
it
{
is_expected
.
to
have_one
(
:project_feature
)
}
it
{
is_expected
.
to
have_one
(
:project_repository
)
}
it
{
is_expected
.
to
have_one
(
:statistics
).
class_name
(
'ProjectStatistics'
)
}
it
{
is_expected
.
to
have_one
(
:import_data
).
class_name
(
'ProjectImportData'
)
}
it
{
is_expected
.
to
have_one
(
:last_event
).
class_name
(
'Event'
)
}
...
...
@@ -1618,6 +1619,30 @@ describe Project do
end
end
describe
'#track_project_repository'
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
it
'creates a project_repository'
do
project
.
track_project_repository
expect
(
project
.
reload
.
project_repository
).
to
be_present
expect
(
project
.
project_repository
.
disk_path
).
to
eq
(
project
.
disk_path
)
expect
(
project
.
project_repository
.
shard_name
).
to
eq
(
project
.
repository_storage
)
end
it
'updates the project_repository'
do
project
.
track_project_repository
allow
(
project
).
to
receive
(
:disk_path
).
and_return
(
'@fancy/new/path'
)
expect
do
project
.
track_project_repository
end
.
not_to
change
(
ProjectRepository
,
:count
)
expect
(
project
.
reload
.
project_repository
.
disk_path
).
to
eq
(
project
.
disk_path
)
end
end
describe
'#create_repository'
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:shell
)
{
Gitlab
::
Shell
.
new
}
...
...
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