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) command.check(alembic_cfg)
except util.exc.AutogenerateDiffsDetected as exc: except util.exc.AutogenerateDiffsDetected as exc:
logger.exception("AutogenerateDiffsDetected: {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: if fix:
self.try_downgrade_upgrade_until_success(alembic_cfg) 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 # if the exception involves tables already existing
# we can ignore it # we can ignore it
if "already exists" not in str(exc): if "already exists" not in str(exc):
logger.error(f"Error running migrations: {exc}") logger.error(exc)
raise RuntimeError("Error running migrations") from exc
raise exc
logger.debug("Database initialized") logger.debug("Database initialized")

View file

@ -200,7 +200,11 @@ def initialize_services(fix_migration: bool = False):
# Test cache connection # Test cache connection
service_manager.get(ServiceType.CACHE_SERVICE) service_manager.get(ServiceType.CACHE_SERVICE)
# Setup the superuser # 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())) setup_superuser(service_manager.get(ServiceType.SETTINGS_SERVICE), next(get_session()))
try: try:
get_db_service().migrate_flows_if_auto_login() get_db_service().migrate_flows_if_auto_login()