Files
authentik/packages/django-channels-postgres/django_channels_postgres/migrations/0001_initial.py
2025-10-06 13:39:28 +02:00

95 lines
3.9 KiB
Python

# Generated by Django 5.1.13 on 2025-10-04 14:35
import django_channels_postgres.models
import pgtrigger.compiler
import pgtrigger.migrations
import uuid
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = []
operations = [
migrations.CreateModel(
name="GroupChannel",
fields=[
(
"id",
models.UUIDField(
default=uuid.uuid4, editable=False, primary_key=True, serialize=False
),
),
("group_key", models.TextField(db_index=True)),
("channel", models.TextField(db_index=True)),
(
"expires",
models.DateTimeField(
db_index=True, default=django_channels_postgres.models._default_group_expiry
),
),
],
options={
"verbose_name": "Group channel",
"verbose_name_plural": "Group channels",
"indexes": [
models.Index(
fields=["group_key", "channel"], name="django_chan_group_k_173f44_idx"
),
models.Index(
fields=["group_key", "expires"], name="django_chan_group_k_45d2e0_idx"
),
],
},
),
migrations.CreateModel(
name="Message",
fields=[
(
"id",
models.UUIDField(
default=uuid.uuid4, editable=False, primary_key=True, serialize=False
),
),
("channel", models.TextField(db_index=True)),
("message", models.BinaryField()),
(
"expires",
models.DateTimeField(
db_index=True,
default=django_channels_postgres.models._default_message_expiry,
),
),
],
options={
"verbose_name": "Message",
"verbose_name_plural": "Messages",
"indexes": [
models.Index(
fields=["channel", "expires"], name="django_chan_channel_e8ca51_idx"
)
],
},
),
pgtrigger.migrations.AddTrigger(
model_name="message",
trigger=pgtrigger.compiler.Trigger(
name="notify_new_channels_message",
sql=pgtrigger.compiler.UpsertTriggerSql(
constraint="CONSTRAINT",
declare="DECLARE payload text; encoded_message text; epoch text;",
func="\n encoded_message := encode(NEW.message, 'base64');\n epoch := extract(epoch from NEW.expires)::text;\n IF octet_length(NEW.id::text) + octet_length(NEW.channel) + octet_length(epoch) + octet_length(encoded_message) + 3 <= 8000 THEN\n payload := NEW.id::text || ':' || NEW.channel || ':' || epoch || ':' || encoded_message;\n ELSE\n payload := NEW.id::text || ':' || NEW.channel || ':' || epoch;\n END IF;\n\n PERFORM pg_notify('channels_messages', payload);\n RETURN NEW;\n ",
hash="cf7a665df0bbb7d865cdbc92b63d818fd25733d8",
operation="INSERT",
pgid="pgtrigger_notify_new_channels_message_d21ae",
table="django_channels_postgres_message",
timing="DEFERRABLE INITIALLY DEFERRED",
when="AFTER",
),
),
),
]