1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-10 12:16:49 +00:00

fix(migrations): a fresh PostgreSQL database migrates, and CI tests it

The first appsettings migrations insert the default rows with fixed ids,
which a PostgreSQL id sequence does not see; the login lockout migration,
the first to insert without an id, then collided with id 1. It now moves
the sequence past the existing rows first (a no-op on sqlite), which also
covers a database upgraded from any earlier migration. A test compute
password exceeded its 14-character column, which only PostgreSQL enforces.
This commit is contained in:
catborise 2026-10-07 15:59:10 +03:00
parent 85706c5df6
commit f889861e18
4 changed files with 63 additions and 3 deletions

View file

@ -1,3 +1,4 @@
from django.core.management.color import no_style
from django.db import migrations
@ -12,6 +13,12 @@ SETTINGS = [
def add_settings(apps, schema_editor):
setting = apps.get_model("appsettings", "AppSettings")
db_alias = schema_editor.connection.alias
# Earlier migrations inserted the default rows with fixed ids, which a
# PostgreSQL id sequence does not see: move it past them before inserting
# without an id (a no-op on sqlite).
with schema_editor.connection.cursor() as cursor:
for sql in schema_editor.connection.ops.sequence_reset_sql(no_style(), [setting]):
cursor.execute(sql)
for name, key, value, description in SETTINGS:
setting.objects.using(db_alias).get_or_create(
key=key, defaults={"name": name, "value": value, "choices": "", "description": description}