Skip to content

Commit

Permalink
Merge pull request #1 from Agilefreaks/create_dbt_project
Browse files Browse the repository at this point in the history
[Create DBT Project] Add DBT Project
  • Loading branch information
Aciroh authored Apr 20, 2024
2 parents 7c80859 + 41de806 commit 7ff28eb
Show file tree
Hide file tree
Showing 13 changed files with 154 additions and 0 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/dbt_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# This is a basic workflow to help you get started with Actions

name: DBT Build

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
pull_request:

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

env:
pass_prod: ${{ secrets.PASS_PROD }}
pass_dev: ${{ secrets.PASS_DEV }}
dbname: ${{ vars.DBNAME }}
host: ${{ vars.HOST }}
port: ${{ vars.PORT }}
user_prod: ${{ vars.USER_PROD }}
user_dev: ${{ vars.USER_DEV }}

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: [self-hosted]
environment: dbt

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.8"

- name: Install dependencies
run: |
pip install -r requirements.txt
dbt deps
# Add dbt seed or other commands here if needed
- name: Build dbt models
run: dbt build
4 changes: 4 additions & 0 deletions dbt/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

target/
dbt_packages/
logs/
1 change: 1 addition & 0 deletions dbt/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
opendataexplorer_dbt
Empty file added dbt/analyses/.gitkeep
Empty file.
37 changes: 37 additions & 0 deletions dbt/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

# 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: 'opendataexplorer'
version: '1.0.0'
config-version: 2

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

# These configurations specify where dbt should look for different types of files.
# The `model-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!
model-paths: ["models"]
analysis-paths: ["analyses"]
test-paths: ["tests"]
seed-paths: ["seeds"]
macro-paths: ["macros"]
snapshot-paths: ["snapshots"]

clean-targets: # directories to be removed by `dbt clean`
- "target"
- "dbt_packages"


# 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 views. These settings can be overridden in the individual model
# files using the `{{ config(...) }}` macro.
models:
opendataexplorer:
# Config indicated by + and applies to all files under models/example/
example:
+materialized: view
Empty file added dbt/macros/.gitkeep
Empty file.
27 changes: 27 additions & 0 deletions dbt/models/example/my_first_dbt_model.sql
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
6 changes: 6 additions & 0 deletions dbt/models/example/my_second_dbt_model.sql
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 dbt/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
11 changes: 11 additions & 0 deletions dbt/profiles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
opendataexplorer:
outputs:
dev:
dbname: db_name
host: hostname
port: 5432
schema: db_schema
threads: 1
user: "{{ env_var('user_dev') }}"
pass: "{{ env_var('pass_dev') }}"
target: dev
Empty file added dbt/seeds/.gitkeep
Empty file.
Empty file added dbt/snapshots/.gitkeep
Empty file.
Empty file added dbt/tests/.gitkeep
Empty file.

0 comments on commit 7ff28eb

Please sign in to comment.