Skip to content

Commit 8b20fef

Browse files
authored
update Migration042 to be MigrationRequiringRebase (#7534)
1 parent 4f77799 commit 8b20fef

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

backend/infrahub/core/migrations/graph/m042_create_hfid_display_label_in_db.py

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
from typing import TYPE_CHECKING, Any
44

55
from rich.progress import Progress
6-
from typing_extensions import Self
76

87
from infrahub.core import registry
98
from infrahub.core.branch import Branch
109
from infrahub.core.constants import SchemaPathType
1110
from infrahub.core.initialization import get_root_node
1211
from infrahub.core.migrations.schema.node_attribute_add import NodeAttributeAddMigration
13-
from infrahub.core.migrations.shared import InternalSchemaMigration, MigrationResult
12+
from infrahub.core.migrations.shared import MigrationRequiringRebase, MigrationResult
1413
from infrahub.core.path import SchemaPath
1514
from infrahub.core.query import Query, QueryType
1615

@@ -45,17 +44,21 @@ def get_node_ids_by_kind(self) -> dict[str, list[str]]:
4544
return node_ids_by_kind
4645

4746

48-
class Migration042(InternalSchemaMigration):
47+
class Migration042(MigrationRequiringRebase):
4948
name: str = "042_create_hfid_display_label_in_db"
5049
minimum_version: int = 41
5150

52-
@classmethod
53-
def init(cls, **kwargs: Any) -> Self:
54-
internal_schema = cls.get_internal_schema()
55-
schema_node = internal_schema.get_node(name="SchemaNode")
56-
schema_generic = internal_schema.get_node(name="SchemaGeneric")
51+
async def execute(self, db: InfrahubDatabase) -> MigrationResult:
52+
result = MigrationResult()
5753

58-
cls.migrations = [
54+
root_node = await get_root_node(db=db, initialize=False)
55+
default_branch_name = root_node.default_branch
56+
default_branch = await Branch.get_by_name(db=db, name=default_branch_name)
57+
main_schema_branch = await get_or_load_schema_branch(db=db, branch=default_branch)
58+
schema_node = main_schema_branch.get_node(name="SchemaNode")
59+
schema_generic = main_schema_branch.get_node(name="SchemaGeneric")
60+
61+
migrations = [
5962
# HFID is not needed, it was introduced at graph v8
6063
NodeAttributeAddMigration(
6164
new_node_schema=schema_node,
@@ -72,20 +75,9 @@ def init(cls, **kwargs: Any) -> Self:
7275
),
7376
),
7477
]
75-
return cls(migrations=cls.migrations, **kwargs) # type: ignore[arg-type]
76-
77-
async def execute(self, db: InfrahubDatabase) -> MigrationResult:
78-
result = MigrationResult()
79-
80-
root_node = await get_root_node(db=db, initialize=False)
81-
default_branch_name = root_node.default_branch
82-
default_branch = await Branch.get_by_name(db=db, name=default_branch_name)
83-
schema_branch = await get_or_load_schema_branch(db=db, branch=default_branch)
84-
85-
migrations = list(self.migrations)
8678

87-
for node_schema_kind in schema_branch.node_names:
88-
schema = schema_branch.get(name=node_schema_kind, duplicate=False)
79+
for node_schema_kind in main_schema_branch.node_names:
80+
schema = main_schema_branch.get(name=node_schema_kind, duplicate=False)
8981
migrations.extend(
9082
[
9183
NodeAttributeAddMigration(

backend/infrahub/core/migrations/graph/m043_backfill_hfid_display_label_in_db.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,8 +800,6 @@ async def _do_one_schema_branch(
800800
formatted_v = " ".join(item for item in v if item is not None)
801801
formatted_schema_path_values_map[k] = formatted_v
802802

803-
print(schema.kind, schema_property, k, v)
804-
805803
update_attr_values_query = await UpdateAttributeValuesQuery.init(
806804
db=db,
807805
branch=branch,

0 commit comments

Comments
 (0)