dbt v0.11.0 introduces a new syntax for schema.yml files. This syntax is more flexible and expressive than the v1 spec, making it possible to add documentation strings for columns and models. Documentation for this new syntax can be found here.
Migrating from the v1 syntax to the v2 syntax manually can be tedious, so we’ve created a helpful script to automatically migrate your schema.yml files. Follow along for instructions on using the script.
Pre-Requisites
This guide assumes that you’re using macOS or Linux.
The script below requires that the PyYAML
module is installed in your python environment, eg. with:
pip install PyYAML
Migration guide
-
First, make sure your dbt project is checked into a version control system (like git). Also make sure that there are no uncommitted changes in your repo, as the script below will overwrite your schema.yml files with their v2 representations.
-
cd
to the root of your dbt project (wheredbt_project.yml
lives) -
Download the script:
curl -o upgrade_dbt_schema_tests_v1_to_v2.py https://raw.githubusercontent.com/fishtown-analytics/dbt/development/scripts/upgrade_dbt_schema_tests_v1_to_v2.py
- Run the script in dry-run mode. Changes will not be applied, but the script will validate your schema.yml files and report on the files that it would upgrade.
python upgrade_dbt_schema_tests_v1_to_v2.py .
- If everything looks good, run with
--apply
to apply the changes:
python upgrade_dbt_schema_tests_v1_to_v2.py . --apply
After running the last command, a git status
should show you that your schema.yml files have been upgraded and new .backup
files were created with the previous versions of your schema.yml files.
If everything looks good, then we can clean up the .backup
files:
# Be careful with this - it will delete files called schema.yml.backup in your `models` directory
find models -name schema.yml.backup -exec rm {} \;
And that’s it! dbt test
should work exactly as it did before, but you should now have v2 schema.yml files. Happy documenting