Skip to content

Commit

Permalink
fix(server): add wait until table exists before inserting
Browse files Browse the repository at this point in the history
  • Loading branch information
kritish-dhaubanjar committed Jan 21, 2025
1 parent f7fe18f commit 65fdf53
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion server/src/services/table.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 65fdf53

Please sign in to comment.