-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue with NumberPoolGetUsed query
- Loading branch information
Showing
10 changed files
with
115 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
GRAPH_VERSION = 13 | ||
GRAPH_VERSION = 14 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
backend/infrahub/core/migrations/graph/m014_remove_index_attr_value.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING, Sequence | ||
|
||
from infrahub.core.migrations.shared import MigrationResult | ||
from infrahub.core.query import Query # noqa: TCH001 | ||
from infrahub.database import DatabaseType | ||
from infrahub.database.constants import IndexType | ||
from infrahub.database.index import IndexItem | ||
|
||
from ..shared import GraphMigration | ||
|
||
if TYPE_CHECKING: | ||
from infrahub.database import InfrahubDatabase | ||
|
||
|
||
INDEX_TO_DELETE = IndexItem(name="attr_value", label="AttributeValue", properties=["value"], type=IndexType.RANGE) | ||
|
||
|
||
class Migration014(GraphMigration): | ||
name: str = "014_remove_index_attr_value" | ||
queries: Sequence[type[Query]] = [] | ||
minimum_version: int = 13 | ||
|
||
async def execute(self, db: InfrahubDatabase) -> MigrationResult: | ||
result = MigrationResult() | ||
|
||
# Only execute this migration for Neo4j | ||
if db.db_type != DatabaseType.NEO4J: | ||
return result | ||
|
||
async with db.start_transaction() as ts: | ||
try: | ||
ts.manager.index.init(nodes=[INDEX_TO_DELETE], rels=[]) | ||
await ts.manager.index.drop() | ||
except Exception as exc: # pylint: disable=broad-exception-caught | ||
result.errors.append(str(exc)) | ||
return result | ||
|
||
return result | ||
|
||
async def validate_migration(self, db: InfrahubDatabase) -> MigrationResult: | ||
result = MigrationResult() | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from infrahub.core.migrations.graph.m014_remove_index_attr_value import ( | ||
Migration014, | ||
) | ||
from infrahub.database import DatabaseType, InfrahubDatabase | ||
from infrahub.database.constants import IndexType | ||
from infrahub.database.index import IndexItem | ||
|
||
|
||
async def test_migration_014( | ||
db: InfrahubDatabase, | ||
reset_registry, | ||
default_branch, | ||
delete_all_nodes_in_db, | ||
): | ||
indexes = [ | ||
IndexItem(name="node_uuid", label="Node", properties=["uuid"], type=IndexType.RANGE), | ||
IndexItem(name="attr_value", label="AttributeValue", properties=["value"], type=IndexType.RANGE), | ||
] | ||
|
||
db.manager.index.init(nodes=indexes, rels=[]) | ||
await db.manager.index.add() | ||
nbr_indexes_before = len(await db.manager.index.list()) | ||
|
||
async with db.start_session() as dbs: | ||
migration = Migration014() | ||
execution_result = await migration.execute(db=dbs) | ||
assert not execution_result.errors | ||
|
||
validation_result = await migration.validate_migration(db=dbs) | ||
assert not validation_result.errors | ||
|
||
nbr_indexes_after = len(await db.manager.index.list()) | ||
if db.db_type == DatabaseType.NEO4J: | ||
assert nbr_indexes_before - nbr_indexes_after == 1 | ||
else: | ||
assert nbr_indexes_before - nbr_indexes_after == 0 |
26 changes: 26 additions & 0 deletions
26
backend/tests/unit/core/resource_manager/test_number_pool.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from infrahub.core.branch import Branch | ||
from infrahub.core.initialization import initialize_registry | ||
from infrahub.core.node import Node | ||
from infrahub.core.schema import SchemaRoot | ||
from infrahub.database import InfrahubDatabase | ||
from tests.helpers.schema import TICKET, load_schema | ||
|
||
|
||
async def test_allocate_from_number_pool(db: InfrahubDatabase, default_branch: Branch, register_core_models_schema): | ||
await load_schema(db=db, schema=SchemaRoot(nodes=[TICKET])) | ||
await initialize_registry(db=db) | ||
|
||
np1 = await Node.init(db=db, schema="CoreNumberPool") | ||
await np1.new(db=db, name="pool1", node="TestingTicket", node_attribute="ticket_id", start_range=1, end_range=10) | ||
await np1.save(db=db) | ||
|
||
ticket1 = await Node.init(db=db, schema=TICKET.kind) | ||
await ticket1.new(db=db, title="ticket1", ticket_id={"from_pool": {"id": np1.id}}) | ||
await ticket1.save(db=db) | ||
|
||
ticket2 = await Node.init(db=db, schema=TICKET.kind) | ||
await ticket2.new(db=db, title="ticket2", ticket_id={"from_pool": {"id": np1.id}}) | ||
await ticket2.save(db=db) | ||
|
||
assert ticket1.ticket_id.value == 1 | ||
assert ticket2.ticket_id.value == 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Removed database index in Attribute Value to attribute larger than 8167 bytes |