chore: update drizzle schema and migrations
This commit is contained in:
@@ -1,13 +1,30 @@
|
||||
import {
|
||||
boolean,
|
||||
index,
|
||||
integer,
|
||||
jsonb,
|
||||
pgEnum,
|
||||
pgTable,
|
||||
text,
|
||||
timestamp,
|
||||
jsonb,
|
||||
integer,
|
||||
boolean,
|
||||
varchar,
|
||||
index,
|
||||
} from "drizzle-orm/pg-core";
|
||||
import { createId } from "@paralleldrive/cuid2";
|
||||
|
||||
export const users = pgTable("users", {
|
||||
id: text("id").primaryKey(),
|
||||
name: text("name"),
|
||||
email: text("email").notNull().unique(),
|
||||
emailVerified: timestamp("email_verified", { withTimezone: true }),
|
||||
image: text("image"),
|
||||
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
});
|
||||
|
||||
export const comparisonStatusEnum = pgEnum("comparison_status", [
|
||||
"researching",
|
||||
"completed",
|
||||
"failed",
|
||||
]);
|
||||
|
||||
export const users = pgTable("users", {
|
||||
id: text("id").primaryKey(),
|
||||
@@ -33,55 +50,65 @@ export const sessions = pgTable("sessions", {
|
||||
export const comparisons = pgTable(
|
||||
"comparisons",
|
||||
{
|
||||
id: text("id").primaryKey(),
|
||||
userId: text("user_id"),
|
||||
title: text("title").notNull(),
|
||||
query: text("query"),
|
||||
slug: varchar("slug", { length: 255 }).notNull().unique(),
|
||||
status: text("status", {
|
||||
enum: ["researching", "completed", "failed"],
|
||||
})
|
||||
id: text("id")
|
||||
.primaryKey()
|
||||
.$defaultFn(() => createId()),
|
||||
userId: text("user_id")
|
||||
.notNull()
|
||||
.default("researching"),
|
||||
.references(() => users.id),
|
||||
title: text("title").notNull(),
|
||||
query: text("query").notNull(),
|
||||
slug: text("slug").notNull().unique(),
|
||||
status: comparisonStatusEnum("status").notNull().default("researching"),
|
||||
summary: text("summary"),
|
||||
overallData: jsonb("overall_data"),
|
||||
tags: text("tags").array(),
|
||||
isPublic: boolean("is_public").default(false),
|
||||
viewCount: integer("view_count").default(0),
|
||||
createdAt: timestamp("created_at").defaultNow().notNull(),
|
||||
updatedAt: timestamp("updated_at").defaultNow().notNull(),
|
||||
isPublic: boolean("is_public").notNull().default(true),
|
||||
viewCount: integer("view_count").notNull().default(0),
|
||||
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
},
|
||||
(table) => [index("comparisons_user_id_idx").on(table.userId)]
|
||||
(table) => [
|
||||
index("comparisons_user_id_idx").on(table.userId),
|
||||
index("comparisons_slug_idx").on(table.slug),
|
||||
index("comparisons_status_idx").on(table.status),
|
||||
],
|
||||
);
|
||||
|
||||
export const comparisonItems = pgTable("comparison_items", {
|
||||
id: text("id").primaryKey(),
|
||||
comparisonId: text("comparison_id")
|
||||
.notNull()
|
||||
.references(() => comparisons.id, { onDelete: "cascade" }),
|
||||
name: text("name").notNull(),
|
||||
description: text("description"),
|
||||
imageUrl: text("image_url"),
|
||||
researchData: jsonb("research_data"),
|
||||
scores: jsonb("scores"),
|
||||
pros: text("pros").array(),
|
||||
cons: text("cons").array(),
|
||||
order: integer("order").notNull(),
|
||||
});
|
||||
export const comparisonItems = pgTable(
|
||||
"comparison_items",
|
||||
{
|
||||
id: text("id")
|
||||
.primaryKey()
|
||||
.$defaultFn(() => createId()),
|
||||
comparisonId: text("comparison_id")
|
||||
.notNull()
|
||||
.references(() => comparisons.id, { onDelete: "cascade" }),
|
||||
name: text("name").notNull(),
|
||||
description: text("description"),
|
||||
imageUrl: text("image_url"),
|
||||
researchData: jsonb("research_data"),
|
||||
scores: jsonb("scores"),
|
||||
pros: text("pros").array(),
|
||||
cons: text("cons").array(),
|
||||
order: integer("order").notNull().default(0),
|
||||
},
|
||||
(table) => [index("comparison_items_comparison_id_idx").on(table.comparisonId)],
|
||||
);
|
||||
|
||||
export const comparisonDimensions = pgTable("comparison_dimensions", {
|
||||
id: text("id").primaryKey(),
|
||||
comparisonId: text("comparison_id")
|
||||
.notNull()
|
||||
.references(() => comparisons.id, { onDelete: "cascade" }),
|
||||
name: text("name").notNull(),
|
||||
description: text("description"),
|
||||
weight: integer("weight").default(1),
|
||||
order: integer("order").notNull(),
|
||||
});
|
||||
|
||||
export type Comparison = typeof comparisons.$inferSelect;
|
||||
export type NewComparison = typeof comparisons.$inferInsert;
|
||||
export type ComparisonItem = typeof comparisonItems.$inferSelect;
|
||||
export type NewComparisonItem = typeof comparisonItems.$inferInsert;
|
||||
export type ComparisonDimension = typeof comparisonDimensions.$inferSelect;
|
||||
export const comparisonDimensions = pgTable(
|
||||
"comparison_dimensions",
|
||||
{
|
||||
id: text("id")
|
||||
.primaryKey()
|
||||
.$defaultFn(() => createId()),
|
||||
comparisonId: text("comparison_id")
|
||||
.notNull()
|
||||
.references(() => comparisons.id, { onDelete: "cascade" }),
|
||||
name: text("name").notNull(),
|
||||
description: text("description"),
|
||||
weight: integer("weight").notNull().default(1),
|
||||
order: integer("order").notNull().default(0),
|
||||
},
|
||||
(table) => [index("comparison_dimensions_comparison_id_idx").on(table.comparisonId)],
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user