Skip to content

Commit 9a28d13

Browse files
committed
Move code around to store branch status en graph version
1 parent a073bda commit 9a28d13

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
@@ -245,32 +245,24 @@ class MigrationWithRebase(BaseModel):
245245
def init(cls, **kwargs: dict[str, Any]) -> Self:
246246
return cls(**kwargs) # type: ignore[arg-type]
247247

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

252-
# NOTE: need service/bus component up and running to use prefect flow
253252
console = Console()
254253
console.print(f"Rebasing branch '{branch.name}' (ID: {branch.uuid})...", end="")
255254
try:
256-
# await branch.rebase(db=db)
257255
await rebase_branch(
258256
branch=branch.name,
259257
context=InfrahubContext.init(
260-
branch=branch,
261-
# FIXME: or superuser account?
262-
account=AccountSession(auth_type=AuthType.NONE, authenticated=False, account_id=""),
258+
branch=branch, account=AccountSession(auth_type=AuthType.NONE, authenticated=False, account_id="")
263259
),
264260
send_events=False,
265261
)
266262
console.print("done")
267-
branch.graph_version = self.minimum_version + 1
268263
except ValidationError:
269264
console.print("failed")
270-
branch.status = BranchStatus.NEED_UPGRADE_REBASE
271265
return False
272-
finally:
273-
await branch.save(db=db)
274266

275267
return True
276268

@@ -286,14 +278,19 @@ async def execute_against_branches(self, db: InfrahubDatabase, branches: Sequenc
286278
for branch in branches:
287279
await registry.schema.load_schema(db=db, branch=branch)
288280

289-
if not await self.rebase_branch(db=db, branch=branch):
281+
if not await self.rebase_branch(branch=branch):
290282
result.errors.append(f"Failed to rebase branch '{branch.name}' ({branch.uuid})")
283+
branch.status = BranchStatus.NEED_UPGRADE_REBASE
284+
await branch.save(db=db)
291285
continue
292286

293287
r = await self.execute_against_branch(db=db, branch=branch)
294288
result.nbr_migrations_executed += 1
295289
if r.errors:
296290
result.errors.extend(r.errors)
291+
if r.success:
292+
branch.graph_version = self.minimum_version + 1
293+
await branch.save(db=db)
297294

298295
return result
299296

0 commit comments

Comments
 (0)