Skip to content
This repository was archived by the owner on Jul 20, 2023. It is now read-only.

Commit 349e171

Browse files
t-karasovakweinmeistertkarasyova
authored
feat: Retail Tutorials. If create BQ table is requested, check if it exists and remove before creation (#157)
* Update setup-cleanup.js * fix: change BQ table creation logic Co-authored-by: Karl Weinmeister <[email protected]> Co-authored-by: tkarasyova <[email protected]>
1 parent 5dd1ea9 commit 349e171

2 files changed

Lines changed: 17 additions & 61 deletions

File tree

samples/interactive-tutorials/setup/setup-cleanup.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -231,26 +231,25 @@ const isTableExist = async (datasetId, tableId) => {
231231

232232
const createBqTable = async (datasetId, tableId, schemaFile) => {
233233
if (await isTableExist(datasetId, tableId)) {
234-
console.log(`Table ${tableId} already exists`);
235-
return false;
236-
} else {
237-
const schemaFileData = fs.readFileSync(schemaFile);
238-
const schema = JSON.parse(schemaFileData);
239-
240-
const bigquery = new BigQuery();
241-
const options = {
242-
schema: schema,
243-
location: 'US',
244-
};
234+
console.log(`Table ${tableId} exists and will be removed`);
235+
await deleteBqTable(datasetId, tableId);
236+
}
237+
console.log(`Table name ${tableId} is unique for the dataset ${datasetId}`);
238+
//Create a new table in the dataset
239+
const schemaFileData = fs.readFileSync(schemaFile);
240+
const schema = JSON.parse(schemaFileData);
241+
const bigquery = new BigQuery();
242+
const options = {
243+
schema: schema,
244+
location: 'US',
245+
};
245246

246-
//Create a new table in the dataset
247-
const [table] = await bigquery
248-
.dataset(datasetId)
249-
.createTable(tableId, options);
247+
const [table] = await bigquery
248+
.dataset(datasetId)
249+
.createTable(tableId, options);
250250

251-
console.log(`Table ${table.id} created.`);
252-
return true;
253-
}
251+
console.log(`Table ${table.id} created.`);
252+
return true;
254253
};
255254

256255
const deleteBqTable = async (datasetId, tableId) => {

samples/interactive-tutorials/test/get-products-list.test.js

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)