mirror of https://github.com/zulip/zulip.git
retention: Fix migration making archive_transaction field not null.
DELETing from archive tables and ALTERing ArchivedMessage needs to be split into separate transactions. zerver_archivedattachment_messages needs to be cleared out before zerver_archivedattachment.
This commit is contained in:
parent
e14a40675b
commit
b8839302c0
|
@ -4,21 +4,30 @@ from __future__ import unicode_literals
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
"""
|
||||||
|
Tables cannot have data deleted from them and be altered in a single transaction,
|
||||||
|
but we need the DELETEs to be atomic together. So we set atomic=False for the migration
|
||||||
|
in general, and run the DELETEs in one transaction, and AlterField in another.
|
||||||
|
"""
|
||||||
|
atomic = False
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('zerver', '0231_add_archive_transaction_model'),
|
('zerver', '0231_add_archive_transaction_model'),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.RunSQL("DELETE FROM zerver_archivedusermessage"),
|
migrations.RunSQL("""
|
||||||
migrations.RunSQL("DELETE FROM zerver_archivedreaction"),
|
BEGIN;
|
||||||
migrations.RunSQL("DELETE FROM zerver_archivedsubmessage"),
|
DELETE FROM zerver_archivedusermessage;
|
||||||
migrations.RunSQL("DELETE FROM zerver_archivedattachment"),
|
DELETE FROM zerver_archivedreaction;
|
||||||
migrations.RunSQL("DELETE FROM zerver_archivedattachment_messages"),
|
DELETE FROM zerver_archivedsubmessage;
|
||||||
migrations.RunSQL("DELETE FROM zerver_archivedmessage"),
|
DELETE FROM zerver_archivedattachment_messages;
|
||||||
migrations.RunSQL("DELETE FROM zerver_archivetransaction"),
|
DELETE FROM zerver_archivedattachment;
|
||||||
|
DELETE FROM zerver_archivedmessage;
|
||||||
|
DELETE FROM zerver_archivetransaction;
|
||||||
|
COMMIT;
|
||||||
|
"""),
|
||||||
migrations.AlterField(
|
migrations.AlterField(
|
||||||
model_name='archivedmessage',
|
model_name='archivedmessage',
|
||||||
name='archive_transaction',
|
name='archive_transaction',
|
||||||
|
|
Loading…
Reference in New Issue