diff --git a/.changes/unreleased/Features-20240422-082925.yaml b/.changes/unreleased/Features-20240422-082925.yaml new file mode 100644 index 00000000000..b2e029fcf38 --- /dev/null +++ b/.changes/unreleased/Features-20240422-082925.yaml @@ -0,0 +1,6 @@ +kind: Features +body: Allows snapshots to take a list as a unique_key +time: 2024-04-22T08:29:25.458309-04:00 +custom: + Author: agpapa + Issue: "9992" diff --git a/core/dbt/artifacts/resources/v1/snapshot.py b/core/dbt/artifacts/resources/v1/snapshot.py index 6164d953184..732e9a96b53 100644 --- a/core/dbt/artifacts/resources/v1/snapshot.py +++ b/core/dbt/artifacts/resources/v1/snapshot.py @@ -11,11 +11,11 @@ class SnapshotConfig(NodeConfig): materialized: str = "snapshot" strategy: Optional[str] = None - unique_key: Optional[str] = None target_schema: Optional[str] = None target_database: Optional[str] = None updated_at: Optional[str] = None # Not using Optional because of serialization issues with a Union of str and List[str] + unique_key: Union[str, List[str], None] = None check_cols: Union[str, List[str], None] = None @classmethod diff --git a/core/dbt/contracts/graph/model_config.py b/core/dbt/contracts/graph/model_config.py index 14317f769b5..4658bca52e7 100644 --- a/core/dbt/contracts/graph/model_config.py +++ b/core/dbt/contracts/graph/model_config.py @@ -1,5 +1,5 @@ from dataclasses import dataclass, field -from typing import Any, Dict, List, Optional, Type +from typing import Any, Dict, List, Optional, Type, Union from dbt.artifacts.resources import ( ExposureConfig, @@ -42,7 +42,7 @@ class UnitTestNodeConfig(NodeConfig): @dataclass class EmptySnapshotConfig(NodeConfig): materialized: str = "snapshot" - unique_key: Optional[str] = None # override NodeConfig unique_key definition + unique_key: Union[str, List[str], None] = None # override NodeConfig unique_key definition RESOURCE_TYPES: Dict[NodeType, Type[BaseConfig]] = {