Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
a0a36a99
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a0a36a99
编写于
8月 02, 2018
作者:
🙈
🙈 jacopo beschi 🙉
提交者:
Sean McGivern
8月 02, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Resolve "Remove ghost notification settings for groups and projects"
上级
1db427f9
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
73 addition
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
未找到文件。
app/models/user.rb
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录