-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from cofacts/add-user-to-events
Add user to events
- Loading branch information
Showing
4 changed files
with
40 additions
and
29 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
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 was deleted.
Oops, something went wrong.
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,38 @@ | ||
/** | ||
* BigQuery client and schema | ||
*/ | ||
import 'dotenv/config'; | ||
import { BigQuery } from '@google-cloud/bigquery'; | ||
import type { TableSchema } from '@google-cloud/bigquery'; | ||
import * as bqEvents from '../bq/events'; | ||
|
||
const bqDataset = new BigQuery().dataset( | ||
process.env.BIGQUERY_ANALYTICS_DATASET || '' | ||
); | ||
|
||
async function loadSchema({TABLE, SCHEMA}: {TABLE: string, SCHEMA: TableSchema[]}) { | ||
const table = bqDataset.table(TABLE); | ||
|
||
if(await table.exists()) { | ||
const [result] = await table.setMetadata({schema: SCHEMA}); | ||
|
||
console.log(`Table ${table.id} fields updated to:`, result.schema.fields); | ||
return; | ||
} | ||
|
||
const [createdTable] = await bqDataset.createTable(TABLE, { | ||
schema: SCHEMA, | ||
timePartitioning: { | ||
type: 'MONTH', | ||
field: 'createdAt', | ||
}, | ||
}); | ||
|
||
console.log(`Table ${table.id} created under dataset ${createdTable.dataset.id}.`); | ||
console.log('You may need to wait up to 2 minutes before seeing it in GCS console.'); | ||
} | ||
|
||
loadSchema(bqEvents).catch((e) => { | ||
console.error('[setBqTables]', e); | ||
process.exit(1); | ||
}); |