@@ -137,7 +137,8 @@ async def add_indexes(db: InfrahubDatabase) -> None:
137137 await index_manager .add ()
138138
139139
140- async def initialization (db : InfrahubDatabase , add_database_indexes : bool = False ) -> None :
140+ async def initialization (db : InfrahubDatabase , add_database_indexes : bool = False ) -> bool :
141+ """Run initialization and setup, returns a boolean to indicate if it's the initial setup."""
141142 if config .SETTINGS .database .db_type == config .DatabaseType .MEMGRAPH :
142143 session = await db .session ()
143144 await session .run (query = "SET DATABASE SETTING 'log.level' TO 'INFO'" )
@@ -148,6 +149,7 @@ async def initialization(db: InfrahubDatabase, add_database_indexes: bool = Fals
148149 # Initialize the database and Load the Root node
149150 # ---------------------------------------------------
150151 async with lock .registry .initialization ():
152+ first_time_initialization = len (await Root .get_list (db = db )) == 0
151153 log .debug ("Checking Root Node" )
152154 await initialize_registry (db = db , initialize = True )
153155
@@ -210,6 +212,7 @@ async def initialization(db: InfrahubDatabase, add_database_indexes: bool = Fals
210212 ip_namespace = await get_default_ipnamespace (db = db )
211213 if ip_namespace :
212214 registry .default_ipnamespace = ip_namespace .id
215+ return first_time_initialization
213216
214217
215218async def create_root_node (db : InfrahubDatabase ) -> Root :
0 commit comments