Skip to content

Commit

Permalink
Correctly initialize the sequence with PostgreSQL
Browse files Browse the repository at this point in the history
  • Loading branch information
vrigal committed Nov 25, 2024
1 parent eff7cb8 commit 9e58392
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by Django 5.1.2 on 2024-11-18 15:53

from django.conf import settings
from django.db import migrations, models


Expand All @@ -23,3 +24,17 @@ class Migration(migrations.Migration):
options={"ordering": ("id",), "verbose_name_plural": "repositories"},
),
]
if "postgresql" in settings.DATABASES["default"]["ENGINE"]:
# Correctly initialize the sequence with PostgreSQL
migrations.append(
migrations.RunSQL(
"""
SELECT setval(
pg_get_serial_sequence('issues_repository', 'id'),
coalesce(max(id)+1, 0),
false
) FROM issues_repository;
""",
reverse_sql=migrations.RunSQL.noop,
)
)

0 comments on commit 9e58392

Please sign in to comment.