Skip to content

Commit

Permalink
update renameable relations attribute on BaseRelation
Browse files Browse the repository at this point in the history
  • Loading branch information
mikealfare committed Aug 31, 2023
1 parent a31189e commit 24ebc37
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions core/dbt/adapters/base/relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ class BaseRelation(FakeAPIObject, Hashable):
include_policy: Policy = field(default_factory=lambda: Policy())
quote_policy: Policy = field(default_factory=lambda: Policy())
dbt_created: bool = False
relations_that_can_be_renamed: List[StrEnum] = field(default_factory=list)
# register relation types that can be renamed for the purpose of replacing relations using stages and backups
renameable_relations: List[StrEnum] = field(
default_factory=lambda: [RelationType.Table, RelationType.View]
)

def _is_exactish_match(self, field: ComponentName, value: str) -> bool:
if self.dbt_created and self.quote_policy.get_part(field) is False:
Expand Down Expand Up @@ -289,7 +292,7 @@ def create(

@property
def can_be_renamed(self):
return self.type in self.relations_that_can_be_renamed
return self.type in self.renameable_relations

def __repr__(self) -> str:
return "<{} {}>".format(self.__class__.__name__, self.render())
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
)
def test_can_be_renamed(relation_type, result):
my_relation = BaseRelation.create(type=relation_type)
my_relation = replace(my_relation, relations_that_can_be_renamed=[RelationType.View])
my_relation = replace(my_relation, renameable_relations=[RelationType.View])
assert my_relation.can_be_renamed is result

0 comments on commit 24ebc37

Please sign in to comment.