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
449dc6c4
Commit
449dc6c4
authored
Feb 15, 2021
by
Lee Tickett
Committed by
Jan Provaznik
Feb 15, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Populate and migrate issue_email_participants
parent
f9d82f3e
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
155 additions
and
1 deletion
+155
-1
changelogs/unreleased/288715-populate-and-migration-issue_email_participants.yml
...88715-populate-and-migration-issue_email_participants.yml
+5
-0
db/migrate/20201221225303_add_service_desk_reply_to_is_not_null_index_on_issues.rb
..._add_service_desk_reply_to_is_not_null_index_on_issues.rb
+18
-0
db/post_migrate/20201128210234_schedule_populate_issue_email_participants.rb
...01128210234_schedule_populate_issue_email_participants.rb
+31
-0
db/schema_migrations/20201128210234
db/schema_migrations/20201128210234
+1
-0
db/schema_migrations/20201221225303
db/schema_migrations/20201221225303
+1
-0
db/structure.sql
db/structure.sql
+2
-0
lib/gitlab/background_migration/populate_issue_email_participants.rb
...background_migration/populate_issue_email_participants.rb
+28
-0
lib/gitlab/email/handler/service_desk_handler.rb
lib/gitlab/email/handler/service_desk_handler.rb
+9
-1
spec/lib/gitlab/background_migration/populate_issue_email_participants_spec.rb
...round_migration/populate_issue_email_participants_spec.rb
+20
-0
spec/lib/gitlab/email/handler/service_desk_handler_spec.rb
spec/lib/gitlab/email/handler/service_desk_handler_spec.rb
+7
-0
spec/migrations/schedule_populate_issue_email_participants_spec.rb
...ations/schedule_populate_issue_email_participants_spec.rb
+33
-0
No files found.
changelogs/unreleased/288715-populate-and-migration-issue_email_participants.yml
0 → 100644
View file @
449dc6c4
---
title
:
Populate and migrate issue_email_participants
merge_request
:
48711
author
:
Lee Tickett @leetickett
type
:
added
db/migrate/20201221225303_add_service_desk_reply_to_is_not_null_index_on_issues.rb
0 → 100644
View file @
449dc6c4
# frozen_string_literal: true
class
AddServiceDeskReplyToIsNotNullIndexOnIssues
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
INDEX_NAME
=
'idx_on_issues_where_service_desk_reply_to_is_not_null'
disable_ddl_transaction!
def
up
add_concurrent_index
(
:issues
,
[
:id
],
name:
INDEX_NAME
,
where:
'service_desk_reply_to IS NOT NULL'
)
end
def
down
remove_concurrent_index_by_name
(
:issues
,
INDEX_NAME
)
end
end
db/post_migrate/20201128210234_schedule_populate_issue_email_participants.rb
0 → 100644
View file @
449dc6c4
# frozen_string_literal: true
class
SchedulePopulateIssueEmailParticipants
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
BATCH_SIZE
=
1_000
DELAY_INTERVAL
=
2
.
minutes
MIGRATION
=
'PopulateIssueEmailParticipants'
disable_ddl_transaction!
class
Issue
<
ActiveRecord
::
Base
include
EachBatch
self
.
table_name
=
'issues'
end
def
up
queue_background_migration_jobs_by_range_at_intervals
(
Issue
.
where
.
not
(
service_desk_reply_to:
nil
),
MIGRATION
,
DELAY_INTERVAL
,
batch_size:
BATCH_SIZE
)
end
def
down
# no-op
end
end
db/schema_migrations/20201128210234
0 → 100644
View file @
449dc6c4
7c2f83a5821765f3657a6dd6f69bc8711a3b9388aec7335293748b883f7ab872
\ No newline at end of file
db/schema_migrations/20201221225303
0 → 100644
View file @
449dc6c4
06dcd1a1f4bc0598357d48d9a0e838d9af1cf078234f2aabaa53ff9df01d2c17
\ No newline at end of file
db/structure.sql
View file @
449dc6c4
...
@@ -21255,6 +21255,8 @@ CREATE INDEX idx_mr_cc_diff_files_on_mr_cc_id_and_sha ON merge_request_context_c
...
@@ -21255,6 +21255,8 @@ CREATE INDEX idx_mr_cc_diff_files_on_mr_cc_id_and_sha ON merge_request_context_c
CREATE
UNIQUE
INDEX
idx_on_compliance_management_frameworks_namespace_id_name
ON
compliance_management_frameworks
USING
btree
(
namespace_id
,
name
);
CREATE
UNIQUE
INDEX
idx_on_compliance_management_frameworks_namespace_id_name
ON
compliance_management_frameworks
USING
btree
(
namespace_id
,
name
);
CREATE
INDEX
idx_on_issues_where_service_desk_reply_to_is_not_null
ON
issues
USING
btree
(
id
)
WHERE
(
service_desk_reply_to
IS
NOT
NULL
);
CREATE
INDEX
idx_packages_build_infos_on_package_id
ON
packages_build_infos
USING
btree
(
package_id
);
CREATE
INDEX
idx_packages_build_infos_on_package_id
ON
packages_build_infos
USING
btree
(
package_id
);
CREATE
INDEX
idx_packages_debian_group_component_files_on_architecture_id
ON
packages_debian_group_component_files
USING
btree
(
architecture_id
);
CREATE
INDEX
idx_packages_debian_group_component_files_on_architecture_id
ON
packages_debian_group_component_files
USING
btree
(
architecture_id
);
...
...
lib/gitlab/background_migration/populate_issue_email_participants.rb
0 → 100644
View file @
449dc6c4
# frozen_string_literal: true
module
Gitlab
module
BackgroundMigration
# Class to migrate service_desk_reply_to email addresses to issue_email_participants
class
PopulateIssueEmailParticipants
# rubocop:disable Style/Documentation
class
TmpIssue
<
ActiveRecord
::
Base
self
.
table_name
=
'issues'
end
def
perform
(
start_id
,
stop_id
)
issues
=
TmpIssue
.
select
(
:id
,
:service_desk_reply_to
,
:created_at
).
where
(
id:
(
start_id
..
stop_id
)).
where
.
not
(
service_desk_reply_to:
nil
)
rows
=
issues
.
map
do
|
issue
|
{
issue_id:
issue
.
id
,
email:
issue
.
service_desk_reply_to
,
created_at:
issue
.
created_at
,
updated_at:
issue
.
created_at
}
end
Gitlab
::
Database
.
bulk_insert
(
:issue_email_participants
,
rows
,
on_conflict: :do_nothing
)
# rubocop:disable Gitlab/BulkInsert
end
end
end
end
lib/gitlab/email/handler/service_desk_handler.rb
View file @
449dc6c4
...
@@ -35,7 +35,11 @@ module Gitlab
...
@@ -35,7 +35,11 @@ module Gitlab
raise
ProjectNotFound
if
project
.
nil?
raise
ProjectNotFound
if
project
.
nil?
create_issue!
create_issue!
send_thank_you_email!
if
from_address
if
from_address
add_email_participant
send_thank_you_email!
end
end
end
def
metrics_params
def
metrics_params
...
@@ -146,6 +150,10 @@ module Gitlab
...
@@ -146,6 +150,10 @@ module Gitlab
def
author
def
author
User
.
support_bot
User
.
support_bot
end
end
def
add_email_participant
@issue
.
issue_email_participants
.
create
(
email:
from_address
)
end
end
end
end
end
end
end
...
...
spec/lib/gitlab/background_migration/populate_issue_email_participants_spec.rb
0 → 100644
View file @
449dc6c4
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Gitlab
::
BackgroundMigration
::
PopulateIssueEmailParticipants
,
schema:
20201128210234
do
let!
(
:namespace
)
{
table
(
:namespaces
).
create!
(
name:
'namespace'
,
path:
'namespace'
)
}
let!
(
:project
)
{
table
(
:projects
).
create!
(
id:
1
,
namespace_id:
namespace
.
id
)
}
let!
(
:issue1
)
{
table
(
:issues
).
create!
(
id:
1
,
project_id:
project
.
id
,
service_desk_reply_to:
"a@gitlab.com"
)
}
let!
(
:issue2
)
{
table
(
:issues
).
create!
(
id:
2
,
project_id:
project
.
id
,
service_desk_reply_to:
"b@gitlab.com"
)
}
let
(
:issue_email_participants
)
{
table
(
:issue_email_participants
)
}
describe
'#perform'
do
it
'migrates email addresses from service desk issues'
,
:aggregate_failures
do
expect
{
subject
.
perform
(
1
,
2
)
}.
to
change
{
issue_email_participants
.
count
}.
by
(
2
)
expect
(
issue_email_participants
.
find_by
(
issue_id:
1
).
email
).
to
eq
(
"a@gitlab.com"
)
expect
(
issue_email_participants
.
find_by
(
issue_id:
2
).
email
).
to
eq
(
"b@gitlab.com"
)
end
end
end
spec/lib/gitlab/email/handler/service_desk_handler_spec.rb
View file @
449dc6c4
...
@@ -40,6 +40,13 @@ RSpec.describe Gitlab::Email::Handler::ServiceDeskHandler do
...
@@ -40,6 +40,13 @@ RSpec.describe Gitlab::Email::Handler::ServiceDeskHandler do
expect
(
new_issue
.
description
).
to
eq
(
expected_description
.
strip
)
expect
(
new_issue
.
description
).
to
eq
(
expected_description
.
strip
)
end
end
it
'creates an issue_email_participant'
do
receiver
.
execute
new_issue
=
Issue
.
last
expect
(
new_issue
.
issue_email_participants
.
first
.
email
).
to
eq
(
"jake@adventuretime.ooo"
)
end
it
'sends thank you email'
do
it
'sends thank you email'
do
expect
{
receiver
.
execute
}.
to
have_enqueued_job
.
on_queue
(
'mailers'
)
expect
{
receiver
.
execute
}.
to
have_enqueued_job
.
on_queue
(
'mailers'
)
end
end
...
...
spec/migrations/schedule_populate_issue_email_participants_spec.rb
0 → 100644
View file @
449dc6c4
# frozen_string_literal: true
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20201128210234_schedule_populate_issue_email_participants.rb'
)
RSpec
.
describe
SchedulePopulateIssueEmailParticipants
do
let!
(
:namespace
)
{
table
(
:namespaces
).
create!
(
name:
'namespace'
,
path:
'namespace'
)
}
let!
(
:project
)
{
table
(
:projects
).
create!
(
id:
1
,
namespace_id:
namespace
.
id
)
}
let!
(
:issue1
)
{
table
(
:issues
).
create!
(
id:
1
,
project_id:
project
.
id
,
service_desk_reply_to:
"a@gitlab.com"
)
}
let!
(
:issue2
)
{
table
(
:issues
).
create!
(
id:
2
,
project_id:
project
.
id
)
}
let!
(
:issue3
)
{
table
(
:issues
).
create!
(
id:
3
,
project_id:
project
.
id
,
service_desk_reply_to:
"b@gitlab.com"
)
}
let!
(
:issue4
)
{
table
(
:issues
).
create!
(
id:
4
,
project_id:
project
.
id
,
service_desk_reply_to:
"c@gitlab.com"
)
}
let!
(
:issue5
)
{
table
(
:issues
).
create!
(
id:
5
,
project_id:
project
.
id
,
service_desk_reply_to:
"d@gitlab.com"
)
}
let
(
:issue_email_participants
)
{
table
(
:issue_email_participants
)
}
it
'correctly schedules background migrations'
do
stub_const
(
"
#{
described_class
.
name
}
::BATCH_SIZE"
,
2
)
Sidekiq
::
Testing
.
fake!
do
freeze_time
do
migrate!
expect
(
described_class
::
MIGRATION
)
.
to
be_scheduled_delayed_migration
(
2
.
minutes
,
1
,
3
)
expect
(
described_class
::
MIGRATION
)
.
to
be_scheduled_delayed_migration
(
4
.
minutes
,
4
,
5
)
expect
(
BackgroundMigrationWorker
.
jobs
.
size
).
to
eq
(
2
)
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