Fix database initialization issue and add delay
after upgrade
This commit is contained in:
parent
9a697362cb
commit
f1773a906c
1 changed files with 7 additions and 5 deletions
|
|
@ -5,16 +5,17 @@ from typing import TYPE_CHECKING
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
from alembic import command, util
|
from alembic import command, util
|
||||||
from alembic.config import Config
|
from alembic.config import Config
|
||||||
|
from loguru import logger
|
||||||
|
from sqlalchemy import inspect
|
||||||
|
from sqlalchemy.exc import OperationalError
|
||||||
|
from sqlmodel import Session, SQLModel, create_engine, text
|
||||||
|
|
||||||
from langflow.services.base import Service
|
from langflow.services.base import Service
|
||||||
from langflow.services.database import models # noqa
|
from langflow.services.database import models # noqa
|
||||||
from langflow.services.database.models.user.crud import get_user_by_username
|
from langflow.services.database.models.user.crud import get_user_by_username
|
||||||
from langflow.services.database.utils import Result, TableResults
|
from langflow.services.database.utils import Result, TableResults
|
||||||
from langflow.services.deps import get_settings_service
|
from langflow.services.deps import get_settings_service
|
||||||
from langflow.services.utils import teardown_superuser
|
from langflow.services.utils import teardown_superuser
|
||||||
from loguru import logger
|
|
||||||
from sqlalchemy import inspect
|
|
||||||
from sqlalchemy.exc import OperationalError
|
|
||||||
from sqlmodel import Session, SQLModel, create_engine
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from sqlalchemy.engine import Engine
|
from sqlalchemy.engine import Engine
|
||||||
|
|
@ -130,7 +131,7 @@ class DatabaseService(Service):
|
||||||
# If the table does not exist it throws an error
|
# If the table does not exist it throws an error
|
||||||
# so we need to catch it
|
# so we need to catch it
|
||||||
try:
|
try:
|
||||||
session.execute("SELECT * FROM alembic_version")
|
session.exec(text("SELECT * FROM alembic_version"))
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.info("Alembic not initialized")
|
logger.info("Alembic not initialized")
|
||||||
try:
|
try:
|
||||||
|
|
@ -150,6 +151,7 @@ class DatabaseService(Service):
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
if isinstance(exc, util.exc.CommandError) or isinstance(exc, util.exc.AutogenerateDiffsDetected):
|
if isinstance(exc, util.exc.CommandError) or isinstance(exc, util.exc.AutogenerateDiffsDetected):
|
||||||
command.upgrade(alembic_cfg, "head")
|
command.upgrade(alembic_cfg, "head")
|
||||||
|
time.sleep(3)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
command.check(alembic_cfg)
|
command.check(alembic_cfg)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue