Skip to content

Commit

Permalink
Bug 1842924 - Update deletion constraints for performancedatumreplica…
Browse files Browse the repository at this point in the history
…te. (#7744)
  • Loading branch information
gmierz committed Jul 13, 2023
1 parent c64a8ec commit 49aa450
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/model/cycle_data/test_perfherder_cycling.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from treeherder.perf.exceptions import MaxRuntimeExceeded
from treeherder.perf.models import (
PerformanceDatum,
PerformanceDatumReplicate,
PerformanceSignature,
PerformanceAlertSummary,
PerformanceAlert,
Expand Down Expand Up @@ -823,6 +824,29 @@ def test_deleting_performance_data_cascades_to_perf_multicomit_data(test_perf_da
assert MultiCommitDatum.objects.count() == 0


def test_deleting_performance_data_cascades_to_perf_datum_replicate(test_perf_data):
perf_datum = test_perf_data[0]
PerformanceDatumReplicate.objects.create(performance_datum=perf_datum, value=0.0)

assert PerformanceDatumReplicate.objects.count() == 1

try:
cursor = connection.cursor()
cursor.execute(
'''
DELETE FROM `performance_datum`
WHERE id = %s
''',
[perf_datum.id],
)
except IntegrityError:
pytest.fail()
finally:
cursor.close()

assert PerformanceDatumReplicate.objects.count() == 0


def test_alerts_older_than_a_year_are_removed_even_if_signature_is_active(test_perf_alert):
# alert (fixture) comes pre linked to an active signature
test_perf_alert.created = datetime.now() - timedelta(days=365)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Generated by Django 3.0.8 on 2020-12-11 14:42

from django.db import migrations

DATUM_REPLICATE_CONSTRAINT_SYMBOL = (
'performance_datum_re_performance_datum_id_fe2ed518_fk_performan'
)


class Migration(migrations.Migration):
dependencies = [
('perf', '0049_performancedatumreplicate'),
]

operations = [
migrations.RunSQL(
# add ON DELETE CASCADE at database level
[
f'ALTER TABLE performance_datum_replicate '
f'DROP FOREIGN KEY {DATUM_REPLICATE_CONSTRAINT_SYMBOL};',
f'ALTER TABLE performance_datum_replicate '
f'ADD CONSTRAINT {DATUM_REPLICATE_CONSTRAINT_SYMBOL} '
f'FOREIGN KEY (performance_datum_id) REFERENCES performance_datum (ID) ON DELETE CASCADE;',
],
# put back the non-CASCADE foreign key constraint
reverse_sql=[
f'ALTER TABLE performance_datum_replicate '
f'DROP FOREIGN KEY {DATUM_REPLICATE_CONSTRAINT_SYMBOL};',
f'ALTER TABLE performance_datum_replicate '
f'ADD CONSTRAINT {DATUM_REPLICATE_CONSTRAINT_SYMBOL} '
f'FOREIGN KEY (performance_datum_id) REFERENCES performance_datum (ID);',
],
)
]

0 comments on commit 49aa450

Please sign in to comment.