27 lines
882 B
TypeScript
27 lines
882 B
TypeScript
import { sql } from "drizzle-orm";
|
|
import { index, pgTable, text, timestamp, uniqueIndex, uuid } from "drizzle-orm/pg-core";
|
|
|
|
import { users } from "./auth";
|
|
import { editorialAccounts } from "./editorials";
|
|
|
|
export const albumAutoRules = pgTable(
|
|
"album_auto_rules",
|
|
{
|
|
id: uuid("id").defaultRandom().primaryKey(),
|
|
editorialAccountId: uuid("editorial_account_id")
|
|
.notNull()
|
|
.references(() => editorialAccounts.id, { onDelete: "restrict" }),
|
|
keyword: text("keyword").notNull(),
|
|
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
createdByUserId: uuid("created_by_user_id").references(() => users.id, {
|
|
onDelete: "restrict",
|
|
}),
|
|
},
|
|
(table) => [
|
|
uniqueIndex("album_auto_rules_editorial_account_id_keyword_idx").on(
|
|
table.editorialAccountId,
|
|
sql`lower(${table.keyword})`,
|
|
),
|
|
],
|
|
);
|