add timeline schema
This commit is contained in:
47
packages/db/src/schema/timeline.ts
Normal file
47
packages/db/src/schema/timeline.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { relations } from "drizzle-orm";
|
||||
import { integer, pgEnum, pgTable, text, timestamp } from "drizzle-orm/pg-core";
|
||||
import { user } from "./auth";
|
||||
import { id, timestamps } from "./shared";
|
||||
|
||||
export const visibility = pgEnum("visibility", ["private", "public"]);
|
||||
|
||||
export const timeline = pgTable("timeline", {
|
||||
...id,
|
||||
ownerId: text("owner_id")
|
||||
.notNull()
|
||||
.references(() => user.id, { onDelete: "cascade" }),
|
||||
title: text("title").notNull(),
|
||||
visibility: visibility().notNull().default("public"),
|
||||
...timestamps,
|
||||
});
|
||||
|
||||
export const timelineGroup = pgTable("timeline_group", {
|
||||
...id,
|
||||
title: text("title").notNull(),
|
||||
sortOrder: integer().notNull().default(0),
|
||||
timelineId: text("timeline_id")
|
||||
.notNull()
|
||||
.references(() => timeline.id, { onDelete: "cascade" }),
|
||||
...timestamps,
|
||||
});
|
||||
|
||||
export const timelineItem = pgTable("timeline_item", {
|
||||
...id,
|
||||
timelineGroupId: text("timeline_group_id")
|
||||
.notNull()
|
||||
.references(() => timelineGroup.id, { onDelete: "cascade" }),
|
||||
title: text("title").notNull(),
|
||||
description: text("description").notNull().default(""),
|
||||
start: timestamp("start", { withTimezone: true }).notNull().defaultNow(),
|
||||
// Allow null to denote a event without duration
|
||||
end: timestamp("end", { withTimezone: true }),
|
||||
...timestamps,
|
||||
});
|
||||
|
||||
export const timelineRelations = relations(timeline, ({ many }) => ({
|
||||
groups: many(timelineGroup),
|
||||
}));
|
||||
|
||||
export const groupRelations = relations(timelineGroup, ({ many }) => ({
|
||||
items: many(timelineItem),
|
||||
}));
|
||||
Reference in New Issue
Block a user