mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-10 20:26:48 +00:00
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.
37 lines
1.5 KiB
Python
37 lines
1.5 KiB
Python
from django.core.management.color import no_style
|
|
from django.db import migrations
|
|
|
|
|
|
SETTINGS = [
|
|
("Login Failure Limit", "LOGIN_FAILURE_LIMIT", "5",
|
|
"Failed logins of a user from one address before it is locked"),
|
|
("Login Lockout Minutes", "LOGIN_LOCKOUT_MINUTES", "15",
|
|
"How long a locked login stays locked, in minutes"),
|
|
]
|
|
|
|
|
|
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}
|
|
)
|
|
|
|
|
|
def del_settings(apps, schema_editor):
|
|
setting = apps.get_model("appsettings", "AppSettings")
|
|
db_alias = schema_editor.connection.alias
|
|
setting.objects.using(db_alias).filter(key__in=[key for _, key, _, _ in SETTINGS]).delete()
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
dependencies = [("appsettings", "0013_remove_qemu_console_default_type")]
|
|
|
|
operations = [migrations.RunPython(add_settings, del_settings)]
|