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
Hide 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
...
@@ -17,11 +17,9 @@ module IssuableStates
# Needed to prevent breaking some migration specs that
# Needed to prevent breaking some migration specs that
# rollback database to a point where state_id does not exist.
# rollback database to a point where state_id does not exist.
# We can use this guard clause for now since this file will
# We can use this guard clause for now since this file will
# be removed
on a future
the next release.
# be removed
in
the next release.
return
unless
self
.
respond_to
?
(
:state_id
)
return
unless
self
.
has_attribute
?
(
:state_id
)
states_hash
=
self
.
class
.
available_states
self
.
state_id
=
self
.
class
.
available_states
[
state
]
self
.
state_id
=
states_hash
[
state
]
end
end
end
end
lib/gitlab/background_migration/sync_issues_state_id.rb
View file @
b2fb3a9c
...
@@ -5,7 +5,7 @@ module Gitlab
...
@@ -5,7 +5,7 @@ module Gitlab
module
BackgroundMigration
module
BackgroundMigration
class
SyncIssuesStateId
class
SyncIssuesStateId
def
perform
(
start_id
,
end_id
)
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
ActiveRecord
::
Base
.
connection
.
execute
<<~
SQL
UPDATE issues
UPDATE issues
...
...
spec/migrations/schedule_sync_issuables_state_id_spec.rb
View file @
b2fb3a9c
...
@@ -9,11 +9,8 @@ describe ScheduleSyncIssuablesStateId, :migration do
...
@@ -9,11 +9,8 @@ describe ScheduleSyncIssuablesStateId, :migration do
let
(
:merge_requests
)
{
table
(
:merge_requests
)
}
let
(
:merge_requests
)
{
table
(
:merge_requests
)
}
let
(
:issues
)
{
table
(
:issues
)
}
let
(
:issues
)
{
table
(
:issues
)
}
let
(
:migration
)
{
described_class
.
new
}
let
(
:migration
)
{
described_class
.
new
}
let
(
:group
)
{
namespaces
.
create!
(
name:
'gitlab'
,
path:
'gitlab'
)
}
before
do
let
(
:project
)
{
projects
.
create!
(
namespace_id:
group
.
id
)
}
@group
=
namespaces
.
create!
(
name:
'gitlab'
,
path:
'gitlab'
)
@project
=
projects
.
create!
(
namespace_id:
@group
.
id
)
end
shared_examples
'scheduling migrations'
do
shared_examples
'scheduling migrations'
do
before
do
before
do
...
@@ -40,14 +37,12 @@ describe ScheduleSyncIssuablesStateId, :migration do
...
@@ -40,14 +37,12 @@ describe ScheduleSyncIssuablesStateId, :migration do
opened_issue
=
issues
.
create!
(
description:
'first'
,
state:
'opened'
)
opened_issue
=
issues
.
create!
(
description:
'first'
,
state:
'opened'
)
closed_issue
=
issues
.
create!
(
description:
'second'
,
state:
'closed'
)
closed_issue
=
issues
.
create!
(
description:
'second'
,
state:
'closed'
)
invalid_state_issue
=
issues
.
create!
(
description:
'fourth'
,
state:
'not valid'
)
invalid_state_issue
=
issues
.
create!
(
description:
'fourth'
,
state:
'not valid'
)
nil_state_issue
=
issues
.
create!
(
description:
'third'
,
state:
nil
)
migrate!
migrate!
expect
(
opened_issue
.
reload
.
state_id
).
to
eq
(
Issue
.
available_states
[
:opened
])
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
(
closed_issue
.
reload
.
state_id
).
to
eq
(
Issue
.
available_states
[
:closed
])
expect
(
invalid_state_issue
.
reload
.
state_id
).
to
be_nil
expect
(
invalid_state_issue
.
reload
.
state_id
).
to
be_nil
expect
(
nil_state_issue
.
reload
.
state_id
).
to
be_nil
end
end
it_behaves_like
'scheduling migrations'
do
it_behaves_like
'scheduling migrations'
do
...
@@ -61,11 +56,10 @@ describe ScheduleSyncIssuablesStateId, :migration do
...
@@ -61,11 +56,10 @@ describe ScheduleSyncIssuablesStateId, :migration do
context
'merge requests'
do
context
'merge requests'
do
it
'migrates state column to integer'
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'
)
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'
)
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'
)
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'
)
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'
)
migrate!
migrate!
...
@@ -73,15 +67,14 @@ describe ScheduleSyncIssuablesStateId, :migration do
...
@@ -73,15 +67,14 @@ describe ScheduleSyncIssuablesStateId, :migration do
expect
(
closed_merge_request
.
reload
.
state_id
).
to
eq
(
MergeRequest
.
available_states
[
:closed
])
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
(
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
(
locked_merge_request
.
reload
.
state_id
).
to
eq
(
MergeRequest
.
available_states
[
:locked
])
expect
(
invalid_state_merge_request
.
reload
.
state_id
).
to
be_nil
end
end
it_behaves_like
'scheduling migrations'
do
it_behaves_like
'scheduling migrations'
do
let
(
:migration
)
{
described_class
::
MERGE_REQUESTS_MIGRATION
}
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_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_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_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_4
)
{
merge_requests
.
create!
(
state:
'locked'
,
target_project_id:
project
.
id
,
target_branch:
'feature4'
,
source_branch:
'master'
)
}
end
end
end
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