[birds] Fix reset sequence for ebird imports
All checks were successful
build & deploy / test (push) Successful in 2m1s
build & deploy / build-and-deploy (push) Successful in 41s

This commit is contained in:
2026-05-24 10:39:47 -04:00
parent 83e7061b92
commit 939c89d368

View File

@ -0,0 +1,30 @@
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),
]