Skip to content

Commit 20755a5

Browse files
committed
Move code around to store branch status en graph version
1 parent 7498d1c commit 20755a5

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

backend/infrahub/core/migrations/shared.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -247,32 +247,24 @@ class MigrationWithRebase(BaseModel):
247247
def init(cls, **kwargs: dict[str, Any]) -> Self:
248248
return cls(**kwargs) # type: ignore[arg-type]
249249

250-
async def rebase_branch(self, db: InfrahubDatabase, branch: Branch) -> bool:
250+
async def rebase_branch(self, branch: Branch) -> bool:
251251
# Circular deps if imported inside import block
252252
from infrahub.core.branch.tasks import rebase_branch
253253

254-
# NOTE: need service/bus component up and running to use prefect flow
255254
console = Console()
256255
console.print(f"Rebasing branch '{branch.name}' (ID: {branch.uuid})...", end="")
257256
try:
258-
# await branch.rebase(db=db)
259257
await rebase_branch(
260258
branch=branch.name,
261259
context=InfrahubContext.init(
262-
branch=branch,
263-
# FIXME: or superuser account?
264-
account=AccountSession(auth_type=AuthType.NONE, authenticated=False, account_id=""),
260+
branch=branch, account=AccountSession(auth_type=AuthType.NONE, authenticated=False, account_id="")
265261
),
266262
send_events=False,
267263
)
268264
console.print("done")
269-
branch.graph_version = self.minimum_version + 1
270265
except ValidationError:
271266
console.print("failed")
272-
branch.status = BranchStatus.NEED_UPGRADE_REBASE
273267
return False
274-
finally:
275-
await branch.save(db=db)
276268

277269
return True
278270

@@ -288,14 +280,19 @@ async def execute_against_branches(self, db: InfrahubDatabase, branches: Sequenc
288280
for branch in branches:
289281
await registry.schema.load_schema(db=db, branch=branch)
290282

291-
if not await self.rebase_branch(db=db, branch=branch):
283+
if not await self.rebase_branch(branch=branch):
292284
result.errors.append(f"Failed to rebase branch '{branch.name}' ({branch.uuid})")
285+
branch.status = BranchStatus.NEED_UPGRADE_REBASE
286+
await branch.save(db=db)
293287
continue
294288

295289
r = await self.execute_against_branch(db=db, branch=branch)
296290
result.nbr_migrations_executed += 1
297291
if r.errors:
298292
result.errors.extend(r.errors)
293+
if r.success:
294+
branch.graph_version = self.minimum_version + 1
295+
await branch.save(db=db)
299296

300297
return result
301298

0 commit comments

Comments
 (0)