|
| 1 | +import os |
1 | 2 | from pathlib import Path
|
2 |
| -from ddpui.models.org import OrgWarehouse, OrgDbt |
3 |
| -from ddpui.utils import secretsmanager |
4 |
| -from dbt_automation.utils.warehouseclient import get_client |
5 | 3 |
|
6 |
| -# operations |
7 |
| -from dbt_automation.operations.flattenjson import flattenjson |
8 | 4 | from dbt_automation.operations.arithmetic import arithmetic
|
9 | 5 | from dbt_automation.operations.castdatatypes import cast_datatypes
|
10 | 6 | from dbt_automation.operations.coalescecolumns import coalesce_columns
|
11 | 7 | from dbt_automation.operations.concatcolumns import concat_columns
|
12 | 8 | from dbt_automation.operations.droprenamecolumns import drop_columns, rename_columns
|
13 | 9 | from dbt_automation.operations.flattenairbyte import flatten_operation
|
| 10 | + |
| 11 | +# operations |
| 12 | +from dbt_automation.operations.flattenjson import flattenjson |
14 | 13 | from dbt_automation.operations.mergetables import union_tables
|
15 | 14 | from dbt_automation.operations.regexextraction import regex_extraction
|
| 15 | +from dbt_automation.operations.syncsources import sync_sources |
| 16 | +from dbt_automation.utils.warehouseclient import get_client |
| 17 | +from dbt_automation.utils.dbtproject import dbtProject |
16 | 18 |
|
| 19 | +from ddpui.models.org import OrgDbt, OrgWarehouse |
| 20 | +from ddpui.utils import secretsmanager |
17 | 21 |
|
18 | 22 | OPERATIONS_DICT = {
|
19 | 23 | "flatten": flatten_operation,
|
@@ -52,3 +56,20 @@ def create_dbt_model_in_project(
|
52 | 56 | )
|
53 | 57 |
|
54 | 58 | return str(sql_file_path), None
|
| 59 | + |
| 60 | + |
| 61 | +def sync_sources_to_dbt( |
| 62 | + schema_name: str, source_name: str, org: str, org_warehouse: str |
| 63 | +): |
| 64 | + """ |
| 65 | + Sync sources from a given schema to dbt. |
| 66 | + """ |
| 67 | + warehouse_client = _get_wclient(org_warehouse) |
| 68 | + |
| 69 | + sources_file_path = sync_sources( |
| 70 | + config={"source_schema": schema_name, "source_name": source_name}, |
| 71 | + warehouse=warehouse_client, |
| 72 | + dbtproject=dbtProject(Path(os.getenv("CLIENTDBT_ROOT")) / org.slug / "dbtrepo"), |
| 73 | + ) |
| 74 | + |
| 75 | + return str(sources_file_path), None |
0 commit comments