diff --git a/.changes/unreleased/Under the Hood-20240226-225642.yaml b/.changes/unreleased/Under the Hood-20240226-225642.yaml new file mode 100644 index 00000000..dd5d0645 --- /dev/null +++ b/.changes/unreleased/Under the Hood-20240226-225642.yaml @@ -0,0 +1,6 @@ +kind: Under the Hood +body: Add unit test for transaction semantics. +time: 2024-02-26T22:56:42.202429-08:00 +custom: + Author: versusfacit + Issue: "23" diff --git a/dbt/adapters/postgres/relation.py b/dbt/adapters/postgres/relation.py index 3f659fb4..677b12ac 100644 --- a/dbt/adapters/postgres/relation.py +++ b/dbt/adapters/postgres/relation.py @@ -1,4 +1,4 @@ -from dataclasses import dataclass +from dataclasses import dataclass, field from typing import FrozenSet, Optional, Set from dbt.adapters.base.relation import BaseRelation @@ -20,19 +20,19 @@ @dataclass(frozen=True, eq=False, repr=False) class PostgresRelation(BaseRelation): - renameable_relations = frozenset( + renameable_relations: FrozenSet[RelationType] = field(default_factory=lambda: frozenset( { RelationType.View, RelationType.Table, RelationType.MaterializedView, } - ) - replaceable_relations = frozenset( + )) + replaceable_relations: FrozenSet[RelationType] = field(default_factory=lambda: frozenset( { RelationType.View, RelationType.Table, } - ) + )) def __post_init__(self): # Check for length of Postgres table/view names. diff --git a/tests/unit/test_renamed_relations.py b/tests/unit/test_renamed_relations.py new file mode 100644 index 00000000..49900d8e --- /dev/null +++ b/tests/unit/test_renamed_relations.py @@ -0,0 +1,16 @@ +from dbt.adapters.postgres.relation import PostgresRelation +from dbt.adapters.contracts.relation import RelationType + + +def test_renameable_relation(): + relation = PostgresRelation.create( + database="my_db", + schema="my_schema", + identifier="my_table", + type=RelationType.Table, + ) + assert relation.renameable_relations == frozenset({ + RelationType.View, + RelationType.Table, + RelationType.MaterializedView, + })