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
bde02026
Commit
bde02026
authored
Oct 31, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unique index to subscriptions on subscribable and user and project
parent
731946ba
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
34 additions
and
3 deletions
+34
-3
app/models/subscription.rb
app/models/subscription.rb
+2
-2
db/migrate/20161031181638_add_unique_index_to_subscriptions.rb
...grate/20161031181638_add_unique_index_to_subscriptions.rb
+18
-0
db/schema.rb
db/schema.rb
+1
-1
spec/factories/subscriptions.rb
spec/factories/subscriptions.rb
+7
-0
spec/models/subscription_spec.rb
spec/models/subscription_spec.rb
+6
-0
No files found.
app/models/subscription.rb
View file @
bde02026
...
@@ -5,7 +5,7 @@ class Subscription < ActiveRecord::Base
...
@@ -5,7 +5,7 @@ class Subscription < ActiveRecord::Base
validates
:user
,
:project
,
:subscribable
,
presence:
true
validates
:user
,
:project
,
:subscribable
,
presence:
true
validates
:
user
_id
,
validates
:
project
_id
,
uniqueness:
{
scope:
[
:subscribable_id
,
:subscribable_type
]
},
uniqueness:
{
scope:
[
:subscribable_id
,
:subscribable_type
,
:user_id
]
},
presence:
true
presence:
true
end
end
db/migrate/20161031181638_add_unique_index_to_subscriptions.rb
0 → 100644
View file @
bde02026
class
AddUniqueIndexToSubscriptions
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
true
DOWNTIME_REASON
=
'This migration requires downtime because it changes a column to not accept null values.'
disable_ddl_transaction!
def
up
add_concurrent_index
:subscriptions
,
[
:subscribable_id
,
:subscribable_type
,
:user_id
,
:project_id
],
{
unique:
true
,
name:
'index_subscriptions_on_subscribable_and_user_id_and_project_id'
}
remove_index
:subscriptions
,
name:
'subscriptions_user_id_and_ref_fields'
if
index_name_exists?
(
:subscriptions
,
'subscriptions_user_id_and_ref_fields'
,
false
)
end
def
down
add_concurrent_index
:subscriptions
,
[
:subscribable_id
,
:subscribable_type
,
:user_id
],
{
unique:
true
,
name:
'subscriptions_user_id_and_ref_fields'
}
remove_index
:subscriptions
,
name:
'index_subscriptions_on_subscribable_and_user_id_and_project_id'
if
index_name_exists?
(
:subscriptions
,
'index_subscriptions_on_subscribable_and_user_id_and_project_id'
,
false
)
end
end
db/schema.rb
View file @
bde02026
...
@@ -1055,7 +1055,7 @@ ActiveRecord::Schema.define(version: 20161109150329) do
...
@@ -1055,7 +1055,7 @@ ActiveRecord::Schema.define(version: 20161109150329) do
t
.
integer
"project_id"
t
.
integer
"project_id"
end
end
add_index
"subscriptions"
,
[
"subscribable_id"
,
"subscribable_type"
,
"user_id"
],
name:
"subscriptions_user_id_and_ref_fields
"
,
unique:
true
,
using: :btree
add_index
"subscriptions"
,
[
"subscribable_id"
,
"subscribable_type"
,
"user_id"
,
"project_id"
],
name:
"index_subscriptions_on_subscribable_and_user_id_and_project_id
"
,
unique:
true
,
using: :btree
create_table
"taggings"
,
force: :cascade
do
|
t
|
create_table
"taggings"
,
force: :cascade
do
|
t
|
t
.
integer
"tag_id"
t
.
integer
"tag_id"
...
...
spec/factories/subscriptions.rb
0 → 100644
View file @
bde02026
FactoryGirl
.
define
do
factory
:subscription
do
user
project
factory: :empty_project
subscribable
factory: :issue
end
end
spec/models/subscription_spec.rb
View file @
bde02026
...
@@ -11,5 +11,11 @@ describe Subscription, models: true do
...
@@ -11,5 +11,11 @@ describe Subscription, models: true do
it
{
is_expected
.
to
validate_presence_of
(
:project
)
}
it
{
is_expected
.
to
validate_presence_of
(
:project
)
}
it
{
is_expected
.
to
validate_presence_of
(
:subscribable
)
}
it
{
is_expected
.
to
validate_presence_of
(
:subscribable
)
}
it
{
is_expected
.
to
validate_presence_of
(
:user
)
}
it
{
is_expected
.
to
validate_presence_of
(
:user
)
}
it
'validates uniqueness of project_id scoped to subscribable_id, subscribable_type, and user_id'
do
create
(
:subscription
)
expect
(
subject
).
to
validate_uniqueness_of
(
:project_id
).
scoped_to
([
:subscribable_id
,
:subscribable_type
,
:user_id
])
end
end
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