Skip to content

Commit 75199cd

Browse files
committed
feat(dynamodb): remove executed attribute from migrations table schema
The attribute is useless, so a scan can be just performed to get applyed migrations
1 parent caf92b2 commit 75199cd

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/storages/dynamodb.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default class DynamoDBStorage implements Storage {
2323
* @param options
2424
* @param options.dynamodb - a DynamoDB document client instance
2525
* @param options.tableName - name of migration table in DynamoDB
26-
* @param options.attributeName - name of the table rangeKey attribute in DynamoDB
26+
* @param options.attributeName - name of the table primaryKey attribute in DynamoDB
2727
* @param options.timestamp - option to add timestamps to the DynamoDB table
2828
*/
2929
constructor({ dynamodb, tableName, attributeName, timestamp }: DynamoDBStorageOptions = {}) {
@@ -42,7 +42,7 @@ export default class DynamoDBStorage implements Storage {
4242
* @param migrationName - Name of the migration to be logged.
4343
*/
4444
async logMigration(migrationName: string) {
45-
const item: DocumentClient.PutItemInputAttributeMap = { [this.attributeName]: migrationName, executed: 'OK' };
45+
const item: DocumentClient.PutItemInputAttributeMap = { [this.attributeName]: migrationName };
4646

4747
if (this.timestamp) {
4848
item.createdAt = Date.now();
@@ -57,7 +57,7 @@ export default class DynamoDBStorage implements Storage {
5757
* @param migrationName - Name of the migration to be unlogged.
5858
*/
5959
async unlogMigration(migrationName: string) {
60-
const key: DocumentClient.Key = { [this.attributeName]: migrationName, executed: 'OK' };
60+
const key: DocumentClient.Key = { [this.attributeName]: migrationName };
6161

6262
await this.dynamodb.delete({ TableName: this.tableName, Key: key }).promise();
6363
}
@@ -70,10 +70,8 @@ export default class DynamoDBStorage implements Storage {
7070
let startKey: DocumentClient.Key;
7171

7272
do {
73-
const { Items, LastEvaluatedKey } = await this.dynamodb.query({
73+
const { Items, LastEvaluatedKey } = await this.dynamodb.scan({
7474
TableName: this.tableName,
75-
KeyConditionExpression: 'executed = :executed',
76-
ExpressionAttributeValues: { ':executed': 'OK' },
7775
ExclusiveStartKey: startKey,
7876
}).promise();
7977

0 commit comments

Comments
 (0)