@@ -51,6 +51,7 @@ async def upgrade_cmd(
5151    ctx : typer .Context ,
5252    config_file : str  =  typer .Argument ("infrahub.toml" , envvar = "INFRAHUB_CONFIG" ),
5353    check : bool  =  typer .Option (False , help = "Check the state of the system without upgrading." ),
54+     rebase_branches : bool  =  typer .Option (False , help = "Rebase and apply migrations to branches if required." ),
5455) ->  None :
5556    """Upgrade Infrahub to the latest version.""" 
5657
@@ -93,12 +94,6 @@ async def upgrade_cmd(
9394    await  initialize_internal_schema ()
9495    await  update_core_schema (db = dbdriver , initialize = False )
9596
96-     if  not  await  rebase_and_migrate_branches (db = dbdriver , current_graph_version = root_node .graph_version ):
97-         # A migration failed, stop the upgrade process 
98-         rprint ("Upgrade cancelled due to branch rebase and migration failure." )
99-         await  dbdriver .close ()
100-         return 
101- 
10297    # ------------------------------------------- 
10398    # Upgrade Internal Objects, generated and managed by Infrahub 
10499    # ------------------------------------------- 
@@ -114,6 +109,17 @@ async def upgrade_cmd(
114109        await  setup_deployments (client = client )
115110        await  trigger_configure_all ()
116111
112+     # ------------------------------------------- 
113+     # Perform branch rebase and apply migrations to them 
114+     # ------------------------------------------- 
115+     if  rebase_branches  and  not  await  rebase_and_migrate_branches (
116+         db = dbdriver , current_graph_version = root_node .graph_version 
117+     ):
118+         # A migration failed, stop the upgrade process 
119+         rprint ("Upgrade cancelled due to branch rebase and migration failure." )
120+         await  dbdriver .close ()
121+         return 
122+ 
117123    await  dbdriver .close ()
118124
119125
0 commit comments