2026-03-04 18:07:18 +01:00
|
|
|
import {
|
|
|
|
|
pgTable,
|
|
|
|
|
text,
|
|
|
|
|
timestamp,
|
|
|
|
|
boolean,
|
|
|
|
|
index,
|
|
|
|
|
uniqueIndex,
|
|
|
|
|
} from "drizzle-orm/pg-core";
|
2026-03-04 18:42:58 +01:00
|
|
|
import { users } from "./users";
|
|
|
|
|
import { files } from "./files";
|
2026-03-04 18:07:18 +01:00
|
|
|
|
|
|
|
|
export const articles = pgTable(
|
|
|
|
|
"articles",
|
|
|
|
|
{
|
|
|
|
|
id: text("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
|
|
|
|
|
slug: text("slug").notNull(),
|
|
|
|
|
title: text("title").notNull(),
|
|
|
|
|
excerpt: text("excerpt"),
|
|
|
|
|
content: text("content"),
|
|
|
|
|
image: text("image").references(() => files.id, { onDelete: "set null" }),
|
|
|
|
|
tags: text("tags").array().default([]),
|
|
|
|
|
publish_date: timestamp("publish_date").notNull().defaultNow(),
|
|
|
|
|
author: text("author").references(() => users.id, { onDelete: "set null" }),
|
|
|
|
|
category: text("category"),
|
|
|
|
|
featured: boolean("featured").default(false),
|
|
|
|
|
date_created: timestamp("date_created").notNull().defaultNow(),
|
|
|
|
|
date_updated: timestamp("date_updated"),
|
|
|
|
|
},
|
|
|
|
|
(t) => [
|
|
|
|
|
uniqueIndex("articles_slug_idx").on(t.slug),
|
|
|
|
|
index("articles_publish_date_idx").on(t.publish_date),
|
|
|
|
|
index("articles_featured_idx").on(t.featured),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export type Article = typeof articles.$inferSelect;
|
|
|
|
|
export type NewArticle = typeof articles.$inferInsert;
|