Skip to content

Commit

Permalink
Support saved_queries when upgrading from manifests <= v10 (and reg…
Browse files Browse the repository at this point in the history
…enerate v11)
  • Loading branch information
QMalcolm committed Oct 10, 2023
1 parent 5961bd2 commit 0e15768
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 2 deletions.
2 changes: 2 additions & 0 deletions core/dbt/contracts/graph/manifest_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,6 @@ def upgrade_manifest_json(manifest: dict, manifest_schema_version: int) -> dict:
doc_content["resource_type"] = "doc"
if "semantic_models" not in manifest:
manifest["semantic_models"] = {}
if "saved_queries" not in manifest:
manifest["saved_queries"] = {}
return manifest
192 changes: 192 additions & 0 deletions schemas/dbt/manifest/v11.json
Original file line number Diff line number Diff line change
Expand Up @@ -5069,6 +5069,183 @@
"owner"
]
},
"SavedQueryConfig": {
"type": "object",
"title": "SavedQueryConfig",
"properties": {
"_extra": {
"type": "object",
"propertyNames": {
"type": "string"
}
},
"enabled": {
"type": "boolean",
"default": true
},
"group": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null
},
"meta": {
"type": "object",
"propertyNames": {
"type": "string"
}
}
},
"additionalProperties": true
},
"SavedQuery": {
"type": "object",
"title": "SavedQuery",
"properties": {
"name": {
"type": "string"
},
"resource_type": {
"enum": [
"model",
"analysis",
"test",
"snapshot",
"operation",
"seed",
"rpc",
"sql_operation",
"doc",
"source",
"macro",
"exposure",
"metric",
"group",
"saved_query",
"semantic_model"
]
},
"package_name": {
"type": "string"
},
"path": {
"type": "string"
},
"original_file_path": {
"type": "string"
},
"unique_id": {
"type": "string"
},
"fqn": {
"type": "array",
"items": {
"type": "string"
}
},
"metrics": {
"type": "array",
"items": {
"type": "string"
}
},
"group_bys": {
"type": "array",
"items": {
"type": "string"
}
},
"where": {
"type": "array",
"items": {
"$ref": "#/$defs/WhereFilter"
}
},
"description": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null
},
"label": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null
},
"metadata": {
"anyOf": [
{
"$ref": "#/$defs/SourceFileMetadata"
},
{
"type": "null"
}
],
"default": null
},
"config": {
"$ref": "#/$defs/SavedQueryConfig"
},
"unrendered_config": {
"type": "object",
"propertyNames": {
"type": "string"
}
},
"group": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null
},
"depends_on": {
"$ref": "#/$defs/DependsOn"
},
"created_at": {
"type": "number"
},
"refs": {
"type": "array",
"items": {
"$ref": "#/$defs/RefArgs"
}
}
},
"additionalProperties": false,
"required": [
"name",
"resource_type",
"package_name",
"path",
"original_file_path",
"unique_id",
"fqn",
"metrics",
"group_bys",
"where"
]
},
"NodeRelation": {
"type": "object",
"title": "NodeRelation",
Expand Down Expand Up @@ -5530,6 +5707,7 @@
"exposure",
"metric",
"group",
"saved_query",
"semantic_model"
]
},
Expand Down Expand Up @@ -5841,6 +6019,9 @@
{
"$ref": "#/$defs/Metric"
},
{
"$ref": "#/$defs/SavedQuery"
},
{
"$ref": "#/$defs/SemanticModel"
}
Expand Down Expand Up @@ -5916,6 +6097,16 @@
}
]
},
"saved_queries": {
"type": "object",
"description": "The saved queries defined in the dbt project",
"additionalProperties": {
"$ref": "#/$defs/SavedQuery"
},
"propertyNames": {
"type": "string"
}
},
"semantic_models": {
"type": "object",
"description": "The semantic models defined in the dbt project",
Expand All @@ -5942,6 +6133,7 @@
"parent_map",
"child_map",
"group_map",
"saved_queries",
"semantic_models"
]
}
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/artifacts/data/state/v11/manifest.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions tests/functional/artifacts/expected_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,7 @@ def expected_seeded_manifest(project, model_database=None, quote_model=False):
},
"disabled": {},
"semantic_models": {},
"saved_queries": {},
}


Expand Down Expand Up @@ -1448,6 +1449,7 @@ def expected_references_manifest(project):
}
},
"semantic_models": {},
"saved_queries": {},
}


Expand Down Expand Up @@ -1927,4 +1929,5 @@ def expected_versions_manifest(project):
"disabled": {},
"macros": {},
"semantic_models": {},
"saved_queries": {},
}
3 changes: 2 additions & 1 deletion tests/functional/artifacts/test_artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ def verify_manifest(project, expected_manifest, start_time, manifest_schema_path
"exposures",
"selectors",
"semantic_models",
"saved_queries",
}

assert set(manifest.keys()) == manifest_keys
Expand All @@ -494,7 +495,7 @@ def verify_manifest(project, expected_manifest, start_time, manifest_schema_path
for unique_id, node in expected_manifest[key].items():
assert unique_id in manifest[key]
assert manifest[key][unique_id] == node, f"{unique_id} did not match"
else: # ['docs', 'parent_map', 'child_map', 'group_map', 'selectors']
else: # ['docs', 'parent_map', 'child_map', 'group_map', 'selectors', 'semantic_models', 'saved_queries']
assert manifest[key] == expected_manifest[key]


Expand Down

0 comments on commit 0e15768

Please sign in to comment.