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