This repository has been archived by the owner on Sep 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Problem: Duplicate
user_allocation_source
Events (#351)
* Problem : Duplicate user_allocation_source Events * Problem: Can't freeze time more than once Solution: If `context.freezer` already exists, set `context.freezer.time_to_freeze` to `context.frozen_current_time`. * Problem: No test for #350 - Duplicate `user_allocation_source` Events Solution: Added behave scenario to ensure that we don't create duplicate events when checking the TAS API multiple times. * Problem: No migration to remove existing duplicate events re #350 Solution: Added migration to remove duplicate events with name `user_allocation_source_created`. * Added an entry to the CHANGELOG.md file for #350 * Renamed the projects.
- Loading branch information
1 parent
653ec46
commit e971c94
Showing
6 changed files
with
162 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
core/migrations/0080_delete_duplicate_user_allocation_source_events.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.9.8 on 2017-03-29 18:34 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
('core', '0079_add_events_for_old_allocationsource'), | ||
] | ||
|
||
rename_duplicate_events = '''UPDATE event_table | ||
SET name = 'user_allocation_source_created_DELETE' | ||
FROM ( | ||
SELECT | ||
entity_id, | ||
name, | ||
payload, | ||
count(*), | ||
min(timestamp) AS min_timestamp, | ||
max(timestamp) AS max_timestamp | ||
FROM event_table | ||
WHERE name = 'user_allocation_source_created' | ||
GROUP BY entity_id, name, payload | ||
HAVING count(*) > 1 | ||
) AS duplicates | ||
WHERE | ||
event_table.entity_id = duplicates.entity_id | ||
AND event_table.name = duplicates.name | ||
AND event_table.payload = duplicates.payload | ||
AND event_table.timestamp > duplicates.min_timestamp;''' | ||
|
||
delete_renamed_duplicate_events = '''DELETE FROM event_table | ||
WHERE name = 'user_allocation_source_created_DELETE'; | ||
''' | ||
|
||
operations = [ | ||
migrations.RunSQL(rename_duplicate_events), | ||
migrations.RunSQL(delete_renamed_duplicate_events), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters