All Projects → offbi → pre-commit-dbt

offbi / pre-commit-dbt

Licence: MIT License
🎣 List of `pre-commit` hooks to ensure the quality of your `dbt` projects.

Programming Languages

python
139335 projects - #7 most used programming language
Dockerfile
14818 projects

Projects that are alternatives of or similar to pre-commit-dbt

tellery
Tellery lets you build metrics using SQL and bring them to your team. As easy as using a document. As powerful as a data modeling tool.
Stars: ✭ 219 (+46.98%)
Mutual labels:  bigquery, snowflake, business-intelligence, dbt
dbt-ml-preprocessing
A SQL port of python's scikit-learn preprocessing module, provided as cross-database dbt macros.
Stars: ✭ 128 (-14.09%)
Mutual labels:  bigquery, snowflake, dbt
Redash
Make Your Company Data Driven. Connect to any data source, easily visualize, dashboard and share your data.
Stars: ✭ 20,147 (+13421.48%)
Mutual labels:  bigquery, business-intelligence
Tbls
tbls is a CI-Friendly tool for document a database, written in Go.
Stars: ✭ 940 (+530.87%)
Mutual labels:  bigquery, snowflake
snowflake-starter
A _simple_ starter template for Snowflake Cloud Data Platform
Stars: ✭ 31 (-79.19%)
Mutual labels:  snowflake, dbt
dbd
dbd is a database prototyping tool that enables data analysts and engineers to quickly load and transform data in SQL databases.
Stars: ✭ 30 (-79.87%)
Mutual labels:  bigquery, snowflake
Sqlpad
Web-based SQL editor run in your own private cloud. Supports MySQL, Postgres, SQL Server, Vertica, Crate, ClickHouse, Trino, Presto, SAP HANA, Cassandra, Snowflake, BigQuery, SQLite, and more with ODBC
Stars: ✭ 4,113 (+2660.4%)
Mutual labels:  bigquery, snowflake
Mprove
Open source Business Intelligence tool 🎉
Stars: ✭ 212 (+42.28%)
Mutual labels:  bigquery, business-intelligence
Sql Runner
Run templatable playbooks of SQL scripts in series and parallel on Redshift, PostgreSQL, BigQuery and Snowflake
Stars: ✭ 68 (-54.36%)
Mutual labels:  bigquery, snowflake
starlake
Starlake is a Spark Based On Premise and Cloud ELT/ETL Framework for Batch & Stream Processing
Stars: ✭ 16 (-89.26%)
Mutual labels:  bigquery, snowflake
blackbricks
Black for Databricks notebooks
Stars: ✭ 40 (-73.15%)
Mutual labels:  pre-commit, pre-commit-hook
conventional-pre-commit
A pre-commit hook that checks commit messages for Conventional Commits formatting
Stars: ✭ 66 (-55.7%)
Mutual labels:  pre-commit, pre-commit-hook
growthbook
Open Source Feature Flagging and A/B Testing Platform
Stars: ✭ 2,342 (+1471.81%)
Mutual labels:  bigquery, snowflake
astro
Astro allows rapid and clean development of {Extract, Load, Transform} workflows using Python and SQL, powered by Apache Airflow.
Stars: ✭ 79 (-46.98%)
Mutual labels:  bigquery, snowflake
ready
A program to run tasks before a commit.
Stars: ✭ 16 (-89.26%)
Mutual labels:  pre-commit, pre-commit-hook
lightdash
An open source alternative to Looker built using dbt. Made for analysts ❤️
Stars: ✭ 1,082 (+626.17%)
Mutual labels:  business-intelligence, dbt
carto-spatial-extension
A set of UDFs and Procedures to extend BigQuery, Snowflake, Redshift and Postgres with Spatial Analytics capabilities
Stars: ✭ 131 (-12.08%)
Mutual labels:  bigquery, snowflake
airflow-dbt
Apache Airflow integration for dbt
Stars: ✭ 233 (+56.38%)
Mutual labels:  dbt
dbq
CLI tool to easily Decorate BigQuery table name
Stars: ✭ 13 (-91.28%)
Mutual labels:  bigquery
airflow-tutorial
Use Airflow to move data from multiple MySQL databases to BigQuery
Stars: ✭ 96 (-35.57%)
Mutual labels:  bigquery

dbt-pre-commit

pre-commit-dbt

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, pre-commit-dbt is here to help you!

List of pre-commit-dbt hooks

💡 Click on hook name to view the details.

Model checks:

Script checks:

Source checks:

Macro checks:

Modifiers:

dbt commands:


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

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/offbi/pre-commit-dbt
  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 pre-commit-dbt if you are using dbt Cloud. But you can run checks after you push changes into Github.

pre-commit-dbt 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/offbi/pre-commit-dbt
 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/offbi/pre-commit-dbt
 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/[email protected]
    with:
      output: ' '
  - uses: offbi/[email protected]
    env:
      DB_PASSWORD: ${{ secrets.SuperSecret }}
    with:
      args: run --files ${{ steps.file_changes.outputs.files}}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].