Abhishek Singh
07/22/2024, 6:00 PMMarvin
07/22/2024, 6:00 PMpython
from prefect import flow, task
from prefect_dbt import DbtCoreOperation
@task
def dbt_run():
return DbtCoreOperation(
commands=["dbt run"],
project_dir="/path/to/your/dbt/project",
profiles_dir="/path/to/your/dbt/profiles"
).run()
@task
def dbt_test():
return DbtCoreOperation(
commands=["dbt test"],
project_dir="/path/to/your/dbt/project",
profiles_dir="/path/to/your/dbt/profiles"
).run()
@task
def dbt_docs():
return DbtCoreOperation(
commands=["dbt docs generate"],
project_dir="/path/to/your/dbt/project",
profiles_dir="/path/to/your/dbt/profiles"
).run()
@flow
def dbt_flow():
dbt_run()
dbt_test()
dbt_docs()
if __name__ == "__main__":
dbt_flow()
This script defines three tasks (dbt_run
, dbt_test
, dbt_docs
) to run dbt
commands sequentially within the dbt_flow
. Adjust the paths for your dbt
project and profiles as necessary.
Feel free to reach out for more details: https://docs.prefect.io/latest/