feat: add portal database schema
This commit is contained in:
1 parent
763098b129
commit
7acaacb92e
17 files changed
+4410
-111
No files matched your search
@@ -0,0 +1,63 @@
|
||||
import { integer, pgEnum, pgTable, text, timestamp, uniqueIndex, uuid, bigint } from "drizzle-orm/pg-core";
|
||||
|
||||
import { editorialAccounts } from "./editorials";
|
||||
import { billingReports } from "./billing";
|
||||
|
||||
export const usageBillingStatuses = ["open", "billed", "reopened"] as const;
|
||||
export const usageBillingStatus = pgEnum("usage_billing_status", usageBillingStatuses);
|
||||
|
||||
export const downloadStatuses = [
|
||||
"authorized",
|
||||
"streaming",
|
||||
"completed",
|
||||
"failed_before_delivery",
|
||||
"interrupted",
|
||||
] as const;
|
||||
export const downloadStatus = pgEnum("download_status", downloadStatuses);
|
||||
|
||||
export const usages = pgTable("usages", {
|
||||
id: uuid("id").defaultRandom().primaryKey(),
|
||||
editorialAccountId: uuid("editorial_account_id")
|
||||
.notNull()
|
||||
.references(() => editorialAccounts.id, { onDelete: "restrict" }),
|
||||
immichAssetId: text("immich_asset_id").notNull(),
|
||||
filenameSnapshot: text("filename_snapshot").notNull(),
|
||||
immichAlbumIdSnapshot: text("immich_album_id_snapshot").notNull(),
|
||||
albumNameSnapshot: text("album_name_snapshot").notNull(),
|
||||
purpose: text("purpose").notNull(),
|
||||
internalReference: text("internal_reference"),
|
||||
priceCents: integer("price_cents").notNull(),
|
||||
billingStatus: usageBillingStatus("billing_status").notNull().default("open"),
|
||||
billingReportId: uuid("billing_report_id").references(() => billingReports.id, {
|
||||
onDelete: "restrict",
|
||||
}),
|
||||
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
});
|
||||
|
||||
export const downloadEvents = pgTable(
|
||||
"download_events",
|
||||
{
|
||||
id: uuid("id").defaultRandom().primaryKey(),
|
||||
editorialAccountId: uuid("editorial_account_id")
|
||||
.notNull()
|
||||
.references(() => editorialAccounts.id, { onDelete: "restrict" }),
|
||||
usageId: uuid("usage_id")
|
||||
.notNull()
|
||||
.references(() => usages.id, { onDelete: "restrict" }),
|
||||
immichAssetId: text("immich_asset_id").notNull(),
|
||||
authorizedAt: timestamp("authorized_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
startedAt: timestamp("started_at", { withTimezone: true }),
|
||||
completedAt: timestamp("completed_at", { withTimezone: true }),
|
||||
status: downloadStatus("status").notNull().default("authorized"),
|
||||
transferredBytes: bigint("transferred_bytes", { mode: "number" }),
|
||||
repeatDownloadNote: text("repeat_download_note"),
|
||||
requestId: uuid("request_id").notNull(),
|
||||
idempotencyKey: text("idempotency_key").notNull(),
|
||||
},
|
||||
(table) => [
|
||||
uniqueIndex("download_events_editorial_idempotency_key_unique").on(
|
||||
table.editorialAccountId,
|
||||
table.idempotencyKey,
|
||||
),
|
||||
],
|
||||
);
|
||||
Reference in new issue
Block a user