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
Léo-Paul Géneau
gitlab-ce
Commits
b2fb3a9c
Commit
b2fb3a9c
authored
Mar 28, 2019
by
Felipe Artur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Address review comments
parent
16a3fea3
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
23 deletions
+14
-23
app/models/concerns/issuable_states.rb
app/models/concerns/issuable_states.rb
+3
-5
lib/gitlab/background_migration/sync_issues_state_id.rb
lib/gitlab/background_migration/sync_issues_state_id.rb
+1
-1
spec/migrations/schedule_sync_issuables_state_id_spec.rb
spec/migrations/schedule_sync_issuables_state_id_spec.rb
+10
-17
No files found.
app/models/concerns/issuable_states.rb
View file @
b2fb3a9c
...
...
@@ -17,11 +17,9 @@ module IssuableStates
# Needed to prevent breaking some migration specs that
# rollback database to a point where state_id does not exist.
# We can use this guard clause for now since this file will
# be removed
on a future
the next release.
return
unless
self
.
respond_to
?
(
:state_id
)
# be removed
in
the next release.
return
unless
self
.
has_attribute
?
(
:state_id
)
states_hash
=
self
.
class
.
available_states
self
.
state_id
=
states_hash
[
state
]
self
.
state_id
=
self
.
class
.
available_states
[
state
]
end
end
lib/gitlab/background_migration/sync_issues_state_id.rb
View file @
b2fb3a9c
...
...
@@ -5,7 +5,7 @@ module Gitlab
module
BackgroundMigration
class
SyncIssuesStateId
def
perform
(
start_id
,
end_id
)
Rails
.
l
ogger
.
info
(
"Issues - Populating state_id:
#{
start_id
}
-
#{
end_id
}
"
)
Gitlab
::
AppL
ogger
.
info
(
"Issues - Populating state_id:
#{
start_id
}
-
#{
end_id
}
"
)
ActiveRecord
::
Base
.
connection
.
execute
<<~
SQL
UPDATE issues
...
...
spec/migrations/schedule_sync_issuables_state_id_spec.rb
View file @
b2fb3a9c
...
...
@@ -9,11 +9,8 @@ describe ScheduleSyncIssuablesStateId, :migration do
let
(
:merge_requests
)
{
table
(
:merge_requests
)
}
let
(
:issues
)
{
table
(
:issues
)
}
let
(
:migration
)
{
described_class
.
new
}
before
do
@group
=
namespaces
.
create!
(
name:
'gitlab'
,
path:
'gitlab'
)
@project
=
projects
.
create!
(
namespace_id:
@group
.
id
)
end
let
(
:group
)
{
namespaces
.
create!
(
name:
'gitlab'
,
path:
'gitlab'
)
}
let
(
:project
)
{
projects
.
create!
(
namespace_id:
group
.
id
)
}
shared_examples
'scheduling migrations'
do
before
do
...
...
@@ -40,14 +37,12 @@ describe ScheduleSyncIssuablesStateId, :migration do
opened_issue
=
issues
.
create!
(
description:
'first'
,
state:
'opened'
)
closed_issue
=
issues
.
create!
(
description:
'second'
,
state:
'closed'
)
invalid_state_issue
=
issues
.
create!
(
description:
'fourth'
,
state:
'not valid'
)
nil_state_issue
=
issues
.
create!
(
description:
'third'
,
state:
nil
)
migrate!
expect
(
opened_issue
.
reload
.
state_id
).
to
eq
(
Issue
.
available_states
[
:opened
])
expect
(
closed_issue
.
reload
.
state_id
).
to
eq
(
Issue
.
available_states
[
:closed
])
expect
(
invalid_state_issue
.
reload
.
state_id
).
to
be_nil
expect
(
nil_state_issue
.
reload
.
state_id
).
to
be_nil
end
it_behaves_like
'scheduling migrations'
do
...
...
@@ -61,11 +56,10 @@ describe ScheduleSyncIssuablesStateId, :migration do
context
'merge requests'
do
it
'migrates state column to integer'
do
opened_merge_request
=
merge_requests
.
create!
(
state:
'opened'
,
target_project_id:
@project
.
id
,
target_branch:
'feature1'
,
source_branch:
'master'
)
closed_merge_request
=
merge_requests
.
create!
(
state:
'closed'
,
target_project_id:
@project
.
id
,
target_branch:
'feature2'
,
source_branch:
'master'
)
merged_merge_request
=
merge_requests
.
create!
(
state:
'merged'
,
target_project_id:
@project
.
id
,
target_branch:
'feature3'
,
source_branch:
'master'
)
locked_merge_request
=
merge_requests
.
create!
(
state:
'locked'
,
target_project_id:
@project
.
id
,
target_branch:
'feature4'
,
source_branch:
'master'
)
invalid_state_merge_request
=
merge_requests
.
create!
(
state:
'not valid'
,
target_project_id:
@project
.
id
,
target_branch:
'feature5'
,
source_branch:
'master'
)
opened_merge_request
=
merge_requests
.
create!
(
state:
'opened'
,
target_project_id:
project
.
id
,
target_branch:
'feature1'
,
source_branch:
'master'
)
closed_merge_request
=
merge_requests
.
create!
(
state:
'closed'
,
target_project_id:
project
.
id
,
target_branch:
'feature2'
,
source_branch:
'master'
)
merged_merge_request
=
merge_requests
.
create!
(
state:
'merged'
,
target_project_id:
project
.
id
,
target_branch:
'feature3'
,
source_branch:
'master'
)
locked_merge_request
=
merge_requests
.
create!
(
state:
'locked'
,
target_project_id:
project
.
id
,
target_branch:
'feature4'
,
source_branch:
'master'
)
migrate!
...
...
@@ -73,15 +67,14 @@ describe ScheduleSyncIssuablesStateId, :migration do
expect
(
closed_merge_request
.
reload
.
state_id
).
to
eq
(
MergeRequest
.
available_states
[
:closed
])
expect
(
merged_merge_request
.
reload
.
state_id
).
to
eq
(
MergeRequest
.
available_states
[
:merged
])
expect
(
locked_merge_request
.
reload
.
state_id
).
to
eq
(
MergeRequest
.
available_states
[
:locked
])
expect
(
invalid_state_merge_request
.
reload
.
state_id
).
to
be_nil
end
it_behaves_like
'scheduling migrations'
do
let
(
:migration
)
{
described_class
::
MERGE_REQUESTS_MIGRATION
}
let!
(
:resource_1
)
{
merge_requests
.
create!
(
state:
'opened'
,
target_project_id:
@
project
.
id
,
target_branch:
'feature1'
,
source_branch:
'master'
)
}
let!
(
:resource_2
)
{
merge_requests
.
create!
(
state:
'closed'
,
target_project_id:
@
project
.
id
,
target_branch:
'feature2'
,
source_branch:
'master'
)
}
let!
(
:resource_3
)
{
merge_requests
.
create!
(
state:
'merged'
,
target_project_id:
@
project
.
id
,
target_branch:
'feature3'
,
source_branch:
'master'
)
}
let!
(
:resource_4
)
{
merge_requests
.
create!
(
state:
'locked'
,
target_project_id:
@
project
.
id
,
target_branch:
'feature4'
,
source_branch:
'master'
)
}
let!
(
:resource_1
)
{
merge_requests
.
create!
(
state:
'opened'
,
target_project_id:
project
.
id
,
target_branch:
'feature1'
,
source_branch:
'master'
)
}
let!
(
:resource_2
)
{
merge_requests
.
create!
(
state:
'closed'
,
target_project_id:
project
.
id
,
target_branch:
'feature2'
,
source_branch:
'master'
)
}
let!
(
:resource_3
)
{
merge_requests
.
create!
(
state:
'merged'
,
target_project_id:
project
.
id
,
target_branch:
'feature3'
,
source_branch:
'master'
)
}
let!
(
:resource_4
)
{
merge_requests
.
create!
(
state:
'locked'
,
target_project_id:
project
.
id
,
target_branch:
'feature4'
,
source_branch:
'master'
)
}
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