infrahub-server 1.7.0rc0__py3-none-any.whl → 1.7.2__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.
Files changed (124) hide show
  1. infrahub/actions/gather.py +2 -2
  2. infrahub/api/query.py +3 -2
  3. infrahub/api/schema.py +5 -0
  4. infrahub/api/transformation.py +3 -3
  5. infrahub/cli/db.py +6 -2
  6. infrahub/computed_attribute/gather.py +2 -0
  7. infrahub/config.py +2 -2
  8. infrahub/core/attribute.py +21 -2
  9. infrahub/core/branch/models.py +11 -117
  10. infrahub/core/branch/tasks.py +7 -3
  11. infrahub/core/diff/merger/merger.py +5 -1
  12. infrahub/core/diff/model/path.py +43 -0
  13. infrahub/core/graph/__init__.py +1 -1
  14. infrahub/core/graph/index.py +2 -0
  15. infrahub/core/initialization.py +2 -1
  16. infrahub/core/ipam/resource_allocator.py +229 -0
  17. infrahub/core/migrations/graph/__init__.py +10 -0
  18. infrahub/core/migrations/graph/m014_remove_index_attr_value.py +3 -2
  19. infrahub/core/migrations/graph/m015_diff_format_update.py +3 -2
  20. infrahub/core/migrations/graph/m016_diff_delete_bug_fix.py +3 -2
  21. infrahub/core/migrations/graph/m017_add_core_profile.py +6 -4
  22. infrahub/core/migrations/graph/m018_uniqueness_nulls.py +3 -4
  23. infrahub/core/migrations/graph/m020_duplicate_edges.py +3 -3
  24. infrahub/core/migrations/graph/m025_uniqueness_nulls.py +3 -4
  25. infrahub/core/migrations/graph/m026_0000_prefix_fix.py +4 -5
  26. infrahub/core/migrations/graph/m028_delete_diffs.py +3 -2
  27. infrahub/core/migrations/graph/m029_duplicates_cleanup.py +3 -2
  28. infrahub/core/migrations/graph/m031_check_number_attributes.py +4 -3
  29. infrahub/core/migrations/graph/m032_cleanup_orphaned_branch_relationships.py +3 -2
  30. infrahub/core/migrations/graph/m034_find_orphaned_schema_fields.py +3 -2
  31. infrahub/core/migrations/graph/m035_orphan_relationships.py +3 -3
  32. infrahub/core/migrations/graph/m036_drop_attr_value_index.py +3 -2
  33. infrahub/core/migrations/graph/m037_index_attr_vals.py +3 -2
  34. infrahub/core/migrations/graph/m038_redo_0000_prefix_fix.py +4 -5
  35. infrahub/core/migrations/graph/m039_ipam_reconcile.py +3 -2
  36. infrahub/core/migrations/graph/m041_deleted_dup_edges.py +3 -2
  37. infrahub/core/migrations/graph/m042_profile_attrs_in_db.py +5 -4
  38. infrahub/core/migrations/graph/m043_create_hfid_display_label_in_db.py +12 -5
  39. infrahub/core/migrations/graph/m044_backfill_hfid_display_label_in_db.py +15 -4
  40. infrahub/core/migrations/graph/m045_backfill_hfid_display_label_in_db_profile_template.py +10 -4
  41. infrahub/core/migrations/graph/m046_fill_agnostic_hfid_display_labels.py +6 -5
  42. infrahub/core/migrations/graph/m047_backfill_or_null_display_label.py +19 -5
  43. infrahub/core/migrations/graph/m048_undelete_rel_props.py +6 -4
  44. infrahub/core/migrations/graph/m049_remove_is_visible_relationship.py +3 -3
  45. infrahub/core/migrations/graph/m050_backfill_vertex_metadata.py +3 -3
  46. infrahub/core/migrations/graph/m051_subtract_branched_from_microsecond.py +39 -0
  47. infrahub/core/migrations/graph/m052_fix_global_branch_level.py +51 -0
  48. infrahub/core/migrations/graph/m053_fix_branch_level_zero.py +61 -0
  49. infrahub/core/migrations/graph/m054_cleanup_orphaned_nodes.py +87 -0
  50. infrahub/core/migrations/graph/m055_remove_webhook_validate_certificates_default.py +86 -0
  51. infrahub/core/migrations/runner.py +6 -3
  52. infrahub/core/migrations/schema/attribute_kind_update.py +8 -11
  53. infrahub/core/migrations/schema/attribute_supports_profile.py +3 -8
  54. infrahub/core/migrations/schema/models.py +8 -0
  55. infrahub/core/migrations/schema/node_attribute_add.py +24 -29
  56. infrahub/core/migrations/schema/tasks.py +7 -1
  57. infrahub/core/migrations/shared.py +37 -30
  58. infrahub/core/node/__init__.py +2 -1
  59. infrahub/core/node/lock_utils.py +23 -2
  60. infrahub/core/node/resource_manager/ip_address_pool.py +5 -11
  61. infrahub/core/node/resource_manager/ip_prefix_pool.py +5 -21
  62. infrahub/core/node/resource_manager/number_pool.py +109 -39
  63. infrahub/core/query/__init__.py +7 -1
  64. infrahub/core/query/branch.py +18 -2
  65. infrahub/core/query/ipam.py +629 -40
  66. infrahub/core/query/node.py +128 -0
  67. infrahub/core/query/resource_manager.py +114 -1
  68. infrahub/core/relationship/model.py +9 -3
  69. infrahub/core/schema/attribute_parameters.py +28 -1
  70. infrahub/core/schema/attribute_schema.py +9 -2
  71. infrahub/core/schema/definitions/core/webhook.py +0 -1
  72. infrahub/core/schema/definitions/internal.py +7 -4
  73. infrahub/core/schema/manager.py +50 -38
  74. infrahub/core/validators/attribute/kind.py +5 -2
  75. infrahub/core/validators/determiner.py +4 -0
  76. infrahub/graphql/analyzer.py +3 -1
  77. infrahub/graphql/app.py +7 -10
  78. infrahub/graphql/execution.py +95 -0
  79. infrahub/graphql/manager.py +8 -2
  80. infrahub/graphql/mutations/proposed_change.py +15 -0
  81. infrahub/graphql/parser.py +10 -7
  82. infrahub/graphql/queries/ipam.py +20 -25
  83. infrahub/graphql/queries/search.py +29 -9
  84. infrahub/lock.py +7 -0
  85. infrahub/proposed_change/tasks.py +2 -0
  86. infrahub/services/adapters/cache/redis.py +7 -0
  87. infrahub/services/adapters/http/httpx.py +27 -0
  88. infrahub/trigger/catalogue.py +2 -0
  89. infrahub/trigger/models.py +73 -4
  90. infrahub/trigger/setup.py +1 -1
  91. infrahub/trigger/system.py +36 -0
  92. infrahub/webhook/models.py +4 -2
  93. infrahub/webhook/tasks.py +2 -2
  94. infrahub/workflows/initialization.py +2 -2
  95. infrahub_sdk/analyzer.py +2 -2
  96. infrahub_sdk/branch.py +12 -39
  97. infrahub_sdk/checks.py +4 -4
  98. infrahub_sdk/client.py +36 -0
  99. infrahub_sdk/ctl/cli_commands.py +2 -1
  100. infrahub_sdk/ctl/graphql.py +15 -4
  101. infrahub_sdk/ctl/utils.py +2 -2
  102. infrahub_sdk/enums.py +6 -0
  103. infrahub_sdk/graphql/renderers.py +21 -0
  104. infrahub_sdk/graphql/utils.py +85 -0
  105. infrahub_sdk/node/attribute.py +12 -2
  106. infrahub_sdk/node/constants.py +11 -0
  107. infrahub_sdk/node/metadata.py +69 -0
  108. infrahub_sdk/node/node.py +65 -14
  109. infrahub_sdk/node/property.py +3 -0
  110. infrahub_sdk/node/related_node.py +24 -1
  111. infrahub_sdk/node/relationship.py +10 -1
  112. infrahub_sdk/operation.py +2 -2
  113. infrahub_sdk/schema/repository.py +1 -2
  114. infrahub_sdk/transforms.py +2 -2
  115. infrahub_sdk/types.py +18 -2
  116. {infrahub_server-1.7.0rc0.dist-info → infrahub_server-1.7.2.dist-info}/METADATA +8 -8
  117. {infrahub_server-1.7.0rc0.dist-info → infrahub_server-1.7.2.dist-info}/RECORD +123 -114
  118. {infrahub_server-1.7.0rc0.dist-info → infrahub_server-1.7.2.dist-info}/entry_points.txt +0 -1
  119. infrahub_testcontainers/docker-compose-cluster.test.yml +16 -10
  120. infrahub_testcontainers/docker-compose.test.yml +11 -10
  121. infrahub_testcontainers/performance_test.py +1 -1
  122. infrahub/pools/address.py +0 -16
  123. {infrahub_server-1.7.0rc0.dist-info → infrahub_server-1.7.2.dist-info}/WHEEL +0 -0
  124. {infrahub_server-1.7.0rc0.dist-info → infrahub_server-1.7.2.dist-info}/licenses/LICENSE.txt +0 -0
@@ -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, db: InfrahubDatabase) -> MigrationResult:
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, db: InfrahubDatabase) -> MigrationResult:
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, db: InfrahubDatabase, branch: Branch) -> MigrationResult:
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 MigrationRequiringRebase, MigrationResult, get_migration_console
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, db: InfrahubDatabase) -> MigrationResult:
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(db=db, branch=default_branch)
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, db: InfrahubDatabase, branch: Branch) -> MigrationResult:
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(db=db, branch=branch)
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, db: InfrahubDatabase) -> MigrationResult:
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, db: InfrahubDatabase, branch: Branch) -> MigrationResult:
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, db: InfrahubDatabase) -> MigrationResult:
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, db: InfrahubDatabase, branch: Branch) -> MigrationResult:
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, db: InfrahubDatabase) -> MigrationResult:
137
+ async def execute(self, migration_input: MigrationInput) -> MigrationResult:
138
138
  try:
139
- return await self._do_execute(db=db)
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, db: InfrahubDatabase) -> MigrationResult:
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(db=db, branch=global_branch)
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 MigrationRequiringRebase, MigrationResult, get_migration_console
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, db: InfrahubDatabase) -> MigrationResult:
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, db: InfrahubDatabase, branch: Branch) -> MigrationResult:
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, db: InfrahubDatabase) -> MigrationResult:
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, db: InfrahubDatabase) -> MigrationResult:
53
- return await self.do_execute(db=db)
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, db: InfrahubDatabase) -> MigrationResult:
168
- return await self.do_execute(db=db)
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
@@ -0,0 +1,51 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING, Any, Sequence
4
+
5
+ from infrahub.core.constants import GLOBAL_BRANCH_NAME
6
+ from infrahub.core.migrations.shared import GraphMigration, MigrationInput, MigrationResult
7
+ from infrahub.core.query import Query, QueryType
8
+
9
+ if TYPE_CHECKING:
10
+ from infrahub.database import InfrahubDatabase
11
+
12
+
13
+ class FixGlobalBranchLevelQuery(Query):
14
+ """Update edges on the global branch to have branch_level = 1."""
15
+
16
+ name = "fix_global_branch_level"
17
+ type: QueryType = QueryType.WRITE
18
+ insert_return = False
19
+ raise_error_if_empty = False
20
+
21
+ async def query_init(self, db: InfrahubDatabase, **kwargs: dict[str, Any]) -> None: # noqa: ARG002
22
+ self.params["global_branch_name"] = GLOBAL_BRANCH_NAME
23
+
24
+ query = """
25
+ MATCH ()-[e {branch: $global_branch_name}]->()
26
+ WHERE e.branch_level <> 1
27
+ CALL (e) {
28
+ SET e.branch_level = 1
29
+ } IN TRANSACTIONS
30
+ """
31
+ self.add_to_query(query)
32
+
33
+
34
+ class Migration052(GraphMigration):
35
+ """
36
+ Fix edges on the global branch that have incorrect branch_level.
37
+
38
+ Edges on the global branch ("-global-") should always have branch_level = 1.
39
+ This migration corrects any edges that were incorrectly created with a different
40
+ branch_level value (e.g., branch_level = 2 when created from a user branch).
41
+ """
42
+
43
+ name: str = "052_fix_global_branch_level"
44
+ minimum_version: int = 51
45
+ queries: Sequence[type[Query]] = [FixGlobalBranchLevelQuery]
46
+
47
+ async def validate_migration(self, db: InfrahubDatabase) -> MigrationResult: # noqa: ARG002
48
+ return MigrationResult()
49
+
50
+ async def execute(self, migration_input: MigrationInput) -> MigrationResult:
51
+ return await self.do_execute(migration_input=migration_input)
@@ -0,0 +1,61 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING, Any, Sequence
4
+
5
+ from infrahub.core.constants import GLOBAL_BRANCH_NAME
6
+ from infrahub.core.migrations.shared import GraphMigration, MigrationInput, MigrationResult
7
+ from infrahub.core.query import Query, QueryType
8
+
9
+ if TYPE_CHECKING:
10
+ from infrahub.database import InfrahubDatabase
11
+
12
+
13
+ class FixBranchLevelZeroQuery(Query):
14
+ """Update edges with branch_level=0 to the correct branch_level.
15
+
16
+ Edges on the global branch or default branch should have branch_level=1.
17
+ Edges on other branches should have branch_level=2.
18
+ """
19
+
20
+ name = "fix_branch_level_zero"
21
+ type: QueryType = QueryType.WRITE
22
+ insert_return = False
23
+ raise_error_if_empty = False
24
+
25
+ async def query_init(self, db: InfrahubDatabase, **kwargs: dict[str, Any]) -> None: # noqa: ARG002
26
+ self.params["global_branch_name"] = GLOBAL_BRANCH_NAME
27
+
28
+ query = """
29
+ MATCH (branch_node:Branch {is_default: true})
30
+ WITH branch_node.name AS default_branch_name
31
+ MATCH ()-[e]->()
32
+ WHERE e.branch_level = 0
33
+ CALL (e, default_branch_name) {
34
+ SET e.branch_level = CASE
35
+ WHEN e.branch = $global_branch_name OR e.branch = default_branch_name THEN 1
36
+ ELSE 2
37
+ END
38
+ } IN TRANSACTIONS
39
+ """
40
+ self.add_to_query(query)
41
+
42
+
43
+ class Migration053(GraphMigration):
44
+ """
45
+ Fix edges with branch_level=0 to have the correct branch_level.
46
+
47
+ Edges with branch_level=0 indicate a bug where the branch level was not
48
+ properly set during creation. This migration fixes them:
49
+ - Edges on the global branch ("-global-") or default branch: branch_level=1
50
+ - Edges on other branches: branch_level=2
51
+ """
52
+
53
+ name: str = "053_fix_branch_level_zero"
54
+ minimum_version: int = 52
55
+ queries: Sequence[type[Query]] = [FixBranchLevelZeroQuery]
56
+
57
+ async def validate_migration(self, db: InfrahubDatabase) -> MigrationResult: # noqa: ARG002
58
+ return MigrationResult()
59
+
60
+ async def execute(self, migration_input: MigrationInput) -> MigrationResult:
61
+ return await self.do_execute(migration_input=migration_input)