forked from cyverse/atmosphere
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged
xylotomous-xenops
into allocations
* xylotomous-xenops: Problem: Duplicate `user_allocation_source` Events (cyverse#351)
- Loading branch information
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