|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from typing import TYPE_CHECKING, Sequence |
| 4 | + |
| 5 | +from infrahub.core.migrations.shared import MigrationResult |
| 6 | +from infrahub.core.query import Query # noqa: TCH001 |
| 7 | +from infrahub.database import DatabaseType |
| 8 | +from infrahub.database.constants import IndexType |
| 9 | +from infrahub.database.index import IndexItem |
| 10 | + |
| 11 | +from ..shared import GraphMigration |
| 12 | + |
| 13 | +if TYPE_CHECKING: |
| 14 | + from infrahub.database import InfrahubDatabase |
| 15 | + |
| 16 | + |
| 17 | +INDEX_TO_DELETE = IndexItem(name="attr_value", label="AttributeValue", properties=["value"], type=IndexType.RANGE) |
| 18 | + |
| 19 | + |
| 20 | +class Migration014(GraphMigration): |
| 21 | + name: str = "014_remove_index_attr_value" |
| 22 | + queries: Sequence[type[Query]] = [] |
| 23 | + minimum_version: int = 13 |
| 24 | + |
| 25 | + async def execute(self, db: InfrahubDatabase) -> MigrationResult: |
| 26 | + result = MigrationResult() |
| 27 | + |
| 28 | + # Only execute this migration for Neo4j |
| 29 | + if db.db_type != DatabaseType.NEO4J: |
| 30 | + return result |
| 31 | + |
| 32 | + async with db.start_transaction() as ts: |
| 33 | + try: |
| 34 | + ts.manager.index.init(nodes=[INDEX_TO_DELETE], rels=[]) |
| 35 | + await ts.manager.index.drop() |
| 36 | + except Exception as exc: # pylint: disable=broad-exception-caught |
| 37 | + result.errors.append(str(exc)) |
| 38 | + return result |
| 39 | + |
| 40 | + return result |
| 41 | + |
| 42 | + async def validate_migration(self, db: InfrahubDatabase) -> MigrationResult: |
| 43 | + result = MigrationResult() |
| 44 | + return result |
0 commit comments