add timeline schema
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
"check-types": "turbo check-types",
|
||||
"dev:native": "turbo -F native dev",
|
||||
"dev:web": "turbo -F web dev",
|
||||
"auth:generate": "turbo -F @zendegi/auth auth:generate",
|
||||
"db:push": "turbo -F @zendegi/db db:push",
|
||||
"db:studio": "turbo -F @zendegi/db db:studio",
|
||||
"db:generate": "turbo -F @zendegi/db db:generate",
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"auth:generate": "DOTENV_CONFIG_PATH=../../apps/web/.env pnpx @better-auth/cli generate --config src/index.ts --output ../db/src/schema/auth.ts",
|
||||
"check-types": "tsc --noEmit",
|
||||
"lint": "eslint ."
|
||||
},
|
||||
|
||||
@@ -16,4 +16,9 @@ export const auth = betterAuth({
|
||||
enabled: true,
|
||||
},
|
||||
plugins: [tanstackStartCookies()],
|
||||
advanced: {
|
||||
database: {
|
||||
generateId: "uuid",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
import { relations } from "drizzle-orm";
|
||||
import { boolean, index, pgTable, text, timestamp } from "drizzle-orm/pg-core";
|
||||
import { relations, sql } from "drizzle-orm";
|
||||
import {
|
||||
boolean,
|
||||
index,
|
||||
pgTable,
|
||||
text,
|
||||
timestamp,
|
||||
uuid,
|
||||
} from "drizzle-orm/pg-core";
|
||||
|
||||
export const user = pgTable("user", {
|
||||
id: text("id").primaryKey(),
|
||||
id: uuid("id")
|
||||
.default(sql`pg_catalog.gen_random_uuid()`)
|
||||
.primaryKey(),
|
||||
name: text("name").notNull(),
|
||||
email: text("email").notNull().unique(),
|
||||
emailVerified: boolean("email_verified").default(false).notNull(),
|
||||
@@ -17,7 +26,9 @@ export const user = pgTable("user", {
|
||||
export const session = pgTable(
|
||||
"session",
|
||||
{
|
||||
id: text("id").primaryKey(),
|
||||
id: uuid("id")
|
||||
.default(sql`pg_catalog.gen_random_uuid()`)
|
||||
.primaryKey(),
|
||||
expiresAt: timestamp("expires_at").notNull(),
|
||||
token: text("token").notNull().unique(),
|
||||
createdAt: timestamp("created_at").defaultNow().notNull(),
|
||||
@@ -26,7 +37,7 @@ export const session = pgTable(
|
||||
.notNull(),
|
||||
ipAddress: text("ip_address"),
|
||||
userAgent: text("user_agent"),
|
||||
userId: text("user_id")
|
||||
userId: uuid("user_id")
|
||||
.notNull()
|
||||
.references(() => user.id, { onDelete: "cascade" }),
|
||||
},
|
||||
@@ -36,10 +47,12 @@ export const session = pgTable(
|
||||
export const account = pgTable(
|
||||
"account",
|
||||
{
|
||||
id: text("id").primaryKey(),
|
||||
id: uuid("id")
|
||||
.default(sql`pg_catalog.gen_random_uuid()`)
|
||||
.primaryKey(),
|
||||
accountId: text("account_id").notNull(),
|
||||
providerId: text("provider_id").notNull(),
|
||||
userId: text("user_id")
|
||||
userId: uuid("user_id")
|
||||
.notNull()
|
||||
.references(() => user.id, { onDelete: "cascade" }),
|
||||
accessToken: text("access_token"),
|
||||
@@ -60,7 +73,9 @@ export const account = pgTable(
|
||||
export const verification = pgTable(
|
||||
"verification",
|
||||
{
|
||||
id: text("id").primaryKey(),
|
||||
id: uuid("id")
|
||||
.default(sql`pg_catalog.gen_random_uuid()`)
|
||||
.primaryKey(),
|
||||
identifier: text("identifier").notNull(),
|
||||
value: text("value").notNull(),
|
||||
expiresAt: timestamp("expires_at").notNull(),
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
export * from "./auth";
|
||||
export {};
|
||||
export * from "./timeline";
|
||||
|
||||
18
packages/db/src/schema/shared.ts
Normal file
18
packages/db/src/schema/shared.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { text, timestamp } from "drizzle-orm/pg-core";
|
||||
import { sql } from "drizzle-orm";
|
||||
|
||||
export const id = {
|
||||
id: text("id")
|
||||
.default(sql`pg_catalog.gen_random_uuid()`)
|
||||
.primaryKey(),
|
||||
};
|
||||
|
||||
export const timestamps = {
|
||||
createdAt: timestamp("created_at", { withTimezone: true })
|
||||
.defaultNow()
|
||||
.notNull(),
|
||||
updatedAt: timestamp("updated_at", { withTimezone: true })
|
||||
.defaultNow()
|
||||
.$onUpdate(() => new Date())
|
||||
.notNull(),
|
||||
};
|
||||
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),
|
||||
}));
|
||||
@@ -20,6 +20,9 @@
|
||||
"cache": false,
|
||||
"persistent": true
|
||||
},
|
||||
"auth:generate": {
|
||||
"cache": false
|
||||
},
|
||||
"db:push": {
|
||||
"cache": false
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user