Skip to content

Commit

Permalink
Truncate the syncqueue table before we add the unique constraint.
Browse files Browse the repository at this point in the history
  • Loading branch information
rtibbles committed May 22, 2024
1 parent a5ec048 commit 8562347
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 8562347

Please sign in to comment.