You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.6 KiB
46 lines
1.6 KiB
import { integer, sqliteTable, text, uniqueIndex } from "drizzle-orm/sqlite-core";
|
|
|
|
import { users } from "./auth";
|
|
|
|
export const posts = sqliteTable(
|
|
"posts",
|
|
{
|
|
id: integer().primaryKey(),
|
|
userId: integer("user_id")
|
|
.notNull()
|
|
.references(() => users.id, { onDelete: "cascade" }),
|
|
title: text().notNull(),
|
|
slug: text().notNull(),
|
|
bodyMarkdown: text("body_markdown").notNull(),
|
|
excerpt: text().notNull(),
|
|
coverUrl: text("cover_url"),
|
|
tagsJson: text("tags_json").notNull().default("[]"),
|
|
publishedAt: integer("published_at", { mode: "timestamp_ms" }),
|
|
visibility: text().notNull().default("private"),
|
|
shareToken: text("share_token"),
|
|
createdAt: integer("created_at", { mode: "timestamp_ms" }).defaultNow().notNull(),
|
|
updatedAt: integer("updated_at", { mode: "timestamp_ms" })
|
|
.defaultNow()
|
|
.$onUpdate(() => new Date())
|
|
.notNull(),
|
|
},
|
|
(table) => [uniqueIndex("posts_user_id_slug_unique").on(table.userId, table.slug)],
|
|
);
|
|
|
|
export const timelineEvents = sqliteTable("timeline_events", {
|
|
id: integer().primaryKey(),
|
|
userId: integer("user_id")
|
|
.notNull()
|
|
.references(() => users.id, { onDelete: "cascade" }),
|
|
occurredOn: integer("occurred_on", { mode: "timestamp_ms" }).notNull(),
|
|
title: text().notNull(),
|
|
bodyMarkdown: text("body_markdown"),
|
|
linkUrl: text("link_url"),
|
|
visibility: text().notNull().default("private"),
|
|
shareToken: text("share_token"),
|
|
createdAt: integer("created_at", { mode: "timestamp_ms" }).defaultNow().notNull(),
|
|
updatedAt: integer("updated_at", { mode: "timestamp_ms" })
|
|
.defaultNow()
|
|
.$onUpdate(() => new Date())
|
|
.notNull(),
|
|
});
|
|
|