Skip to content

Commit

Permalink
Move starter project into dbt repo (dbt-labs#3474)
Browse files Browse the repository at this point in the history
Addresses issue dbt-labs#3005
  • Loading branch information
leahwicz authored Jun 22, 2021
1 parent 9d414f6 commit c794600
Show file tree
Hide file tree
Showing 14 changed files with 122 additions and 24 deletions.
2 changes: 1 addition & 1 deletion core/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
recursive-include dbt/include *.py *.sql *.yml *.html *.md
recursive-include dbt/include *.py *.sql *.yml *.html *.md .gitkeep
15 changes: 15 additions & 0 deletions core/dbt/include/starter_project/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Welcome to your new dbt project!

### Using the starter project

Try running the following commands:
- dbt run
- dbt test


### Resources:
- Learn more about dbt [in the docs](https://docs.getdbt.com/docs/introduction)
- Check out [Discourse](https://discourse.getdbt.com/) for commonly asked questions and answers
- Join the [chat](https://community.getdbt.com/) on Slack for live discussions and support
- Find [dbt events](https://events.getdbt.com) near you
- Check out [the blog](https://blog.getdbt.com/) for the latest news on dbt's development and best practices
3 changes: 3 additions & 0 deletions core/dbt/include/starter_project/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import os

PACKAGE_PATH = os.path.dirname(__file__)
Empty file.
Empty file.
38 changes: 38 additions & 0 deletions core/dbt/include/starter_project/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

# Name your project! Project names should contain only lowercase characters
# and underscores. A good package name should reflect your organization's
# name or the intended use of these models
name: 'my_new_project'
version: '1.0.0'
config-version: 2

# This setting configures which "profile" dbt uses for this project.
profile: 'default'

# These configurations specify where dbt should look for different types of files.
# The `source-paths` config, for example, states that models in this project can be
# found in the "models/" directory. You probably won't need to change these!
source-paths: ["models"]
analysis-paths: ["analysis"]
test-paths: ["tests"]
data-paths: ["data"]
macro-paths: ["macros"]
snapshot-paths: ["snapshots"]

target-path: "target" # directory which will store compiled SQL files
clean-targets: # directories to be removed by `dbt clean`
- "target"
- "dbt_modules"


# Configuring models
# Full documentation: https://docs.getdbt.com/docs/configuring-models

# In this example config, we tell dbt to build all models in the example/ directory
# as tables. These settings can be overridden in the individual model files
# using the `{{ config(...) }}` macro.
models:
my_new_project:
# Config indicated by + and applies to all files under models/example/
example:
+materialized: view
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

/*
Welcome to your first dbt model!
Did you know that you can also configure models directly within SQL files?
This will override configurations stated in dbt_project.yml
Try changing "table" to "view" below
*/

{{ config(materialized='table') }}

with source_data as (

select 1 as id
union all
select null as id

)

select *
from source_data

/*
Uncomment the line below to remove records with null `id` values
*/

-- where id is not null
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

-- Use the `ref` function to select from other models

select *
from {{ ref('my_first_dbt_model') }}
where id = 1
21 changes: 21 additions & 0 deletions core/dbt/include/starter_project/models/example/schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

version: 2

models:
- name: my_first_dbt_model
description: "A starter dbt model"
columns:
- name: id
description: "The primary key for this table"
tests:
- unique
- not_null

- name: my_second_dbt_model
description: "A starter dbt model"
columns:
- name: id
description: "The primary key for this table"
tests:
- unique
- not_null
Empty file.
Empty file.
22 changes: 10 additions & 12 deletions core/dbt/task/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@
import shutil

import dbt.config
import dbt.clients.git
import dbt.clients.system
from dbt.adapters.factory import load_plugin, get_include_paths
from dbt.exceptions import RuntimeException

from dbt.logger import GLOBAL_LOGGER as logger

from dbt.include.starter_project import PACKAGE_PATH as starter_project_directory

from dbt.task.base import BaseTask

STARTER_REPO = 'https://github.com/fishtown-analytics/dbt-starter-project.git'
STARTER_BRANCH = 'dbt-yml-config-version-2'
DOCS_URL = 'https://docs.getdbt.com/docs/configure-your-profile'

# This file is not needed for the starter project but exists for finding the resource path
IGNORE_FILE = "__init__.py"

ON_COMPLETE_MESSAGE = """
Your new dbt project "{project_name}" was created! If this is your first time
using dbt, you'll need to set up your profiles.yml file (we've created a sample
Expand All @@ -36,14 +38,10 @@


class InitTask(BaseTask):
def clone_starter_repo(self, project_name):
dbt.clients.git.clone(
STARTER_REPO,
cwd='.',
dirname=project_name,
remove_git_dir=True,
revision=STARTER_BRANCH,
)
def copy_starter_repo(self, project_name):
logger.debug("Starter project path: " + starter_project_directory)
shutil.copytree(starter_project_directory, project_name,
ignore=shutil.ignore_patterns(IGNORE_FILE))

def create_profiles_dir(self, profiles_dir):
if not os.path.exists(profiles_dir):
Expand Down Expand Up @@ -98,7 +96,7 @@ def run(self):
project_dir
))

self.clone_starter_repo(project_dir)
self.copy_starter_repo(project_dir)

addendum = self.get_addendum(project_dir, profiles_dir, sample_adapter)
logger.info(addendum)
12 changes: 1 addition & 11 deletions core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,7 @@ def read(fname):
author_email="info@fishtownanalytics.com",
url="https://github.com/fishtown-analytics/dbt",
packages=find_namespace_packages(include=['dbt', 'dbt.*']),
package_data={
'dbt': [
'include/index.html',
'include/global_project/dbt_project.yml',
'include/global_project/docs/*.md',
'include/global_project/macros/*.sql',
'include/global_project/macros/**/*.sql',
'include/global_project/macros/**/**/*.sql',
'py.typed',
]
},
include_package_data = True,
test_suite='test',
entry_points={
'console_scripts': [
Expand Down

0 comments on commit c794600

Please sign in to comment.