Revert "lifecycle: improve reliability of system migrations"

This reverts commit 3b8b307c4d.
This commit is contained in:
Jens Langhammer
2023-10-06 15:46:45 +02:00
parent 3b8b307c4d
commit 090d2d8362
8 changed files with 98 additions and 93 deletions

View File

@ -1,12 +1,12 @@
#!/usr/bin/env python
"""System Migration handler"""
import os
from importlib.util import module_from_spec, spec_from_file_location
from inspect import getmembers, isclass
from os import environ, system
from pathlib import Path
from typing import Any
from psycopg import Connection, Cursor, connect
from psycopg import connect
from structlog.stdlib import get_logger
from authentik.lib.config import CONFIG
@ -19,24 +19,13 @@ LOCKED = False
class BaseMigration:
"""Base System Migration"""
cur: Cursor
con: Connection
cur: Any
con: Any
def __init__(self, cur: Any, con: Any):
self.cur = cur
self.con = con
def system_crit(self, command: str):
"""Run system command"""
LOGGER.debug("Running system_crit command", command=command)
retval = system(command) # nosec
if retval != 0:
raise Exception("Migration error")
def fake_migration(self, *app_migration: tuple[str, str]):
for app, migration in app_migration:
self.system_crit(f"./manage.py migrate {app} {migration} --fake")
def needs_migration(self) -> bool:
"""Return true if Migration needs to be run"""
return False
@ -93,7 +82,7 @@ if __name__ == "__main__":
LOGGER.info("Migration finished applying", migration=sub)
release_lock()
LOGGER.info("applying django migrations")
environ.setdefault("DJANGO_SETTINGS_MODULE", "authentik.root.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "authentik.root.settings")
wait_for_lock()
try:
from django.core.management import execute_from_command_line