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

Add GH Action to drop staging db if PR is closed #196

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .github/workflows/closed_py_cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Drop test db if pr is closed

on: # yamllint disable-line rule:truthy
pull_request:
types:
- closed

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

# This cancels a run if another change is pushed to the same branch
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
dbt:
name: Pull Request dbt Tests
runs-on: ubuntu-latest

# Set environment variables in
# https://github.com//<your org>/<your repo>/settings/variables/actions
#
# Alternatively, You can define multiple ENV for different workflows.
# https://github.com/<org>/<repo>/settings/environments
# environment: PR_ENV
container: datacoves/ci-basic-dbt-snowflake:2

defaults:
run:
working-directory: /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }}/transform

env:
DBT_PROFILES_DIR: /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }}/automate/dbt
DATACOVES__DBT_HOME: /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }}/transform
DATACOVES__YAML_DAGS_FOLDER: /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }}/schedule

DATACOVES__MAIN__ACCOUNT: ${{ vars.DATACOVES__MAIN__ACCOUNT }}

DATACOVES__MAIN__DATABASE: ${{ vars.DATACOVES__MAIN__DATABASE }}_PR_${{ github.event.number }}
DATACOVES__MAIN__SCHEMA: ${{ vars.DATACOVES__MAIN__SCHEMA }}

DATACOVES__MAIN__ROLE: ${{ vars.DATACOVES__MAIN__ROLE }}
DATACOVES__MAIN__WAREHOUSE: ${{ vars.DATACOVES__MAIN__WAREHOUSE }}

DATACOVES__MAIN__USER: ${{ vars.DATACOVES__MAIN__USER }}
DATACOVES__MAIN__PASSWORD: ${{ secrets.DATACOVES__MAIN__PASSWORD }}


steps:
- name: Checkout branch
uses: actions/[email protected]
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}

- name: Set Secure Directory
run: git config --global --add safe.directory /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }}

- name: Install dbt packages
run: "dbt deps"

- name: Drop PR database
run: "dbt --no-write-json run-operation drop_recreate_db --args '{db_name: ${{env.DATACOVES__MAIN__DATABASE}}, recreate: False}'" # yamllint disable-line rule:line-length
10 changes: 6 additions & 4 deletions transform/macros/tooling/drop_recreate_db.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{# This macro drops and recreates in a given database #}
{#
To run:
To run:
dbt run-operation drop_recreate_db --args '{db_name: dev_commercial_dw2, recreate: False}'
#}

Expand All @@ -11,10 +11,12 @@
drop database if exists {{ db_name }};
{% if recreate %}
create database if not exists {{ db_name }};
{{ log("Recreating Database: " ~ db_name, info=true) }}
{{ print("Recreating Database: " ~ db_name) }}
{% else %}
{{ print("Dropped Database: " ~ db_name) }}
{% endif %}
{% endset %}

{% do run_query(drop_recreate_sql) %}

{% if recreate %}
Expand All @@ -27,4 +29,4 @@
{% do run_query(apply_grants_sql) %}
{% endif %}

{%- endmacro -%}
{%- endmacro -%}
2 changes: 2 additions & 0 deletions transform/models/L1_inlets/loans/personal_loans.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ models:
description: The state in which the borrower resides
meta:
masking_policy: masking_policy_pii_string
tests:
- not_null
- name: annual_inc
description: The borrower's annual income
meta:
Expand Down
Loading