generate-missing-sources
What it doesIf any source is missing this hook tries to create it.When to use itYou are too lazy to define schemas manually :D.
--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
-- as the last argument. Otherwise pre-commit would not be able to separate a list of files with args.
Requirements
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.
schema-file, something like this:
unify-column-description
What it doesUnify column descriptions across all models.When to use itYou want the descriptions of the same columns to be the same. E.g. in two of your models, you have
customer_id with the description This is cutomer_id, but there is one model where column customer_id has a description Something else. This hook finds discrepancies between column descriptions and replaces them. So as the results all columns going to have the description This is customer_id--ignore: Columns for which do not check whether have a different description.
Example
-- as the last argument. Otherwise pre-commit would not be able to separate a list of files with args.
Requirements
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.
replace-script-table-names
What it doesReplace table names with
source or ref macros in the script.When to use itYou are running and debugging your SQL in the editor. This editor does not know source or ref macros. So every time you copy the script from the editor into dbt project you need to rewrite all table names to source or ref. That’s boring and error-prone. If you run this hook it will replace all table names with macros instead of you.--manifest: location of manifest.json file. Usually target/manifest.json. This file contains a full representation of dbt project. Default: target/manifest.json.
Example
-- as the last argument. Otherwise pre-commit would not be able to separate a list of files with args.
Requirements
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
What it doesGenerate model properties file if does not exist.When to use itYou are running and debugging your
SQL in the editor. This editor does not know source or ref macros. So every time you copy the script from the editor into dbt project you need to rewrite all table names to source or ref. That’s boring and error-prone. If you run this hook it will replace all table names with macros instead of you.--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 , , and variables. E.g. /models//.yml for model foo.bar will create properties file in /models/foo/bar.yml. If path already exists, properties are appended.
Example
-- as the last argument. Otherwise pre-commit would not be able to separate a list of files with args.
Requirements
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.
remove-script-semicolon
What it doesRemove the semicolon at the end of the script.When to use itYou are too lazy or forgetful to delete one character at the end of the script.
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.