Skip to content

Commit

Permalink
Merge pull request #12197 from rtibbles/truncate_syncqueue
Browse files Browse the repository at this point in the history
Truncate the syncqueue table before we add the unique constraint.
  • Loading branch information
rtibbles authored May 23, 2024
2 parents a5ec048 + 8562347 commit 4abdca3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 9 additions & 1 deletion kolibri/core/device/migrations/0019_syncqueue_and_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import django.db.models.deletion
import morango.models.fields.uuids
from django.conf import settings
from django.db import connection
from django.db import migrations
from django.db import models

Expand All @@ -20,6 +20,14 @@ class Migration(migrations.Migration):
model_name="usersyncstatus",
name="queued",
),
migrations.RunSQL(
[
"DELETE FROM device_syncqueue;"
if "sqlite" in connection.vendor
else "TRUNCATE TABLE device_syncqueue;"
],
hints={"is_syncqueue": True},
),
migrations.AddField(
model_name="syncqueue",
name="attempts",
Expand Down
5 changes: 2 additions & 3 deletions kolibri/core/device/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,8 @@ def allow_relation(self, obj1, obj2, **hints):

def allow_migrate(self, db, app_label, model_name=None, **hints):
"""Ensure that the SyncQueue models get created on the right database."""
if (
app_label == SyncQueue._meta.app_label
and model_name == SyncQueue._meta.model_name
if app_label == SyncQueue._meta.app_label and (
model_name == SyncQueue._meta.model_name or hints.get("is_syncqueue")
):
# The SyncQueue model should be migrated only on the SYNC_QUEUE database.
return db == SYNC_QUEUE
Expand Down

0 comments on commit 4abdca3

Please sign in to comment.