Compare commits

...

1 Commits

Author SHA1 Message Date
Doug Beatty
491e1802e7 Add ability to configure index names 2023-09-16 17:21:54 -06:00
2 changed files with 14 additions and 2 deletions

View File

@@ -28,8 +28,17 @@ class PostgresIndexConfig(dbtClassMixin):
columns: List[str]
unique: bool = False
type: Optional[str] = None
name: Optional[str] = None
def render(self, relation):
# Use the index name if given
# Otherwise, generate a unique index name
if self.name:
return self.name
else:
return self.default_index_name(relation)
def default_index_name(self, relation):
# We append the current timestamp to the index name because otherwise
# the index will only be created on every other run. See
# https://github.com/dbt-labs/dbt-core/issues/1945#issuecomment-576714925

View File

@@ -29,7 +29,7 @@ class PostgresIndexMethod(StrEnum):
@dataclass(frozen=True, eq=True, unsafe_hash=True)
class PostgresIndexConfig(RelationConfigBase, RelationConfigValidationMixin):
"""
This config fallows the specs found here:
This config follows the specs found here:
https://www.postgresql.org/docs/current/sql-createindex.html
The following parameters are configurable by dbt:
@@ -76,6 +76,7 @@ class PostgresIndexConfig(RelationConfigBase, RelationConfigValidationMixin):
@classmethod
def parse_model_node(cls, model_node_entry: dict) -> dict:
config_dict = {
"name": model_node_entry.get("name"),
"column_names": set(model_node_entry.get("columns", set())),
"unique": model_node_entry.get("unique"),
"method": model_node_entry.get("type"),
@@ -98,10 +99,12 @@ class PostgresIndexConfig(RelationConfigBase, RelationConfigValidationMixin):
Returns: a dictionary that can be passed into `get_create_index_sql()`
"""
node_config = {
"name": self.name,
"columns": list(self.column_names),
"unique": self.unique,
"type": self.method.value,
"type": self.method,
}
return node_config