Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
b0e30189
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,发现更多精彩内容 >>
提交
b0e30189
编写于
8月 25, 2017
作者:
J
Jarka Kadlecova
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Migrate issues authored by deleted user to the Ghost user
上级
597bc292
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
108 addition
and
1 deletion
+108
-1
changelogs/unreleased/36860-migrate-issues-author.yml
changelogs/unreleased/36860-migrate-issues-author.yml
+5
-0
db/migrate/20170825104051_migrate_issues_to_ghost_user.rb
db/migrate/20170825104051_migrate_issues_to_ghost_user.rb
+36
-0
db/migrate/20170901071411_add_foreign_key_to_issue_author.rb
db/migrate/20170901071411_add_foreign_key_to_issue_author.rb
+14
-0
db/schema.rb
db/schema.rb
+2
-1
spec/migrations/migrate_issues_to_ghost_user_spec.rb
spec/migrations/migrate_issues_to_ghost_user_spec.rb
+51
-0
未找到文件。
changelogs/unreleased/36860-migrate-issues-author.yml
0 → 100644
浏览文件 @
b0e30189
---
title
:
Migrate issues authored by deleted user to the Ghost user
merge_request
:
author
:
type
:
fixed
db/migrate/20170825104051_migrate_issues_to_ghost_user.rb
0 → 100644
浏览文件 @
b0e30189
class
MigrateIssuesToGhostUser
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
class
User
<
ActiveRecord
::
Base
self
.
table_name
=
'users'
end
class
Issue
<
ActiveRecord
::
Base
self
.
table_name
=
'issues'
include
::
EachBatch
end
def
reset_column_in_migration_models
ActiveRecord
::
Base
.
clear_cache!
::
User
.
reset_column_information
end
def
up
reset_column_in_migration_models
# we use the model method because rewriting it is too complicated and would require copying multiple methods
ghost_id
=
::
User
.
ghost
.
id
Issue
.
where
(
'NOT EXISTS (?)'
,
User
.
unscoped
.
select
(
1
).
where
(
'issues.author_id = users.id'
)).
each_batch
do
|
relation
|
relation
.
update_all
(
author_id:
ghost_id
)
end
end
def
down
end
end
db/migrate/20170901071411_add_foreign_key_to_issue_author.rb
0 → 100644
浏览文件 @
b0e30189
class
AddForeignKeyToIssueAuthor
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
up
add_concurrent_foreign_key
(
:issues
,
:users
,
column: :author_id
,
on_delete: :nullify
)
end
def
down
remove_foreign_key
(
:issues
,
column: :author_id
)
end
end
db/schema.rb
浏览文件 @
b0e30189
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
20170
824162758
)
do
ActiveRecord
::
Schema
.
define
(
version:
20170
901071411
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
...
...
@@ -1707,6 +1707,7 @@ ActiveRecord::Schema.define(version: 20170824162758) do
add_foreign_key
"issue_assignees"
,
"users"
,
name:
"fk_5e0c8d9154"
,
on_delete: :cascade
add_foreign_key
"issue_metrics"
,
"issues"
,
on_delete: :cascade
add_foreign_key
"issues"
,
"projects"
,
name:
"fk_899c8f3231"
,
on_delete: :cascade
add_foreign_key
"issues"
,
"users"
,
column:
"author_id"
,
name:
"fk_05f1e72feb"
,
on_delete: :cascade
add_foreign_key
"label_priorities"
,
"labels"
,
on_delete: :cascade
add_foreign_key
"label_priorities"
,
"projects"
,
on_delete: :cascade
add_foreign_key
"labels"
,
"namespaces"
,
column:
"group_id"
,
on_delete: :cascade
...
...
spec/migrations/migrate_issues_to_ghost_user_spec.rb
0 → 100644
浏览文件 @
b0e30189
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'migrate'
,
'20170825104051_migrate_issues_to_ghost_user.rb'
)
describe
MigrateIssuesToGhostUser
,
:migration
do
describe
'#up'
do
let
(
:projects
)
{
table
(
:projects
)
}
let
(
:issues
)
{
table
(
:issues
)
}
let
(
:users
)
{
table
(
:users
)
}
before
do
projects
.
create!
(
name:
'gitlab'
)
user
=
users
.
create
(
email:
'test@example.com'
)
issues
.
create
(
title:
'Issue 1'
,
author_id:
nil
,
project_id:
1
)
issues
.
create
(
title:
'Issue 2'
,
author_id:
user
.
id
,
project_id:
1
)
end
context
'when ghost user exists'
do
let!
(
:ghost
)
{
users
.
create
(
ghost:
true
,
email:
'ghost@example.com'
)
}
it
'does not create a new user'
do
expect
{
schema_migrate_up!
}.
not_to
change
{
User
.
count
}
end
it
'migrates issues where author = nil to the ghost user'
do
schema_migrate_up!
expect
(
issues
.
first
.
reload
.
author_id
).
to
eq
(
ghost
.
id
)
end
it
'does not change issues authored by an existing user'
do
expect
{
schema_migrate_up!
}.
not_to
change
{
issues
.
second
.
reload
.
author_id
}
end
end
context
'when ghost user does not exist'
do
it
'creates a new user'
do
expect
{
schema_migrate_up!
}.
to
change
{
User
.
count
}.
by
(
1
)
end
it
'migrates issues where author = nil to the ghost user'
do
schema_migrate_up!
expect
(
issues
.
first
.
reload
.
author_id
).
to
eq
(
User
.
ghost
.
id
)
end
it
'does not change issues authored by an existing user'
do
expect
{
schema_migrate_up!
}.
not_to
change
{
issues
.
second
.
reload
.
author_id
}
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录