agendas: change Event id field to have a BigAutoField (#74008)
This commit is contained in:
parent
d994258018
commit
4db8e384c9
|
@ -0,0 +1,42 @@
|
|||
import os
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
sql_forwards_bigint = """
|
||||
ALTER SEQUENCE "agendas_event_id_seq" as bigint MAXVALUE 9223372036854775807;
|
||||
ALTER TABLE "agendas_event" ALTER COLUMN "id" TYPE bigint USING "id"::bigint, ALTER COLUMN "primary_event_id" TYPE bigint USING "primary_event_id"::bigint;
|
||||
ALTER TABLE "agendas_booking" ALTER COLUMN "event_id" TYPE bigint USING "event_id"::bigint;
|
||||
ALTER TABLE "agendas_event_resources" ALTER COLUMN "event_id" TYPE bigint USING "event_id"::bigint;
|
||||
ALTER TABLE "agendas_eventcancellationreport" ALTER COLUMN "event_id" TYPE bigint USING "event_id"::bigint;
|
||||
ALTER TABLE "agendas_recurrenceexceptionsreport_events" ALTER COLUMN "event_id" TYPE bigint USING "event_id"::bigint;
|
||||
"""
|
||||
|
||||
|
||||
with open(
|
||||
os.path.join(
|
||||
os.path.dirname(os.path.realpath(__file__)), '..', 'sql', 'event_booked_places_and_full_triggers.sql'
|
||||
)
|
||||
) as sql_file:
|
||||
sql_forwards_triggers = sql_file.read()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('agendas', '0145_user_phone_number'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunSQL(
|
||||
sql=sql_forwards_bigint,
|
||||
reverse_sql=migrations.RunSQL.noop,
|
||||
state_operations=[
|
||||
migrations.AlterField(
|
||||
model_name='event',
|
||||
name='id',
|
||||
field=models.BigAutoField(primary_key=True, serialize=False),
|
||||
),
|
||||
],
|
||||
),
|
||||
migrations.RunSQL(sql=sql_forwards_triggers, reverse_sql=migrations.RunSQL.noop),
|
||||
]
|
|
@ -1434,6 +1434,7 @@ class MeetingType(models.Model):
|
|||
|
||||
|
||||
class Event(models.Model):
|
||||
id = models.BigAutoField(primary_key=True)
|
||||
INTERVAL_CHOICES = [
|
||||
(1, _('Every week')),
|
||||
(2, _('Every two weeks')),
|
||||
|
|
|
@ -35,7 +35,7 @@ $$ LANGUAGE plpgsql;
|
|||
|
||||
CREATE OR REPLACE FUNCTION update_event_places_fields() RETURNS TRIGGER AS $$
|
||||
DECLARE
|
||||
e_id integer;
|
||||
e_id bigint;
|
||||
BEGIN
|
||||
IF (TG_OP = 'DELETE') THEN
|
||||
e_id = OLD.event_id;
|
||||
|
|
|
@ -8,7 +8,7 @@ import requests
|
|||
from django.contrib.auth.models import Group, User
|
||||
from django.core.files.base import ContentFile
|
||||
from django.core.management import call_command
|
||||
from django.db import IntegrityError, transaction
|
||||
from django.db import IntegrityError, connection, transaction
|
||||
from django.db.models import Q
|
||||
from django.test import override_settings
|
||||
from django.utils.timezone import localtime, make_aware, now
|
||||
|
@ -2625,6 +2625,13 @@ def test_recurring_events_display(freezer):
|
|||
|
||||
|
||||
def test_event_triggered_fields():
|
||||
# alter event pk sequence to have a bigint
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute("SELECT nextval('agendas_event_id_seq')")
|
||||
row = cursor.fetchone()
|
||||
if row[0] < 2**31:
|
||||
cursor.execute("ALTER SEQUENCE agendas_event_id_seq RESTART WITH %s;" % 2**31)
|
||||
|
||||
agenda = Agenda.objects.create(label='Agenda', kind='events')
|
||||
event = Event.objects.create(
|
||||
agenda=agenda, start_datetime=now() + datetime.timedelta(days=10), places=10, label='Event'
|
||||
|
|
Loading…
Reference in New Issue