-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
data porter supports multiple schema (#14)
- Loading branch information
1 parent
ccbbe10
commit a16dca0
Showing
8 changed files
with
75 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
DB_TYPE= | ||
DB_SCHEMA= | ||
DB_TABLES= | ||
DB_PASSWORD= | ||
DB_TABLES= | ||
|
||
DUNE_API_KEY= | ||
DUNE_TABLE_NAMES= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ClientConfig } from 'pg'; | ||
|
||
import { env } from './parseEnv'; | ||
import { getDbConfig } from '../consts'; | ||
|
||
export const getClientConfig = (): ClientConfig => { | ||
const dbConfig = getDbConfig(env.DB_TYPE); | ||
return { | ||
...dbConfig, | ||
password: env.DB_PASSWORD, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import assert from 'assert'; | ||
|
||
import { env } from './parseEnv'; | ||
|
||
export const getQueryTarget = () => { | ||
const dbTargets = env.DB_TABLES | ||
.trim() | ||
.split(',') | ||
.map(pair => { | ||
const [schema, table] = pair.split('.'); | ||
if (!schema || !table) { | ||
throw new Error(`invalid schema.table: ${pair}`); | ||
} | ||
return { | ||
schema: schema.trim(), | ||
table: table.trim(), | ||
}; | ||
}); | ||
|
||
const tableNames = env.DUNE_TABLE_NAMES.split(','); | ||
assert(dbTargets.length === tableNames.length, | ||
`db tables and dune table names count mismatch: ${dbTargets.length} | ${tableNames.length}`); | ||
|
||
return { dbTargets, tableNames }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './parseEnv'; | ||
export * from './getQueryTarget'; | ||
export * from './getClientConfig'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { cleanEnv, str } from 'envalid'; | ||
import dotenv from 'dotenv'; | ||
|
||
import { DbType } from '../consts'; | ||
|
||
dotenv.config(); | ||
|
||
export const env = cleanEnv(process.env, { | ||
DB_TYPE: str({ choices: Object.values(DbType) }), | ||
DB_TABLES: str(), | ||
DB_PASSWORD: str(), | ||
|
||
DUNE_API_KEY: str(), | ||
DUNE_TABLE_NAMES: str(), | ||
}); |