Skip to content

Commit c5ca844

Browse files
authored
Merge pull request #7421 from opsmill/pog-warn-graph-version
Warn if the database graph version is incorrect
2 parents b2ecd49 + 892ab08 commit c5ca844

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

backend/infrahub/database/graph.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from __future__ import annotations
2+
3+
from typing import TYPE_CHECKING
4+
5+
from infrahub.core.graph import GRAPH_VERSION
6+
from infrahub.core.initialization import get_root_node
7+
from infrahub.log import get_logger
8+
9+
if TYPE_CHECKING:
10+
from infrahub.database import InfrahubDatabase
11+
12+
13+
log = get_logger()
14+
15+
16+
async def validate_graph_version(db: InfrahubDatabase) -> None:
17+
root = await get_root_node(db=db)
18+
if root.graph_version != GRAPH_VERSION:
19+
log.warning(
20+
f"Expected database graph version {GRAPH_VERSION} but got {root.graph_version}, possibly 'infrahub upgrade' has not been executed"
21+
)

backend/infrahub/server.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from infrahub.components import ComponentType
2525
from infrahub.constants.environment import INSTALLATION_TYPE
2626
from infrahub.core.initialization import initialization
27+
from infrahub.database.graph import validate_graph_version
2728
from infrahub.dependencies.registry import build_component_registry
2829
from infrahub.exceptions import Error, ValidationError
2930
from infrahub.graphql.api.endpoints import router as graphql_router
@@ -85,6 +86,9 @@ async def app_initialization(application: FastAPI, enable_scheduler: bool = True
8586
async with application.state.db.start_session() as db:
8687
await initialization(db=db, add_database_indexes=True)
8788

89+
async with database.start_session() as dbs:
90+
await validate_graph_version(db=dbs)
91+
8892
# Initialize the workflow after the registry has been setup
8993
await service.initialize_workflow()
9094

backend/infrahub/workers/infrahub_async.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from infrahub.components import ComponentType
1919
from infrahub.core import registry
2020
from infrahub.core.initialization import initialization
21+
from infrahub.database.graph import validate_graph_version
2122
from infrahub.dependencies.registry import build_component_registry
2223
from infrahub.git import initialize_repositories_directory
2324
from infrahub.lock import initialize_lock
@@ -129,6 +130,9 @@ async def setup(
129130

130131
await self.service.component.refresh_schema_hash()
131132

133+
async with self.service.database.start_session() as dbs:
134+
await validate_graph_version(db=dbs)
135+
132136
initialize_repositories_directory()
133137
build_component_registry()
134138
await self.service.scheduler.start_schedule()

0 commit comments

Comments
 (0)