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
|
@@ -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 Migration036(GraphMigration):
|
|
|
23
23
|
queries: Sequence[type[Query]] = []
|
|
24
24
|
minimum_version: int = 35
|
|
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
|
|
@@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, Any
|
|
|
5
5
|
|
|
6
6
|
from infrahub.constants.database import IndexType
|
|
7
7
|
from infrahub.core.attribute import MAX_STRING_LENGTH
|
|
8
|
-
from infrahub.core.migrations.shared import MigrationResult, get_migration_console
|
|
8
|
+
from infrahub.core.migrations.shared import MigrationInput, MigrationResult, get_migration_console
|
|
9
9
|
from infrahub.core.query import Query, QueryType
|
|
10
10
|
from infrahub.database.index import IndexItem
|
|
11
11
|
from infrahub.database.neo4j import IndexManagerNeo4j
|
|
@@ -463,8 +463,9 @@ class Migration037(ArbitraryMigration):
|
|
|
463
463
|
|
|
464
464
|
return result
|
|
465
465
|
|
|
466
|
-
async def execute(self,
|
|
466
|
+
async def execute(self, migration_input: MigrationInput) -> MigrationResult: # noqa: PLR0915
|
|
467
467
|
console = get_migration_console()
|
|
468
|
+
db = migration_input.db
|
|
468
469
|
result = MigrationResult()
|
|
469
470
|
|
|
470
471
|
# find the active schema attributes that have a LARGE_ATTRIBUTE_TYPE kind on all branches
|
|
@@ -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
|
|
|
@@ -38,12 +36,13 @@ class Migration038(InternalSchemaMigration):
|
|
|
38
36
|
async def validate_migration(self, db: InfrahubDatabase) -> MigrationResult: # noqa: ARG002
|
|
39
37
|
return MigrationResult()
|
|
40
38
|
|
|
41
|
-
async def execute(self,
|
|
39
|
+
async def execute(self, migration_input: MigrationInput) -> MigrationResult:
|
|
40
|
+
db = migration_input.db
|
|
41
|
+
at = migration_input.at
|
|
42
42
|
# load schemas from database into registry
|
|
43
43
|
initialize_lock()
|
|
44
44
|
await initialization(db=db)
|
|
45
45
|
|
|
46
|
-
at = Timestamp()
|
|
47
46
|
for branch in await Branch.get_list(db=db):
|
|
48
47
|
prefix_0000s = await NodeManager.query(
|
|
49
48
|
db=db, schema="BuiltinIPPrefix", branch=branch, filters={"prefix__values": ["0.0.0.0/0", "::/0"]}
|
|
@@ -10,7 +10,7 @@ from infrahub.core.branch.models import Branch
|
|
|
10
10
|
from infrahub.core.constants import InfrahubKind
|
|
11
11
|
from infrahub.core.initialization import initialization
|
|
12
12
|
from infrahub.core.ipam.reconciler import IpamReconciler
|
|
13
|
-
from infrahub.core.migrations.shared import MigrationResult, get_migration_console
|
|
13
|
+
from infrahub.core.migrations.shared import MigrationInput, MigrationResult, get_migration_console
|
|
14
14
|
from infrahub.core.query import Query, QueryType
|
|
15
15
|
from infrahub.lock import initialize_lock
|
|
16
16
|
from infrahub.log import get_logger
|
|
@@ -233,7 +233,8 @@ class Migration039(ArbitraryMigration):
|
|
|
233
233
|
async def validate_migration(self, db: InfrahubDatabase) -> MigrationResult: # noqa: ARG002
|
|
234
234
|
return MigrationResult()
|
|
235
235
|
|
|
236
|
-
async def execute(self,
|
|
236
|
+
async def execute(self, migration_input: MigrationInput) -> MigrationResult:
|
|
237
|
+
db = migration_input.db
|
|
237
238
|
console = get_migration_console()
|
|
238
239
|
result = MigrationResult()
|
|
239
240
|
# load schemas from database into registry
|
|
@@ -7,7 +7,7 @@ from rich import print as rprint
|
|
|
7
7
|
from infrahub.core.branch import Branch
|
|
8
8
|
from infrahub.core.diff.repository.repository import DiffRepository
|
|
9
9
|
from infrahub.core.initialization import get_root_node
|
|
10
|
-
from infrahub.core.migrations.shared import MigrationResult
|
|
10
|
+
from infrahub.core.migrations.shared import MigrationInput, MigrationResult
|
|
11
11
|
from infrahub.core.query import Query, QueryType
|
|
12
12
|
from infrahub.dependencies.registry import build_component_registry, get_component_registry
|
|
13
13
|
from infrahub.log import get_logger
|
|
@@ -140,7 +140,8 @@ class Migration041(ArbitraryMigration):
|
|
|
140
140
|
|
|
141
141
|
return result
|
|
142
142
|
|
|
143
|
-
async def execute(self,
|
|
143
|
+
async def execute(self, migration_input: MigrationInput) -> MigrationResult:
|
|
144
|
+
db = migration_input.db
|
|
144
145
|
root_node = await get_root_node(db=db)
|
|
145
146
|
default_branch_name = root_node.default_branch
|
|
146
147
|
default_branch = await Branch.get_by_name(db=db, name=default_branch_name)
|
|
@@ -7,7 +7,7 @@ from rich.progress import Progress
|
|
|
7
7
|
from infrahub.core.branch.models import Branch
|
|
8
8
|
from infrahub.core.initialization import get_root_node
|
|
9
9
|
from infrahub.core.manager import NodeManager
|
|
10
|
-
from infrahub.core.migrations.shared import MigrationResult, get_migration_console
|
|
10
|
+
from infrahub.core.migrations.shared import MigrationInput, MigrationResult, get_migration_console
|
|
11
11
|
from infrahub.core.query import Query, QueryType
|
|
12
12
|
from infrahub.core.timestamp import Timestamp
|
|
13
13
|
from infrahub.log import get_logger
|
|
@@ -87,14 +87,15 @@ class Migration042(MigrationRequiringRebase):
|
|
|
87
87
|
async def validate_migration(self, db: InfrahubDatabase) -> MigrationResult: # noqa: ARG002
|
|
88
88
|
return MigrationResult()
|
|
89
89
|
|
|
90
|
-
async def execute(self,
|
|
90
|
+
async def execute(self, migration_input: MigrationInput) -> MigrationResult:
|
|
91
|
+
db = migration_input.db
|
|
91
92
|
root_node = await get_root_node(db=db, initialize=False)
|
|
92
93
|
default_branch_name = root_node.default_branch
|
|
93
94
|
default_branch = await Branch.get_by_name(db=db, name=default_branch_name)
|
|
94
95
|
return await self._do_execute_for_branch(db=db, branch=default_branch)
|
|
95
96
|
|
|
96
|
-
async def execute_against_branch(self,
|
|
97
|
-
return await self._do_execute_for_branch(db=db, branch=branch)
|
|
97
|
+
async def execute_against_branch(self, migration_input: MigrationInput, branch: Branch) -> MigrationResult:
|
|
98
|
+
return await self._do_execute_for_branch(db=migration_input.db, branch=branch)
|
|
98
99
|
|
|
99
100
|
async def _do_execute_for_branch(self, db: InfrahubDatabase, branch: Branch) -> MigrationResult:
|
|
100
101
|
console = get_migration_console()
|
|
@@ -9,7 +9,12 @@ from infrahub.core.branch import Branch
|
|
|
9
9
|
from infrahub.core.constants import BranchSupportType, SchemaPathType
|
|
10
10
|
from infrahub.core.initialization import get_root_node
|
|
11
11
|
from infrahub.core.migrations.schema.node_attribute_add import NodeAttributeAddMigration
|
|
12
|
-
from infrahub.core.migrations.shared import
|
|
12
|
+
from infrahub.core.migrations.shared import (
|
|
13
|
+
MigrationInput,
|
|
14
|
+
MigrationRequiringRebase,
|
|
15
|
+
MigrationResult,
|
|
16
|
+
get_migration_console,
|
|
17
|
+
)
|
|
13
18
|
from infrahub.core.path import SchemaPath
|
|
14
19
|
from infrahub.core.query import Query, QueryType
|
|
15
20
|
|
|
@@ -48,7 +53,8 @@ class Migration043(MigrationRequiringRebase):
|
|
|
48
53
|
name: str = "043_create_hfid_display_label_in_db"
|
|
49
54
|
minimum_version: int = 42
|
|
50
55
|
|
|
51
|
-
async def execute(self,
|
|
56
|
+
async def execute(self, migration_input: MigrationInput) -> MigrationResult:
|
|
57
|
+
db = migration_input.db
|
|
52
58
|
result = MigrationResult()
|
|
53
59
|
|
|
54
60
|
root_node = await get_root_node(db=db, initialize=False)
|
|
@@ -104,7 +110,7 @@ class Migration043(MigrationRequiringRebase):
|
|
|
104
110
|
|
|
105
111
|
for migration in migrations:
|
|
106
112
|
try:
|
|
107
|
-
execution_result = await migration.execute(
|
|
113
|
+
execution_result = await migration.execute(migration_input=migration_input, branch=default_branch)
|
|
108
114
|
result.errors.extend(execution_result.errors)
|
|
109
115
|
progress.update(update_task, advance=1)
|
|
110
116
|
except Exception as exc:
|
|
@@ -113,7 +119,8 @@ class Migration043(MigrationRequiringRebase):
|
|
|
113
119
|
|
|
114
120
|
return result
|
|
115
121
|
|
|
116
|
-
async def execute_against_branch(self,
|
|
122
|
+
async def execute_against_branch(self, migration_input: MigrationInput, branch: Branch) -> MigrationResult:
|
|
123
|
+
db = migration_input.db
|
|
117
124
|
result = MigrationResult()
|
|
118
125
|
|
|
119
126
|
schema_branch = await registry.schema.load_schema_from_db(db=db, branch=branch)
|
|
@@ -155,7 +162,7 @@ class Migration043(MigrationRequiringRebase):
|
|
|
155
162
|
|
|
156
163
|
for migration in migrations:
|
|
157
164
|
try:
|
|
158
|
-
execution_result = await migration.execute(
|
|
165
|
+
execution_result = await migration.execute(migration_input=migration_input, branch=branch)
|
|
159
166
|
result.errors.extend(execution_result.errors)
|
|
160
167
|
progress.update(update_task, advance=1)
|
|
161
168
|
except Exception as exc:
|
|
@@ -11,7 +11,7 @@ from infrahub.core import registry
|
|
|
11
11
|
from infrahub.core.branch import Branch
|
|
12
12
|
from infrahub.core.constants import GLOBAL_BRANCH_NAME, BranchSupportType, RelationshipDirection
|
|
13
13
|
from infrahub.core.initialization import get_root_node
|
|
14
|
-
from infrahub.core.migrations.shared import MigrationResult, get_migration_console
|
|
14
|
+
from infrahub.core.migrations.shared import MigrationInput, MigrationResult, get_migration_console
|
|
15
15
|
from infrahub.core.query import Query, QueryType
|
|
16
16
|
from infrahub.core.schema import NodeSchema
|
|
17
17
|
from infrahub.exceptions import SchemaNotFoundError
|
|
@@ -24,9 +24,9 @@ if TYPE_CHECKING:
|
|
|
24
24
|
from infrahub.core.schema import AttributeSchema, NodeSchema, ProfileSchema, TemplateSchema
|
|
25
25
|
from infrahub.core.schema.basenode_schema import SchemaAttributePath
|
|
26
26
|
from infrahub.core.schema.schema_branch import SchemaBranch
|
|
27
|
+
from infrahub.core.timestamp import Timestamp
|
|
27
28
|
from infrahub.database import InfrahubDatabase
|
|
28
29
|
|
|
29
|
-
|
|
30
30
|
console = get_migration_console()
|
|
31
31
|
|
|
32
32
|
|
|
@@ -631,6 +631,7 @@ class Migration044(MigrationRequiringRebase):
|
|
|
631
631
|
schema: NodeSchema | ProfileSchema | TemplateSchema,
|
|
632
632
|
schema_branch: SchemaBranch,
|
|
633
633
|
attribute_schema_map: dict[AttributeSchema, AttributeSchema],
|
|
634
|
+
at: Timestamp,
|
|
634
635
|
progress: Progress | None = None,
|
|
635
636
|
update_task: TaskID | None = None,
|
|
636
637
|
) -> None:
|
|
@@ -696,6 +697,7 @@ class Migration044(MigrationRequiringRebase):
|
|
|
696
697
|
branch=branch,
|
|
697
698
|
attribute_schema=destination_attribute_schema,
|
|
698
699
|
values_by_id_map=formatted_schema_path_values_map,
|
|
700
|
+
at=at,
|
|
699
701
|
)
|
|
700
702
|
await update_display_label_query.execute(db=db)
|
|
701
703
|
|
|
@@ -709,7 +711,9 @@ class Migration044(MigrationRequiringRebase):
|
|
|
709
711
|
|
|
710
712
|
print("done")
|
|
711
713
|
|
|
712
|
-
async def execute(self,
|
|
714
|
+
async def execute(self, migration_input: MigrationInput) -> MigrationResult:
|
|
715
|
+
db = migration_input.db
|
|
716
|
+
at = migration_input.at
|
|
713
717
|
root_node = await get_root_node(db=db, initialize=False)
|
|
714
718
|
default_branch_name = root_node.default_branch
|
|
715
719
|
default_branch = await Branch.get_by_name(db=db, name=default_branch_name)
|
|
@@ -754,6 +758,7 @@ class Migration044(MigrationRequiringRebase):
|
|
|
754
758
|
schema=node_schema,
|
|
755
759
|
schema_branch=main_schema_branch,
|
|
756
760
|
attribute_schema_map=attribute_schema_map,
|
|
761
|
+
at=at,
|
|
757
762
|
progress=progress,
|
|
758
763
|
update_task=update_task,
|
|
759
764
|
)
|
|
@@ -770,6 +775,7 @@ class Migration044(MigrationRequiringRebase):
|
|
|
770
775
|
schema_branch: SchemaBranch,
|
|
771
776
|
source_attribute_schema: AttributeSchema,
|
|
772
777
|
destination_attribute_schema: AttributeSchema,
|
|
778
|
+
at: Timestamp,
|
|
773
779
|
) -> None:
|
|
774
780
|
print(f"Processing {schema.kind}.{destination_attribute_schema.name} for {branch.name}...", end="")
|
|
775
781
|
|
|
@@ -814,12 +820,15 @@ class Migration044(MigrationRequiringRebase):
|
|
|
814
820
|
branch=branch,
|
|
815
821
|
attribute_schema=destination_attribute_schema,
|
|
816
822
|
values_by_id_map=formatted_schema_path_values_map,
|
|
823
|
+
at=at,
|
|
817
824
|
)
|
|
818
825
|
await update_attr_values_query.execute(db=db)
|
|
819
826
|
|
|
820
827
|
offset += self.update_batch_size
|
|
821
828
|
|
|
822
|
-
async def execute_against_branch(self,
|
|
829
|
+
async def execute_against_branch(self, migration_input: MigrationInput, branch: Branch) -> MigrationResult:
|
|
830
|
+
db = migration_input.db
|
|
831
|
+
at = migration_input.at
|
|
823
832
|
default_branch = await Branch.get_by_name(db=db, name=registry.default_branch)
|
|
824
833
|
main_schema_branch = await get_or_load_schema_branch(db=db, branch=default_branch)
|
|
825
834
|
schema_branch = await get_or_load_schema_branch(db=db, branch=branch)
|
|
@@ -869,6 +878,7 @@ class Migration044(MigrationRequiringRebase):
|
|
|
869
878
|
schema=node_schema,
|
|
870
879
|
schema_branch=schema_branch,
|
|
871
880
|
attribute_schema_map=schemas_for_universal_update_map,
|
|
881
|
+
at=at,
|
|
872
882
|
)
|
|
873
883
|
|
|
874
884
|
if not schemas_for_targeted_update_map:
|
|
@@ -882,6 +892,7 @@ class Migration044(MigrationRequiringRebase):
|
|
|
882
892
|
schema_branch=schema_branch,
|
|
883
893
|
source_attribute_schema=source_attribute_schema,
|
|
884
894
|
destination_attribute_schema=destination_attribute_schema,
|
|
895
|
+
at=at,
|
|
885
896
|
)
|
|
886
897
|
|
|
887
898
|
except Exception as exc:
|
|
@@ -8,14 +8,13 @@ from infrahub.core import registry
|
|
|
8
8
|
from infrahub.core.branch import Branch
|
|
9
9
|
from infrahub.core.initialization import get_root_node
|
|
10
10
|
from infrahub.core.migrations.graph.m044_backfill_hfid_display_label_in_db import DefaultBranchNodeCount, Migration044
|
|
11
|
-
from infrahub.core.migrations.shared import MigrationResult, get_migration_console
|
|
11
|
+
from infrahub.core.migrations.shared import MigrationInput, MigrationResult, get_migration_console
|
|
12
12
|
from infrahub.exceptions import SchemaNotFoundError
|
|
13
13
|
|
|
14
14
|
from .load_schema_branch import get_or_load_schema_branch
|
|
15
15
|
|
|
16
16
|
if TYPE_CHECKING:
|
|
17
17
|
from infrahub.core.schema import ProfileSchema, TemplateSchema
|
|
18
|
-
from infrahub.database import InfrahubDatabase
|
|
19
18
|
|
|
20
19
|
|
|
21
20
|
console = get_migration_console()
|
|
@@ -30,7 +29,9 @@ class Migration045(Migration044):
|
|
|
30
29
|
minimum_version: int = 44
|
|
31
30
|
update_batch_size: int = 1000
|
|
32
31
|
|
|
33
|
-
async def execute(self,
|
|
32
|
+
async def execute(self, migration_input: MigrationInput) -> MigrationResult:
|
|
33
|
+
db = migration_input.db
|
|
34
|
+
at = migration_input.at
|
|
34
35
|
root_node = await get_root_node(db=db, initialize=False)
|
|
35
36
|
default_branch_name = root_node.default_branch
|
|
36
37
|
default_branch = await Branch.get_by_name(db=db, name=default_branch_name)
|
|
@@ -77,6 +78,7 @@ class Migration045(Migration044):
|
|
|
77
78
|
schema=node_schema,
|
|
78
79
|
schema_branch=main_schema_branch,
|
|
79
80
|
attribute_schema_map=attribute_schema_map,
|
|
81
|
+
at=at,
|
|
80
82
|
progress=progress,
|
|
81
83
|
update_task=update_task,
|
|
82
84
|
)
|
|
@@ -85,7 +87,9 @@ class Migration045(Migration044):
|
|
|
85
87
|
return MigrationResult(errors=[str(exc)])
|
|
86
88
|
return MigrationResult()
|
|
87
89
|
|
|
88
|
-
async def execute_against_branch(self,
|
|
90
|
+
async def execute_against_branch(self, migration_input: MigrationInput, branch: Branch) -> MigrationResult:
|
|
91
|
+
db = migration_input.db
|
|
92
|
+
at = migration_input.at
|
|
89
93
|
default_branch = await Branch.get_by_name(db=db, name=registry.default_branch)
|
|
90
94
|
main_schema_branch = await get_or_load_schema_branch(db=db, branch=default_branch)
|
|
91
95
|
schema_branch = await get_or_load_schema_branch(db=db, branch=branch)
|
|
@@ -143,6 +147,7 @@ class Migration045(Migration044):
|
|
|
143
147
|
schema=node_schema,
|
|
144
148
|
schema_branch=schema_branch,
|
|
145
149
|
attribute_schema_map=schemas_for_universal_update_map,
|
|
150
|
+
at=at,
|
|
146
151
|
)
|
|
147
152
|
|
|
148
153
|
if not schemas_for_targeted_update_map:
|
|
@@ -156,6 +161,7 @@ class Migration045(Migration044):
|
|
|
156
161
|
schema_branch=schema_branch,
|
|
157
162
|
source_attribute_schema=source_attribute_schema,
|
|
158
163
|
destination_attribute_schema=destination_attribute_schema,
|
|
164
|
+
at=at,
|
|
159
165
|
)
|
|
160
166
|
|
|
161
167
|
except Exception as exc:
|
|
@@ -16,7 +16,7 @@ from infrahub.core.migrations.graph.m044_backfill_hfid_display_label_in_db impor
|
|
|
16
16
|
UpdateAttributeValuesQuery,
|
|
17
17
|
)
|
|
18
18
|
from infrahub.core.migrations.schema.node_attribute_add import NodeAttributeAddMigration
|
|
19
|
-
from infrahub.core.migrations.shared import ArbitraryMigration, MigrationResult, get_migration_console
|
|
19
|
+
from infrahub.core.migrations.shared import ArbitraryMigration, MigrationInput, MigrationResult, get_migration_console
|
|
20
20
|
from infrahub.core.path import SchemaPath
|
|
21
21
|
from infrahub.core.query import Query, QueryType
|
|
22
22
|
|
|
@@ -134,13 +134,14 @@ class Migration046(ArbitraryMigration):
|
|
|
134
134
|
|
|
135
135
|
print("done")
|
|
136
136
|
|
|
137
|
-
async def execute(self,
|
|
137
|
+
async def execute(self, migration_input: MigrationInput) -> MigrationResult:
|
|
138
138
|
try:
|
|
139
|
-
return await self._do_execute(
|
|
139
|
+
return await self._do_execute(migration_input=migration_input)
|
|
140
140
|
except Exception as exc:
|
|
141
141
|
return MigrationResult(errors=[str(exc)])
|
|
142
142
|
|
|
143
|
-
async def _do_execute(self,
|
|
143
|
+
async def _do_execute(self, migration_input: MigrationInput) -> MigrationResult:
|
|
144
|
+
db = migration_input.db
|
|
144
145
|
console = get_migration_console()
|
|
145
146
|
result = MigrationResult()
|
|
146
147
|
|
|
@@ -188,7 +189,7 @@ class Migration046(ArbitraryMigration):
|
|
|
188
189
|
|
|
189
190
|
for migration in migrations:
|
|
190
191
|
try:
|
|
191
|
-
execution_result = await migration.execute(
|
|
192
|
+
execution_result = await migration.execute(migration_input=migration_input, branch=global_branch)
|
|
192
193
|
result.errors.extend(execution_result.errors)
|
|
193
194
|
progress.update(update_task, advance=1)
|
|
194
195
|
except Exception as exc:
|
|
@@ -9,7 +9,12 @@ from infrahub.core import registry
|
|
|
9
9
|
from infrahub.core.branch import Branch
|
|
10
10
|
from infrahub.core.constants import GLOBAL_BRANCH_NAME, NULL_VALUE, BranchSupportType
|
|
11
11
|
from infrahub.core.initialization import get_root_node
|
|
12
|
-
from infrahub.core.migrations.shared import
|
|
12
|
+
from infrahub.core.migrations.shared import (
|
|
13
|
+
MigrationInput,
|
|
14
|
+
MigrationRequiringRebase,
|
|
15
|
+
MigrationResult,
|
|
16
|
+
get_migration_console,
|
|
17
|
+
)
|
|
13
18
|
from infrahub.core.query import Query, QueryType
|
|
14
19
|
|
|
15
20
|
from .load_schema_branch import get_or_load_schema_branch
|
|
@@ -24,6 +29,7 @@ if TYPE_CHECKING:
|
|
|
24
29
|
from infrahub.core.schema import AttributeSchema, MainSchemaTypes
|
|
25
30
|
from infrahub.core.schema.basenode_schema import SchemaAttributePath
|
|
26
31
|
from infrahub.core.schema.schema_branch import SchemaBranch
|
|
32
|
+
from infrahub.core.timestamp import Timestamp
|
|
27
33
|
from infrahub.database import InfrahubDatabase
|
|
28
34
|
|
|
29
35
|
|
|
@@ -409,6 +415,7 @@ class Migration047(MigrationRequiringRebase):
|
|
|
409
415
|
schema: MainSchemaTypes,
|
|
410
416
|
schema_branch: SchemaBranch,
|
|
411
417
|
attribute_schema: AttributeSchema,
|
|
418
|
+
at: Timestamp,
|
|
412
419
|
progress: Progress | None = None,
|
|
413
420
|
update_task: TaskID | None = None,
|
|
414
421
|
) -> None:
|
|
@@ -466,6 +473,7 @@ class Migration047(MigrationRequiringRebase):
|
|
|
466
473
|
branch=branch,
|
|
467
474
|
attribute_schema=attribute_schema,
|
|
468
475
|
values_by_id_map=formatted_schema_path_values_map,
|
|
476
|
+
at=at,
|
|
469
477
|
)
|
|
470
478
|
await update_display_label_query.execute(db=db)
|
|
471
479
|
|
|
@@ -477,7 +485,9 @@ class Migration047(MigrationRequiringRebase):
|
|
|
477
485
|
|
|
478
486
|
offset += self.update_batch_size
|
|
479
487
|
|
|
480
|
-
async def execute(self,
|
|
488
|
+
async def execute(self, migration_input: MigrationInput) -> MigrationResult:
|
|
489
|
+
db = migration_input.db
|
|
490
|
+
at = migration_input.at
|
|
481
491
|
root_node = await get_root_node(db=db, initialize=False)
|
|
482
492
|
default_branch_name = root_node.default_branch
|
|
483
493
|
default_branch = await Branch.get_by_name(db=db, name=default_branch_name)
|
|
@@ -531,7 +541,7 @@ class Migration047(MigrationRequiringRebase):
|
|
|
531
541
|
break
|
|
532
542
|
|
|
533
543
|
create_display_label_query = await CreateDisplayLabelNullQuery.init(
|
|
534
|
-
db=db, branch=default_branch, node_uuids=batch_uuids
|
|
544
|
+
db=db, branch=default_branch, node_uuids=batch_uuids, at=at
|
|
535
545
|
)
|
|
536
546
|
await create_display_label_query.execute(db=db)
|
|
537
547
|
|
|
@@ -551,6 +561,7 @@ class Migration047(MigrationRequiringRebase):
|
|
|
551
561
|
schema=main_schema_branch.get(name=node_schema_name, duplicate=False),
|
|
552
562
|
schema_branch=main_schema_branch,
|
|
553
563
|
attribute_schema=display_label_attribute_schema,
|
|
564
|
+
at=at,
|
|
554
565
|
progress=progress,
|
|
555
566
|
update_task=backfill_task,
|
|
556
567
|
)
|
|
@@ -559,7 +570,9 @@ class Migration047(MigrationRequiringRebase):
|
|
|
559
570
|
return MigrationResult(errors=[str(exc)])
|
|
560
571
|
return MigrationResult()
|
|
561
572
|
|
|
562
|
-
async def execute_against_branch(self,
|
|
573
|
+
async def execute_against_branch(self, migration_input: MigrationInput, branch: Branch) -> MigrationResult:
|
|
574
|
+
db = migration_input.db
|
|
575
|
+
at = migration_input.at
|
|
563
576
|
schema_branch = await get_or_load_schema_branch(db=db, branch=branch)
|
|
564
577
|
|
|
565
578
|
base_node_schema = schema_branch.get("SchemaNode", duplicate=False)
|
|
@@ -579,7 +592,7 @@ class Migration047(MigrationRequiringRebase):
|
|
|
579
592
|
break
|
|
580
593
|
|
|
581
594
|
create_display_label_query = await CreateDisplayLabelNullQuery.init(
|
|
582
|
-
db=db, branch=branch, node_uuids=batch_uuids
|
|
595
|
+
db=db, branch=branch, node_uuids=batch_uuids, at=at
|
|
583
596
|
)
|
|
584
597
|
await create_display_label_query.execute(db=db)
|
|
585
598
|
|
|
@@ -599,6 +612,7 @@ class Migration047(MigrationRequiringRebase):
|
|
|
599
612
|
schema=node_schema,
|
|
600
613
|
schema_branch=schema_branch,
|
|
601
614
|
attribute_schema=display_label_attribute_schema,
|
|
615
|
+
at=at,
|
|
602
616
|
)
|
|
603
617
|
|
|
604
618
|
except Exception as exc:
|
|
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
from typing import TYPE_CHECKING, Any
|
|
4
4
|
|
|
5
5
|
from infrahub.core.migrations.graph.m041_deleted_dup_edges import DeleteDuplicatedRelationshipEdges
|
|
6
|
-
from infrahub.core.migrations.shared import ArbitraryMigration, MigrationResult, get_migration_console
|
|
6
|
+
from infrahub.core.migrations.shared import ArbitraryMigration, MigrationInput, MigrationResult, get_migration_console
|
|
7
7
|
from infrahub.core.query import Query, QueryType
|
|
8
8
|
|
|
9
9
|
if TYPE_CHECKING:
|
|
@@ -143,18 +143,20 @@ class Migration048(ArbitraryMigration):
|
|
|
143
143
|
async def validate_migration(self, db: InfrahubDatabase) -> MigrationResult: # noqa: ARG002
|
|
144
144
|
return MigrationResult()
|
|
145
145
|
|
|
146
|
-
async def execute(self,
|
|
146
|
+
async def execute(self, migration_input: MigrationInput) -> MigrationResult:
|
|
147
|
+
db = migration_input.db
|
|
148
|
+
at = migration_input.at
|
|
147
149
|
console = get_migration_console()
|
|
148
150
|
|
|
149
151
|
console.log("Deleting duplicate edges for all Relationships", end="...")
|
|
150
152
|
delete_duplicate_edges_query = await DeleteDuplicatedRelationshipEdges.init(
|
|
151
|
-
db=db, migrated_kind_nodes_only=False
|
|
153
|
+
db=db, migrated_kind_nodes_only=False, at=at
|
|
152
154
|
)
|
|
153
155
|
await delete_duplicate_edges_query.execute(db=db)
|
|
154
156
|
console.log("done")
|
|
155
157
|
|
|
156
158
|
console.log("Undeleting Relationship properties", end="...")
|
|
157
|
-
undelete_rel_props_query = await UndeleteRelationshipProperties.init(db=db)
|
|
159
|
+
undelete_rel_props_query = await UndeleteRelationshipProperties.init(db=db, at=at)
|
|
158
160
|
await undelete_rel_props_query.execute(db=db)
|
|
159
161
|
console.log("done")
|
|
160
162
|
|
|
@@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, Any, Sequence
|
|
|
5
5
|
from infrahub.core.migrations.shared import MigrationResult
|
|
6
6
|
from infrahub.core.query import Query, QueryType
|
|
7
7
|
|
|
8
|
-
from ..shared import GraphMigration
|
|
8
|
+
from ..shared import GraphMigration, MigrationInput
|
|
9
9
|
|
|
10
10
|
if TYPE_CHECKING:
|
|
11
11
|
from infrahub.database import InfrahubDatabase
|
|
@@ -49,5 +49,5 @@ class Migration049(GraphMigration):
|
|
|
49
49
|
async def validate_migration(self, db: InfrahubDatabase) -> MigrationResult: # noqa: ARG002
|
|
50
50
|
return MigrationResult()
|
|
51
51
|
|
|
52
|
-
async def execute(self,
|
|
53
|
-
return await self.do_execute(
|
|
52
|
+
async def execute(self, migration_input: MigrationInput) -> MigrationResult:
|
|
53
|
+
return await self.do_execute(migration_input=migration_input)
|
|
@@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, Any, Sequence
|
|
|
5
5
|
from infrahub.core.migrations.shared import MigrationResult
|
|
6
6
|
from infrahub.core.query import Query, QueryType
|
|
7
7
|
|
|
8
|
-
from ..shared import GraphMigration
|
|
8
|
+
from ..shared import GraphMigration, MigrationInput
|
|
9
9
|
|
|
10
10
|
if TYPE_CHECKING:
|
|
11
11
|
from infrahub.database import InfrahubDatabase
|
|
@@ -164,5 +164,5 @@ class Migration050(GraphMigration):
|
|
|
164
164
|
async def validate_migration(self, db: InfrahubDatabase) -> MigrationResult: # noqa: ARG002
|
|
165
165
|
return MigrationResult()
|
|
166
166
|
|
|
167
|
-
async def execute(self,
|
|
168
|
-
return await self.do_execute(
|
|
167
|
+
async def execute(self, migration_input: MigrationInput) -> MigrationResult:
|
|
168
|
+
return await self.do_execute(migration_input=migration_input)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING
|
|
4
|
+
|
|
5
|
+
from infrahub.core.branch import Branch
|
|
6
|
+
from infrahub.core.migrations.shared import ArbitraryMigration, MigrationInput, MigrationResult
|
|
7
|
+
from infrahub.core.timestamp import Timestamp
|
|
8
|
+
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
from infrahub.database import InfrahubDatabase
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Migration051(ArbitraryMigration):
|
|
14
|
+
name: str = "051_subtract_branched_from_microsecond"
|
|
15
|
+
minimum_version: int = 50
|
|
16
|
+
|
|
17
|
+
async def validate_migration(self, db: InfrahubDatabase) -> MigrationResult: # noqa: ARG002
|
|
18
|
+
return MigrationResult()
|
|
19
|
+
|
|
20
|
+
async def execute(self, migration_input: MigrationInput) -> MigrationResult:
|
|
21
|
+
db = migration_input.db
|
|
22
|
+
result = MigrationResult()
|
|
23
|
+
|
|
24
|
+
branches = await Branch.get_list(db=db)
|
|
25
|
+
|
|
26
|
+
for branch in branches:
|
|
27
|
+
if branch.is_default or branch.is_global:
|
|
28
|
+
continue
|
|
29
|
+
|
|
30
|
+
if not branch.branched_from:
|
|
31
|
+
continue
|
|
32
|
+
|
|
33
|
+
original_ts = Timestamp(branch.branched_from)
|
|
34
|
+
new_ts = original_ts.subtract(microseconds=1)
|
|
35
|
+
branch.branched_from = new_ts.to_string()
|
|
36
|
+
|
|
37
|
+
await branch.save(db=db)
|
|
38
|
+
|
|
39
|
+
return result
|
|
@@ -7,10 +7,11 @@ from infrahub.core.constants import GLOBAL_BRANCH_NAME
|
|
|
7
7
|
from infrahub.core.migrations.graph import MIGRATIONS
|
|
8
8
|
|
|
9
9
|
from .exceptions import MigrationFailureError
|
|
10
|
-
from .shared import MigrationRequiringRebase
|
|
10
|
+
from .shared import MigrationInput, MigrationRequiringRebase
|
|
11
11
|
|
|
12
12
|
if TYPE_CHECKING:
|
|
13
13
|
from infrahub.core.branch import Branch
|
|
14
|
+
from infrahub.core.timestamp import Timestamp
|
|
14
15
|
from infrahub.database import InfrahubDatabase
|
|
15
16
|
|
|
16
17
|
|
|
@@ -35,12 +36,14 @@ class MigrationRunner:
|
|
|
35
36
|
def has_migrations(self) -> bool:
|
|
36
37
|
return bool(self.applicable_migrations)
|
|
37
38
|
|
|
38
|
-
async def run(self, db: InfrahubDatabase) -> None:
|
|
39
|
+
async def run(self, db: InfrahubDatabase, at: Timestamp) -> None:
|
|
39
40
|
if not self.has_migrations():
|
|
40
41
|
return
|
|
41
42
|
|
|
42
43
|
for migration in self.applicable_migrations:
|
|
43
|
-
execution_result = await migration.execute_against_branch(
|
|
44
|
+
execution_result = await migration.execute_against_branch(
|
|
45
|
+
migration_input=MigrationInput(db=db, at=at), branch=self.branch
|
|
46
|
+
)
|
|
44
47
|
validation_result = None
|
|
45
48
|
|
|
46
49
|
if execution_result.success:
|