Skip to content

Commit

Permalink
feat: support dbt 1.9 (#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
gouline authored Feb 21, 2025
1 parent 86b35dc commit ccfed72
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 590 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:

- uses: actions/setup-python@v2
with:
python-version: "3.8.x"
python-version: "3.9.x"

- name: Install uv
run: pipx install uv
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

- uses: actions/setup-python@v5
with:
python-version: "3.8"
python-version: "3.9"

- name: Install uv
run: pipx install uv
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

- uses: actions/setup-python@v5
with:
python-version: "3.8"
python-version: "3.9"

- name: Install uv
run: pipx install uv
Expand Down
40 changes: 29 additions & 11 deletions dbtmetabase/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@

# Foreign key constraint: "schema.model (column)" / "model (column)"
_CONSTRAINT_FK_PARSER = re.compile(r"(?P<model>.+)\s+\((?P<column>.+)\)")
# Ref parser: "ref('model')"
_REF_PARSER = re.compile(r"ref\('(?P<model>.+)'\)")


class Manifest:
Expand Down Expand Up @@ -290,17 +292,33 @@ def _set_column_relationship(
column.semantic_type = "type/PK"

elif constraint["type"] == "foreign_key":
constraint_expr = constraint.get("expression", "")
constraint_fk = _CONSTRAINT_FK_PARSER.search(constraint_expr)
if constraint_fk:
fk_target_table = constraint_fk.group("model")
fk_target_field = constraint_fk.group("column")
else:
_logger.warning(
"Unparsable '%s' foreign key constraint: %s",
column.name,
constraint_expr,
)
# Constraint: expression
if constraint_expr := constraint.get("expression"):
constraint_fk = _CONSTRAINT_FK_PARSER.search(constraint_expr)
if constraint_fk:
fk_target_table = constraint_fk.group("model")
fk_target_field = constraint_fk.group("column")
else:
_logger.warning(
"Unparsable '%s' foreign key constraint: %s",
column.name,
constraint_expr,
)

# Constraint: to + to_columns
elif constraint_to := constraint.get("to"):
constraint_fk = _REF_PARSER.search(constraint_to)
constraint_to_columns = constraint.get("to_columns", [])
if constraint_fk and len(constraint_to_columns) == 1:
fk_target_table = constraint_fk.group("model")
fk_target_field = constraint_to_columns[0]
else:
_logger.warning(
"Unparsable '%s' foreign key constraint: %s, %s",
column.name,
constraint_to,
constraint_to_columns,
)

# Precedence 3: Meta fields
meta = manifest_column.get("meta", {})
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
name = "dbt-metabase"
description = "dbt + Metabase integration."
readme = "README.md"
requires-python = ">=3.8"
requires-python = ">=3.9"
dependencies = [
"PyYAML>=5.4.1",
"requests>=2.26.0",
Expand Down Expand Up @@ -51,7 +51,7 @@ dev-dependencies = [
"mypy>=1.7.1",
"pytest>=8.3.1",
"molot~=1.0.0",
"dbt-postgres~=1.8.1",
"dbt-postgres~=1.9.0",
"python-dotenv~=1.0.1",
"types-requests",
"types-PyYAML",
Expand Down
Binary file modified sandbox/metabase.db/metabase.db.mv.db
Binary file not shown.
3 changes: 2 additions & 1 deletion sandbox/models/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ models:
description: Foreign key to the orders table
constraints:
- type: foreign_key
expression: orders (order_id)
to: ref('orders')
to_columns: [order_id]
data_tests:
- not_null

Expand Down
634 changes: 61 additions & 573 deletions uv.lock

Large diffs are not rendered by default.

0 comments on commit ccfed72

Please sign in to comment.