infrahub-server 1.1.7__py3-none-any.whl → 1.2.0b1__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/artifact.py +16 -4
- infrahub/api/dependencies.py +8 -0
- infrahub/api/oauth2.py +0 -1
- infrahub/api/oidc.py +0 -1
- infrahub/api/query.py +18 -7
- infrahub/api/schema.py +32 -6
- infrahub/api/transformation.py +12 -5
- infrahub/{message_bus/messages/check_artifact_create.py → artifacts/models.py} +5 -3
- infrahub/{message_bus/operations/check/artifact.py → artifacts/tasks.py} +26 -25
- infrahub/cli/__init__.py +0 -2
- infrahub/cli/db.py +6 -7
- infrahub/cli/events.py +8 -3
- infrahub/cli/git_agent.py +9 -7
- infrahub/cli/tasks.py +4 -6
- infrahub/computed_attribute/models.py +1 -1
- infrahub/computed_attribute/tasks.py +64 -17
- infrahub/computed_attribute/triggers.py +90 -0
- infrahub/config.py +1 -1
- infrahub/context.py +39 -0
- infrahub/core/account.py +5 -8
- infrahub/core/attribute.py +50 -21
- infrahub/core/branch/models.py +4 -4
- infrahub/core/branch/tasks.py +130 -125
- infrahub/core/changelog/__init__.py +0 -0
- infrahub/core/changelog/diff.py +283 -0
- infrahub/core/changelog/models.py +499 -0
- infrahub/core/constants/__init__.py +43 -2
- infrahub/core/constants/infrahubkind.py +1 -0
- infrahub/core/constants/schema.py +2 -0
- infrahub/core/diff/combiner.py +1 -1
- infrahub/core/diff/enricher/cardinality_one.py +6 -1
- infrahub/core/diff/enricher/hierarchy.py +22 -7
- infrahub/core/diff/enricher/labels.py +6 -1
- infrahub/core/diff/enricher/path_identifier.py +5 -1
- infrahub/core/diff/enricher/summary_counts.py +107 -0
- infrahub/core/diff/merger/merger.py +3 -1
- infrahub/core/diff/model/path.py +34 -11
- infrahub/core/diff/parent_node_adder.py +78 -0
- infrahub/core/diff/payload_builder.py +13 -2
- infrahub/core/diff/query/all_conflicts.py +1 -1
- infrahub/core/diff/query/artifact.py +1 -1
- infrahub/core/diff/query/delete_query.py +1 -1
- infrahub/core/diff/query/diff_get.py +1 -1
- infrahub/core/diff/query/diff_summary.py +1 -1
- infrahub/core/diff/query/field_specifiers.py +1 -1
- infrahub/core/diff/query/field_summary.py +1 -1
- infrahub/core/diff/query/filters.py +2 -2
- infrahub/core/diff/query/get_conflict_query.py +1 -1
- infrahub/core/diff/query/has_conflicts_query.py +1 -1
- infrahub/core/diff/query/merge.py +3 -3
- infrahub/core/diff/query/merge_tracking_id.py +1 -1
- infrahub/core/diff/query/roots_metadata.py +1 -1
- infrahub/core/diff/query/save.py +191 -185
- infrahub/core/diff/query/summary_counts_enricher.py +52 -5
- infrahub/core/diff/query/time_range_query.py +1 -1
- infrahub/core/diff/query/update_conflict_query.py +1 -1
- infrahub/core/diff/repository/deserializer.py +9 -4
- infrahub/core/diff/repository/repository.py +156 -38
- infrahub/core/diff/tasks.py +13 -12
- infrahub/core/enums.py +1 -1
- infrahub/core/graph/__init__.py +1 -1
- infrahub/core/graph/index.py +3 -0
- infrahub/core/integrity/object_conflict/conflict_recorder.py +1 -1
- infrahub/core/ipam/reconciler.py +1 -1
- infrahub/core/ipam/tasks.py +2 -3
- infrahub/core/manager.py +20 -15
- infrahub/core/merge.py +5 -2
- infrahub/core/migrations/graph/__init__.py +4 -0
- infrahub/core/migrations/graph/m001_add_version_to_graph.py +1 -1
- infrahub/core/migrations/graph/m002_attribute_is_default.py +2 -2
- infrahub/core/migrations/graph/m003_relationship_parent_optional.py +2 -2
- infrahub/core/migrations/graph/m004_add_attr_documentation.py +1 -1
- infrahub/core/migrations/graph/m005_add_rel_read_only.py +1 -1
- infrahub/core/migrations/graph/m006_add_rel_on_delete.py +1 -1
- infrahub/core/migrations/graph/m007_add_rel_allow_override.py +1 -1
- infrahub/core/migrations/graph/m008_add_human_friendly_id.py +1 -1
- infrahub/core/migrations/graph/m009_add_generate_profile_attr.py +1 -1
- infrahub/core/migrations/graph/m010_add_generate_profile_attr_generic.py +1 -1
- infrahub/core/migrations/graph/m011_remove_profile_relationship_schema.py +2 -2
- infrahub/core/migrations/graph/m012_convert_account_generic.py +12 -23
- infrahub/core/migrations/graph/m013_convert_git_password_credential.py +7 -11
- infrahub/core/migrations/graph/m014_remove_index_attr_value.py +2 -2
- infrahub/core/migrations/graph/m015_diff_format_update.py +1 -1
- infrahub/core/migrations/graph/m016_diff_delete_bug_fix.py +1 -1
- infrahub/core/migrations/graph/m017_add_core_profile.py +1 -1
- infrahub/core/migrations/graph/m018_uniqueness_nulls.py +2 -2
- infrahub/core/migrations/graph/m019_restore_rels_to_time.py +256 -0
- infrahub/core/migrations/graph/m020_add_generate_template_attr.py +48 -0
- infrahub/core/migrations/query/attribute_add.py +1 -1
- infrahub/core/migrations/query/attribute_rename.py +1 -1
- infrahub/core/migrations/query/delete_element_in_schema.py +1 -1
- infrahub/core/migrations/query/node_duplicate.py +39 -19
- infrahub/core/migrations/query/relationship_duplicate.py +1 -1
- infrahub/core/migrations/query/schema_attribute_update.py +1 -1
- infrahub/core/migrations/schema/node_attribute_remove.py +1 -1
- infrahub/core/migrations/schema/node_remove.py +27 -13
- infrahub/core/migrations/schema/tasks.py +5 -5
- infrahub/core/migrations/shared.py +4 -4
- infrahub/core/models.py +7 -8
- infrahub/core/node/__init__.py +164 -45
- infrahub/core/node/base.py +1 -1
- infrahub/core/node/delete_validator.py +4 -4
- infrahub/core/node/ipam.py +7 -7
- infrahub/core/node/resource_manager/ip_prefix_pool.py +8 -5
- infrahub/core/node/standard.py +3 -5
- infrahub/core/property.py +1 -1
- infrahub/core/protocols.py +6 -0
- infrahub/core/protocols_base.py +4 -2
- infrahub/core/query/__init__.py +2 -5
- infrahub/core/query/attribute.py +9 -9
- infrahub/core/query/branch.py +5 -5
- infrahub/core/query/delete.py +1 -1
- infrahub/core/query/diff.py +4 -4
- infrahub/core/query/ipam.py +4 -4
- infrahub/core/query/node.py +11 -12
- infrahub/core/query/relationship.py +211 -25
- infrahub/core/query/resource_manager.py +10 -10
- infrahub/core/query/standard_node.py +6 -6
- infrahub/core/query/task.py +3 -3
- infrahub/core/query/task_log.py +1 -1
- infrahub/core/query/utils.py +5 -5
- infrahub/core/registry.py +0 -2
- infrahub/core/relationship/constraints/count.py +1 -1
- infrahub/core/relationship/constraints/peer_kind.py +1 -1
- infrahub/core/relationship/model.py +76 -38
- infrahub/core/schema/__init__.py +6 -4
- infrahub/core/schema/attribute_schema.py +8 -0
- infrahub/core/schema/basenode_schema.py +13 -3
- infrahub/core/schema/definitions/core/__init__.py +153 -0
- infrahub/core/schema/definitions/core/account.py +168 -0
- infrahub/core/schema/definitions/core/artifact.py +127 -0
- infrahub/core/schema/definitions/core/builtin.py +21 -0
- infrahub/core/schema/definitions/core/check.py +60 -0
- infrahub/core/schema/definitions/core/generator.py +96 -0
- infrahub/core/schema/definitions/core/graphql_query.py +77 -0
- infrahub/core/schema/definitions/core/group.py +105 -0
- infrahub/core/schema/definitions/core/ipam.py +252 -0
- infrahub/core/schema/definitions/core/lineage.py +17 -0
- infrahub/core/schema/definitions/core/menu.py +46 -0
- infrahub/core/schema/definitions/core/permission.py +161 -0
- infrahub/core/schema/definitions/core/profile.py +29 -0
- infrahub/core/schema/definitions/core/propose_change.py +88 -0
- infrahub/core/schema/definitions/core/propose_change_comment.py +188 -0
- infrahub/core/schema/definitions/core/propose_change_validator.py +326 -0
- infrahub/core/schema/definitions/core/repository.py +280 -0
- infrahub/core/schema/definitions/core/resource_pool.py +180 -0
- infrahub/core/schema/definitions/core/template.py +12 -0
- infrahub/core/schema/definitions/core/transform.py +87 -0
- infrahub/core/schema/definitions/core/webhook.py +108 -0
- infrahub/core/schema/definitions/internal.py +16 -0
- infrahub/core/schema/generated/genericnode_schema.py +5 -0
- infrahub/core/schema/generated/node_schema.py +5 -0
- infrahub/core/schema/generic_schema.py +5 -1
- infrahub/core/schema/manager.py +45 -42
- infrahub/core/schema/node_schema.py +4 -0
- infrahub/core/schema/profile_schema.py +4 -0
- infrahub/core/schema/relationship_schema.py +10 -2
- infrahub/core/schema/schema_branch.py +260 -16
- infrahub/core/schema/template_schema.py +36 -0
- infrahub/core/task/user_task.py +7 -5
- infrahub/core/timestamp.py +3 -3
- infrahub/core/utils.py +2 -2
- infrahub/core/validators/attribute/choices.py +1 -1
- infrahub/core/validators/attribute/enum.py +1 -1
- infrahub/core/validators/attribute/kind.py +1 -1
- infrahub/core/validators/attribute/length.py +1 -1
- infrahub/core/validators/attribute/optional.py +1 -1
- infrahub/core/validators/attribute/regex.py +1 -1
- infrahub/core/validators/attribute/unique.py +1 -1
- infrahub/core/validators/checks_runner.py +37 -0
- infrahub/core/validators/node/generate_profile.py +1 -1
- infrahub/core/validators/node/hierarchy.py +1 -1
- infrahub/core/validators/query.py +1 -1
- infrahub/core/validators/relationship/count.py +1 -1
- infrahub/core/validators/relationship/optional.py +1 -1
- infrahub/core/validators/relationship/peer.py +1 -1
- infrahub/core/validators/tasks.py +8 -6
- infrahub/core/validators/uniqueness/query.py +1 -1
- infrahub/database/__init__.py +3 -2
- infrahub/database/memgraph.py +1 -1
- infrahub/dependencies/builder/diff/combiner.py +1 -1
- infrahub/dependencies/builder/diff/conflicts_enricher.py +1 -1
- infrahub/dependencies/builder/diff/deserializer.py +4 -2
- infrahub/dependencies/builder/diff/enricher/hierarchy.py +3 -1
- infrahub/dependencies/builder/diff/enricher/summary_counts.py +8 -0
- infrahub/dependencies/builder/diff/parent_node_adder.py +8 -0
- infrahub/events/artifact_action.py +76 -0
- infrahub/events/branch_action.py +50 -21
- infrahub/events/group_action.py +117 -0
- infrahub/events/models.py +164 -51
- infrahub/events/node_action.py +70 -8
- infrahub/events/repository_action.py +8 -8
- infrahub/events/schema_action.py +21 -8
- infrahub/exceptions.py +9 -0
- infrahub/generators/models.py +1 -0
- infrahub/generators/tasks.py +34 -15
- infrahub/git/base.py +3 -5
- infrahub/git/constants.py +0 -1
- infrahub/git/integrator.py +60 -36
- infrahub/git/models.py +80 -1
- infrahub/git/repository.py +7 -8
- infrahub/git/tasks.py +432 -112
- infrahub/git_credential/helper.py +2 -3
- infrahub/graphql/analyzer.py +572 -11
- infrahub/graphql/app.py +34 -26
- infrahub/graphql/auth/query_permission_checker/anonymous_checker.py +5 -5
- infrahub/graphql/auth/query_permission_checker/default_branch_checker.py +4 -4
- infrahub/graphql/auth/query_permission_checker/merge_operation_checker.py +4 -4
- infrahub/graphql/auth/query_permission_checker/object_permission_checker.py +28 -35
- infrahub/graphql/auth/query_permission_checker/super_admin_checker.py +5 -5
- infrahub/graphql/context.py +33 -0
- infrahub/graphql/enums.py +1 -1
- infrahub/graphql/initialization.py +5 -1
- infrahub/graphql/loaders/node.py +2 -2
- infrahub/graphql/manager.py +63 -63
- infrahub/graphql/mutations/account.py +20 -13
- infrahub/graphql/mutations/artifact_definition.py +16 -12
- infrahub/graphql/mutations/branch.py +86 -40
- infrahub/graphql/mutations/computed_attribute.py +24 -15
- infrahub/graphql/mutations/diff.py +33 -17
- infrahub/graphql/mutations/diff_conflict.py +14 -8
- infrahub/graphql/mutations/generator.py +83 -0
- infrahub/graphql/mutations/graphql_query.py +19 -11
- infrahub/graphql/mutations/ipam.py +25 -23
- infrahub/graphql/mutations/main.py +233 -45
- infrahub/graphql/mutations/menu.py +10 -10
- infrahub/graphql/mutations/proposed_change.py +36 -28
- infrahub/graphql/mutations/relationship.py +341 -130
- infrahub/graphql/mutations/repository.py +41 -35
- infrahub/graphql/mutations/resource_manager.py +26 -26
- infrahub/graphql/mutations/schema.py +66 -33
- infrahub/graphql/mutations/tasks.py +10 -7
- infrahub/graphql/parser.py +1 -1
- infrahub/graphql/permissions.py +3 -10
- infrahub/graphql/queries/account.py +22 -18
- infrahub/graphql/queries/branch.py +6 -4
- infrahub/graphql/queries/diff/tree.py +63 -52
- infrahub/graphql/queries/event.py +115 -0
- infrahub/graphql/queries/internal.py +3 -3
- infrahub/graphql/queries/ipam.py +23 -18
- infrahub/graphql/queries/relationship.py +11 -10
- infrahub/graphql/queries/resource_manager.py +37 -25
- infrahub/graphql/queries/search.py +9 -8
- infrahub/graphql/queries/status.py +12 -9
- infrahub/graphql/queries/task.py +11 -9
- infrahub/graphql/resolvers/resolver.py +69 -43
- infrahub/graphql/resolvers/single_relationship.py +16 -10
- infrahub/graphql/schema.py +4 -0
- infrahub/graphql/subscription/__init__.py +1 -1
- infrahub/graphql/subscription/events.py +1 -1
- infrahub/graphql/subscription/graphql_query.py +8 -8
- infrahub/graphql/types/branch.py +2 -2
- infrahub/graphql/types/common.py +6 -1
- infrahub/graphql/types/context.py +12 -0
- infrahub/graphql/types/enums.py +2 -0
- infrahub/graphql/types/event.py +158 -0
- infrahub/graphql/types/interface.py +2 -2
- infrahub/graphql/types/node.py +3 -3
- infrahub/graphql/types/permission.py +2 -2
- infrahub/graphql/types/relationship.py +3 -3
- infrahub/graphql/types/standard_node.py +9 -11
- infrahub/graphql/utils.py +28 -182
- infrahub/groups/tasks.py +2 -3
- infrahub/lock.py +21 -21
- infrahub/menu/generator.py +0 -1
- infrahub/menu/menu.py +116 -138
- infrahub/menu/models.py +4 -4
- infrahub/message_bus/__init__.py +11 -13
- infrahub/message_bus/messages/__init__.py +0 -14
- infrahub/message_bus/messages/check_generator_run.py +1 -3
- infrahub/message_bus/messages/event_branch_merge.py +3 -0
- infrahub/message_bus/messages/proposed_change/request_proposedchange_refreshartifacts.py +6 -0
- infrahub/message_bus/messages/request_proposedchange_pipeline.py +2 -0
- infrahub/message_bus/messages/send_echo_request.py +1 -1
- infrahub/message_bus/operations/__init__.py +4 -13
- infrahub/message_bus/operations/check/__init__.py +2 -2
- infrahub/message_bus/operations/check/generator.py +1 -3
- infrahub/message_bus/operations/event/branch.py +7 -3
- infrahub/message_bus/operations/event/schema.py +1 -1
- infrahub/message_bus/operations/event/worker.py +0 -3
- infrahub/message_bus/operations/finalize/validator.py +1 -1
- infrahub/message_bus/operations/git/file.py +2 -2
- infrahub/message_bus/operations/git/repository.py +1 -1
- infrahub/message_bus/operations/requests/__init__.py +0 -4
- infrahub/message_bus/operations/requests/generator_definition.py +2 -4
- infrahub/message_bus/operations/requests/proposed_change.py +37 -20
- infrahub/message_bus/operations/send/echo.py +1 -1
- infrahub/message_bus/types.py +1 -1
- infrahub/permissions/globals.py +15 -0
- infrahub/pools/prefix.py +29 -165
- infrahub/prefect_server/__init__.py +0 -0
- infrahub/prefect_server/app.py +18 -0
- infrahub/prefect_server/database.py +20 -0
- infrahub/prefect_server/events.py +28 -0
- infrahub/prefect_server/models.py +46 -0
- infrahub/proposed_change/models.py +18 -1
- infrahub/proposed_change/tasks.py +195 -53
- infrahub/pytest_plugin.py +4 -4
- infrahub/server.py +13 -12
- infrahub/services/__init__.py +148 -63
- infrahub/services/adapters/cache/__init__.py +11 -11
- infrahub/services/adapters/cache/nats.py +42 -25
- infrahub/services/adapters/cache/redis.py +3 -11
- infrahub/services/adapters/event/__init__.py +10 -18
- infrahub/services/adapters/http/__init__.py +0 -5
- infrahub/services/adapters/http/httpx.py +22 -15
- infrahub/services/adapters/message_bus/__init__.py +25 -8
- infrahub/services/adapters/message_bus/local.py +9 -7
- infrahub/services/adapters/message_bus/nats.py +14 -8
- infrahub/services/adapters/message_bus/rabbitmq.py +23 -10
- infrahub/services/adapters/workflow/__init__.py +11 -8
- infrahub/services/adapters/workflow/local.py +27 -6
- infrahub/services/adapters/workflow/worker.py +23 -7
- infrahub/services/component.py +43 -40
- infrahub/services/protocols.py +7 -7
- infrahub/services/scheduler.py +30 -29
- infrahub/storage.py +2 -4
- infrahub/task_manager/constants.py +1 -1
- infrahub/task_manager/event.py +261 -0
- infrahub/task_manager/models.py +147 -3
- infrahub/task_manager/task.py +1 -1
- infrahub/tasks/artifact.py +19 -18
- infrahub/tasks/registry.py +1 -1
- infrahub/tasks/telemetry.py +13 -14
- infrahub/transformations/tasks.py +3 -5
- infrahub/trigger/__init__.py +0 -0
- infrahub/trigger/catalogue.py +16 -0
- infrahub/trigger/constants.py +9 -0
- infrahub/trigger/models.py +105 -0
- infrahub/trigger/tasks.py +91 -0
- infrahub/types.py +1 -1
- infrahub/utils.py +1 -1
- infrahub/webhook/constants.py +0 -2
- infrahub/webhook/models.py +161 -40
- infrahub/webhook/tasks.py +123 -202
- infrahub/webhook/triggers.py +27 -0
- infrahub/workers/infrahub_async.py +36 -25
- infrahub/workers/utils.py +63 -0
- infrahub/workflows/catalogue.py +71 -52
- infrahub/workflows/initialization.py +14 -8
- infrahub/workflows/models.py +28 -4
- infrahub/workflows/utils.py +1 -1
- infrahub_sdk/batch.py +2 -2
- infrahub_sdk/client.py +8 -0
- infrahub_sdk/config.py +1 -1
- infrahub_sdk/ctl/branch.py +3 -2
- infrahub_sdk/ctl/check.py +4 -4
- infrahub_sdk/ctl/cli_commands.py +16 -11
- infrahub_sdk/ctl/exceptions.py +0 -6
- infrahub_sdk/ctl/exporter.py +1 -1
- infrahub_sdk/ctl/generator.py +5 -5
- infrahub_sdk/ctl/importer.py +3 -2
- infrahub_sdk/ctl/menu.py +1 -1
- infrahub_sdk/ctl/object.py +1 -1
- infrahub_sdk/ctl/repository.py +23 -15
- infrahub_sdk/ctl/schema.py +2 -2
- infrahub_sdk/ctl/utils.py +6 -21
- infrahub_sdk/ctl/validate.py +2 -1
- infrahub_sdk/data.py +1 -1
- infrahub_sdk/exceptions.py +12 -0
- infrahub_sdk/generator.py +3 -0
- infrahub_sdk/node.py +5 -8
- infrahub_sdk/protocols.py +20 -8
- infrahub_sdk/schema/__init__.py +14 -5
- infrahub_sdk/schema/main.py +7 -0
- infrahub_sdk/task/__init__.py +1 -0
- infrahub_sdk/task/constants.py +3 -0
- infrahub_sdk/task/exceptions.py +25 -0
- infrahub_sdk/task/manager.py +545 -0
- infrahub_sdk/task/models.py +74 -0
- infrahub_sdk/testing/docker.py +30 -0
- infrahub_sdk/timestamp.py +134 -33
- infrahub_sdk/transfer/exporter/json.py +1 -1
- infrahub_sdk/utils.py +39 -1
- infrahub_sdk/yaml.py +2 -3
- {infrahub_server-1.1.7.dist-info → infrahub_server-1.2.0b1.dist-info}/METADATA +7 -6
- {infrahub_server-1.1.7.dist-info → infrahub_server-1.2.0b1.dist-info}/RECORD +383 -339
- infrahub_testcontainers/container.py +2 -3
- infrahub_testcontainers/docker-compose.test.yml +2 -2
- infrahub/core/branch/constants.py +0 -2
- infrahub/core/schema/definitions/core.py +0 -2274
- infrahub/graphql/query.py +0 -52
- infrahub/message_bus/messages/check_repository_checkdefinition.py +0 -20
- infrahub/message_bus/messages/check_repository_mergeconflicts.py +0 -16
- infrahub/message_bus/messages/check_repository_usercheck.py +0 -26
- infrahub/message_bus/messages/request_artifactdefinition_check.py +0 -17
- infrahub/message_bus/messages/request_repository_checks.py +0 -12
- infrahub/message_bus/messages/request_repository_userchecks.py +0 -18
- infrahub/message_bus/operations/check/repository.py +0 -293
- infrahub/message_bus/operations/requests/artifact_definition.py +0 -148
- infrahub/message_bus/operations/requests/repository.py +0 -133
- infrahub/schema/constants.py +0 -1
- infrahub/schema/tasks.py +0 -76
- infrahub/services/adapters/database/__init__.py +0 -9
- infrahub_sdk/ctl/_file.py +0 -13
- /infrahub/{schema → artifacts}/__init__.py +0 -0
- {infrahub_server-1.1.7.dist-info → infrahub_server-1.2.0b1.dist-info}/LICENSE.txt +0 -0
- {infrahub_server-1.1.7.dist-info → infrahub_server-1.2.0b1.dist-info}/WHEEL +0 -0
- {infrahub_server-1.1.7.dist-info → infrahub_server-1.2.0b1.dist-info}/entry_points.txt +0 -0
|
@@ -28,7 +28,7 @@ class DiffMergeQuery(Query):
|
|
|
28
28
|
self.target_branch = target_branch
|
|
29
29
|
self.source_branch_name = self.branch.name
|
|
30
30
|
|
|
31
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None:
|
|
31
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa: ARG002
|
|
32
32
|
self.params = {
|
|
33
33
|
"node_diff_dicts": self.node_diff_dicts,
|
|
34
34
|
"at": self.at.to_string(),
|
|
@@ -339,7 +339,7 @@ class DiffMergePropertiesQuery(Query):
|
|
|
339
339
|
self.target_branch = target_branch
|
|
340
340
|
self.source_branch_name = self.branch.name
|
|
341
341
|
|
|
342
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None:
|
|
342
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa: ARG002
|
|
343
343
|
self.params = {
|
|
344
344
|
"property_diff_dicts": self.property_diff_dicts,
|
|
345
345
|
"at": self.at.to_string(),
|
|
@@ -514,7 +514,7 @@ class DiffMergeRollbackQuery(Query):
|
|
|
514
514
|
self.target_branch = target_branch
|
|
515
515
|
self.source_branch_name = self.branch.name
|
|
516
516
|
|
|
517
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None:
|
|
517
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa: ARG002
|
|
518
518
|
self.params = {
|
|
519
519
|
"at": self.at.to_string(),
|
|
520
520
|
"target_branch": self.target_branch.name,
|
|
@@ -15,7 +15,7 @@ class EnrichedDiffMergedTrackingIdQuery(Query):
|
|
|
15
15
|
super().__init__(**kwargs)
|
|
16
16
|
self.tracking_ids = tracking_ids
|
|
17
17
|
|
|
18
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None:
|
|
18
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa: ARG002
|
|
19
19
|
self.params = {"tracking_ids": [t_id.serialize() for t_id in self.tracking_ids]}
|
|
20
20
|
query = """
|
|
21
21
|
MATCH (d_root:DiffRoot)
|
|
@@ -29,7 +29,7 @@ class EnrichedDiffRootsMetadataQuery(Query):
|
|
|
29
29
|
self.to_time = to_time
|
|
30
30
|
self.tracking_id = tracking_id
|
|
31
31
|
|
|
32
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None:
|
|
32
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa: ARG002
|
|
33
33
|
self.params = {
|
|
34
34
|
"diff_branch_names": self.diff_branch_names,
|
|
35
35
|
"base_branch_names": self.base_branch_names,
|
infrahub/core/diff/query/save.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import Any
|
|
1
|
+
from typing import Any, Iterable
|
|
2
2
|
|
|
3
3
|
from infrahub.core.query import Query, QueryType
|
|
4
4
|
from infrahub.database import InfrahubDatabase
|
|
@@ -25,7 +25,7 @@ class EnrichedDiffRootsUpsertQuery(Query):
|
|
|
25
25
|
super().__init__(**kwargs)
|
|
26
26
|
self.enriched_diffs = enriched_diffs
|
|
27
27
|
|
|
28
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None:
|
|
28
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa: ARG002
|
|
29
29
|
self.params = self._build_diff_root_params(enriched_diffs=self.enriched_diffs)
|
|
30
30
|
query = """
|
|
31
31
|
UNWIND $diff_root_list AS diff_root_map
|
|
@@ -42,6 +42,7 @@ CALL {
|
|
|
42
42
|
}
|
|
43
43
|
WITH DISTINCT diff_root AS diff_root
|
|
44
44
|
WITH collect(diff_root) AS diff_roots
|
|
45
|
+
WHERE SIZE(diff_roots) = 2
|
|
45
46
|
CALL {
|
|
46
47
|
WITH diff_roots
|
|
47
48
|
WITH diff_roots[0] AS base_diff_node, diff_roots[1] AS branch_diff_node
|
|
@@ -77,38 +78,63 @@ class EnrichedNodeBatchCreateQuery(Query):
|
|
|
77
78
|
super().__init__(**kwargs)
|
|
78
79
|
self.node_create_batch = node_create_batch
|
|
79
80
|
|
|
80
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None:
|
|
81
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa: ARG002
|
|
81
82
|
self.params = self._build_node_batch_params()
|
|
82
83
|
query = """
|
|
83
84
|
UNWIND $node_details_list AS node_details
|
|
84
|
-
WITH
|
|
85
|
+
WITH
|
|
86
|
+
node_details.root_uuid AS root_uuid,
|
|
87
|
+
node_details.node_map AS node_map,
|
|
88
|
+
toString(node_details.node_map.node_properties.uuid) AS node_uuid
|
|
89
|
+
MERGE (diff_root:DiffRoot {uuid: root_uuid})
|
|
90
|
+
MERGE (diff_root)-[:DIFF_HAS_NODE]->(diff_node:DiffNode {uuid: node_uuid})
|
|
91
|
+
WITH root_uuid, node_map, diff_node, (node_map.conflict_params IS NOT NULL) AS has_node_conflict
|
|
92
|
+
SET
|
|
93
|
+
diff_node.kind = node_map.node_properties.kind,
|
|
94
|
+
diff_node.label = node_map.node_properties.label,
|
|
95
|
+
diff_node.changed_at = node_map.node_properties.changed_at,
|
|
96
|
+
diff_node.action = node_map.node_properties.action,
|
|
97
|
+
diff_node.path_identifier = node_map.node_properties.path_identifier
|
|
98
|
+
WITH root_uuid, node_map, diff_node, has_node_conflict
|
|
85
99
|
CALL {
|
|
86
|
-
WITH root_uuid, node_map
|
|
87
|
-
MATCH (diff_root {uuid: root_uuid})
|
|
88
|
-
MERGE (diff_root)-[:DIFF_HAS_NODE]->(diff_node:DiffNode {uuid: node_map.node_properties.uuid})
|
|
89
|
-
SET
|
|
90
|
-
diff_node.kind = node_map.node_properties.kind,
|
|
91
|
-
diff_node.label = node_map.node_properties.label,
|
|
92
|
-
diff_node.changed_at = node_map.node_properties.changed_at,
|
|
93
|
-
diff_node.action = node_map.node_properties.action,
|
|
94
|
-
diff_node.path_identifier = node_map.node_properties.path_identifier
|
|
95
100
|
// -------------------------
|
|
96
|
-
//
|
|
101
|
+
// delete parent-child relationships for included nodes, they will be added in EnrichedNodesLinkQuery
|
|
97
102
|
// -------------------------
|
|
98
|
-
WITH diff_node
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
103
|
+
WITH diff_node
|
|
104
|
+
MATCH (diff_node)-[:DIFF_HAS_RELATIONSHIP]->(:DiffRelationship)-[parent_rel:DIFF_HAS_NODE]->(:DiffNode)
|
|
105
|
+
DELETE parent_rel
|
|
106
|
+
}
|
|
107
|
+
OPTIONAL MATCH (diff_node)-[:DIFF_HAS_CONFLICT]->(current_node_conflict:DiffConflict)
|
|
108
|
+
CALL {
|
|
109
|
+
// -------------------------
|
|
110
|
+
// create a node-level conflict, if necessary
|
|
111
|
+
// -------------------------
|
|
112
|
+
WITH diff_node, current_node_conflict, has_node_conflict
|
|
113
|
+
WITH diff_node, current_node_conflict, has_node_conflict
|
|
114
|
+
WHERE current_node_conflict IS NULL AND has_node_conflict = TRUE
|
|
115
|
+
CREATE (diff_node)-[:DIFF_HAS_CONFLICT]->(:DiffConflict)
|
|
116
|
+
}
|
|
117
|
+
CALL {
|
|
118
|
+
// -------------------------
|
|
119
|
+
// delete a node-level conflict, if necessary
|
|
120
|
+
// -------------------------
|
|
121
|
+
WITH current_node_conflict, has_node_conflict
|
|
122
|
+
WITH current_node_conflict, has_node_conflict
|
|
123
|
+
WHERE current_node_conflict IS NOT NULL AND has_node_conflict = FALSE
|
|
124
|
+
DETACH DELETE current_node_conflict
|
|
125
|
+
}
|
|
126
|
+
WITH root_uuid, node_map, diff_node, has_node_conflict, node_map.conflict_params AS node_conflict_params
|
|
127
|
+
CALL {
|
|
128
|
+
// -------------------------
|
|
129
|
+
// set the properties of the node-level conflict, if necessary
|
|
130
|
+
// -------------------------
|
|
131
|
+
WITH diff_node, has_node_conflict, node_conflict_params
|
|
132
|
+
WITH diff_node, has_node_conflict, node_conflict_params
|
|
133
|
+
WHERE has_node_conflict = TRUE
|
|
134
|
+
OPTIONAL MATCH (diff_node)-[:DIFF_HAS_CONFLICT]->(node_conflict:DiffConflict)
|
|
135
|
+
SET node_conflict = node_conflict_params
|
|
108
136
|
}
|
|
109
137
|
CALL {
|
|
110
|
-
WITH root_uuid, node_map
|
|
111
|
-
MATCH (diff_root {uuid: root_uuid})-[:DIFF_HAS_NODE]->(diff_node:DiffNode {uuid: node_map.node_properties.uuid})
|
|
112
138
|
// -------------------------
|
|
113
139
|
// remove stale attributes for this node
|
|
114
140
|
// -------------------------
|
|
@@ -125,138 +151,131 @@ CALL {
|
|
|
125
151
|
// -------------------------
|
|
126
152
|
// add attributes for this node
|
|
127
153
|
// -------------------------
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
MERGE (diff_node)-[:DIFF_HAS_ATTRIBUTE]->(diff_attribute:DiffAttribute {name: node_attribute.node_properties.name})
|
|
132
|
-
SET diff_attribute = node_attribute.node_properties
|
|
133
|
-
// -------------------------
|
|
134
|
-
// add properties for this attribute
|
|
135
|
-
// -------------------------
|
|
136
|
-
WITH diff_attribute, node_attribute
|
|
137
|
-
// -------------------------
|
|
138
|
-
// remove stale properties for this attribute
|
|
139
|
-
// -------------------------
|
|
140
|
-
CALL {
|
|
141
|
-
WITH diff_attribute, node_attribute
|
|
142
|
-
WITH diff_attribute, %(attr_props_list_comp)s AS prop_types
|
|
143
|
-
OPTIONAL MATCH (diff_attribute)-[:DIFF_HAS_PROPERTY]->(prop_to_delete:DiffProperty)
|
|
144
|
-
WHERE NOT (prop_to_delete.property_type IN prop_types)
|
|
145
|
-
OPTIONAL MATCH (prop_to_delete)-[*..4]->(next_to_delete)
|
|
146
|
-
DETACH DELETE next_to_delete
|
|
147
|
-
DETACH DELETE prop_to_delete
|
|
148
|
-
}
|
|
149
|
-
UNWIND node_attribute.properties AS attr_property
|
|
150
|
-
MERGE (diff_attribute)-[:DIFF_HAS_PROPERTY]->(diff_attr_prop:DiffProperty {property_type: attr_property.node_properties.property_type})
|
|
151
|
-
SET diff_attr_prop = attr_property.node_properties
|
|
152
|
-
// -------------------------
|
|
153
|
-
// add/remove conflict for this property
|
|
154
|
-
// -------------------------
|
|
155
|
-
WITH diff_attr_prop, attr_property
|
|
156
|
-
OPTIONAL MATCH (diff_attr_prop)-[:DIFF_HAS_CONFLICT]->(current_attr_prop_conflict:DiffConflict)
|
|
157
|
-
WITH diff_attr_prop, attr_property, current_attr_prop_conflict, (attr_property.conflict_params IS NOT NULL) AS has_prop_conflict
|
|
158
|
-
FOREACH (i in CASE WHEN has_prop_conflict = FALSE THEN [1] ELSE [] END |
|
|
159
|
-
DETACH DELETE current_attr_prop_conflict
|
|
160
|
-
)
|
|
161
|
-
FOREACH (i in CASE WHEN has_prop_conflict = TRUE THEN [1] ELSE [] END |
|
|
162
|
-
MERGE (diff_attr_prop)-[:DIFF_HAS_CONFLICT]->(diff_attr_prop_conflict:DiffConflict)
|
|
163
|
-
SET diff_attr_prop_conflict = attr_property.conflict_params
|
|
164
|
-
)
|
|
165
|
-
}
|
|
154
|
+
UNWIND node_map.attributes AS node_attribute
|
|
155
|
+
MERGE (diff_node)-[:DIFF_HAS_ATTRIBUTE]->(diff_attribute:DiffAttribute {name: node_attribute.node_properties.name})
|
|
156
|
+
SET diff_attribute = node_attribute.node_properties
|
|
166
157
|
// -------------------------
|
|
167
|
-
//
|
|
158
|
+
// add properties for this attribute
|
|
159
|
+
// -------------------------
|
|
160
|
+
WITH diff_attribute, node_attribute
|
|
161
|
+
// -------------------------
|
|
162
|
+
// remove stale properties for this attribute
|
|
168
163
|
// -------------------------
|
|
169
|
-
WITH diff_node, node_map
|
|
170
164
|
CALL {
|
|
171
|
-
WITH
|
|
172
|
-
WITH
|
|
173
|
-
OPTIONAL MATCH (
|
|
174
|
-
WHERE NOT (
|
|
175
|
-
OPTIONAL MATCH (
|
|
165
|
+
WITH diff_attribute, node_attribute
|
|
166
|
+
WITH diff_attribute, %(attr_props_list_comp)s AS prop_types
|
|
167
|
+
OPTIONAL MATCH (diff_attribute)-[:DIFF_HAS_PROPERTY]->(prop_to_delete:DiffProperty)
|
|
168
|
+
WHERE NOT (prop_to_delete.property_type IN prop_types)
|
|
169
|
+
OPTIONAL MATCH (prop_to_delete)-[*..4]->(next_to_delete)
|
|
176
170
|
DETACH DELETE next_to_delete
|
|
177
|
-
DETACH DELETE
|
|
171
|
+
DETACH DELETE prop_to_delete
|
|
178
172
|
}
|
|
173
|
+
UNWIND node_attribute.properties AS attr_property
|
|
174
|
+
MERGE (diff_attribute)-[:DIFF_HAS_PROPERTY]->(diff_attr_prop:DiffProperty {property_type: attr_property.node_properties.property_type})
|
|
175
|
+
SET diff_attr_prop = attr_property.node_properties
|
|
179
176
|
// -------------------------
|
|
180
|
-
// add
|
|
177
|
+
// add/remove conflict for this property
|
|
181
178
|
// -------------------------
|
|
179
|
+
WITH diff_attr_prop, attr_property
|
|
180
|
+
OPTIONAL MATCH (diff_attr_prop)-[:DIFF_HAS_CONFLICT]->(current_attr_prop_conflict:DiffConflict)
|
|
181
|
+
WITH diff_attr_prop, attr_property, current_attr_prop_conflict, (attr_property.conflict_params IS NOT NULL) AS has_prop_conflict
|
|
182
|
+
FOREACH (i in CASE WHEN has_prop_conflict = FALSE THEN [1] ELSE [] END |
|
|
183
|
+
DETACH DELETE current_attr_prop_conflict
|
|
184
|
+
)
|
|
185
|
+
FOREACH (i in CASE WHEN has_prop_conflict = TRUE THEN [1] ELSE [] END |
|
|
186
|
+
MERGE (diff_attr_prop)-[:DIFF_HAS_CONFLICT]->(diff_attr_prop_conflict:DiffConflict)
|
|
187
|
+
SET diff_attr_prop_conflict = attr_property.conflict_params
|
|
188
|
+
)
|
|
189
|
+
}
|
|
190
|
+
// -------------------------
|
|
191
|
+
// remove stale relationships for this node
|
|
192
|
+
// -------------------------
|
|
193
|
+
CALL {
|
|
182
194
|
WITH diff_node, node_map
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
// remove stale elements for this relationship group
|
|
190
|
-
// -------------------------
|
|
191
|
-
WITH diff_relationship, node_relationship
|
|
192
|
-
CALL {
|
|
193
|
-
WITH diff_relationship, node_relationship
|
|
194
|
-
WITH diff_relationship, %(rel_peers_list_comp)s AS rel_peers
|
|
195
|
-
OPTIONAL MATCH (diff_relationship)-[:DIFF_HAS_ELEMENT]->(element_to_delete:DiffRelationshipElement)
|
|
196
|
-
WHERE NOT (element_to_delete.peer_id IN rel_peers)
|
|
197
|
-
OPTIONAL MATCH (element_to_delete)-[*..6]->(next_to_delete)
|
|
198
|
-
DETACH DELETE next_to_delete
|
|
199
|
-
DETACH DELETE element_to_delete
|
|
200
|
-
}
|
|
201
|
-
// -------------------------
|
|
202
|
-
// add elements for this relationship group
|
|
203
|
-
// -------------------------
|
|
204
|
-
WITH diff_relationship, node_relationship
|
|
205
|
-
UNWIND node_relationship.relationships as node_single_relationship
|
|
206
|
-
MERGE (diff_relationship)-[:DIFF_HAS_ELEMENT]
|
|
207
|
-
->(diff_relationship_element:DiffRelationshipElement {peer_id: node_single_relationship.node_properties.peer_id})
|
|
208
|
-
SET diff_relationship_element = node_single_relationship.node_properties
|
|
209
|
-
// -------------------------
|
|
210
|
-
// add/remove conflict for this relationship element
|
|
211
|
-
// -------------------------
|
|
212
|
-
WITH diff_relationship_element, node_single_relationship
|
|
213
|
-
OPTIONAL MATCH (diff_relationship_element)-[:DIFF_HAS_CONFLICT]->(current_element_conflict:DiffConflict)
|
|
214
|
-
WITH diff_relationship_element, node_single_relationship, current_element_conflict,
|
|
215
|
-
(node_single_relationship.conflict_params IS NOT NULL) AS has_element_conflict
|
|
216
|
-
FOREACH (i in CASE WHEN has_element_conflict = FALSE THEN [1] ELSE [] END |
|
|
217
|
-
DETACH DELETE current_element_conflict
|
|
218
|
-
)
|
|
219
|
-
FOREACH (i in CASE WHEN has_element_conflict = TRUE THEN [1] ELSE [] END |
|
|
220
|
-
MERGE (diff_relationship_element)-[:DIFF_HAS_CONFLICT]->(element_conflict:DiffConflict)
|
|
221
|
-
SET element_conflict = node_single_relationship.conflict_params
|
|
222
|
-
)
|
|
223
|
-
// -------------------------
|
|
224
|
-
// remove stale properties for this relationship element
|
|
225
|
-
// -------------------------
|
|
226
|
-
WITH diff_relationship_element, node_single_relationship
|
|
227
|
-
CALL {
|
|
228
|
-
WITH diff_relationship_element, node_single_relationship
|
|
229
|
-
WITH diff_relationship_element, %(element_props_list_comp)s AS element_props
|
|
230
|
-
OPTIONAL MATCH (diff_relationship_element)-[:DIFF_HAS_PROPERTY]->(property_to_delete:DiffProperty)
|
|
231
|
-
WHERE NOT (property_to_delete.property_type IN element_props)
|
|
232
|
-
OPTIONAL MATCH (property_to_delete)-[*..4]->(next_to_delete)
|
|
233
|
-
DETACH DELETE next_to_delete
|
|
234
|
-
DETACH DELETE property_to_delete
|
|
235
|
-
}
|
|
236
|
-
// -------------------------
|
|
237
|
-
// add properties for this relationship element
|
|
238
|
-
// -------------------------
|
|
239
|
-
WITH diff_relationship_element, node_single_relationship
|
|
240
|
-
UNWIND node_single_relationship.properties as node_relationship_property
|
|
241
|
-
MERGE (diff_relationship_element)-[:DIFF_HAS_PROPERTY]
|
|
242
|
-
->(diff_relationship_property:DiffProperty {property_type: node_relationship_property.node_properties.property_type})
|
|
243
|
-
SET diff_relationship_property = node_relationship_property.node_properties
|
|
244
|
-
// -------------------------
|
|
245
|
-
// add conflict for this relationship element
|
|
246
|
-
// -------------------------
|
|
247
|
-
WITH diff_relationship_property, node_relationship_property
|
|
248
|
-
OPTIONAL MATCH (diff_relationship_property)-[:DIFF_HAS_CONFLICT]->(diff_relationship_property_conflict:DiffConflict)
|
|
249
|
-
WITH diff_relationship_property, node_relationship_property, diff_relationship_property_conflict,
|
|
250
|
-
(node_relationship_property.conflict_params IS NOT NULL) AS has_property_conflict
|
|
251
|
-
FOREACH (i in CASE WHEN has_property_conflict = FALSE THEN [1] ELSE [] END |
|
|
252
|
-
DETACH DELETE diff_relationship_property_conflict
|
|
253
|
-
)
|
|
254
|
-
FOREACH (i in CASE WHEN has_property_conflict = TRUE THEN [1] ELSE [] END |
|
|
255
|
-
MERGE (diff_relationship_property)-[:DIFF_HAS_CONFLICT]->(property_conflict:DiffConflict)
|
|
256
|
-
SET property_conflict = node_relationship_property.conflict_params
|
|
257
|
-
)
|
|
258
|
-
}
|
|
195
|
+
WITH diff_node, %(rel_name_list_comp)s AS rel_names
|
|
196
|
+
OPTIONAL MATCH (diff_node)-[:DIFF_HAS_RELATIONSHIP]->(rel_to_delete:DiffRelationship)
|
|
197
|
+
WHERE NOT (rel_to_delete.name IN rel_names)
|
|
198
|
+
OPTIONAL MATCH (rel_to_delete)-[*..8]->(next_to_delete)
|
|
199
|
+
DETACH DELETE next_to_delete
|
|
200
|
+
DETACH DELETE rel_to_delete
|
|
259
201
|
}
|
|
202
|
+
// -------------------------
|
|
203
|
+
// add relationships for this node
|
|
204
|
+
// -------------------------
|
|
205
|
+
WITH diff_node, node_map
|
|
206
|
+
UNWIND node_map.relationships as node_relationship
|
|
207
|
+
MERGE (diff_node)-[:DIFF_HAS_RELATIONSHIP]->(diff_relationship:DiffRelationship {name: node_relationship.node_properties.name})
|
|
208
|
+
SET diff_relationship = node_relationship.node_properties
|
|
209
|
+
// -------------------------
|
|
210
|
+
// remove stale elements for this relationship group
|
|
211
|
+
// -------------------------
|
|
212
|
+
WITH diff_relationship, node_relationship
|
|
213
|
+
CALL {
|
|
214
|
+
WITH diff_relationship, node_relationship
|
|
215
|
+
WITH diff_relationship, %(rel_peers_list_comp)s AS rel_peers
|
|
216
|
+
OPTIONAL MATCH (diff_relationship)-[:DIFF_HAS_ELEMENT]->(element_to_delete:DiffRelationshipElement)
|
|
217
|
+
WHERE NOT (element_to_delete.peer_id IN rel_peers)
|
|
218
|
+
OPTIONAL MATCH (element_to_delete)-[*..6]->(next_to_delete)
|
|
219
|
+
DETACH DELETE next_to_delete
|
|
220
|
+
DETACH DELETE element_to_delete
|
|
221
|
+
}
|
|
222
|
+
// -------------------------
|
|
223
|
+
// add elements for this relationship group
|
|
224
|
+
// -------------------------
|
|
225
|
+
WITH diff_relationship, node_relationship
|
|
226
|
+
UNWIND node_relationship.relationships as node_single_relationship
|
|
227
|
+
MERGE (diff_relationship)-[:DIFF_HAS_ELEMENT]
|
|
228
|
+
->(diff_relationship_element:DiffRelationshipElement {peer_id: node_single_relationship.node_properties.peer_id})
|
|
229
|
+
SET diff_relationship_element = node_single_relationship.node_properties
|
|
230
|
+
// -------------------------
|
|
231
|
+
// add/remove conflict for this relationship element
|
|
232
|
+
// -------------------------
|
|
233
|
+
WITH diff_relationship_element, node_single_relationship
|
|
234
|
+
OPTIONAL MATCH (diff_relationship_element)-[:DIFF_HAS_CONFLICT]->(current_element_conflict:DiffConflict)
|
|
235
|
+
WITH diff_relationship_element, node_single_relationship, current_element_conflict,
|
|
236
|
+
(node_single_relationship.conflict_params IS NOT NULL) AS has_element_conflict
|
|
237
|
+
FOREACH (i in CASE WHEN has_element_conflict = FALSE THEN [1] ELSE [] END |
|
|
238
|
+
DETACH DELETE current_element_conflict
|
|
239
|
+
)
|
|
240
|
+
FOREACH (i in CASE WHEN has_element_conflict = TRUE THEN [1] ELSE [] END |
|
|
241
|
+
MERGE (diff_relationship_element)-[:DIFF_HAS_CONFLICT]->(element_conflict:DiffConflict)
|
|
242
|
+
SET element_conflict = node_single_relationship.conflict_params
|
|
243
|
+
)
|
|
244
|
+
// -------------------------
|
|
245
|
+
// remove stale properties for this relationship element
|
|
246
|
+
// -------------------------
|
|
247
|
+
WITH diff_relationship_element, node_single_relationship
|
|
248
|
+
CALL {
|
|
249
|
+
WITH diff_relationship_element, node_single_relationship
|
|
250
|
+
WITH diff_relationship_element, %(element_props_list_comp)s AS element_props
|
|
251
|
+
OPTIONAL MATCH (diff_relationship_element)-[:DIFF_HAS_PROPERTY]->(property_to_delete:DiffProperty)
|
|
252
|
+
WHERE NOT (property_to_delete.property_type IN element_props)
|
|
253
|
+
OPTIONAL MATCH (property_to_delete)-[*..4]->(next_to_delete)
|
|
254
|
+
DETACH DELETE next_to_delete
|
|
255
|
+
DETACH DELETE property_to_delete
|
|
256
|
+
}
|
|
257
|
+
// -------------------------
|
|
258
|
+
// add properties for this relationship element
|
|
259
|
+
// -------------------------
|
|
260
|
+
WITH diff_relationship_element, node_single_relationship
|
|
261
|
+
UNWIND node_single_relationship.properties as node_relationship_property
|
|
262
|
+
MERGE (diff_relationship_element)-[:DIFF_HAS_PROPERTY]
|
|
263
|
+
->(diff_relationship_property:DiffProperty {property_type: node_relationship_property.node_properties.property_type})
|
|
264
|
+
SET diff_relationship_property = node_relationship_property.node_properties
|
|
265
|
+
// -------------------------
|
|
266
|
+
// add conflict for this relationship element
|
|
267
|
+
// -------------------------
|
|
268
|
+
WITH diff_relationship_property, node_relationship_property
|
|
269
|
+
OPTIONAL MATCH (diff_relationship_property)-[:DIFF_HAS_CONFLICT]->(diff_relationship_property_conflict:DiffConflict)
|
|
270
|
+
WITH diff_relationship_property, node_relationship_property, diff_relationship_property_conflict,
|
|
271
|
+
(node_relationship_property.conflict_params IS NOT NULL) AS has_property_conflict
|
|
272
|
+
FOREACH (i in CASE WHEN has_property_conflict = FALSE THEN [1] ELSE [] END |
|
|
273
|
+
DETACH DELETE diff_relationship_property_conflict
|
|
274
|
+
)
|
|
275
|
+
FOREACH (i in CASE WHEN has_property_conflict = TRUE THEN [1] ELSE [] END |
|
|
276
|
+
MERGE (diff_relationship_property)-[:DIFF_HAS_CONFLICT]->(property_conflict:DiffConflict)
|
|
277
|
+
SET property_conflict = node_relationship_property.conflict_params
|
|
278
|
+
)
|
|
260
279
|
""" % {
|
|
261
280
|
"attr_name_list_comp": db.render_list_comprehension(
|
|
262
281
|
items="node_map.attributes", item_name="node_properties.name"
|
|
@@ -409,47 +428,34 @@ class EnrichedNodesLinkQuery(Query):
|
|
|
409
428
|
type = QueryType.WRITE
|
|
410
429
|
insert_return = False
|
|
411
430
|
|
|
412
|
-
def __init__(self,
|
|
431
|
+
def __init__(self, diff_root_uuid: str, diff_nodes: Iterable[EnrichedDiffNode], **kwargs: Any) -> None:
|
|
413
432
|
super().__init__(**kwargs)
|
|
414
|
-
self.
|
|
433
|
+
self.diff_root_uuid = diff_root_uuid
|
|
434
|
+
self.diff_nodes = diff_nodes
|
|
415
435
|
|
|
416
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None:
|
|
417
|
-
|
|
418
|
-
for
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
436
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa: ARG002
|
|
437
|
+
parent_node_map: dict[str, dict[str, str]] = {}
|
|
438
|
+
for diff_node in self.diff_nodes:
|
|
439
|
+
if diff_node.uuid not in parent_node_map:
|
|
440
|
+
parent_node_map[diff_node.uuid] = {}
|
|
441
|
+
for relationship in diff_node.relationships:
|
|
442
|
+
for parent_node in relationship.nodes:
|
|
443
|
+
parent_node_map[diff_node.uuid][relationship.name] = parent_node.uuid
|
|
444
|
+
self.params = {"root_uuid": self.diff_root_uuid, "parent_node_map": parent_node_map}
|
|
422
445
|
query = """
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
node_link_details.child_uuid AS child_uuid,
|
|
428
|
-
node_link_details.relationship_name AS relationship_name
|
|
446
|
+
WITH keys($parent_node_map) AS child_node_uuids
|
|
447
|
+
MATCH (diff_root:DiffRoot {uuid: $root_uuid})
|
|
448
|
+
MATCH (diff_root)-[:DIFF_HAS_NODE]->(child_node:DiffNode)
|
|
449
|
+
WHERE child_node.uuid IN child_node_uuids
|
|
429
450
|
CALL {
|
|
430
|
-
WITH
|
|
431
|
-
|
|
451
|
+
WITH diff_root, child_node
|
|
452
|
+
WITH diff_root, child_node, $parent_node_map[child_node.uuid] AS sub_map
|
|
453
|
+
WITH diff_root, child_node, sub_map, keys(sub_map) AS relationship_names
|
|
454
|
+
MATCH (child_node)-[:DIFF_HAS_RELATIONSHIP]->(diff_rel_group:DiffRelationship)
|
|
455
|
+
WHERE diff_rel_group.name IN relationship_names
|
|
456
|
+
WITH diff_root, diff_rel_group, toString(sub_map[diff_rel_group.name]) AS parent_uuid
|
|
432
457
|
MATCH (diff_root)-[:DIFF_HAS_NODE]->(parent_node:DiffNode {uuid: parent_uuid})
|
|
433
|
-
|
|
434
|
-
MATCH (diff_root)-[:DIFF_HAS_NODE]->(child_node:DiffNode {uuid: child_uuid})
|
|
435
|
-
MERGE (diff_rel_group)-[:DIFF_HAS_NODE]->(child_node)
|
|
458
|
+
MERGE (diff_rel_group)-[:DIFF_HAS_NODE]->(parent_node)
|
|
436
459
|
}
|
|
437
460
|
"""
|
|
438
461
|
self.add_to_query(query)
|
|
439
|
-
|
|
440
|
-
def _build_node_parent_links(self, enriched_node: EnrichedDiffNode, root_uuid: str) -> list[dict[str, str]]:
|
|
441
|
-
if not enriched_node.relationships:
|
|
442
|
-
return []
|
|
443
|
-
parent_links = []
|
|
444
|
-
for relationship in enriched_node.relationships:
|
|
445
|
-
for child_node in relationship.nodes:
|
|
446
|
-
parent_links.append(
|
|
447
|
-
{
|
|
448
|
-
"parent_uuid": enriched_node.uuid,
|
|
449
|
-
"relationship_name": relationship.name,
|
|
450
|
-
"child_uuid": child_node.uuid,
|
|
451
|
-
"root_uuid": root_uuid,
|
|
452
|
-
}
|
|
453
|
-
)
|
|
454
|
-
parent_links.extend(self._build_node_parent_links(enriched_node=child_node, root_uuid=root_uuid))
|
|
455
|
-
return parent_links
|
|
@@ -6,10 +6,10 @@ from infrahub.database import InfrahubDatabase
|
|
|
6
6
|
from ..model.path import TrackingId
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
class
|
|
10
|
-
"""Update summary counters for a
|
|
9
|
+
class DiffFieldsSummaryCountsEnricherQuery(Query):
|
|
10
|
+
"""Update summary counters for the attributes and relationshipsin in a diff"""
|
|
11
11
|
|
|
12
|
-
name = "
|
|
12
|
+
name = "diff_fields_summary_count_enricher"
|
|
13
13
|
type = QueryType.WRITE
|
|
14
14
|
insert_return = False
|
|
15
15
|
|
|
@@ -23,7 +23,9 @@ class DiffSummaryCountsEnricherQuery(Query):
|
|
|
23
23
|
) -> None:
|
|
24
24
|
super().__init__(**kwargs)
|
|
25
25
|
if (diff_id is None and tracking_id is None) or (diff_id and tracking_id):
|
|
26
|
-
raise ValueError(
|
|
26
|
+
raise ValueError(
|
|
27
|
+
"DiffFieldsSummaryCountsEnricherQuery requires one and only one of `tracking_id` or `diff_id`"
|
|
28
|
+
)
|
|
27
29
|
self.diff_branch_name = diff_branch_name
|
|
28
30
|
self.tracking_id = tracking_id
|
|
29
31
|
self.diff_id = diff_id
|
|
@@ -31,7 +33,7 @@ class DiffSummaryCountsEnricherQuery(Query):
|
|
|
31
33
|
raise RuntimeError("tracking_id or diff_id is required")
|
|
32
34
|
self.node_uuids = node_uuids
|
|
33
35
|
|
|
34
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None:
|
|
36
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa: ARG002
|
|
35
37
|
self.params = {
|
|
36
38
|
"diff_branch_name": self.diff_branch_name,
|
|
37
39
|
"diff_id": self.diff_id,
|
|
@@ -138,6 +140,51 @@ CALL {
|
|
|
138
140
|
SET dr.num_removed = num_removed
|
|
139
141
|
}
|
|
140
142
|
}
|
|
143
|
+
"""
|
|
144
|
+
self.add_to_query(query)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
class DiffNodesSummaryCountsEnricherQuery(Query):
|
|
148
|
+
"""Update summary counters for the nodes and root in a diff"""
|
|
149
|
+
|
|
150
|
+
name = "diff_nodes_summary_count_enricher"
|
|
151
|
+
type = QueryType.WRITE
|
|
152
|
+
insert_return = False
|
|
153
|
+
|
|
154
|
+
def __init__(
|
|
155
|
+
self,
|
|
156
|
+
diff_branch_name: str,
|
|
157
|
+
tracking_id: TrackingId | None = None,
|
|
158
|
+
diff_id: str | None = None,
|
|
159
|
+
node_uuids: list[str] | None = None,
|
|
160
|
+
**kwargs: Any,
|
|
161
|
+
) -> None:
|
|
162
|
+
super().__init__(**kwargs)
|
|
163
|
+
if (diff_id is None and tracking_id is None) or (diff_id and tracking_id):
|
|
164
|
+
raise ValueError(
|
|
165
|
+
"DiffNodesSummaryCountsEnricherQuery requires one and only one of `tracking_id` or `diff_id`"
|
|
166
|
+
)
|
|
167
|
+
self.diff_branch_name = diff_branch_name
|
|
168
|
+
self.tracking_id = tracking_id
|
|
169
|
+
self.diff_id = diff_id
|
|
170
|
+
if self.tracking_id is None and self.diff_id is None:
|
|
171
|
+
raise RuntimeError("tracking_id or diff_id is required")
|
|
172
|
+
self.node_uuids = node_uuids
|
|
173
|
+
|
|
174
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa: ARG002
|
|
175
|
+
self.params = {
|
|
176
|
+
"diff_branch_name": self.diff_branch_name,
|
|
177
|
+
"diff_id": self.diff_id,
|
|
178
|
+
"tracking_id": self.tracking_id.serialize() if self.tracking_id else None,
|
|
179
|
+
"node_uuids": self.node_uuids,
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
query = """
|
|
183
|
+
MATCH (root:DiffRoot)
|
|
184
|
+
WHERE ($diff_id IS NOT NULL AND root.uuid = $diff_id)
|
|
185
|
+
OR ($tracking_id IS NOT NULL AND root.tracking_id = $tracking_id AND root.diff_branch = $diff_branch_name)
|
|
186
|
+
MATCH (root)-[:DIFF_HAS_NODE]->(dn:DiffNode)
|
|
187
|
+
WHERE $node_uuids IS NULL OR dn.uuid IN $node_uuids
|
|
141
188
|
// ----------------------
|
|
142
189
|
// handle node count updates
|
|
143
190
|
// ----------------------
|
|
@@ -30,7 +30,7 @@ class EnrichedDiffTimeRangeQuery(Query):
|
|
|
30
30
|
self.from_time = from_time
|
|
31
31
|
self.to_time = to_time
|
|
32
32
|
|
|
33
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None:
|
|
33
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa: ARG002
|
|
34
34
|
self.params = {
|
|
35
35
|
"base_branch": self.base_branch_name,
|
|
36
36
|
"diff_branch": self.diff_branch_name,
|
|
@@ -21,7 +21,7 @@ class EnrichedDiffConflictUpdateQuery(Query):
|
|
|
21
21
|
self.conflict_id = conflict_id
|
|
22
22
|
self.selection = selection
|
|
23
23
|
|
|
24
|
-
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None:
|
|
24
|
+
async def query_init(self, db: InfrahubDatabase, **kwargs: Any) -> None: # noqa: ARG002
|
|
25
25
|
self.params = {"conflict_id": self.conflict_id, "selection": self.selection.value if self.selection else None}
|
|
26
26
|
query = """
|
|
27
27
|
MATCH (conflict:DiffConflict {uuid: $conflict_id})
|
|
@@ -18,10 +18,12 @@ from ..model.path import (
|
|
|
18
18
|
EnrichedDiffSingleRelationship,
|
|
19
19
|
deserialize_tracking_id,
|
|
20
20
|
)
|
|
21
|
+
from ..parent_node_adder import DiffParentNodeAdder, ParentNodeAddRequest
|
|
21
22
|
|
|
22
23
|
|
|
23
24
|
class EnrichedDiffDeserializer:
|
|
24
|
-
def __init__(self) -> None:
|
|
25
|
+
def __init__(self, parent_adder: DiffParentNodeAdder) -> None:
|
|
26
|
+
self.parent_adder = parent_adder
|
|
25
27
|
self._diff_root_map: dict[str, EnrichedDiffRoot] = {}
|
|
26
28
|
self._diff_node_map: dict[tuple[str, str], EnrichedDiffNode] = {}
|
|
27
29
|
self._diff_node_attr_map: dict[tuple[str, str, str], EnrichedDiffAttribute] = {}
|
|
@@ -127,14 +129,15 @@ class EnrichedDiffDeserializer:
|
|
|
127
129
|
|
|
128
130
|
def _deserialize_parents(self) -> None:
|
|
129
131
|
for enriched_root, node_path_tuples in self._parents_path_map.items():
|
|
132
|
+
self.parent_adder.initialize(enriched_diff_root=enriched_root)
|
|
130
133
|
for node_uuid, parents_path in node_path_tuples:
|
|
131
134
|
# Remove the node itself from the path
|
|
132
135
|
parents_path_slice = parents_path.nodes[1:]
|
|
133
136
|
|
|
134
137
|
# TODO Ensure the list is even
|
|
135
138
|
current_node_uuid = node_uuid
|
|
136
|
-
for rel, parent in zip(parents_path_slice[::2], parents_path_slice[1::2]):
|
|
137
|
-
|
|
139
|
+
for rel, parent in zip(parents_path_slice[::2], parents_path_slice[1::2], strict=False):
|
|
140
|
+
parent_request = ParentNodeAddRequest(
|
|
138
141
|
node_id=current_node_uuid,
|
|
139
142
|
parent_id=parent.get("uuid"),
|
|
140
143
|
parent_kind=parent.get("kind"),
|
|
@@ -144,6 +147,7 @@ class EnrichedDiffDeserializer:
|
|
|
144
147
|
parent_rel_cardinality=RelationshipCardinality(rel.get("cardinality")),
|
|
145
148
|
parent_rel_label=rel.get("label"),
|
|
146
149
|
)
|
|
150
|
+
self.parent_adder.add_parent(parent_request=parent_request)
|
|
147
151
|
current_node_uuid = parent.get("uuid")
|
|
148
152
|
|
|
149
153
|
@classmethod
|
|
@@ -164,6 +168,7 @@ class EnrichedDiffDeserializer:
|
|
|
164
168
|
def build_diff_root_metadata(cls, root_node: Neo4jNode) -> EnrichedDiffRootMetadata:
|
|
165
169
|
from_time = Timestamp(str(root_node.get("from_time")))
|
|
166
170
|
to_time = Timestamp(str(root_node.get("to_time")))
|
|
171
|
+
partner_uuid = cls._get_str_or_none_property_value(node=root_node, property_name="partner_uuid")
|
|
167
172
|
tracking_id_str = str(root_node.get("tracking_id"))
|
|
168
173
|
tracking_id = deserialize_tracking_id(tracking_id_str=tracking_id_str)
|
|
169
174
|
return EnrichedDiffRootMetadata(
|
|
@@ -172,7 +177,7 @@ class EnrichedDiffDeserializer:
|
|
|
172
177
|
from_time=from_time,
|
|
173
178
|
to_time=to_time,
|
|
174
179
|
uuid=str(root_node.get("uuid")),
|
|
175
|
-
partner_uuid=
|
|
180
|
+
partner_uuid=partner_uuid,
|
|
176
181
|
tracking_id=tracking_id,
|
|
177
182
|
num_added=int(root_node.get("num_added", 0)),
|
|
178
183
|
num_updated=int(root_node.get("num_updated", 0)),
|