Fix database initialization issue
This commit is contained in:
parent
f1773a906c
commit
c05108230e
1 changed files with 3 additions and 4 deletions
|
|
@ -4,7 +4,7 @@ from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from alembic.util.exc import CommandError
|
from alembic.util.exc import CommandError
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from sqlmodel import Session
|
from sqlmodel import Session, text
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from langflow.services.database.service import DatabaseService
|
from langflow.services.database.service import DatabaseService
|
||||||
|
|
@ -42,14 +42,13 @@ def initialize_database(fix_migration: bool = False):
|
||||||
# and run the migrations again
|
# and run the migrations again
|
||||||
logger.warning("Wrong revision in DB, deleting alembic_version table and running migrations again")
|
logger.warning("Wrong revision in DB, deleting alembic_version table and running migrations again")
|
||||||
with session_getter(database_service) as session:
|
with session_getter(database_service) as session:
|
||||||
session.execute("DROP TABLE alembic_version")
|
session.exec(text("DROP TABLE alembic_version"))
|
||||||
database_service.run_migrations()
|
database_service.run_migrations(fix=fix_migration)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
# 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(exc)
|
logger.error(exc)
|
||||||
|
|
||||||
raise exc
|
raise exc
|
||||||
logger.debug("Database initialized")
|
logger.debug("Database initialized")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue