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
e634990c
Commit
e634990c
authored
Jun 22, 2020
by
Francisco Javier López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add SnippetStatistics model
parent
f4462041
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
61 additions
and
0 deletions
+61
-0
app/models/snippet.rb
app/models/snippet.rb
+1
-0
app/models/snippet_statistics.rb
app/models/snippet_statistics.rb
+7
-0
changelogs/unreleased/fj-223696-add-snippet-statistics.yml
changelogs/unreleased/fj-223696-add-snippet-statistics.yml
+5
-0
db/migrate/20200622103836_create_snippet_statistics.rb
db/migrate/20200622103836_create_snippet_statistics.rb
+24
-0
db/structure.sql
db/structure.sql
+14
-0
spec/lib/gitlab/import_export/all_models.yml
spec/lib/gitlab/import_export/all_models.yml
+1
-0
spec/models/snippet_spec.rb
spec/models/snippet_spec.rb
+1
-0
spec/models/snippet_statistics_spec.rb
spec/models/snippet_statistics_spec.rb
+8
-0
No files found.
app/models/snippet.rb
View file @
e634990c
...
...
@@ -44,6 +44,7 @@ class Snippet < ApplicationRecord
has_many
:notes
,
as: :noteable
,
dependent: :destroy
# rubocop:disable Cop/ActiveRecordDependent
has_many
:user_mentions
,
class_name:
"SnippetUserMention"
,
dependent: :delete_all
# rubocop:disable Cop/ActiveRecordDependent
has_one
:snippet_repository
,
inverse_of: :snippet
has_one
:statistics
,
class_name:
'SnippetStatistics'
delegate
:name
,
:email
,
to: :author
,
prefix:
true
,
allow_nil:
true
...
...
app/models/snippet_statistics.rb
0 → 100644
View file @
e634990c
# frozen_string_literal: true
class
SnippetStatistics
<
ApplicationRecord
belongs_to
:snippet
validates
:snippet
,
presence:
true
end
changelogs/unreleased/fj-223696-add-snippet-statistics.yml
0 → 100644
View file @
e634990c
---
title
:
Add SnippetStatistics model
merge_request
:
35026
author
:
type
:
added
db/migrate/20200622103836_create_snippet_statistics.rb
0 → 100644
View file @
e634990c
# frozen_string_literal: true
class
CreateSnippetStatistics
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
def
up
with_lock_retries
do
create_table
:snippet_statistics
,
id:
false
do
|
t
|
t
.
references
:snippet
,
primary_key:
true
,
default:
nil
,
index:
false
,
foreign_key:
{
on_delete: :cascade
}
t
.
bigint
:repository_size
,
default:
0
,
null:
false
t
.
bigint
:file_count
,
default:
0
,
null:
false
t
.
bigint
:commit_count
,
default:
0
,
null:
false
end
end
end
def
down
with_lock_retries
do
drop_table
:snippet_statistics
# rubocop:disable Migration/DropTable
end
end
end
db/structure.sql
View file @
e634990c
...
...
@@ -6335,6 +6335,13 @@ CREATE TABLE public.snippet_repositories (
disk_path
character
varying
(
80
)
NOT
NULL
);
CREATE
TABLE
public
.
snippet_statistics
(
snippet_id
bigint
NOT
NULL
,
repository_size
bigint
DEFAULT
0
NOT
NULL
,
file_count
bigint
DEFAULT
0
NOT
NULL
,
commit_count
bigint
DEFAULT
0
NOT
NULL
);
CREATE
TABLE
public
.
snippet_user_mentions
(
id
bigint
NOT
NULL
,
snippet_id
integer
NOT
NULL
,
...
...
@@ -9045,6 +9052,9 @@ ALTER TABLE ONLY public.smartcard_identities
ALTER
TABLE
ONLY
public
.
snippet_repositories
ADD
CONSTRAINT
snippet_repositories_pkey
PRIMARY
KEY
(
snippet_id
);
ALTER
TABLE
ONLY
public
.
snippet_statistics
ADD
CONSTRAINT
snippet_statistics_pkey
PRIMARY
KEY
(
snippet_id
);
ALTER
TABLE
ONLY
public
.
snippet_user_mentions
ADD
CONSTRAINT
snippet_user_mentions_pkey
PRIMARY
KEY
(
id
);
...
...
@@ -12949,6 +12959,9 @@ ALTER TABLE ONLY public.protected_branch_unprotect_access_levels
ALTER
TABLE
ONLY
public
.
alert_management_alert_user_mentions
ADD
CONSTRAINT
fk_rails_eb2de0cdef
FOREIGN
KEY
(
note_id
)
REFERENCES
public
.
notes
(
id
)
ON
DELETE
CASCADE
;
ALTER
TABLE
ONLY
public
.
snippet_statistics
ADD
CONSTRAINT
fk_rails_ebc283ccf1
FOREIGN
KEY
(
snippet_id
)
REFERENCES
public
.
snippets
(
id
)
ON
DELETE
CASCADE
;
ALTER
TABLE
ONLY
public
.
ci_daily_report_results
ADD
CONSTRAINT
fk_rails_ebc2931b90
FOREIGN
KEY
(
project_id
)
REFERENCES
public
.
projects
(
id
)
ON
DELETE
CASCADE
;
...
...
@@ -14104,5 +14117,6 @@ COPY "schema_migrations" (version) FROM STDIN;
20200618105638
20200618134223
20200618134723
20200622103836
\
.
spec/lib/gitlab/import_export/all_models.yml
View file @
e634990c
...
...
@@ -97,6 +97,7 @@ snippets:
-
user_agent_detail
-
user_mentions
-
snippet_repository
-
statistics
releases
:
-
author
-
project
...
...
spec/models/snippet_spec.rb
View file @
e634990c
...
...
@@ -20,6 +20,7 @@ describe Snippet do
it
{
is_expected
.
to
have_many
(
:award_emoji
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:user_mentions
).
class_name
(
"SnippetUserMention"
)
}
it
{
is_expected
.
to
have_one
(
:snippet_repository
)
}
it
{
is_expected
.
to
have_one
(
:statistics
).
class_name
(
'SnippetStatistics'
)
}
end
describe
'validation'
do
...
...
spec/models/snippet_statistics_spec.rb
0 → 100644
View file @
e634990c
# frozen_string_literal: true
require
'spec_helper'
describe
SnippetStatistics
do
it
{
is_expected
.
to
belong_to
(
:snippet
)
}
it
{
is_expected
.
to
validate_presence_of
(
:snippet
)
}
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