-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing inconsistency with duplicated votes (#1277)
* Fixing the bug and inconsistancy with duplicated votes in the karma app. (MIGRATION ADDED). Removing duplicated records while migrating * Fixing the bug and inconsistancy with duplicated votes in the karma app. (MIGRATION ADDED). Removing duplicated records while migrating (FIX for multiple duplicates)
- Loading branch information
Showing
4 changed files
with
51 additions
and
3 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
37 changes: 37 additions & 0 deletions
37
pyplanet/apps/contrib/karma/migrations/001_make_player_map_unique.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,37 @@ | ||
import logging | ||
from peewee import * | ||
from playhouse.migrate import migrate, SchemaMigrator | ||
|
||
from ..models.karma import Karma | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def upgrade(migrator: SchemaMigrator): | ||
# Fix the duplicates in the current setup. | ||
total_processed = 0 | ||
results = None | ||
while results is None or len(results) > 0: | ||
results = (Karma.select() | ||
.order_by(Karma.created_at.desc()) | ||
.group_by(Karma.player_id, Karma.map_id) | ||
.having(fn.Count(Karma.player_id) > 1)) | ||
|
||
for result in results: | ||
result.delete_instance() | ||
total_processed += 1 | ||
|
||
logger.warning('Removing duplicated karma votes, processed {} rows! Now going to execute the migration...'.format( | ||
total_processed | ||
)) | ||
|
||
# Create the indexes. | ||
migrate( | ||
migrator.add_index(Karma._meta.db_table, [ | ||
'player_id', 'map_id' | ||
], unique=True), | ||
) | ||
|
||
|
||
def downgrade(migrator: SchemaMigrator): | ||
pass |
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