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
77197d68
Commit
77197d68
authored
Jul 10, 2020
by
Sean Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add spec for testing DB rollback
- Spec sets up alerts - Rolls back DB and check to see desired behaviour
parent
ee635a86
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
0 deletions
+70
-0
db/migrate/20200706035141_adjust_unique_index_alert_management_alerts.rb
...0706035141_adjust_unique_index_alert_management_alerts.rb
+13
-0
spec/migrations/20200706035141_adjust_unique_index_alert_management_alerts_spec.rb
...35141_adjust_unique_index_alert_management_alerts_spec.rb
+57
-0
No files found.
db/migrate/20200706035141_adjust_unique_index_alert_management_alerts.rb
View file @
77197d68
...
...
@@ -16,6 +16,19 @@ class AdjustUniqueIndexAlertManagementAlerts < ActiveRecord::Migration[6.0]
end
def
down
# Nullify duplicate fingerprints, except for the newest of each match (project_id, fingerprint).
query
=
<<-
SQL
UPDATE alert_management_alerts am
SET fingerprint = NULL
WHERE am.created_at <>
(SELECT MAX(created_at)
FROM alert_management_alerts am2
WHERE am.fingerprint = am2.fingerprint AND am.project_id = am2.project_id)
AND am.fingerprint IS NOT NULL;
SQL
execute
(
query
)
remove_index
:alert_management_alerts
,
name:
NEW_INDEX_NAME
add_index
(
:alert_management_alerts
,
%w(project_id fingerprint)
,
name:
INDEX_NAME
,
unique:
true
,
using: :btree
)
end
...
...
spec/migrations/20200706035141_adjust_unique_index_alert_management_alerts_spec.rb
0 → 100644
View file @
77197d68
# frozen_string_literal: true
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'migrate'
,
'20200706035141_adjust_unique_index_alert_management_alerts.rb'
)
RSpec
.
describe
AdjustUniqueIndexAlertManagementAlerts
,
:migration
do
let
(
:migration
)
{
described_class
.
new
}
let
(
:alerts
)
{
AlertManagement
::
Alert
}
let
(
:project
)
{
create_project
}
let
(
:other_project
)
{
create_project
}
let
(
:resolved_state
)
{
2
}
let
(
:triggered_state
)
{
1
}
let!
(
:existing_alert
)
{
create_alert
(
project
,
resolved_state
,
'1234'
,
1
)
}
let!
(
:p2_alert
)
{
create_alert
(
other_project
,
resolved_state
,
'1234'
,
1
)
}
let!
(
:p2_alert_diff_fingerprint
)
{
create_alert
(
other_project
,
resolved_state
,
'4567'
,
2
)
}
it
'can reverse the migration'
do
expect
(
existing_alert
.
fingerprint
).
not_to
eq
(
nil
)
expect
(
p2_alert
.
fingerprint
).
not_to
eq
(
nil
)
expect
(
p2_alert_diff_fingerprint
.
fingerprint
).
not_to
eq
(
nil
)
migrate!
# Adding a second alert with the same fingerprint now that we can
second_alert
=
create_alert
(
project
,
triggered_state
,
'1234'
,
2
)
expect
(
alerts
.
count
).
to
eq
(
4
)
schema_migrate_down!
# We keep the alerts, but the oldest ones fingerprint is removed
expect
(
alerts
.
count
).
to
eq
(
4
)
expect
(
second_alert
.
reload
.
fingerprint
).
not_to
eq
(
nil
)
expect
(
p2_alert
.
fingerprint
).
not_to
eq
(
nil
)
expect
(
p2_alert_diff_fingerprint
.
fingerprint
).
not_to
eq
(
nil
)
expect
(
existing_alert
.
reload
.
fingerprint
).
to
eq
(
nil
)
end
def
namespace
@namespace
||=
table
(
:namespaces
).
create!
(
name:
'foo'
,
path:
'foo'
)
end
def
create_project
table
(
:projects
).
create!
(
namespace_id:
namespace
.
id
)
end
def
create_alert
(
project
,
status
,
fingerprint
,
iid
)
params
=
{
title:
'test'
,
started_at:
Time
.
current
,
iid:
iid
,
project_id:
project
.
id
,
status:
status
,
fingerprint:
fingerprint
}
table
(
:alert_management_alerts
).
create!
(
params
)
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