Skip to content

Commit

Permalink
Merge pull request #25 from brooklyn-data/2.0.0
Browse files Browse the repository at this point in the history
Release 2.0.0
  • Loading branch information
NiallRees authored Mar 28, 2022
2 parents a6e2020 + 9533927 commit 27d1a99
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

## [2.0.0](https://github.com/brooklyn-data/dbtenv/compare/v2.0.0a2...v2.0.0)

### Added
- dbtenv now operates at the adapter-version level, introduced by dbt in version 1.0.0. dbtenv can automatically detect the needed adapter version from `profiles.yml`, or the `--adapter` argument set in a dbt command passed to `dbtenv --execute`.
- The execute command's `--dbt` argument can now take either a dbt version (e.g. 1.0.0) or full pip specifier to use (e.g. dbt-snowflake==1.0.0). dbtenv will attempt to automatically detect the required adapter or version from the environment if not specified.
- dbtenv's version command and config files can now use a dbt version (e.g. 1.0.0) or full pip specifier to use (e.g. dbt-snowflake==1.0.0). dbtenv will attempt to automatically detect the required adapter or version from the environment if not specified.

### Changed
- Dropped support for Homebrew.
- Previously created environments through dbtenv 1.0.0 will be ignored.
- dbtenv's default behaviour is now to install missing dbt adapter versions automatically. It can be disabled by setting the `DBTENV_AUTO_INSTALL` environment variable to `false`.
- Attempting to install a version of dbt which doesn't exist will exit cleanly, and provide a list of available versions for that adapter.
- Failed dbt version installations exit cleanly, removing the created virtual environment.

### Fixed
- Only entries in the environment directory which are dbtenv 2.0.0 environments will be read as installed dbt versions, fixing an issue where dbtenv 1.0.0 environments caused a failure.
- Fixed version command, and all dbtenv config files. These can now take either a dbt version (e.g. 1.0.0) or full pip specifier to use (e.g. dbt-snowflake==1.0.0). dbtenv will attempt to automatically detect the required adapter or version from the environment if not specified.

## [2.0.0a2](https://github.com/brooklyn-data/dbtenv/compare/v2.0.0a1...v2.0.0a2)

### Added
Expand Down
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ dbtenv is a version manager for dbt, automatically installing and switching to t
1. Install [pipx](https://pypa.github.io/pipx/) if you haven't already.
2. Run `pipx install dbtenv`.

## Basic example usage

Run `dbtenv execute -- build` in a dbt project, and dbtenv will automatically download the required adapter and version for the project and run `dbt build`. We recommend [setting up an alias to dbtenv](https://github.com/brooklyn-data/dbtenv#running-dbt-with-dbtenv-more-seamlessly) so that you can run dbt commands as normal but through dbtenv.


## How it works

Expand All @@ -28,7 +32,7 @@ Some tips:

### Switching between dbt versions
#### Adapter type
If a dbtenv command is invoked from within a dbt project, dbtenv will try to determine the in-use adapter from the default set for the project's profile in `profiles.yml`. If the `--adapter` argument is set in the dbt command passed to `dbtenv execute`, dbtenv will use that adapter's type instead.
If a dbtenv command is invoked from within a dbt project, dbtenv will try to determine the in-use adapter from the default set for the project's profile in `profiles.yml`. If the `--adapter` argument is set in the dbt command passed to `dbtenv execute`, dbtenv will use that adapter's type instead. If running outside of a dbt project, a pip specifier should be passed to dbtenv execute's `--dbt` argument so that dbtenv knows which adapter to use.

#### dbt version

Expand All @@ -37,7 +41,7 @@ dbtenv determines which dbt version to use by trying to read it from the followi
1. The `dbtenv execute` command's optional `--dbt <version>` argument.
2. A `DBT_VERSION` environment variable.
3. A `.dbt_version` file in the dbt project directory.
4. The [dbt version requirements](https://docs.getdbt.com/reference/project-configs/require-dbt-version/) of the dbt project and any dbt packages it uses.
4. The [dbt version requirements](https://docs.getdbt.com/reference/project-configs/require-dbt-version/) of the dbt project.
- If the dbt version requirements specify a range of versions rather than an exact version, then dbtenv will try to read a preferred dbt version from the sources below and will use that version if it's compatible with the requirements.
5. The first `.dbt_version` file found by searching the dbt project's parent directories.
6. The `~/.dbt/version` file.
Expand All @@ -47,15 +51,17 @@ dbtenv determines which dbt version to use by trying to read it from the followi
You can:
- Run `dbtenv version` to show which dbt version dbtenv determines dynamically based on the current environment.
- Run `dbtenv which` to show the full path to the executable of the dbt version dbtenv determines dynamically based on the current environment.
- Run `dbtenv version --global <version>` to set the dbt version globally in the `~/.dbt/version` file.
- Run `dbtenv version --local <version>` to set the dbt version for the current directory in a `.dbt_version` file.
- Run `dbtenv version --global <version>` to set the dbt version globally in the `~/.dbt/version` file. The `<version>` can be either a dbt version (e.g. 1.0.0) or full pip specifier (e.g. dbt-snowflake==1.0.0). dbtenv will attempt to automatically detect the required adapter or version from the environment if not specified.
- Run `dbtenv version --local <version>` to set the dbt version for the current directory in a `.dbt_version` file. The `<version>` can be either a dbt version (e.g. 1.0.0) or full pip specifier (e.g. dbt-snowflake==1.0.0). dbtenv will attempt to automatically detect the required adapter or version from the environment if not specified.

### Running dbt through dbtenv
Run `dbtenv execute -- <dbt arguments>` to execute the dbt version determined dynamically based on the current environment, or run `dbtenv execute --dbt <version> -- <dbt arguments>` to execute the specified dbt version.

For example:
- `dbtenv execute -- run` will execute `dbt run` using the version determined dynamically based on the current environment.
- `dbtenv execute --dbt 0.19.0 -- run` will execute `dbt run` using dbt 0.19.0.
- `dbtenv execute --dbt 1.0.0 -- run` will execute `dbt run` using dbt 1.0.0, automatically detecting the required adapter from the default target in `profiles.yml`.
- `dbtenv execute --dbt 1.0.0 -- run --target prod` will execute `dbt run` using dbt 1.0.0, using the required adapter for the 'prod' target in `profiles.yml`.
- `dbtenv execute --dbt 1.0.0==dbt-bigquery -- run` will execute `dbt run` using dbt-bigquery==1.0.0.

**Important:** It's highly recommended to put two dashes with spaces on both sides before the list of dbt arguments (as shown in the examples above) so that dbtenv doesn't try to interpret the dbt arguments itself.

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dbtenv"
version = "2.0.0a2"
version = "2.0.0"
description = "dbtenv is a version manager for dbt, automatically installing and switching to the needed adapter and version of dbt."
authors = ["Brooklyn Data Co. <[email protected]>"]
keywords = ["dbt"]
Expand Down

0 comments on commit 27d1a99

Please sign in to comment.