Merge pull request #989 from logspace-ai:fix_db_superuser

🐛 fix(utils.py): handle exception when creating DB and tables to ignore if tables already exist
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-09-29 19:13:23 -03:00 committed by GitHub
commit 880626cf7b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View file

@ -13,7 +13,17 @@ def initialize_database():
logger.debug("Initializing database")
from langflow.services import service_manager, ServiceType
database_service = service_manager.get(ServiceType.DATABASE_SERVICE)
database_service: "DatabaseService" = service_manager.get(
ServiceType.DATABASE_SERVICE
)
try:
database_service.create_db_and_tables()
except Exception as exc:
# if the exception involves tables already existing
# we can ignore it
if "already exists" not in str(exc):
logger.error(f"Error creating DB and tables: {exc}")
raise RuntimeError("Error creating DB and tables") from exc
try:
database_service.check_schema_health()
except Exception as exc:
@ -39,7 +49,6 @@ def initialize_database():
if "already exists" not in str(exc):
logger.error(f"Error running migrations: {exc}")
raise RuntimeError("Error running migrations") from exc
database_service.create_db_and_tables()
logger.debug("Database initialized")

View file

@ -34,7 +34,7 @@ class AuthSettings(BaseSettings):
# If AUTO_LOGIN = True
# > The application does not request login and logs in automatically as a super user.
AUTO_LOGIN: bool = False
AUTO_LOGIN: bool = True
NEW_USER_IS_ACTIVE: bool = False
SUPERUSER: str = DEFAULT_SUPERUSER
SUPERUSER_PASSWORD: str = DEFAULT_SUPERUSER_PASSWORD