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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
484353b6
Commit
484353b6
authored
Jul 31, 2020
by
Sean Arnold
Committed by
Mayra Cabrera
Jul 31, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add post migration to update incident issues
- Spec to test behaviour
parent
464be48e
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
108 additions
and
0 deletions
+108
-0
changelogs/unreleased/229544-populate-issue-type-for-incident-issues.yml
...leased/229544-populate-issue-type-for-incident-issues.yml
+5
-0
db/post_migrate/20200723040950_migrate_incident_issues_to_incident_type.rb
...0200723040950_migrate_incident_issues_to_incident_type.rb
+47
-0
db/schema_migrations/20200723040950
db/schema_migrations/20200723040950
+1
-0
spec/migrations/migrate_incident_issues_to_incident_type_spec.rb
...grations/migrate_incident_issues_to_incident_type_spec.rb
+55
-0
No files found.
changelogs/unreleased/229544-populate-issue-type-for-incident-issues.yml
0 → 100644
View file @
484353b6
---
title
:
Migrate all 'incident' labelled issues to have issue type 'incident'
merge_request
:
37668
author
:
type
:
added
db/post_migrate/20200723040950_migrate_incident_issues_to_incident_type.rb
0 → 100644
View file @
484353b6
# frozen_string_literal: true
class
MigrateIncidentIssuesToIncidentType
<
ActiveRecord
::
Migration
[
6.0
]
DOWNTIME
=
false
BATCH_SIZE
=
100
disable_ddl_transaction!
LABEL_PROPERTIES
=
{
title:
'incident'
}.
freeze
class
Issue
<
ActiveRecord
::
Base
include
EachBatch
self
.
table_name
=
'issues'
scope
:incident_labelled
,
->
do
joins
(
"INNER JOIN label_links ON label_links.target_type = 'Issue' AND label_links.target_id = issues.id"
)
.
joins
(
"INNER JOIN labels ON labels.id = label_links.label_id"
)
.
where
(
labels:
LABEL_PROPERTIES
)
end
enum
issue_type:
{
issue:
0
,
incident:
1
}
scope
:incident_typed
,
->
{
where
(
issue_type: :incident
)
}
end
def
up
incident_issues
=
Issue
.
incident_labelled
incident_issues
.
each_batch
(
of:
BATCH_SIZE
)
do
|
batch
|
batch
.
update_all
(
issue_type: :incident
)
end
end
def
down
incident_issues
=
Issue
.
incident_typed
incident_issues
.
each_batch
(
of:
BATCH_SIZE
)
do
|
batch
|
batch
.
update_all
(
issue_type: :issue
)
end
end
end
db/schema_migrations/20200723040950
0 → 100644
View file @
484353b6
085b3ad0f7da78a1e13f5cd3d2e7df297284a682c3bcd3883e487b18497430ff
\ No newline at end of file
spec/migrations/migrate_incident_issues_to_incident_type_spec.rb
0 → 100644
View file @
484353b6
# frozen_string_literal: true
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20200723040950_migrate_incident_issues_to_incident_type.rb'
)
RSpec
.
describe
MigrateIncidentIssuesToIncidentType
do
let
(
:migration
)
{
described_class
.
new
}
let
(
:projects
)
{
table
(
:projects
)
}
let
(
:namespaces
)
{
table
(
:namespaces
)
}
let
(
:labels
)
{
table
(
:labels
)
}
let
(
:issues
)
{
table
(
:issues
)
}
let
(
:label_links
)
{
table
(
:label_links
)
}
let
(
:label_props
)
{
IncidentManagement
::
CreateIncidentLabelService
::
LABEL_PROPERTIES
}
let
(
:namespace
)
{
namespaces
.
create!
(
name:
'foo'
,
path:
'foo'
)
}
let!
(
:project
)
{
projects
.
create!
(
namespace_id:
namespace
.
id
)
}
let
(
:label
)
{
labels
.
create!
(
project_id:
project
.
id
,
**
label_props
)
}
let!
(
:incident_issue
)
{
issues
.
create!
(
project_id:
project
.
id
)
}
let!
(
:other_issue
)
{
issues
.
create!
(
project_id:
project
.
id
)
}
# Issue issue_type enum
let
(
:issue_type
)
{
0
}
let
(
:incident_type
)
{
1
}
before
do
label_links
.
create!
(
target_id:
incident_issue
.
id
,
label_id:
label
.
id
,
target_type:
'Issue'
)
end
describe
'#up'
do
it
'updates the incident issue type'
do
expect
{
migrate!
}
.
to
change
{
incident_issue
.
reload
.
issue_type
}
.
from
(
issue_type
)
.
to
(
incident_type
)
expect
(
other_issue
.
reload
.
issue_type
).
to
eql
(
issue_type
)
end
end
describe
'#down'
do
let!
(
:incident_issue
)
{
issues
.
create!
(
project_id:
project
.
id
,
issue_type:
issue_type
)
}
it
'updates the incident issue type'
do
migration
.
up
expect
{
migration
.
down
}
.
to
change
{
incident_issue
.
reload
.
issue_type
}
.
from
(
incident_type
)
.
to
(
issue_type
)
expect
(
other_issue
.
reload
.
issue_type
).
to
eql
(
issue_type
)
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