Fix migration error and initialize database in

utils.py
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-12-01 16:37:11 -03:00
commit dcefb8363c
3 changed files with 9 additions and 4 deletions

View file

@ -155,7 +155,7 @@ class DatabaseService(Service):
command.check(alembic_cfg)
except util.exc.AutogenerateDiffsDetected as exc:
logger.exception("AutogenerateDiffsDetected: {exc}")
logger.warning("Something went wrong running migrations. Please, run `langflow migration --fix`")
raise RuntimeError("Something went wrong running migrations. Please, run `langflow migration --fix`")
if fix:
self.try_downgrade_upgrade_until_success(alembic_cfg)

View file

@ -48,8 +48,9 @@ def initialize_database(fix_migration: bool = False):
# if the exception involves tables already existing
# we can ignore it
if "already exists" not in str(exc):
logger.error(f"Error running migrations: {exc}")
raise RuntimeError("Error running migrations") from exc
logger.error(exc)
raise exc
logger.debug("Database initialized")

View file

@ -200,7 +200,11 @@ def initialize_services(fix_migration: bool = False):
# Test cache connection
service_manager.get(ServiceType.CACHE_SERVICE)
# Setup the superuser
initialize_database(fix_migration=fix_migration)
try:
initialize_database(fix_migration=fix_migration)
except Exception as exc:
logger.exception(exc)
raise exc
setup_superuser(service_manager.get(ServiceType.SETTINGS_SERVICE), next(get_session()))
try:
get_db_service().migrate_flows_if_auto_login()