feat: add usage and download intent accounting
This commit is contained in:
1 parent
846904f3db
commit
22fe6bf659
14 files changed
+3008
-2
No files matched your search
+23
-1
@@ -1,4 +1,16 @@
|
||||
import { integer, pgEnum, pgTable, text, timestamp, uniqueIndex, uuid, bigint } from "drizzle-orm/pg-core";
|
||||
import { sql } from "drizzle-orm";
|
||||
import {
|
||||
bigint,
|
||||
check,
|
||||
integer,
|
||||
pgEnum,
|
||||
pgTable,
|
||||
text,
|
||||
timestamp,
|
||||
uniqueIndex,
|
||||
uuid,
|
||||
varchar,
|
||||
} from "drizzle-orm/pg-core";
|
||||
|
||||
import { editorialAccounts } from "./editorials";
|
||||
import { billingReports } from "./billing";
|
||||
@@ -53,11 +65,21 @@ export const downloadEvents = pgTable(
|
||||
repeatDownloadNote: text("repeat_download_note"),
|
||||
requestId: uuid("request_id").notNull(),
|
||||
idempotencyKey: text("idempotency_key").notNull(),
|
||||
intentKind: text("intent_kind").notNull().default("new_usage"),
|
||||
requestFingerprint: varchar("request_fingerprint", { length: 64 }).notNull(),
|
||||
},
|
||||
(table) => [
|
||||
uniqueIndex("download_events_editorial_idempotency_key_unique").on(
|
||||
table.editorialAccountId,
|
||||
table.idempotencyKey,
|
||||
),
|
||||
check(
|
||||
"download_events_intent_kind_check",
|
||||
sql`${table.intentKind} in ('new_usage', 'repeat_download')`,
|
||||
),
|
||||
check(
|
||||
"download_events_request_fingerprint_hex_check",
|
||||
sql`${table.requestFingerprint} ~ '^[0-9a-f]{64}$'`,
|
||||
),
|
||||
],
|
||||
);
|
||||
Reference in new issue
Block a user