Git Product home page Git Product logo

dbtgen's Introduction

dbtgen

NOTE: currently only working with dbt-snowflake

Contents

Install:

Make sure all requirements are installed and then install dbtgen like so:

python -m pip install -e . 

Usage:

Navigate to your dbt project working directory. From here, create a .dbtgen/ folder and start adding your model templates.

Commands:

The sub-commands / actions available to run with dbtgen are:

  • dbtgen model [OPTIONS]
  • dbtgen model-properties [OPTIONS]
  • dbtgen source [OPTIONS]
  • dbtgen package
  • dbtgen clean

model

  dbtgen model [OPTIONS]

Options:

  • -s (--select): The model/schema selected (e.g. -s staging.my_model)
  • -o (--overwrite): Overwrite existing models in the target folder of the project
  • -r (--run): Create the model files (by default, this is not used)

This command is used to help generate dbt model files (.sql) using a parameterised SQL template and model scoped variables defined in YAML.

The nested folder structure within ./.dbtgen/ represents the same structure used in the dbt models directory (./models by default). When the application runs, it iterates through every sub-directory and checks for two types of files:

Template file (*.sql)

These files contain parameterised SQL representing the contents of dbt models. Variables can be specified using curly braces (e.g. {my_variable}). The variable keys used here must be those defined in the models variable file (see below). The file name of the template file itself can (and should) be parameterised. This will be used to generate the individual file names for the models.

There can be an arbitrary number of templates within a folder.

Models variable file (models.yml)

This defines the model scoped variables. The values for these variables defined here will be used in place of those found in any template file(s).

YAML structure

# models.yml

models:
  <model-name>:
    <key>: <value>

When the application finds a template file it will, by default, check for a models.yml in the same directory. If it can't find one, it will traverse through parent directories and take the first one it encounters. This allows us to use one models variable file to generate multiple different dbt models using many nested templates.

Compile mode (default)

By default, the application will execute in compile mode and print the contents of each model file to terminal. You should check these look as expected before executing in run mode.

Example usage

dbtgen model
dbtgen model -s staging

Run mode

By passing in the command line flag -r or ---run will create the models in the projects models directory.

Example usage

dbtgen model -s staging -r
dbtgen model -s staging -r -o

model-properties

  dbtgen model-properties [OPTIONS]

Options:

  • -s (--select): The model/schema selected (e.g. -s staging)
  • -t (--target): The target environment to use to generate the contents (e.g. -t prod). Note, by default this is the target name of the default dbt profile (e.g. dev007), however for generating accurate recency tests, prod data is recommended
  • -uv (--use-views): Whether to use view objects only
  • -ut (--use-tables): Whether to use table objects only
  • -w (--warn-only): Use severity warn only for all recency tests (by default, this will generate both warn and error tests)

This command is used to scrape data from Snowflake and generate a model_properties file.

The structure of the file generated will include:

  • model names
  • model recency schema tests
  • SYS_ columns and schema tests

Model properties files are generated with file name .dbtgen__*.yml and are git ignored by default. This requires the user to check and rename (or replace any other properties file) if they are happy with the contents.

Example usage

dbtgen model-properties -s staging -uv --target prod

TO DO

Include deep merge of existing complex YAML structures, in order to overlay any pre-existing model properties file with the one generated by the application. This will preserve descriptions in the .yml file that is created.


source

  dbtgen source [OPTIONS]

package

  dbtgen package

This command takes all dbt models defined in properties files (*.yml) from the dbt project and creates a sources YAML file for each.

These are generated in: ./.export/<project-name>/sources/.

These sources files will form part of another "export" dbt project that can be used as a package and imported into any dependent project(s).


clean

  dbtgen clean

This will clean up all temporary files created by dbtgen.

The files which are cleaned by this command are controlled using the params.CLEAN_PATHS list of glob strings.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.