Skip to content

extend constraint support #487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions dbt/adapters/sqlserver/sql_server_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Optional

import dbt.exceptions
from dbt.adapters.base import ConstraintSupport
from dbt.adapters.fabric import FabricAdapter
from dbt.contracts.graph.nodes import ConstraintType, ModelLevelConstraint

Expand Down Expand Up @@ -31,13 +32,14 @@ class SQLServerAdapter(FabricAdapter):
# Capability.TableLastModifiedMetadata: CapabilitySupport(support=Support.Full),
# }
# )
# CONSTRAINT_SUPPORT = {
# ConstraintType.check: ConstraintSupport.NOT_SUPPORTED,
# ConstraintType.not_null: ConstraintSupport.ENFORCED,
# ConstraintType.unique: ConstraintSupport.ENFORCED,
# ConstraintType.primary_key: ConstraintSupport.ENFORCED,
# ConstraintType.foreign_key: ConstraintSupport.ENFORCED,
# }
CONSTRAINT_SUPPORT = {
ConstraintType.check: ConstraintSupport.ENFORCED,
ConstraintType.not_null: ConstraintSupport.ENFORCED,
ConstraintType.unique: ConstraintSupport.ENFORCED,
ConstraintType.primary_key: ConstraintSupport.ENFORCED,
ConstraintType.foreign_key: ConstraintSupport.ENFORCED,
ConstraintType.custom: ConstraintSupport.ENFORCED,
}

# @available.parse(lambda *a, **k: [])
# def get_column_schema_from_query(self, sql: str) -> List[BaseColumn]:
Expand Down Expand Up @@ -76,8 +78,10 @@ def render_model_constraint(cls, constraint: ModelLevelConstraint) -> Optional[s
+ f"{constraint.name} foreign key({column_list}) references "
+ constraint.expression
)
elif constraint.type == ConstraintType.check and constraint.expression:
return f"{constraint_prefix} {constraint.name} check ({constraint.expression})"
elif constraint.type == ConstraintType.custom and constraint.expression:
return f"{constraint_prefix}{constraint.expression}"
return f"{constraint_prefix} {constraint.name} {constraint.expression}"
else:
return None

Expand Down