Skip to content

Commit c9fb292

Browse files
authored
Config: Combine Sources & Destinations (#79)
Closes #75 We use `data_sources` as a single list in place of sources and destinations. its up to the user to provide the correct credentials.
1 parent b6dc59a commit c9fb292

File tree

11 files changed

+22
-67
lines changed

11 files changed

+22
-67
lines changed

README.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,16 @@
66

77
Configuration is provided in a single YAML file. Refer to the existing `config.yaml` for an overview.
88
The configuration file consists of three main sections:
9-
- `sources`: Defines available data sources
10-
- `destinations`: Defines available data destinations
9+
- `data_sources`: Defines available databases
1110
- `jobs`: Defines synchronization jobs that connect sources to destinations
1211

13-
#### Source Definitions
12+
#### Data Source Definitions
1413

1514
Sources are defined as a list of configurations, each containing:
1615
- `name`: String. A unique identifier for referencing this source in jobs
1716
- `type`: String. Must be either `dune` or `postgres`
1817
- `key`: String. Connection details, supports environment variable templating using `${VAR_NAME}` syntax such as `${DB_URL}` or `${DUNE_API_KEY}` ([see environment setup](#define-environment))
1918

20-
#### Destination Definitions
21-
22-
Destinations are defined similarly to sources:
23-
- `name`: String. A unique identifier for referencing this destination in jobs
24-
- `type`: String. Must be either `dune` or `postgres`
25-
- `key`: String. Connection details, supports environment variable templating using `${VAR_NAME}` syntax
26-
2719
#### Job Parameters
2820

2921
Each job in the `jobs` list should contain:

config.yaml

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
1-
sources:
2-
- name: Dune1
1+
data_sources:
2+
- name: Dune
33
type: dune
44
key: ${DUNE_API_KEY}
5-
- name: PG1
6-
type: postgres
7-
key: ${DB_URL}
8-
9-
destinations:
10-
- name: Dune1
11-
type: dune
12-
key: ${DUNE_API_KEY}
13-
- name: PG1
5+
- name: PG
146
type: postgres
157
key: ${DB_URL}
168

179
jobs:
1810
- name: Sync Parameterized Dune Query with Multiple Types to Postgres
1911
source:
20-
ref: Dune1
12+
ref: Dune
2113
query_id: 4238114
2214
query_engine: medium
2315
poll_frequency: 5
@@ -32,16 +24,16 @@ jobs:
3224
value: "10"
3325
type: NUMBER
3426
destination:
35-
ref: PG1
27+
ref: PG
3628
table_name: results_4238114
3729
if_exists: replace
3830

3931
- name: Table Independent Query to Dune
4032
source:
41-
ref: PG1
33+
ref: PG
4234
query_string: "SELECT 1 as number, '\\x1234'::bytea as my_bytes;"
4335
destination:
44-
ref: Dune1
36+
ref: Dune
4537
table_name: dune_sync_test_table
4638

4739
- name: Sync Parameterized Dune Query with Multiple Types to Postgres

src/config.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -189,23 +189,16 @@ def load_from_yaml(cls, file_path: Path | str = "config.yaml") -> RuntimeConfig:
189189
with open(file_path, "rb") as _handle:
190190
data = yaml.safe_load(_handle)
191191

192-
# Load sources map
192+
# Load data sources map
193193
sources = {}
194-
for source in data.get("sources", []):
195-
sources[str(source["name"])] = DbRef.from_dict(source)
196-
197-
# Load destinations map
198-
destinations = {}
199-
for destination in data.get("destinations", []):
200-
destinations[str(destination["name"])] = DbRef.from_dict(destination)
194+
for db_ref in data.get("data_sources", []):
195+
sources[str(db_ref["name"])] = DbRef.from_dict(db_ref)
201196

202197
jobs = []
203198
for job_config in data.get("jobs", []):
204199
source = cls._build_source(job_config["source"], sources)
205-
destination = cls._build_destination(
206-
job_config["destination"], destinations
207-
)
208-
jobs.append(Job(source, destination))
200+
dest = cls._build_destination(job_config["destination"], sources)
201+
jobs.append(Job(source, dest))
209202

210203
return cls(jobs=jobs)
211204

tests/fixtures/config/basic.yaml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
11
---
2-
sources:
2+
data_sources:
33
- name: dune
44
type: dune
55
key: ${DUNE_API_KEY}
66
- name: postgres
77
type: postgres
88
key: ${DB_URL}
99

10-
destinations:
11-
- name: postgres
12-
type: postgres
13-
key: ${DB_URL}
14-
- name: dune
15-
type: dune
16-
key: ${DUNE_API_KEY}
17-
1810
jobs:
1911
- name: Download simple test query to local postgres
2012
source:

tests/fixtures/config/buggy.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
---
2-
sources:
2+
data_sources:
33
- name: dune
44
type: dune
55
key: fake-key
6-
7-
destinations:
86
- name: postgres
97
type: postgres
108
key: fake-pg-key

tests/fixtures/config/dune_to_postgres.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
---
2-
sources:
2+
data_sources:
33
- name: dune
44
type: dune
55
key: fake-key
6-
7-
destinations:
86
- name: postgres
97
type: postgres
108
key: postgresql://postgres:postgres@localhost:5432/postgres

tests/fixtures/config/invalid_sql_file.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
---
2-
sources:
2+
data_sources:
33
- name: postgres
44
type: postgres
55
key: ${DB_URL}
6-
7-
destinations:
86
- name: dune
97
type: dune
108
key: fake-pg-key

tests/fixtures/config/postgres_to_dune.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
---
2-
sources:
2+
data_sources:
33
- name: dune
44
type: dune
55
key: fake-key
6-
7-
destinations:
86
- name: postgres
97
type: postgres
108
key: fake-pg-key

tests/fixtures/config/sql_file.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
---
2-
sources:
2+
data_sources:
33
- name: postgres
44
type: postgres
55
key: ${DB_URL}
6-
7-
destinations:
86
- name: dune
97
type: dune
108
key: fake-key

tests/fixtures/config/unsupported_dest.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
---
2-
sources:
2+
data_sources:
33
- name: dune
44
type: dune
55
key: fake-key
6-
7-
destinations:
86
- name: sqlite
97
type: sqlite
108
key: fake-pg-key

0 commit comments

Comments
 (0)