|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from typing import TYPE_CHECKING, Any |
| 4 | + |
| 5 | +from typing_extensions import Self |
| 6 | + |
| 7 | +from infrahub.core.constants import SchemaPathType |
| 8 | +from infrahub.core.migrations.shared import MigrationResult |
| 9 | +from infrahub.core.path import SchemaPath |
| 10 | + |
| 11 | +from ..schema.node_attribute_add import NodeAttributeAddMigration |
| 12 | +from ..shared import InternalSchemaMigration |
| 13 | + |
| 14 | +if TYPE_CHECKING: |
| 15 | + from infrahub.database import InfrahubDatabase |
| 16 | + |
| 17 | + |
| 18 | +class Migration021(InternalSchemaMigration): |
| 19 | + name: str = "021_add_generate_template_attr" |
| 20 | + minimum_version: int = 19 |
| 21 | + |
| 22 | + @classmethod |
| 23 | + def init(cls, **kwargs: dict[str, Any]) -> Self: |
| 24 | + internal_schema = cls.get_internal_schema() |
| 25 | + schema_node = internal_schema.get_node(name="SchemaNode") |
| 26 | + schema_generic = internal_schema.get_node(name="SchemaGeneric") |
| 27 | + |
| 28 | + migrations = [ |
| 29 | + NodeAttributeAddMigration( |
| 30 | + new_node_schema=schema_node, |
| 31 | + previous_node_schema=schema_node, |
| 32 | + schema_path=SchemaPath( |
| 33 | + schema_kind="SchemaNode", path_type=SchemaPathType.ATTRIBUTE, field_name="generate_template" |
| 34 | + ), |
| 35 | + ), |
| 36 | + NodeAttributeAddMigration( |
| 37 | + new_node_schema=schema_generic, |
| 38 | + previous_node_schema=schema_generic, |
| 39 | + schema_path=SchemaPath( |
| 40 | + schema_kind="SchemaNode", path_type=SchemaPathType.ATTRIBUTE, field_name="generate_template" |
| 41 | + ), |
| 42 | + ), |
| 43 | + ] |
| 44 | + return cls(migrations=migrations, **kwargs) # type: ignore[arg-type] |
| 45 | + |
| 46 | + async def validate_migration(self, db: InfrahubDatabase) -> MigrationResult: # noqa: ARG002 |
| 47 | + result = MigrationResult() |
| 48 | + return result |
0 commit comments