Files
vrobbler/vrobbler/apps/scrobbles/migrations/0084_fix_ebird_sequence.py
Colin Powell 939c89d368
All checks were successful
build & deploy / test (push) Successful in 2m1s
build & deploy / build-and-deploy (push) Successful in 41s
[birds] Fix reset sequence for ebird imports
2026-05-24 10:39:47 -04:00

31 lines
926 B
Python

from django.db import migrations
def reset_sequence(apps, schema_editor):
from django.db import connection
with connection.cursor() as cursor:
vendor = connection.vendor
if vendor == "postgresql":
cursor.execute(
"SELECT setval('scrobbles_ebirdcsvimport_id_seq', "
"COALESCE((SELECT MAX(id) + 1 FROM scrobbles_ebirdcsvimport), 1), "
"false)"
)
elif vendor == "sqlite":
cursor.execute(
"UPDATE sqlite_sequence SET seq = ("
"SELECT COALESCE(MAX(id), 0) FROM scrobbles_ebirdcsvimport"
") WHERE name = 'scrobbles_ebirdcsvimport'"
)
class Migration(migrations.Migration):
dependencies = [
("scrobbles", "0083_migrate_birding_data"),
]
operations = [
migrations.RunPython(reset_sequence, migrations.RunPython.noop),
]