Skip to content

Commit 9ec5d83

Browse files
committed
swap partition and sort for letters
1 parent 10ec08f commit 9ec5d83

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

infrastructure/terraform/components/api/ddb_table_letters.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ resource "aws_dynamodb_table" "letters" {
22
name = "${local.csi}-letters"
33
billing_mode = "PAY_PER_REQUEST"
44

5-
hash_key = "supplierId"
6-
range_key = "id"
5+
hash_key = "id"
6+
range_key = "supplierId"
77

88
ttl {
99
attribute_name = "ttl"

internal/datastore/src/__test__/db.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ const createLetterTableCommand = new CreateTableCommand({
5151
TableName: "letters",
5252
BillingMode: "PAY_PER_REQUEST",
5353
KeySchema: [
54-
{ AttributeName: "supplierId", KeyType: "HASH" }, // Partition key
55-
{ AttributeName: "id", KeyType: "RANGE" }, // Sort key
54+
{ AttributeName: "id", KeyType: "HASH" }, // Partition key (letter ID)
55+
{ AttributeName: "supplierId", KeyType: "RANGE" }, // Sort key
5656
],
5757
GlobalSecondaryIndexes: [
5858
{

internal/datastore/src/__test__/heathcheck.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ describe("DBHealthcheck", () => {
2424
await deleteTables(db);
2525
});
2626

27+
afterAll(async () => {
28+
await db.container.stop();
29+
});
30+
2731
it("passes when the database is available", async () => {
2832
const dbHealthCheck = new DBHealthcheck(db.docClient, db.config);
2933
await expect(dbHealthCheck.check()).resolves.not.toThrow();

internal/datastore/src/letter-repository.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ export class LetterRepository {
109109
new GetCommand({
110110
TableName: this.config.lettersTableName,
111111
Key: {
112-
supplierId,
113112
id: letterId,
113+
supplierId,
114114
},
115115
}),
116116
);
@@ -194,8 +194,8 @@ export class LetterRepository {
194194
new UpdateCommand({
195195
TableName: this.config.lettersTableName,
196196
Key: {
197-
supplierId: letterToUpdate.supplierId,
198197
id: letterToUpdate.id,
198+
supplierId: letterToUpdate.supplierId,
199199
},
200200
UpdateExpression: updateExpression,
201201
ConditionExpression: "attribute_exists(id)", // Ensure letter exists

0 commit comments

Comments
 (0)