33from typing import TYPE_CHECKING , Any
44
55from rich .progress import Progress
6- from typing_extensions import Self
76
87from infrahub .core import registry
98from infrahub .core .branch import Branch
109from infrahub .core .constants import SchemaPathType
1110from infrahub .core .initialization import get_root_node
1211from 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
1413from infrahub .core .path import SchemaPath
1514from 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 (
0 commit comments