Skip to content

Commit

Permalink
Add generate_template to node and generic schema
Browse files Browse the repository at this point in the history
  • Loading branch information
gmazoyer committed Mar 3, 2025
1 parent 62a2b9e commit 1a8b1e1
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backend/infrahub/core/graph/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
GRAPH_VERSION = 19
GRAPH_VERSION = 20
2 changes: 2 additions & 0 deletions backend/infrahub/core/migrations/graph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from .m017_add_core_profile import Migration017
from .m018_uniqueness_nulls import Migration018
from .m019_restore_rels_to_time import Migration019
from .m020_add_generate_template_attr import Migration020

if TYPE_CHECKING:
from infrahub.core.root import Root
Expand All @@ -47,6 +48,7 @@
Migration017,
Migration018,
Migration019,
Migration020,
]


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any

from typing_extensions import Self

from infrahub.core.constants import SchemaPathType
from infrahub.core.migrations.shared import MigrationResult
from infrahub.core.path import SchemaPath

from ..schema.node_attribute_add import NodeAttributeAddMigration
from ..shared import InternalSchemaMigration

if TYPE_CHECKING:
from infrahub.database import InfrahubDatabase


class Migration020(InternalSchemaMigration):
name: str = "020_add_generate_template_attr"
minimum_version: int = 19

@classmethod
def init(cls, **kwargs: dict[str, Any]) -> Self:
internal_schema = cls.get_internal_schema()
schema_node = internal_schema.get_node(name="SchemaNode")
schema_generic = internal_schema.get_node(name="SchemaGeneric")

migrations = [
NodeAttributeAddMigration(
new_node_schema=schema_node,
previous_node_schema=schema_node,
schema_path=SchemaPath(
schema_kind="SchemaNode", path_type=SchemaPathType.ATTRIBUTE, field_name="generate_template"
),
),
NodeAttributeAddMigration(
new_node_schema=schema_generic,
previous_node_schema=schema_generic,
schema_path=SchemaPath(
schema_kind="SchemaNode", path_type=SchemaPathType.ATTRIBUTE, field_name="generate_template"
),
),
]
return cls(migrations=migrations, **kwargs) # type: ignore[arg-type]

async def validate_migration(self, db: InfrahubDatabase) -> MigrationResult: # noqa: ARG002
result = MigrationResult()
return result

0 comments on commit 1a8b1e1

Please sign in to comment.