Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write database-specific sample profiles.yml file in dbt init #2533

Closed
drewbanin opened this issue Jun 10, 2020 · 6 comments · Fixed by dbt-labs/dbt-presto#26, dbt-labs/dbt-spark#98 or #2594
Labels
enhancement New feature or request

Comments

@drewbanin
Copy link
Contributor

drewbanin commented Jun 10, 2020

Describe the feature

Let's add a flag to dbt init which controls the sample contents of the ~/.dbt/profiles.yml file.

Example usage:

dbt init my-project --adapter=bigquery
dbt init my-project --adapter=snowflake
dbt init my-project --adapter=redshift

dbt's adapter plugins should provide their own sample profiles .yml contents. Presently, dbt writes out a Redshift-specific profile.

Additional context

Hi Felipe :)

Who will this benefit?

BQ/Snowflake/Postgres/Spark/Presto users!

@drewbanin drewbanin added the enhancement New feature or request label Jun 10, 2020
@drewbanin drewbanin changed the title Write database-specific sample profiles.yml file Write database-specific sample profiles.yml file in dbt init Jun 10, 2020
@brunomurino
Copy link
Contributor

I'm happy to take this, if still available @drewbanin

@brunomurino
Copy link
Contributor

I'm trying to set up a try-catch with the possible adapter options, but can't seem to find a 'list' of possible adapters. I found some stuff in dbt/core/dbt/include/global_project/macros/adapters/common.sql but not sure this is it.

My idea is to create a template profiles.yml in each adapter folder and create a dictionary such that STARTER_PROFILE[sample_adapter] would get the sample from the adapter.

How does that sound?

@beckjake
Copy link
Contributor

beckjake commented Jun 25, 2020

I'm trying to set up a try-catch with the possible adapter options, but can't seem to find a 'list' of possible adapters.

There is no formal list of possible adapters, because users can write their own adapter plugins.

My idea is to create a template profiles.yml in each adapter folder

In #2590, I added a get_include_paths function to dbt.adapters.factory, and the first item in the return value of get_include_paths is always the given adapter's project. Assuming it gets merged, that might make this easier. Each adapter plugin could have a sample_profiles.yml inside its include path (so alongside the dbt_project.yml), and you could use that and the --adapter argument to decide what to use.

You'd have to do something like:

factory.load_plugin(args.adapter)
path = factory.get_include_paths(args.adapter)[0]
sample_path = path / 'sample_profiles.yml'
if not sample_path.exists():
    raise RuntimeException(f'No sample profile for {args.adapter}')
shutil.copy_file(sample_path, dest)

If the chosen adapter is installed and has a sample profile, it should behave okay.

@brunomurino
Copy link
Contributor

makes sense, it would indeed make it easier.

I'm trying to checkout the branch fix/adapter-macro-namespacing but can't find it (?).
If I can't check that out, then I'd just wait on your PR to bet merged

@beckjake
Copy link
Contributor

@brunomurino you might have to set up fishtown-analytics/dbt as a git remote and git fetch that, I think like this:

git remote add upstream https://github.com/fishtown-analytics/dbt.git
git fetch upstream
git checkout upstream/fix/adapter-macro-namespacing

That will probably drop you into a detached HEAD state, so then you'll need to use git checkout -b to create a new local branch

@brunomurino
Copy link
Contributor

Worked like a charm.

Just created the PR for this: #2594
alongside PRs for presto and spark.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
3 participants