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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
a0a36a99
Commit
a0a36a99
authored
Aug 02, 2018
by
🙈 jacopo beschi 🙉
Committed by
Sean McGivern
Aug 02, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resolve "Remove ghost notification settings for groups and projects"
parent
1db427f9
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
73 additions
and
1 deletion
+73
-1
app/models/user.rb
app/models/user.rb
+1
-1
changelogs/unreleased/44824-remove-ghost-notification-settings-for-group-and-project.yml
...ove-ghost-notification-settings-for-group-and-project.yml
+5
-0
db/migrate/20180710162338_add_foreign_key_from_notification_settings_to_users.rb
...38_add_foreign_key_from_notification_settings_to_users.rb
+30
-0
db/schema.rb
db/schema.rb
+1
-0
spec/migrations/add_foreign_key_from_notification_settings_to_users_spec.rb
...d_foreign_key_from_notification_settings_to_users_spec.rb
+36
-0
No files found.
app/models/user.rb
View file @
a0a36a99
...
...
@@ -130,7 +130,7 @@ class User < ActiveRecord::Base
has_many
:builds
,
dependent: :nullify
,
class_name:
'Ci::Build'
# rubocop:disable Cop/ActiveRecordDependent
has_many
:pipelines
,
dependent: :nullify
,
class_name:
'Ci::Pipeline'
# rubocop:disable Cop/ActiveRecordDependent
has_many
:todos
has_many
:notification_settings
,
dependent: :destroy
# rubocop:disable Cop/ActiveRecordDependent
has_many
:notification_settings
has_many
:award_emoji
,
dependent: :destroy
# rubocop:disable Cop/ActiveRecordDependent
has_many
:triggers
,
dependent: :destroy
,
class_name:
'Ci::Trigger'
,
foreign_key: :owner_id
# rubocop:disable Cop/ActiveRecordDependent
...
...
changelogs/unreleased/44824-remove-ghost-notification-settings-for-group-and-project.yml
0 → 100644
View file @
a0a36a99
---
title
:
Adds foreign key to notification_settings.user_id
merge_request
:
20567
author
:
Jacopo Beschi @jacopo-beschi
type
:
added
db/migrate/20180710162338_add_foreign_key_from_notification_settings_to_users.rb
0 → 100644
View file @
a0a36a99
class
AddForeignKeyFromNotificationSettingsToUsers
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
class
NotificationSetting
<
ActiveRecord
::
Base
self
.
table_name
=
'notification_settings'
include
EachBatch
end
class
User
<
ActiveRecord
::
Base
self
.
table_name
=
'users'
end
DOWNTIME
=
false
disable_ddl_transaction!
def
up
NotificationSetting
.
each_batch
(
of:
1000
)
do
|
batch
|
batch
.
where
(
'NOT EXISTS (?)'
,
User
.
select
(
1
).
where
(
'users.id = notification_settings.user_id'
))
.
delete_all
end
add_concurrent_foreign_key
(
:notification_settings
,
:users
,
column: :user_id
,
on_delete: :cascade
)
end
def
down
remove_foreign_key
(
:notification_settings
,
column: :user_id
)
end
end
db/schema.rb
View file @
a0a36a99
...
...
@@ -2350,6 +2350,7 @@ ActiveRecord::Schema.define(version: 20180726172057) do
add_foreign_key
"milestones"
,
"projects"
,
name:
"fk_9bd0a0c791"
,
on_delete: :cascade
add_foreign_key
"note_diff_files"
,
"notes"
,
column:
"diff_note_id"
,
on_delete: :cascade
add_foreign_key
"notes"
,
"projects"
,
name:
"fk_99e097b079"
,
on_delete: :cascade
add_foreign_key
"notification_settings"
,
"users"
,
name:
"fk_0c95e91db7"
,
on_delete: :cascade
add_foreign_key
"oauth_openid_requests"
,
"oauth_access_grants"
,
column:
"access_grant_id"
,
name:
"fk_oauth_openid_requests_oauth_access_grants_access_grant_id"
add_foreign_key
"pages_domains"
,
"projects"
,
name:
"fk_ea2f6dfc6f"
,
on_delete: :cascade
add_foreign_key
"personal_access_tokens"
,
"users"
...
...
spec/migrations/add_foreign_key_from_notification_settings_to_users_spec.rb
0 → 100644
View file @
a0a36a99
# frozen_string_literal: true
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'migrate'
,
'20180710162338_add_foreign_key_from_notification_settings_to_users.rb'
)
describe
AddForeignKeyFromNotificationSettingsToUsers
,
:migration
do
let
(
:notification_settings
)
{
table
(
:notification_settings
)
}
let
(
:users
)
{
table
(
:users
)
}
let
(
:projects
)
{
table
(
:projects
)
}
before
do
users
.
create!
(
email:
'email@email.com'
,
name:
'foo'
,
username:
'foo'
,
projects_limit:
0
)
projects
.
create!
(
name:
'gitlab'
,
path:
'gitlab-org/gitlab-ce'
,
namespace_id:
1
)
end
describe
'removal of orphans without user'
do
let!
(
:notification_setting_without_user
)
{
create_notification_settings!
(
user_id:
123
)
}
let!
(
:notification_setting_with_user
)
{
create_notification_settings!
(
user_id:
users
.
last
.
id
)
}
it
'removes orphaned notification_settings without user'
do
expect
{
migrate!
}.
to
change
{
notification_settings
.
count
}.
by
(
-
1
)
end
it
"doesn't remove notification_settings with valid user"
do
expect
{
migrate!
}.
not_to
change
{
notification_setting_with_user
.
reload
}
end
end
def
create_notification_settings!
(
**
opts
)
notification_settings
.
create!
(
source_id:
projects
.
last
.
id
,
source_type:
'Project'
,
user_id:
users
.
last
.
id
,
**
opts
)
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