30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
import { sql } from "drizzle-orm";
|
|
import { check, index, pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core";
|
|
|
|
import { users } from "./auth";
|
|
import { editorialAccounts } from "./editorials";
|
|
|
|
export const albumGrants = pgTable(
|
|
"album_grants",
|
|
{
|
|
id: uuid("id").defaultRandom().primaryKey(),
|
|
editorialAccountId: uuid("editorial_account_id")
|
|
.notNull()
|
|
.references(() => editorialAccounts.id, { onDelete: "restrict" }),
|
|
immichAlbumId: text("immich_album_id").notNull(),
|
|
grantedAt: timestamp("granted_at", { withTimezone: true }).notNull().defaultNow(),
|
|
revokedAt: timestamp("revoked_at", { withTimezone: true }),
|
|
grantedByUserId: uuid("granted_by_user_id").references(() => users.id, {
|
|
onDelete: "restrict",
|
|
}),
|
|
},
|
|
(table) => [
|
|
index("album_grants_editorial_account_id_idx").on(table.editorialAccountId),
|
|
index("album_grants_immich_album_id_idx").on(table.immichAlbumId),
|
|
check(
|
|
"album_grants_canonical_immich_album_id_check",
|
|
sql`${table.immichAlbumId} ~ '^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'`,
|
|
),
|
|
],
|
|
);
|