Skip to main content

Collection of [pre-commit](https://pre-commit.com) hooks to ensure the quality of your [dbt](https://www.getdbt.com) projects.

Project description

dbt-gloss

CI black black

List of pre-commit hooks to ensure the quality of your dbt projects.

Goal

Quick ensure the quality of your dbt projects.

dbt is awesome, but when a number of models, sources, and macros grow it starts to be challenging to maintain quality. People often forget to update columns in schema files, add descriptions, or test. Besides, with the growing number of objects, dbt slows down, users stop running models/tests (because they want to deploy the feature quickly), and the demands on reviews increase.

If this is the case, dbt-gloss is here to help you!

List of dbt-gloss hooks

:bulb: Click on hook name to view the details.

Model checks:

Script checks:

Source checks:

Macro checks:

Modifiers:

dbt commands:


:exclamation:If you have an idea for a new hook or you found a bug, let us know:exclamation:

Install

For detailed installation and usage, instructions see pre-commit.com site.

pip install pre-commit

Setup

  1. Create a file named .pre-commit-config.yaml in your dbt root folder.
  2. Add list of hooks you want to run befor every commit. E.g.:
repos:
- repo: https://github.com/Montreal-Analytics/dbt-gloss
  rev: v1.0.0
  hooks:
  - id: check-script-semicolon
  - id: check-script-has-no-table-name
  - id: dbt-test
  - id: dbt-docs-generate
  - id: check-model-has-all-columns
    name: Check columns - core
    files: ^models/core
  - id: check-model-has-all-columns
    name: Check columns - mart
    files: ^models/mart
  - id: check-model-columns-have-desc
    files: ^models/mart
  1. Optionally, run pre-commit install to set up the git hook scripts. With this, pre-commit will run automatically on git commit! You can also manually run pre-commit run after you stage all files you want to run. Or pre-commit run --all-files to run the hooks against all of the files (not only staged).

Run as Github Action

Unfortunately, you cannot natively use dbt-gloss if you are using dbt Cloud. But you can run checks after you push changes into Github.

dbt-gloss for the most of the hooks needs manifest.json (see requirements section in hook documentation), that is in the target folder. Since this target folder is usually in .gitignore, you need to generate it. For that you need to run dbt-compile (or dbt-run) command. To be able to compile dbt, you also need profiles.yml file with your credentials. To provide passwords and secrets use Github Secrets (see example).

So you want to e.g. run chach on number of tests:

repos:
- repo: https://github.com/Montreal-Analytics/dbt-gloss
 rev: v1.0.0
 hooks:
 - id: check-model-has-tests
   args: ["--test-cnt", "2", "--"]

To be able to run this in Github actions you need to modified it to:

repos:
- repo: https://github.com/Montreal-Analytics/dbt-gloss
 rev: v1.0.0
 hooks:
 - id: dbt-compile
   args: ["--cmd-flags", "++profiles-dir", "."]
 - id: check-model-has-tests
   args: ["--test-cnt", "2", "--"]

Create profiles.yml

First step is to create profiles.yml. E.g.

# example profiles.yml file
jaffle_shop:
  target: dev
  outputs:
    dev:
      type: postgres
      host: localhost
      user: alice
      password: "{{ env_var('DB_PASSWORD') }}"
      port: 5432
      dbname: jaffle_shop
      schema: dbt_alice
      threads: 4

and store this file in project root ./profiles.yml.

Create new workflow

  • inside your Github repository create folder .github/workflows (unless it already exists).
  • create new file e.g. main.yml
  • specify your workflow e.g.:
name: pre-commit

on:
  pull_request:
  push:
  branches: [main]

jobs:
  pre-commit:
  runs-on: ubuntu-latest
  steps:
  - uses: actions/checkout@v2
  - uses: actions/setup-python@v2
  - id: file_changes
    uses: trilom/file-changes-action@v1.2.4
    with:
      output: ' '
  - uses: Montreal-Analytics/dbt-gloss@v1.0.0
    env:
      DB_PASSWORD: ${{ secrets.SuperSecret }}
    with:
      args: run --files ${{ steps.file_changes.outputs.files}}

Credits

This software is a fork of pre-commit-dbt. We created this fork since the last release of pre-commit-dbt is dated April 2021 and had many unresolved issues with more recent versions of dbt. As of September 2022, dbt-gloss is supported, but not warrantied by Montreal Analytics. Issues and feature requests can be reported via https://github.com/Montreal-Analytics/dbt-gloss/issues, which will be regularly monitored and prioritized by Montreal Analytics, a preferred dbt consulting partner. Major thanks to Radek Tomsej who originally created this tool.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dbt-gloss-1.0.0.tar.gz (26.7 kB view details)

Uploaded Source

Built Distribution

dbt_gloss-1.0.0-py2.py3-none-any.whl (50.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file dbt-gloss-1.0.0.tar.gz.

File metadata

  • Download URL: dbt-gloss-1.0.0.tar.gz
  • Upload date:
  • Size: 26.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.4

File hashes

Hashes for dbt-gloss-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f49b67b675da72156efe63007f93805ed8bb5e9878551d9ee28da0bb1a9b9f47
MD5 1d577a96c2009eb53b6dfc99a75b17b1
BLAKE2b-256 df9f79d147f56e54a4d855023bc175ff304b355dba2cc1febd5d4e1967bc2c4a

See more details on using hashes here.

File details

Details for the file dbt_gloss-1.0.0-py2.py3-none-any.whl.

File metadata

  • Download URL: dbt_gloss-1.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 50.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.4

File hashes

Hashes for dbt_gloss-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 98aadf6d717ae769b4348580bc7b7620f5af73657265e63ac51c8aa0c20a2e75
MD5 0770e95b2ff94c31ae39aebe7494ea49
BLAKE2b-256 d32aff77593786943fb0562095c8140b2e33b1e49ae3de6fab61a64ec5202f78

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page