Skip to content

Commit b7c3123

Browse files
committed
Cleanup lint errors
1 parent 0ba9b38 commit b7c3123

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

backend/infrahub/cli/db.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,12 @@ async def migrate_cmd(
175175
context: CliContext = ctx.obj
176176
dbdriver = await context.init_db(retry=1)
177177

178-
await migrate_database(db=dbdriver, initialize=True, check=check, migration_number=migration_number)
178+
migrations = await detect_migration_to_run(db=dbdriver, migration_number=migration_number)
179+
180+
if check or not migrations:
181+
return
182+
183+
await migrate_database(db=dbdriver, migrations=migrations, initialize=True)
179184

180185
await dbdriver.close()
181186

@@ -343,7 +348,7 @@ async def detect_migration_to_run(
343348
) -> Sequence[GraphMigration | InternalSchemaMigration | ArbitraryMigration | MigrationWithRebase]:
344349
"""Return a sequence of migrations to apply to upgrade the database."""
345350
rprint("Checking current state of the database")
346-
migrations: Sequence[GraphMigration | InternalSchemaMigration | ArbitraryMigration | MigrationWithRebase] = []
351+
migrations: list[GraphMigration | InternalSchemaMigration | ArbitraryMigration | MigrationWithRebase] = []
347352

348353
root_node = await get_root_node(db=db)
349354
if migration_number:
@@ -413,7 +418,7 @@ async def migrate_database(
413418
async def rebase_and_migrate_branches(
414419
db: InfrahubDatabase,
415420
migrations: Sequence[GraphMigration | InternalSchemaMigration | ArbitraryMigration | MigrationWithRebase],
416-
) -> None:
421+
) -> bool:
417422
"""Only applies migrations that aim at rebasing branches."""
418423
branches = [b for b in await Branch.get_list(db=db) if b.name not in [registry.default_branch, GLOBAL_BRANCH_NAME]]
419424
rprint(f"Planning rebase and migrations for {len(branches)} branches: {', '.join([b.name for b in branches])}")
@@ -428,6 +433,17 @@ async def rebase_and_migrate_branches(
428433
if validation_result.success:
429434
rprint(f"Migration: {migration.name} {SUCCESS_BADGE}")
430435

436+
if not execution_result.success or (validation_result and not validation_result.success):
437+
rprint(f"Migration: {migration.name} {FAILED_BADGE}")
438+
for error in execution_result.errors:
439+
rprint(f" {error}")
440+
if validation_result and not validation_result.success:
441+
for error in validation_result.errors:
442+
rprint(f" {error}")
443+
return False
444+
445+
return True
446+
431447

432448
async def initialize_internal_schema() -> None:
433449
registry.schema = SchemaManager()

backend/infrahub/core/migrations/shared.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
from typing import TYPE_CHECKING, Any, Sequence
44

55
from pydantic import BaseModel, ConfigDict, Field
6-
from typing_extensions import Self
76
from rich.console import Console
7+
from typing_extensions import Self
88

9-
from infrahub.auth import AccountSession, AuthType
10-
from infrahub.context import InfrahubContext
119
from infrahub.core import registry
1210
from infrahub.core.path import SchemaPath # noqa: TC001
1311
from infrahub.core.query import Query # noqa: TC001

0 commit comments

Comments
 (0)