dbt™️ Modifiers
generate-missing-sources
generate-missing-sourcesArguments
--manifest: location of manifest.json file. Usually target/manifest.json. This file contains a full representation of dbt project. Default: target/manifest.json.
--schema-file: Location of schema.yml file. Where new source tables should be created.
Example
repos:
- repo: https://github.com/dbt-checkpoint/dbt-checkpoint
rev: v1.0.0
hooks:
- id: generate-missing-sources
args: ["--schema-file", "models/schema.yml", "--"]⚠️ do not forget to include -- as the last argument. Otherwise pre-commit would not be able to separate a list of files with args.
Requirements
Model exists in manifest.json1
Model exists in catalog.json 2
❌ Not needed since this hook tries to generate even non-existent source
❌ Not needed
1 It means that you need to run dbt parse before run this hook (dbt >= 1.5).
2 It means that you need to run dbt docs generate before run this hook.
How it works
Hook takes all changed
SQLfiles.SQL is parsed to find all sources.
If the source exists in the manifest, nothing is done.
If not, a new source is created in specified
schema-fileand the hook fails.
Known limitations
Source "envelope" has to exist in specified schema-file, something like this:
version: 2
sources:
- name: <source_name>Otherwise, it is not possible to automatically generate a new source table.
Unfortunately, this hook breaks your formatting.
unify-column-description
unify-column-descriptionArguments
--ignore: Columns for which do not check whether have a different description.
Example
repos:
- repo: https://github.com/dbt-checkpoint/dbt-checkpoint
rev: v1.0.0
hooks:
- id: generate-missing-sources
args: ["--schema-file", "models/schema.yml", "--"]⚠️ do not forget to include -- as the last argument. Otherwise pre-commit would not be able to separate a list of files with args.
Requirements
Model exists in manifest.json 1
Model exists in catalog.json 2
❌ Not needed since this hook is using only yaml files
❌ Not needed
1 It means that you need to run dbt parse before run this hook (dbt >= 1.5).
2 It means that you need to run dbt docs generate before run this hook.
How it works
Hook takes all changed
YAMLfiles.From those files columns are parsed and compared.
If one column name has more than one (not empty) description, the description with the most occurrences is taken and the hook fails.
If it is not possible to decide which description is dominant, no changes are made.
Known limitations
If it is not possible to decide which description is dominant, no changes are made.
replace-script-table-names
replace-script-table-namesArguments
--manifest: location of manifest.json file. Usually target/manifest.json. This file contains a full representation of dbt project. Default: target/manifest.json.
Example
repos:
- repo: https://github.com/dbt-checkpoint/dbt-checkpoint
rev: v1.0.0
hooks:
- id: replace-script-table-names⚠️ do not forget to include -- as the last argument. Otherwise pre-commit would not be able to separate a list of files with args.
Requirements
Model exists in manifest.json 1
Model exists in catalog.json 2
✅ Yes
❌ Not needed
1 It means that you need to run dbt parse before run this hook (dbt >= 1.5).
2 It means that you need to run dbt docs generate before run this hook.
How it works
Hook takes all changed
SQLfiles.SQL is parsed and table names are found.
Firstly it tries to find table name in models -
ref.Then it tries to find a table in sources -
source.If nothing is found it creates unknown
sourceassource('<schema_name>', '<table_name>')If the script contains only
refandsourcemacros, the hook success.
generate-model-properties-file
generate-model-properties-fileArguments
--manifest: location of manifest.json file. Usually target/manifest.json. This file contains a full representation of dbt project. Default: target/manifest.json.
--catalog: location of catalog.json file. Usually target/catalog.json. dbt uses this file to render information like column types and table statistics into the docs site. In dbt-checkpoint is used for column operations. Default: target/catalog.json
--properties-file: Location of file where new model properties should be generated. Suffix has to be yml or yaml. It can also include {database}, {schema}, {name} and {alias} variables. E.g. /models/{schema}/{name}.yml for model foo.bar will create properties file in /models/foo/bar.yml. If path already exists, properties are appended.
Example
repos:
- repo: https://github.com/dbt-checkpoint/dbt-checkpoint
rev: v1.0.0
hooks:
- id: generate-model-properties-file
args: ["--properties-file", "models/{schema}/{name}.yml", "--"]⚠️ do not forget to include -- as the last argument. Otherwise pre-commit would not be able to separate a list of files with args.
Requirements
Model exists in manifest.json 1
Model exists in catalog.json 2
✅ Yes
❌ Yes
1 It means that you need to run dbt parse before run this hook (dbt >= 1.5).
2 It means that you need to run dbt docs generate before run this hook.
How it works
Hook takes all changed
SQLfiles.The model name is obtained from the
SQLfile name.The manifest is scanned for a model.
The catalog is scanned for a model.
If the model does not have
patch_pathin the manifest, the new schema is written to the specified path. The hook fails.
Known limitations
Unfortunately, this hook breaks your formatting in the written file.
remove-script-semicolon
remove-script-semicolonExample
repos:
- repo: https://github.com/dbt-checkpoint/dbt-checkpoint
rev: v1.0.0
hooks:
- id: remove-script-semicolonRequirements
Model exists in manifest.json 1
Model exists in catalog.json 2
❌ Not needed
❌ Not needed
1 It means that you need to run dbt parse before run this hook (dbt >= 1.5).
2 It means that you need to run dbt docs generate before run this hook.
How it works
Hook takes all changed
SQLfiles.If the file contains a semicolon at the end of the file, it is removed and the hook fails.
Last updated
Was this helpful?