design database
This commit is contained in:
@@ -36,3 +36,79 @@ import {
|
|||||||
import { sql } from "drizzle-orm";
|
import { sql } from "drizzle-orm";
|
||||||
|
|
||||||
import { id, createdAt, updatedAt } from "../common";
|
import { id, createdAt, updatedAt } from "../common";
|
||||||
|
import { user } from "./auth.db";
|
||||||
|
import { attributeFile } from "./basic.db";
|
||||||
|
|
||||||
|
// Enums
|
||||||
|
export const catGenderEnum = pgEnum("cat_gender", ["male", "female"]);
|
||||||
|
export const catGradeEnum = pgEnum("cat_grade", ["A", "B", "C", "D"]);
|
||||||
|
export const catTypeEnum = pgEnum("cat_type", ["breeding_male", "breeding_female", "kitten"]);
|
||||||
|
export const reservationStatusEnum = pgEnum("reservation_status", ["queuing", "reserved", "completed", "cancelled"]);
|
||||||
|
export const orderStatusEnum = pgEnum("order_status", ["pending", "paid", "shipped", "delivered", "cancelled"]);
|
||||||
|
|
||||||
|
// Tables
|
||||||
|
export const shelter = pgTable("shelter", {
|
||||||
|
id,
|
||||||
|
name: varchar("name", { length: 255 }).notNull(),
|
||||||
|
description: text("description"),
|
||||||
|
address: varchar("address", { length: 255 }),
|
||||||
|
phone: varchar("phone", { length: 20 }),
|
||||||
|
imageIds: jsonb("image_ids").$type<number[]>().default([]),
|
||||||
|
createdAt,
|
||||||
|
updatedAt,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const cat = pgTable("cat", {
|
||||||
|
id,
|
||||||
|
name: varchar("name", { length: 255 }).notNull(),
|
||||||
|
age: integer("age").notNull(), // in months
|
||||||
|
gender: catGenderEnum("gender").notNull(),
|
||||||
|
grade: catGradeEnum("grade").notNull(),
|
||||||
|
type: catTypeEnum("type").notNull(),
|
||||||
|
isAvailable: boolean("is_available").default(true).notNull(),
|
||||||
|
description: text("description"),
|
||||||
|
imageIds: jsonb("image_ids").$type<number[]>().default([]),
|
||||||
|
createdAt,
|
||||||
|
updatedAt,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const reservation = pgTable("reservation", {
|
||||||
|
id,
|
||||||
|
userId: text("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
|
||||||
|
catId: integer("cat_id").references(() => cat.id, { onDelete: "set null" }),
|
||||||
|
deposit: numeric("deposit", { precision: 10, scale: 2 }).notNull(),
|
||||||
|
status: reservationStatusEnum("status").default("queuing").notNull(),
|
||||||
|
queueOrder: integer("queue_order"),
|
||||||
|
createdAt,
|
||||||
|
updatedAt,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const product = pgTable("product", {
|
||||||
|
id,
|
||||||
|
name: varchar("name", { length: 255 }).notNull(),
|
||||||
|
description: text("description"),
|
||||||
|
price: numeric("price", { precision: 10, scale: 2 }).notNull(),
|
||||||
|
stock: integer("stock").default(0).notNull(),
|
||||||
|
imageIds: jsonb("image_ids").$type<number[]>().default([]),
|
||||||
|
createdAt,
|
||||||
|
updatedAt,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const orderTable = pgTable("orders", {
|
||||||
|
id,
|
||||||
|
userId: text("user_id").notNull().references(() => user.id, { onDelete: "cascade" }),
|
||||||
|
totalPrice: numeric("total_price", { precision: 10, scale: 2 }).notNull(),
|
||||||
|
status: orderStatusEnum("status").default("pending").notNull(),
|
||||||
|
createdAt,
|
||||||
|
updatedAt,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const orderItem = pgTable("order_item", {
|
||||||
|
id,
|
||||||
|
orderId: integer("order_id").notNull().references(() => orderTable.id, { onDelete: "cascade" }),
|
||||||
|
productId: integer("product_id").notNull().references(() => product.id, { onDelete: "cascade" }),
|
||||||
|
quantity: integer("quantity").notNull(),
|
||||||
|
unitPrice: numeric("unit_price", { precision: 10, scale: 2 }).notNull(),
|
||||||
|
createdAt,
|
||||||
|
updatedAt,
|
||||||
|
});
|
||||||
|
|||||||
19698
pnpm-lock.yaml
generated
19698
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user