|
6 | 6 | boolean, |
7 | 7 | timestamp, |
8 | 8 | index, |
| 9 | + primaryKey, |
| 10 | + jsonb, |
9 | 11 | numeric, |
10 | 12 | check, |
11 | 13 | type PgTableWithColumns, |
@@ -661,6 +663,23 @@ export const backfillProgress = pgTable( |
661 | 663 | }), |
662 | 664 | ); |
663 | 665 |
|
| 666 | +/** Shared durable response cache used by idempotent mutating routes. */ |
| 667 | +export const idempotencyKeys = pgTable( |
| 668 | + "idempotency_keys", |
| 669 | + { |
| 670 | + route: text("route").notNull(), |
| 671 | + key: text("key").notNull(), |
| 672 | + bodyFingerprint: text("body_fingerprint").notNull(), |
| 673 | + statusCode: integer("status_code").notNull(), |
| 674 | + responseBody: jsonb("response_body").notNull().default({}), |
| 675 | + expiresAt: timestamp("expires_at").notNull(), |
| 676 | + }, |
| 677 | + (table) => ({ |
| 678 | + primaryKey: primaryKey({ columns: [table.route, table.key] }), |
| 679 | + expiresAtIdx: index("idempotency_keys_expires_at_idx").on(table.expiresAt), |
| 680 | + }), |
| 681 | +); |
| 682 | + |
664 | 683 | // --------------------------------------------------------------------------- |
665 | 684 | // Compatibility Version |
666 | 685 | // --------------------------------------------------------------------------- |
@@ -796,4 +815,5 @@ export const SCHEMA_TABLES: Array<{ name: string; table: PgTableWithColumns<any> |
796 | 815 | { name: "billingInvoices", table: billingInvoices }, |
797 | 816 | { name: "sessions", table: sessions }, |
798 | 817 | { name: "backfillProgress", table: backfillProgress }, |
| 818 | + { name: "idempotencyKeys", table: idempotencyKeys }, |
799 | 819 | ]; |
0 commit comments