From 65fdf532007c98b5abbcebd8b46b6418150b971e Mon Sep 17 00:00:00 2001 From: Kritish Dhaubanjar Date: Tue, 21 Jan 2025 22:19:26 +0545 Subject: [PATCH] fix(server): add wait until table exists before inserting --- server/src/services/table.service.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/src/services/table.service.js b/server/src/services/table.service.js index 53ffaebf..74cf7bbd 100644 --- a/server/src/services/table.service.js +++ b/server/src/services/table.service.js @@ -2,6 +2,7 @@ import AWS from "../config/aws"; import { OPERATIONS } from "../constants/dynamodb"; import { constructSchema } from "../utils/dynamodb"; import DatabaseServiceProvider from "./database.service"; +import { waitUntilTableExists } from "@aws-sdk/client-dynamodb"; export default class TableServiceProvider { /** @@ -140,7 +141,12 @@ export default class TableServiceProvider { const { Table } = await DatabaseServiceProvider.SOURCE.TableService.describe(tableName); await Promise.allSettled([DatabaseServiceProvider.TARGET.TableService.destroy(tableName)]); - await DatabaseServiceProvider.TARGET.TableService.create(constructSchema(Table)); + await Promise.allSettled([DatabaseServiceProvider.TARGET.TableService.create(constructSchema(Table))]); + + await waitUntilTableExists( + { client: DatabaseServiceProvider.TARGET.AWS.dynamodb, maxWaitTime: 60 }, + { TableName: tableName }, + ); const params = { Limit: 100 }; const schema = Table.KeySchema.map(({ AttributeName }) => AttributeName);