Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Truncate the syncqueue table before we add the unique constraint. #12197

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading