BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
818397f9
Commit
818397f9
authored
Dec 11, 2017
by
Sean McGivern
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add spec for removing issues.assignee_id
This migration also needs to be a post-deployment migration, as it removes a column.
parent
dd45a174
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
1 deletion
+43
-1
issue.rb
app/models/issue.rb
+3
-0
20170523073948_remove_assignee_id_from_issue.rb
...t_migrate/20170523073948_remove_assignee_id_from_issue.rb
+3
-1
remove_assignee_id_from_issue_spec.rb
spec/migrations/remove_assignee_id_from_issue_spec.rb
+37
-0
No files found.
app/models/issue.rb
View file @
818397f9
...
...
@@ -10,6 +10,9 @@ class Issue < ActiveRecord::Base
include
RelativePositioning
include
TimeTrackable
include
ThrottledTouch
include
IgnorableColumn
ignore_column
:assignee_id
DueDateStruct
=
Struct
.
new
(
:title
,
:name
).
freeze
NoDueDate
=
DueDateStruct
.
new
(
'No Due Date'
,
'0'
).
freeze
...
...
db/migrate/20170523073948_remove_assignee_id_from_issue.rb
→
db/
post_
migrate/20170523073948_remove_assignee_id_from_issue.rb
View file @
818397f9
...
...
@@ -41,6 +41,8 @@ class RemoveAssigneeIdFromIssue < ActiveRecord::Migration
update_value
=
Arel
.
sql
(
'(SELECT user_id FROM issue_assignees WHERE issue_assignees.issue_id = issues.id LIMIT 1)'
)
update_column_in_batches
(
:issues
,
:assignee_id
,
update_value
)
# This is only used in the down step, so we can ignore the RuboCop warning
# about large tables, as this is very unlikely to be run on GitLab.com
update_column_in_batches
(
:issues
,
:assignee_id
,
update_value
)
# rubocop:disable Migration/UpdateLargeTable
end
end
spec/migrations/remove_assignee_id_from_issue_spec.rb
0 → 100644
View file @
818397f9
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20170523073948_remove_assignee_id_from_issue.rb'
)
describe
RemoveAssigneeIdFromIssue
,
:migration
do
let
(
:issues
)
{
table
(
:issues
)
}
let
(
:issue_assignees
)
{
table
(
:issue_assignees
)
}
let
(
:users
)
{
table
(
:users
)
}
let!
(
:user_1
)
{
users
.
create
(
email:
'email1@example.com'
)
}
let!
(
:user_2
)
{
users
.
create
(
email:
'email2@example.com'
)
}
let!
(
:user_3
)
{
users
.
create
(
email:
'email3@example.com'
)
}
def
create_issue
(
assignees
:)
issues
.
create
.
tap
do
|
issue
|
assignees
.
each
do
|
assignee
|
issue_assignees
.
create
(
issue_id:
issue
.
id
,
user_id:
assignee
.
id
)
end
end
end
let!
(
:issue_single_assignee
)
{
create_issue
(
assignees:
[
user_1
])
}
let!
(
:issue_no_assignee
)
{
create_issue
(
assignees:
[])
}
let!
(
:issue_multiple_assignees
)
{
create_issue
(
assignees:
[
user_2
,
user_3
])
}
describe
'#down'
do
it
'sets the assignee_id to a random matching assignee from the assignees table'
do
migrate!
disable_migrations_output
{
described_class
.
new
.
down
}
expect
(
issue_single_assignee
.
reload
.
assignee_id
).
to
eq
(
user_1
.
id
)
expect
(
issue_no_assignee
.
reload
.
assignee_id
).
to
be_nil
expect
(
issue_multiple_assignees
.
reload
.
assignee_id
).
to
eq
(
user_2
.
id
).
or
(
user_3
.
id
)
disable_migrations_output
{
described_class
.
new
.
up
}
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