Files
zulip/zerver/migrations/0240_usermessage_migrate_bigint_id_into_id.py
Anders Kaseorg 92ad4455ed requirements: Upgrade Django to 4.1.
zerver/migrations/0240_usermessage_migrate_bigint_id_into_id.py needs
to be updated to account for Django 4.1 creating AutoField as an
identity column rather than a serial column.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-10-06 15:59:07 -07:00

60 lines
2.4 KiB
Python

# Generated by Django 1.11.23 on 2019-08-23 21:03
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("zerver", "0239_usermessage_copy_id_to_bigint_id"),
]
# Note that this migration needs to work whether
# zerver_usermessage.bigint_id was created as a serial column (for
# Zulip initially installed with Django < 4.1) or an identity
# column (for Zulip initially installed with Django ≥ 4.1). If
# you need to edit it, remember to test both cases.
operations = [
migrations.RunSQL(
"""
DROP TRIGGER zerver_usermessage_bigint_id_to_id_trigger ON zerver_usermessage;
DROP FUNCTION zerver_usermessage_bigint_id_to_id_trigger_function();
ALTER TABLE zerver_usermessage
ALTER COLUMN bigint_id SET NOT NULL,
DROP CONSTRAINT zerver_usermessage_pkey,
ALTER COLUMN id DROP IDENTITY IF EXISTS,
ALTER COLUMN id DROP NOT NULL,
ALTER COLUMN id DROP DEFAULT;
ALTER TABLE zerver_usermessage RENAME COLUMN id TO id_old;
ALTER TABLE zerver_usermessage RENAME COLUMN bigint_id TO id;
DROP SEQUENCE IF EXISTS zerver_usermessage_id_seq;
ALTER TABLE zerver_usermessage
ADD CONSTRAINT zerver_usermessage_pkey PRIMARY KEY USING INDEX zerver_usermessage_bigint_id_idx,
ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY;
SELECT setval(
'zerver_usermessage_id_seq',
GREATEST(
(SELECT max(id) FROM zerver_usermessage),
(SELECT max(id) FROM zerver_archivedusermessage)
)
);
""",
state_operations=[
# This just tells Django to understand executing the above SQL as if it just ran the operations below,
# so that it knows these model changes are handled and doesn't to generate them on its own
# in the future makemigration calls.
migrations.RemoveField(
model_name="usermessage",
name="bigint_id",
),
migrations.AlterField(
model_name="usermessage",
name="id",
field=models.BigAutoField(primary_key=True, serialize=False),
),
],
),
]