infrahub-server 1.7.0rc0__py3-none-any.whl → 1.7.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- infrahub/api/schema.py +5 -0
- infrahub/cli/db.py +6 -2
- infrahub/core/branch/models.py +11 -117
- infrahub/core/branch/tasks.py +7 -3
- infrahub/core/diff/merger/merger.py +5 -1
- infrahub/core/graph/__init__.py +1 -1
- infrahub/core/initialization.py +2 -1
- infrahub/core/migrations/graph/__init__.py +2 -0
- infrahub/core/migrations/graph/m014_remove_index_attr_value.py +3 -2
- infrahub/core/migrations/graph/m015_diff_format_update.py +3 -2
- infrahub/core/migrations/graph/m016_diff_delete_bug_fix.py +3 -2
- infrahub/core/migrations/graph/m017_add_core_profile.py +6 -4
- infrahub/core/migrations/graph/m018_uniqueness_nulls.py +3 -4
- infrahub/core/migrations/graph/m020_duplicate_edges.py +3 -3
- infrahub/core/migrations/graph/m025_uniqueness_nulls.py +3 -4
- infrahub/core/migrations/graph/m026_0000_prefix_fix.py +4 -5
- infrahub/core/migrations/graph/m028_delete_diffs.py +3 -2
- infrahub/core/migrations/graph/m029_duplicates_cleanup.py +3 -2
- infrahub/core/migrations/graph/m031_check_number_attributes.py +4 -3
- infrahub/core/migrations/graph/m032_cleanup_orphaned_branch_relationships.py +3 -2
- infrahub/core/migrations/graph/m034_find_orphaned_schema_fields.py +3 -2
- infrahub/core/migrations/graph/m035_orphan_relationships.py +3 -3
- infrahub/core/migrations/graph/m036_drop_attr_value_index.py +3 -2
- infrahub/core/migrations/graph/m037_index_attr_vals.py +3 -2
- infrahub/core/migrations/graph/m038_redo_0000_prefix_fix.py +4 -5
- infrahub/core/migrations/graph/m039_ipam_reconcile.py +3 -2
- infrahub/core/migrations/graph/m041_deleted_dup_edges.py +3 -2
- infrahub/core/migrations/graph/m042_profile_attrs_in_db.py +5 -4
- infrahub/core/migrations/graph/m043_create_hfid_display_label_in_db.py +12 -5
- infrahub/core/migrations/graph/m044_backfill_hfid_display_label_in_db.py +15 -4
- infrahub/core/migrations/graph/m045_backfill_hfid_display_label_in_db_profile_template.py +10 -4
- infrahub/core/migrations/graph/m046_fill_agnostic_hfid_display_labels.py +6 -5
- infrahub/core/migrations/graph/m047_backfill_or_null_display_label.py +19 -5
- infrahub/core/migrations/graph/m048_undelete_rel_props.py +6 -4
- infrahub/core/migrations/graph/m049_remove_is_visible_relationship.py +3 -3
- infrahub/core/migrations/graph/m050_backfill_vertex_metadata.py +3 -3
- infrahub/core/migrations/graph/m051_subtract_branched_from_microsecond.py +39 -0
- infrahub/core/migrations/runner.py +6 -3
- infrahub/core/migrations/schema/attribute_kind_update.py +8 -11
- infrahub/core/migrations/schema/attribute_supports_profile.py +3 -8
- infrahub/core/migrations/schema/models.py +8 -0
- infrahub/core/migrations/schema/node_attribute_add.py +10 -13
- infrahub/core/migrations/schema/tasks.py +7 -1
- infrahub/core/migrations/shared.py +37 -30
- infrahub/core/node/__init__.py +2 -1
- infrahub/core/relationship/model.py +8 -2
- infrahub/core/schema/attribute_parameters.py +28 -1
- infrahub/core/schema/attribute_schema.py +9 -2
- infrahub/core/schema/manager.py +50 -38
- infrahub/core/validators/attribute/kind.py +5 -2
- infrahub/graphql/manager.py +8 -2
- infrahub/lock.py +7 -0
- infrahub/services/adapters/cache/redis.py +7 -0
- infrahub_sdk/analyzer.py +2 -2
- infrahub_sdk/branch.py +12 -39
- infrahub_sdk/checks.py +4 -4
- infrahub_sdk/client.py +36 -0
- infrahub_sdk/ctl/cli_commands.py +2 -1
- infrahub_sdk/ctl/graphql.py +15 -4
- infrahub_sdk/ctl/utils.py +2 -2
- infrahub_sdk/enums.py +6 -0
- infrahub_sdk/graphql/renderers.py +21 -0
- infrahub_sdk/graphql/utils.py +85 -0
- infrahub_sdk/node/attribute.py +12 -2
- infrahub_sdk/node/constants.py +11 -0
- infrahub_sdk/node/metadata.py +69 -0
- infrahub_sdk/node/node.py +65 -14
- infrahub_sdk/node/property.py +3 -0
- infrahub_sdk/node/related_node.py +24 -1
- infrahub_sdk/node/relationship.py +10 -1
- infrahub_sdk/operation.py +2 -2
- infrahub_sdk/schema/repository.py +1 -2
- infrahub_sdk/transforms.py +2 -2
- infrahub_sdk/types.py +18 -2
- {infrahub_server-1.7.0rc0.dist-info → infrahub_server-1.7.1.dist-info}/METADATA +6 -6
- {infrahub_server-1.7.0rc0.dist-info → infrahub_server-1.7.1.dist-info}/RECORD +80 -77
- {infrahub_server-1.7.0rc0.dist-info → infrahub_server-1.7.1.dist-info}/entry_points.txt +0 -1
- infrahub_testcontainers/performance_test.py +1 -1
- {infrahub_server-1.7.0rc0.dist-info → infrahub_server-1.7.1.dist-info}/WHEEL +0 -0
- {infrahub_server-1.7.0rc0.dist-info → infrahub_server-1.7.1.dist-info}/licenses/LICENSE.txt +0 -0
infrahub/api/schema.py
CHANGED
|
@@ -36,6 +36,7 @@ from infrahub.core.schema import (
|
|
|
36
36
|
TemplateSchema,
|
|
37
37
|
)
|
|
38
38
|
from infrahub.core.schema.constants import SchemaNamespace # noqa: TC001
|
|
39
|
+
from infrahub.core.timestamp import Timestamp
|
|
39
40
|
from infrahub.core.validators.models.validate_migration import (
|
|
40
41
|
SchemaValidateMigrationData,
|
|
41
42
|
SchemaValidatorPathResponseData,
|
|
@@ -353,6 +354,8 @@ async def load_schema(
|
|
|
353
354
|
if error_messages:
|
|
354
355
|
raise SchemaNotValidError(",\n".join(error_messages))
|
|
355
356
|
|
|
357
|
+
schema_load_at = Timestamp()
|
|
358
|
+
|
|
356
359
|
# ----------------------------------------------------------
|
|
357
360
|
# Update the schema
|
|
358
361
|
# ----------------------------------------------------------
|
|
@@ -367,6 +370,7 @@ async def load_schema(
|
|
|
367
370
|
limit=result.diff.all,
|
|
368
371
|
update_db=True,
|
|
369
372
|
user_id=account_session.account_id,
|
|
373
|
+
at=schema_load_at,
|
|
370
374
|
)
|
|
371
375
|
branch.update_schema_hash()
|
|
372
376
|
log.info("Schema has been updated", branch=branch.name, hash=branch.active_schema_hash.main)
|
|
@@ -389,6 +393,7 @@ async def load_schema(
|
|
|
389
393
|
previous_schema=origin_schema,
|
|
390
394
|
migrations=result.migrations,
|
|
391
395
|
user_id=account_session.account_id,
|
|
396
|
+
at=schema_load_at,
|
|
392
397
|
)
|
|
393
398
|
migration_error_msgs = await service.workflow.execute_workflow(
|
|
394
399
|
workflow=SCHEMA_APPLY_MIGRATION,
|
infrahub/cli/db.py
CHANGED
|
@@ -40,10 +40,11 @@ from infrahub.core.migrations.exceptions import MigrationFailureError
|
|
|
40
40
|
from infrahub.core.migrations.graph import get_graph_migrations, get_migration_by_number
|
|
41
41
|
from infrahub.core.migrations.schema.models import SchemaApplyMigrationData
|
|
42
42
|
from infrahub.core.migrations.schema.tasks import schema_apply_migrations
|
|
43
|
-
from infrahub.core.migrations.shared import get_migration_console
|
|
43
|
+
from infrahub.core.migrations.shared import MigrationInput, get_migration_console
|
|
44
44
|
from infrahub.core.schema import SchemaRoot, core_models, internal_schema
|
|
45
45
|
from infrahub.core.schema.definitions.deprecated import deprecated_models
|
|
46
46
|
from infrahub.core.schema.manager import SchemaManager
|
|
47
|
+
from infrahub.core.timestamp import Timestamp
|
|
47
48
|
from infrahub.core.validators.models.validate_migration import SchemaValidateMigrationData
|
|
48
49
|
from infrahub.core.validators.tasks import schema_validate_migrations
|
|
49
50
|
from infrahub.database import DatabaseType
|
|
@@ -357,7 +358,7 @@ async def migrate_database(
|
|
|
357
358
|
root_node = await get_root_node(db=db)
|
|
358
359
|
|
|
359
360
|
for migration in migrations:
|
|
360
|
-
execution_result = await migration.execute(db=db)
|
|
361
|
+
execution_result = await migration.execute(migration_input=MigrationInput(db=db))
|
|
361
362
|
validation_result = None
|
|
362
363
|
|
|
363
364
|
if execution_result.success:
|
|
@@ -502,6 +503,7 @@ async def update_core_schema(db: InfrahubDatabase, initialize: bool = True, debu
|
|
|
502
503
|
schema_default_branch.process()
|
|
503
504
|
registry.schema.set_schema_branch(name=default_branch.name, schema=schema_default_branch)
|
|
504
505
|
|
|
506
|
+
update_at = Timestamp()
|
|
505
507
|
async with db.start_transaction() as dbt:
|
|
506
508
|
await registry.schema.update_schema_branch(
|
|
507
509
|
schema=candidate_schema,
|
|
@@ -510,6 +512,7 @@ async def update_core_schema(db: InfrahubDatabase, initialize: bool = True, debu
|
|
|
510
512
|
diff=result.diff,
|
|
511
513
|
limit=result.diff.all,
|
|
512
514
|
update_db=True,
|
|
515
|
+
at=update_at,
|
|
513
516
|
)
|
|
514
517
|
default_branch.update_schema_hash()
|
|
515
518
|
get_migration_console().log(
|
|
@@ -527,6 +530,7 @@ async def update_core_schema(db: InfrahubDatabase, initialize: bool = True, debu
|
|
|
527
530
|
new_schema=candidate_schema,
|
|
528
531
|
previous_schema=origin_schema,
|
|
529
532
|
migrations=result.migrations,
|
|
533
|
+
at=update_at,
|
|
530
534
|
)
|
|
531
535
|
migration_error_msgs = await schema_apply_migrations(message=apply_migration_data)
|
|
532
536
|
|
infrahub/core/branch/models.py
CHANGED
|
@@ -333,7 +333,7 @@ class Branch(StandardNode):
|
|
|
333
333
|
f"({rel}.branch IN $branch{idx} AND {rel}.from <= $time{idx} AND {rel}.to IS NULL)"
|
|
334
334
|
)
|
|
335
335
|
filters_per_rel.append(
|
|
336
|
-
f"({rel}.branch IN $branch{idx} AND {rel}.from <= $time{idx} AND {rel}.to
|
|
336
|
+
f"({rel}.branch IN $branch{idx} AND {rel}.from <= $time{idx} AND {rel}.to > $time{idx})"
|
|
337
337
|
)
|
|
338
338
|
|
|
339
339
|
if not include_outside_parentheses:
|
|
@@ -366,7 +366,9 @@ class Branch(StandardNode):
|
|
|
366
366
|
at = Timestamp(at)
|
|
367
367
|
at_str = at.to_string()
|
|
368
368
|
if branch_agnostic:
|
|
369
|
-
filter_str =
|
|
369
|
+
filter_str = (
|
|
370
|
+
f"{variable_name}.from < ${pp}time1 AND ({variable_name}.to IS NULL or {variable_name}.to > ${pp}time1)"
|
|
371
|
+
)
|
|
370
372
|
params[f"{pp}time1"] = at_str
|
|
371
373
|
return filter_str, params
|
|
372
374
|
|
|
@@ -380,132 +382,24 @@ class Branch(StandardNode):
|
|
|
380
382
|
for idx in range(len(branches_times)):
|
|
381
383
|
filters.append(
|
|
382
384
|
f"({variable_name}.branch IN ${pp}branch{idx} "
|
|
383
|
-
f"AND {variable_name}.from
|
|
385
|
+
f"AND {variable_name}.from <= ${pp}time{idx} AND {variable_name}.to IS NULL)"
|
|
384
386
|
)
|
|
385
387
|
filters.append(
|
|
386
388
|
f"({variable_name}.branch IN ${pp}branch{idx} "
|
|
387
|
-
f"AND {variable_name}.from
|
|
388
|
-
f"AND {variable_name}.to
|
|
389
|
+
f"AND {variable_name}.from <= ${pp}time{idx} "
|
|
390
|
+
f"AND {variable_name}.to > ${pp}time{idx})"
|
|
389
391
|
)
|
|
390
392
|
|
|
391
393
|
filter_str = "(" + "\n OR ".join(filters) + ")"
|
|
392
394
|
|
|
393
395
|
return filter_str, params
|
|
394
396
|
|
|
395
|
-
def
|
|
396
|
-
self,
|
|
397
|
-
|
|
398
|
-
start_time: Timestamp,
|
|
399
|
-
end_time: Timestamp,
|
|
400
|
-
include_outside_parentheses: bool = False,
|
|
401
|
-
include_global: bool = False,
|
|
402
|
-
) -> tuple[list, dict]:
|
|
403
|
-
"""Generate a CYPHER Query filter based on a list of relationships to query a range of values in the graph.
|
|
404
|
-
The goal is to return all the values that are valid during this timerange.
|
|
405
|
-
"""
|
|
406
|
-
|
|
407
|
-
filters = []
|
|
408
|
-
params = {}
|
|
409
|
-
|
|
410
|
-
if not isinstance(rel_labels, list):
|
|
411
|
-
raise TypeError(f"rel_labels must be a list, not a {type(rel_labels)}")
|
|
412
|
-
|
|
413
|
-
start_time = Timestamp(start_time)
|
|
414
|
-
end_time = Timestamp(end_time)
|
|
415
|
-
|
|
416
|
-
if include_global:
|
|
417
|
-
branches_times = self.get_branches_and_times_to_query_global(at=start_time)
|
|
418
|
-
else:
|
|
419
|
-
branches_times = self.get_branches_and_times_to_query(at=start_time)
|
|
420
|
-
|
|
421
|
-
params["branches"] = list({branch for branches in branches_times for branch in branches})
|
|
422
|
-
params["start_time"] = start_time.to_string()
|
|
423
|
-
params["end_time"] = end_time.to_string()
|
|
424
|
-
|
|
425
|
-
for rel in rel_labels:
|
|
426
|
-
filters_per_rel = [
|
|
427
|
-
f"({rel}.branch IN $branches AND {rel}.from <= $end_time AND {rel}.to IS NULL)",
|
|
428
|
-
f"({rel}.branch IN $branches AND ({rel}.from <= $end_time OR ({rel}.to >= $start_time AND {rel}.to <= $end_time)))",
|
|
429
|
-
]
|
|
430
|
-
|
|
431
|
-
if not include_outside_parentheses:
|
|
432
|
-
filters.append("\n OR ".join(filters_per_rel))
|
|
433
|
-
|
|
434
|
-
filters.append("(" + "\n OR ".join(filters_per_rel) + ")")
|
|
435
|
-
|
|
436
|
-
return filters, params
|
|
437
|
-
|
|
438
|
-
def get_query_filter_relationships_diff(
|
|
439
|
-
self, rel_labels: list, diff_from: Timestamp, diff_to: Timestamp
|
|
440
|
-
) -> tuple[list, dict]:
|
|
441
|
-
"""
|
|
442
|
-
Generate a CYPHER Query filter to query all events that are applicable to a given branch based
|
|
443
|
-
- The time when the branch as created
|
|
444
|
-
- The branched_from time of the branch
|
|
445
|
-
- The diff_to and diff_from time as provided
|
|
446
|
-
"""
|
|
447
|
-
|
|
448
|
-
if not isinstance(rel_labels, list):
|
|
449
|
-
raise TypeError(f"rel_labels must be a list, not a {type(rel_labels)}")
|
|
450
|
-
|
|
451
|
-
start_times, end_times = self.get_branches_and_times_for_range(start_time=diff_from, end_time=diff_to)
|
|
452
|
-
|
|
453
|
-
filters = []
|
|
454
|
-
params = {}
|
|
455
|
-
|
|
456
|
-
for idx, branch_name in enumerate(start_times.keys()):
|
|
457
|
-
params[f"branch{idx}"] = branch_name
|
|
458
|
-
params[f"start_time{idx}"] = start_times[branch_name]
|
|
459
|
-
params[f"end_time{idx}"] = end_times[branch_name]
|
|
460
|
-
|
|
461
|
-
for rel in rel_labels:
|
|
462
|
-
filters_per_rel = []
|
|
463
|
-
for idx in range(len(start_times)):
|
|
464
|
-
filters_per_rel.extend(
|
|
465
|
-
[
|
|
466
|
-
f"""({rel}.branch = $branch{idx}
|
|
467
|
-
AND {rel}.from >= $start_time{idx}
|
|
468
|
-
AND {rel}.from <= $end_time{idx}
|
|
469
|
-
AND ( r2.to is NULL or r2.to >= $end_time{idx}))""",
|
|
470
|
-
f"""({rel}.branch = $branch{idx} AND {rel}.from >= $start_time{idx}
|
|
471
|
-
AND {rel}.to <= $start_time{idx})""",
|
|
472
|
-
]
|
|
473
|
-
)
|
|
474
|
-
|
|
475
|
-
filters.append("(" + "\n OR ".join(filters_per_rel) + ")")
|
|
476
|
-
|
|
477
|
-
return filters, params
|
|
478
|
-
|
|
479
|
-
def get_query_filter_range(self, rel_label: list, start_time: Timestamp, end_time: Timestamp) -> tuple[list, dict]:
|
|
480
|
-
"""
|
|
481
|
-
Generate a CYPHER Query filter to query a range of values in the graph between start_time and end_time."""
|
|
482
|
-
|
|
483
|
-
filters = []
|
|
484
|
-
params = {}
|
|
485
|
-
|
|
486
|
-
start_time = Timestamp(start_time)
|
|
487
|
-
end_time = Timestamp(end_time)
|
|
488
|
-
|
|
489
|
-
params["branches"] = self.get_branches_in_scope()
|
|
490
|
-
params["start_time"] = start_time.to_string()
|
|
491
|
-
params["end_time"] = end_time.to_string()
|
|
492
|
-
|
|
493
|
-
filters_per_rel = [
|
|
494
|
-
f"""({rel_label}.branch IN $branches AND {rel_label}.from >= $start_time
|
|
495
|
-
AND {rel_label}.from <= $end_time AND {rel_label}.to IS NULL)""",
|
|
496
|
-
f"""({rel_label}.branch IN $branches AND (({rel_label}.from >= $start_time
|
|
497
|
-
AND {rel_label}.from <= $end_time) OR ({rel_label}.to >= $start_time
|
|
498
|
-
AND {rel_label}.to <= $end_time)))""",
|
|
499
|
-
]
|
|
500
|
-
|
|
501
|
-
filters.append("(" + "\n OR ".join(filters_per_rel) + ")")
|
|
502
|
-
|
|
503
|
-
return filters, params
|
|
504
|
-
|
|
505
|
-
async def rebase(self, db: InfrahubDatabase, user_id: str = SYSTEM_USER_ID) -> None:
|
|
397
|
+
async def rebase(
|
|
398
|
+
self, db: InfrahubDatabase, at: Optional[Union[str, Timestamp]] = None, user_id: str = SYSTEM_USER_ID
|
|
399
|
+
) -> None:
|
|
506
400
|
"""Rebase the current Branch with its origin branch"""
|
|
507
401
|
|
|
508
|
-
at = Timestamp()
|
|
402
|
+
at = Timestamp(at)
|
|
509
403
|
|
|
510
404
|
await self.rebase_graph(db=db, at=at)
|
|
511
405
|
|
infrahub/core/branch/tasks.py
CHANGED
|
@@ -88,7 +88,7 @@ async def migrate_branch(branch: str, context: InfrahubContext, send_events: boo
|
|
|
88
88
|
|
|
89
89
|
try:
|
|
90
90
|
log.info(f"Running migrations for branch '{obj.name}'")
|
|
91
|
-
await migration_runner.run(db=db)
|
|
91
|
+
await migration_runner.run(db=db, at=Timestamp())
|
|
92
92
|
except MigrationFailureError as exc:
|
|
93
93
|
log.error(f"Failed to run migrations for branch '{obj.name}': {exc.errors}")
|
|
94
94
|
raise
|
|
@@ -170,7 +170,8 @@ async def rebase_branch(branch: str, context: InfrahubContext, send_events: bool
|
|
|
170
170
|
migrations = []
|
|
171
171
|
async with lock.registry.global_graph_lock():
|
|
172
172
|
async with db.start_transaction() as dbt:
|
|
173
|
-
|
|
173
|
+
rebase_at = Timestamp()
|
|
174
|
+
await obj.rebase(db=dbt, user_id=context.account.account_id, at=rebase_at)
|
|
174
175
|
log.info("Branch successfully rebased")
|
|
175
176
|
|
|
176
177
|
if obj.has_schema_changes:
|
|
@@ -199,6 +200,7 @@ async def rebase_branch(branch: str, context: InfrahubContext, send_events: bool
|
|
|
199
200
|
previous_schema=schema_in_main_before,
|
|
200
201
|
migrations=migrations,
|
|
201
202
|
user_id=context.account.account_id,
|
|
203
|
+
at=rebase_at,
|
|
202
204
|
)
|
|
203
205
|
)
|
|
204
206
|
for error in errors:
|
|
@@ -291,7 +293,8 @@ async def merge_branch(branch: str, context: InfrahubContext, proposed_change_id
|
|
|
291
293
|
diff_locker=DiffLocker(),
|
|
292
294
|
workflow=get_workflow(),
|
|
293
295
|
)
|
|
294
|
-
|
|
296
|
+
merge_at = Timestamp()
|
|
297
|
+
branch_diff = await merger.merge(at=merge_at)
|
|
295
298
|
await merger.update_schema()
|
|
296
299
|
|
|
297
300
|
changelog_collector = DiffChangelogCollector(diff=branch_diff, branch=obj, db=db)
|
|
@@ -304,6 +307,7 @@ async def merge_branch(branch: str, context: InfrahubContext, proposed_change_id
|
|
|
304
307
|
previous_schema=merger.initial_source_schema,
|
|
305
308
|
migrations=merger.migrations,
|
|
306
309
|
user_id=context.account.account_id,
|
|
310
|
+
at=merge_at,
|
|
307
311
|
)
|
|
308
312
|
)
|
|
309
313
|
for error in errors:
|
|
@@ -125,7 +125,11 @@ class DiffMerger:
|
|
|
125
125
|
)
|
|
126
126
|
await metadata_query.execute(db=self.db)
|
|
127
127
|
|
|
128
|
-
|
|
128
|
+
# set the branched_from time to the previous microsecond to prevent duplicated
|
|
129
|
+
# relationships on the branch after the merge
|
|
130
|
+
branched_from = at.subtract(microseconds=1)
|
|
131
|
+
|
|
132
|
+
self.source_branch.branched_from = branched_from.to_string()
|
|
129
133
|
await self.source_branch.save(db=self.db)
|
|
130
134
|
registry.branch[self.source_branch.name] = self.source_branch
|
|
131
135
|
return enriched_diff
|
infrahub/core/graph/__init__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
GRAPH_VERSION =
|
|
1
|
+
GRAPH_VERSION = 51
|
infrahub/core/initialization.py
CHANGED
|
@@ -30,6 +30,7 @@ from infrahub.core.protocols import CoreAccount, CoreAccountGroup, CoreAccountRo
|
|
|
30
30
|
from infrahub.core.root import Root
|
|
31
31
|
from infrahub.core.schema import SchemaRoot, core_models, internal_schema
|
|
32
32
|
from infrahub.core.schema.manager import SchemaManager
|
|
33
|
+
from infrahub.core.timestamp import Timestamp
|
|
33
34
|
from infrahub.database import InfrahubDatabase
|
|
34
35
|
from infrahub.database.memgraph import IndexManagerMemgraph
|
|
35
36
|
from infrahub.database.neo4j import IndexManagerNeo4j
|
|
@@ -527,7 +528,7 @@ async def first_time_initialization(db: InfrahubDatabase) -> None:
|
|
|
527
528
|
schema_branch = registry.schema.register_schema(schema=schema, branch=default_branch.name)
|
|
528
529
|
schema_branch.load_schema(schema=SchemaRoot(**core_models))
|
|
529
530
|
schema_branch.process()
|
|
530
|
-
await registry.schema.load_schema_to_db(schema=schema_branch, branch=default_branch, db=db)
|
|
531
|
+
await registry.schema.load_schema_to_db(schema=schema_branch, branch=default_branch, db=db, at=Timestamp())
|
|
531
532
|
registry.schema.set_schema_branch(name=default_branch.name, schema=schema_branch)
|
|
532
533
|
default_branch.update_schema_hash()
|
|
533
534
|
await default_branch.save(db=db)
|
|
@@ -52,6 +52,7 @@ from .m047_backfill_or_null_display_label import Migration047
|
|
|
52
52
|
from .m048_undelete_rel_props import Migration048
|
|
53
53
|
from .m049_remove_is_visible_relationship import Migration049
|
|
54
54
|
from .m050_backfill_vertex_metadata import Migration050
|
|
55
|
+
from .m051_subtract_branched_from_microsecond import Migration051
|
|
55
56
|
|
|
56
57
|
if TYPE_CHECKING:
|
|
57
58
|
from ..shared import MigrationTypes
|
|
@@ -108,6 +109,7 @@ MIGRATIONS: list[type[MigrationTypes]] = [
|
|
|
108
109
|
Migration048,
|
|
109
110
|
Migration049,
|
|
110
111
|
Migration050,
|
|
112
|
+
Migration051,
|
|
111
113
|
]
|
|
112
114
|
|
|
113
115
|
|
|
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
from typing import TYPE_CHECKING, Sequence
|
|
4
4
|
|
|
5
5
|
from infrahub.constants.database import IndexType
|
|
6
|
-
from infrahub.core.migrations.shared import MigrationResult
|
|
6
|
+
from infrahub.core.migrations.shared import MigrationInput, MigrationResult
|
|
7
7
|
from infrahub.core.query import Query # noqa: TC001
|
|
8
8
|
from infrahub.database import DatabaseType
|
|
9
9
|
from infrahub.database.index import IndexItem
|
|
@@ -23,7 +23,8 @@ class Migration014(GraphMigration):
|
|
|
23
23
|
queries: Sequence[type[Query]] = []
|
|
24
24
|
minimum_version: int = 13
|
|
25
25
|
|
|
26
|
-
async def execute(self,
|
|
26
|
+
async def execute(self, migration_input: MigrationInput) -> MigrationResult:
|
|
27
|
+
db = migration_input.db
|
|
27
28
|
result = MigrationResult()
|
|
28
29
|
|
|
29
30
|
# Only execute this migration for Neo4j
|
|
@@ -4,7 +4,7 @@ from typing import TYPE_CHECKING
|
|
|
4
4
|
|
|
5
5
|
from infrahub.core import registry
|
|
6
6
|
from infrahub.core.diff.repository.repository import DiffRepository
|
|
7
|
-
from infrahub.core.migrations.shared import MigrationResult
|
|
7
|
+
from infrahub.core.migrations.shared import MigrationInput, MigrationResult
|
|
8
8
|
from infrahub.dependencies.registry import build_component_registry, get_component_registry
|
|
9
9
|
from infrahub.log import get_logger
|
|
10
10
|
|
|
@@ -25,7 +25,8 @@ class Migration015(ArbitraryMigration):
|
|
|
25
25
|
|
|
26
26
|
return result
|
|
27
27
|
|
|
28
|
-
async def execute(self,
|
|
28
|
+
async def execute(self, migration_input: MigrationInput) -> MigrationResult:
|
|
29
|
+
db = migration_input.db
|
|
29
30
|
default_branch = registry.get_branch_from_registry()
|
|
30
31
|
build_component_registry()
|
|
31
32
|
component_registry = get_component_registry()
|
|
@@ -4,7 +4,7 @@ from typing import TYPE_CHECKING
|
|
|
4
4
|
|
|
5
5
|
from infrahub.core import registry
|
|
6
6
|
from infrahub.core.diff.repository.repository import DiffRepository
|
|
7
|
-
from infrahub.core.migrations.shared import MigrationResult
|
|
7
|
+
from infrahub.core.migrations.shared import MigrationInput, MigrationResult
|
|
8
8
|
from infrahub.dependencies.registry import build_component_registry, get_component_registry
|
|
9
9
|
from infrahub.log import get_logger
|
|
10
10
|
|
|
@@ -25,7 +25,8 @@ class Migration016(ArbitraryMigration):
|
|
|
25
25
|
|
|
26
26
|
return result
|
|
27
27
|
|
|
28
|
-
async def execute(self,
|
|
28
|
+
async def execute(self, migration_input: MigrationInput) -> MigrationResult:
|
|
29
|
+
db = migration_input.db
|
|
29
30
|
default_branch = registry.get_branch_from_registry()
|
|
30
31
|
build_component_registry()
|
|
31
32
|
component_registry = get_component_registry()
|
|
@@ -3,8 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
from typing import TYPE_CHECKING, Sequence
|
|
4
4
|
|
|
5
5
|
from infrahub.core import registry
|
|
6
|
-
from infrahub.core.
|
|
7
|
-
from infrahub.core.migrations.shared import MigrationResult
|
|
6
|
+
from infrahub.core.migrations.shared import MigrationInput, MigrationResult
|
|
8
7
|
from infrahub.core.schema.definitions.core import core_profile_schema_definition
|
|
9
8
|
from infrahub.core.schema.manager import SchemaManager
|
|
10
9
|
from infrahub.log import get_logger
|
|
@@ -27,17 +26,20 @@ class Migration017(InternalSchemaMigration):
|
|
|
27
26
|
|
|
28
27
|
return result
|
|
29
28
|
|
|
30
|
-
async def execute(self,
|
|
29
|
+
async def execute(self, migration_input: MigrationInput) -> MigrationResult:
|
|
31
30
|
"""
|
|
32
31
|
Load CoreProfile schema node in db.
|
|
33
32
|
"""
|
|
33
|
+
db = migration_input.db
|
|
34
|
+
at = migration_input.at
|
|
35
|
+
user_id = migration_input.user_id
|
|
34
36
|
default_branch = registry.get_branch_from_registry()
|
|
35
37
|
manager = SchemaManager()
|
|
36
38
|
manager.set_schema_branch(name=default_branch.name, schema=self.get_internal_schema())
|
|
37
39
|
|
|
38
40
|
db.add_schema(manager.get_schema_branch(default_branch.name))
|
|
39
41
|
await manager.load_node_to_db(
|
|
40
|
-
node=core_profile_schema_definition, db=db, branch=default_branch, user_id=user_id
|
|
42
|
+
node=core_profile_schema_definition, db=db, branch=default_branch, user_id=user_id, at=at
|
|
41
43
|
)
|
|
42
44
|
|
|
43
45
|
return MigrationResult()
|
|
@@ -4,9 +4,8 @@ from collections import defaultdict
|
|
|
4
4
|
from typing import TYPE_CHECKING, Sequence
|
|
5
5
|
|
|
6
6
|
from infrahub.core import registry
|
|
7
|
-
from infrahub.core.constants import SYSTEM_USER_ID
|
|
8
7
|
from infrahub.core.diff.payload_builder import get_display_labels_per_kind
|
|
9
|
-
from infrahub.core.migrations.shared import MigrationResult
|
|
8
|
+
from infrahub.core.migrations.shared import MigrationInput, MigrationResult
|
|
10
9
|
from infrahub.core.schema import GenericSchema, NodeSchema, SchemaRoot, internal_schema
|
|
11
10
|
from infrahub.core.schema.manager import SchemaManager
|
|
12
11
|
from infrahub.core.validators.uniqueness.checker import UniquenessChecker
|
|
@@ -96,5 +95,5 @@ class Migration018(InternalSchemaMigration):
|
|
|
96
95
|
async def validate_migration(self, db: InfrahubDatabase) -> MigrationResult: # noqa: ARG002
|
|
97
96
|
return MigrationResult()
|
|
98
97
|
|
|
99
|
-
async def execute(self,
|
|
100
|
-
return await validate_nulls_in_uniqueness_constraints(db=db)
|
|
98
|
+
async def execute(self, migration_input: MigrationInput) -> MigrationResult:
|
|
99
|
+
return await validate_nulls_in_uniqueness_constraints(db=migration_input.db)
|
|
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
from typing import TYPE_CHECKING, Any, Sequence
|
|
4
4
|
|
|
5
5
|
from infrahub.core.constants.database import DatabaseEdgeType
|
|
6
|
-
from infrahub.core.migrations.shared import GraphMigration, MigrationResult
|
|
6
|
+
from infrahub.core.migrations.shared import GraphMigration, MigrationInput, MigrationResult
|
|
7
7
|
from infrahub.log import get_logger
|
|
8
8
|
|
|
9
9
|
from ...query import Query, QueryType
|
|
@@ -140,9 +140,9 @@ class Migration020(GraphMigration):
|
|
|
140
140
|
DeleteDuplicateIsProtectedEdgesQuery,
|
|
141
141
|
]
|
|
142
142
|
|
|
143
|
-
async def execute(self,
|
|
143
|
+
async def execute(self, migration_input: MigrationInput) -> MigrationResult:
|
|
144
144
|
# skip the transaction b/c it will run out of memory on a large database
|
|
145
|
-
return await self.do_execute(
|
|
145
|
+
return await self.do_execute(migration_input=migration_input)
|
|
146
146
|
|
|
147
147
|
async def validate_migration(self, db: InfrahubDatabase) -> MigrationResult: # noqa: ARG002
|
|
148
148
|
result = MigrationResult()
|
|
@@ -2,8 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
from typing import TYPE_CHECKING, Sequence
|
|
4
4
|
|
|
5
|
-
from infrahub.core.
|
|
6
|
-
from infrahub.core.migrations.shared import MigrationResult
|
|
5
|
+
from infrahub.core.migrations.shared import MigrationInput, MigrationResult
|
|
7
6
|
from infrahub.log import get_logger
|
|
8
7
|
|
|
9
8
|
from ..shared import InternalSchemaMigration, SchemaMigration
|
|
@@ -23,5 +22,5 @@ class Migration025(InternalSchemaMigration):
|
|
|
23
22
|
async def validate_migration(self, db: InfrahubDatabase) -> MigrationResult: # noqa: ARG002
|
|
24
23
|
return MigrationResult()
|
|
25
24
|
|
|
26
|
-
async def execute(self,
|
|
27
|
-
return await validate_nulls_in_uniqueness_constraints(db=db)
|
|
25
|
+
async def execute(self, migration_input: MigrationInput) -> MigrationResult:
|
|
26
|
+
return await validate_nulls_in_uniqueness_constraints(db=migration_input.db)
|
|
@@ -4,12 +4,10 @@ import ipaddress
|
|
|
4
4
|
from typing import TYPE_CHECKING, Sequence
|
|
5
5
|
|
|
6
6
|
from infrahub.core.branch.models import Branch
|
|
7
|
-
from infrahub.core.constants import SYSTEM_USER_ID
|
|
8
7
|
from infrahub.core.initialization import initialization
|
|
9
8
|
from infrahub.core.ipam.reconciler import IpamReconciler
|
|
10
9
|
from infrahub.core.manager import NodeManager
|
|
11
|
-
from infrahub.core.migrations.shared import MigrationResult
|
|
12
|
-
from infrahub.core.timestamp import Timestamp
|
|
10
|
+
from infrahub.core.migrations.shared import MigrationInput, MigrationResult
|
|
13
11
|
from infrahub.lock import initialize_lock
|
|
14
12
|
from infrahub.log import get_logger
|
|
15
13
|
|
|
@@ -29,12 +27,13 @@ class Migration026(InternalSchemaMigration):
|
|
|
29
27
|
async def validate_migration(self, db: InfrahubDatabase) -> MigrationResult: # noqa: ARG002
|
|
30
28
|
return MigrationResult()
|
|
31
29
|
|
|
32
|
-
async def execute(self,
|
|
30
|
+
async def execute(self, migration_input: MigrationInput) -> MigrationResult:
|
|
31
|
+
db = migration_input.db
|
|
32
|
+
at = migration_input.at
|
|
33
33
|
# load schemas from database into registry
|
|
34
34
|
initialize_lock()
|
|
35
35
|
await initialization(db=db)
|
|
36
36
|
|
|
37
|
-
at = Timestamp()
|
|
38
37
|
for branch in await Branch.get_list(db=db):
|
|
39
38
|
prefix_0000s = await NodeManager.query(
|
|
40
39
|
db=db, schema="BuiltinIPPrefix", branch=branch, filters={"prefix__values": ["0.0.0.0/0", "::/0"]}
|
|
@@ -4,7 +4,7 @@ from typing import TYPE_CHECKING
|
|
|
4
4
|
|
|
5
5
|
from infrahub.core import registry
|
|
6
6
|
from infrahub.core.diff.repository.repository import DiffRepository
|
|
7
|
-
from infrahub.core.migrations.shared import MigrationResult
|
|
7
|
+
from infrahub.core.migrations.shared import MigrationInput, MigrationResult
|
|
8
8
|
from infrahub.dependencies.registry import build_component_registry, get_component_registry
|
|
9
9
|
from infrahub.log import get_logger
|
|
10
10
|
|
|
@@ -27,7 +27,8 @@ class Migration028(ArbitraryMigration):
|
|
|
27
27
|
|
|
28
28
|
return result
|
|
29
29
|
|
|
30
|
-
async def execute(self,
|
|
30
|
+
async def execute(self, migration_input: MigrationInput) -> MigrationResult:
|
|
31
|
+
db = migration_input.db
|
|
31
32
|
default_branch = registry.get_branch_from_registry()
|
|
32
33
|
build_component_registry()
|
|
33
34
|
component_registry = get_component_registry()
|
|
@@ -4,7 +4,7 @@ from typing import TYPE_CHECKING, Any, Literal
|
|
|
4
4
|
|
|
5
5
|
from infrahub.core.constants import RelationshipDirection
|
|
6
6
|
from infrahub.core.constants.database import DatabaseEdgeType
|
|
7
|
-
from infrahub.core.migrations.shared import MigrationResult
|
|
7
|
+
from infrahub.core.migrations.shared import MigrationInput, MigrationResult
|
|
8
8
|
from infrahub.core.query import Query, QueryType
|
|
9
9
|
from infrahub.log import get_logger
|
|
10
10
|
|
|
@@ -574,8 +574,9 @@ class Migration029(ArbitraryMigration):
|
|
|
574
574
|
|
|
575
575
|
return result
|
|
576
576
|
|
|
577
|
-
async def execute(self,
|
|
577
|
+
async def execute(self, migration_input: MigrationInput) -> MigrationResult:
|
|
578
578
|
migration_result = MigrationResult()
|
|
579
|
+
db = migration_input.db
|
|
579
580
|
limit = self.limit
|
|
580
581
|
offset = 0
|
|
581
582
|
more_nodes_to_process = True
|
|
@@ -5,9 +5,9 @@ from typing import TYPE_CHECKING, Sequence
|
|
|
5
5
|
from infrahub import config
|
|
6
6
|
from infrahub.core import registry
|
|
7
7
|
from infrahub.core.branch import Branch
|
|
8
|
-
from infrahub.core.constants import
|
|
8
|
+
from infrahub.core.constants import SchemaPathType
|
|
9
9
|
from infrahub.core.initialization import initialization
|
|
10
|
-
from infrahub.core.migrations.shared import InternalSchemaMigration, MigrationResult, SchemaMigration
|
|
10
|
+
from infrahub.core.migrations.shared import InternalSchemaMigration, MigrationInput, MigrationResult, SchemaMigration
|
|
11
11
|
from infrahub.core.path import SchemaPath
|
|
12
12
|
from infrahub.core.schema import GenericSchema, NodeSchema
|
|
13
13
|
from infrahub.core.schema.attribute_parameters import NumberAttributeParameters
|
|
@@ -35,7 +35,7 @@ class Migration031(InternalSchemaMigration):
|
|
|
35
35
|
minimum_version: int = 30
|
|
36
36
|
migrations: Sequence[SchemaMigration] = []
|
|
37
37
|
|
|
38
|
-
async def execute(self,
|
|
38
|
+
async def execute(self, migration_input: MigrationInput) -> MigrationResult:
|
|
39
39
|
"""Retrieve all number attributes that have a min/max/excluded_values
|
|
40
40
|
For any of these attributes, check if corresponding existing nodes are valid."""
|
|
41
41
|
|
|
@@ -43,6 +43,7 @@ class Migration031(InternalSchemaMigration):
|
|
|
43
43
|
return MigrationResult()
|
|
44
44
|
|
|
45
45
|
# load schemas from database into registry
|
|
46
|
+
db = migration_input.db
|
|
46
47
|
initialize_lock()
|
|
47
48
|
await initialization(db=db)
|
|
48
49
|
|
|
@@ -2,7 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
from typing import TYPE_CHECKING, Any
|
|
4
4
|
|
|
5
|
-
from infrahub.core.migrations.shared import MigrationResult
|
|
5
|
+
from infrahub.core.migrations.shared import MigrationInput, MigrationResult
|
|
6
6
|
from infrahub.core.query import Query, QueryType
|
|
7
7
|
from infrahub.core.query.branch import DeleteBranchRelationshipsQuery
|
|
8
8
|
from infrahub.log import get_logger
|
|
@@ -68,7 +68,8 @@ class Migration032(ArbitraryMigration):
|
|
|
68
68
|
async def validate_migration(self, db: InfrahubDatabase) -> MigrationResult: # noqa: ARG002
|
|
69
69
|
return MigrationResult()
|
|
70
70
|
|
|
71
|
-
async def execute(self,
|
|
71
|
+
async def execute(self, migration_input: MigrationInput) -> MigrationResult:
|
|
72
|
+
db = migration_input.db
|
|
72
73
|
migration_result = MigrationResult()
|
|
73
74
|
|
|
74
75
|
try:
|
|
@@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, Any, Sequence
|
|
|
5
5
|
|
|
6
6
|
from infrahub.core.initialization import initialization
|
|
7
7
|
from infrahub.core.manager import NodeManager
|
|
8
|
-
from infrahub.core.migrations.shared import ArbitraryMigration, MigrationResult
|
|
8
|
+
from infrahub.core.migrations.shared import ArbitraryMigration, MigrationInput, MigrationResult
|
|
9
9
|
from infrahub.core.timestamp import Timestamp
|
|
10
10
|
from infrahub.lock import initialize_lock
|
|
11
11
|
from infrahub.log import get_logger
|
|
@@ -59,7 +59,8 @@ class Migration034(ArbitraryMigration):
|
|
|
59
59
|
async def validate_migration(self, db: InfrahubDatabase) -> MigrationResult: # noqa: ARG002
|
|
60
60
|
return MigrationResult()
|
|
61
61
|
|
|
62
|
-
async def execute(self,
|
|
62
|
+
async def execute(self, migration_input: MigrationInput) -> MigrationResult:
|
|
63
|
+
db = migration_input.db
|
|
63
64
|
try:
|
|
64
65
|
initialize_lock()
|
|
65
66
|
await initialization(db=db)
|
|
@@ -2,7 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
from typing import TYPE_CHECKING, Any, Sequence
|
|
4
4
|
|
|
5
|
-
from infrahub.core.migrations.shared import GraphMigration, MigrationResult
|
|
5
|
+
from infrahub.core.migrations.shared import GraphMigration, MigrationInput, MigrationResult
|
|
6
6
|
|
|
7
7
|
from ...query import Query, QueryType
|
|
8
8
|
|
|
@@ -38,6 +38,6 @@ class Migration035(GraphMigration):
|
|
|
38
38
|
async def validate_migration(self, db: InfrahubDatabase) -> MigrationResult: # noqa: ARG002
|
|
39
39
|
return MigrationResult()
|
|
40
40
|
|
|
41
|
-
async def execute(self,
|
|
41
|
+
async def execute(self, migration_input: MigrationInput) -> MigrationResult:
|
|
42
42
|
# overrides parent class to skip transaction in case there are a lot of relationships to delete
|
|
43
|
-
return await self.do_execute(
|
|
43
|
+
return await self.do_execute(migration_input=migration_input)
|