import { int, mysqlEnum, mysqlTable, text, timestamp, varchar } from "drizzle-orm/mysql-core"; /** * Core user table backing auth flow. * Extend this file with additional tables as your product grows. * Columns use camelCase to match both database fields and generated types. */ export const users = mysqlTable("users", { /** * Surrogate primary key. Auto-incremented numeric value managed by the database. * Use this for relations between tables. */ id: int("id").autoincrement().primaryKey(), /** Manus OAuth identifier (openId) returned from the OAuth callback. Unique per user. */ openId: varchar("openId", { length: 64 }).notNull().unique(), name: text("name"), email: varchar("email", { length: 320 }), loginMethod: varchar("loginMethod", { length: 64 }), role: mysqlEnum("role", ["user", "admin"]).default("user").notNull(), createdAt: timestamp("createdAt").defaultNow().notNull(), updatedAt: timestamp("updatedAt").defaultNow().onUpdateNow().notNull(), lastSignedIn: timestamp("lastSignedIn").defaultNow().notNull(), }); export type User = typeof users.$inferSelect; export type InsertUser = typeof users.$inferInsert; /** * Products table for storing supplement information */ export const products = mysqlTable("products", { id: int("id").autoincrement().primaryKey(), name: varchar("name", { length: 255 }).notNull(), description: text("description").notNull(), price: int("price").notNull(), // Price in cents capsuleCount: int("capsule_count").notNull(), manufacturer: varchar("manufacturer", { length: 255 }).notNull(), imageUrl: text("image_url"), createdAt: timestamp("createdAt").defaultNow().notNull(), updatedAt: timestamp("updatedAt").defaultNow().onUpdateNow().notNull(), }); export type Product = typeof products.$inferSelect; export type InsertProduct = typeof products.$inferInsert; /** * Orders table for storing customer orders */ export const orders = mysqlTable("orders", { id: int("id").autoincrement().primaryKey(), productId: int("product_id").notNull(), customerName: varchar("customer_name", { length: 255 }).notNull(), customerEmail: varchar("customer_email", { length: 320 }).notNull(), customerPhone: varchar("customer_phone", { length: 50 }), shippingAddress: text("shipping_address").notNull(), quantity: int("quantity").notNull(), totalPrice: int("total_price").notNull(), // Total price in cents status: mysqlEnum("status", ["pending", "processing", "shipped", "delivered", "cancelled"]).default("pending").notNull(), createdAt: timestamp("createdAt").defaultNow().notNull(), updatedAt: timestamp("updatedAt").defaultNow().onUpdateNow().notNull(), }); export type Order = typeof orders.$inferSelect; export type InsertOrder = typeof orders.$inferInsert; /** * Testimonials table for storing customer reviews */ export const testimonials = mysqlTable("testimonials", { id: int("id").autoincrement().primaryKey(), productId: int("product_id").notNull(), customerName: varchar("customer_name", { length: 255 }).notNull(), customerTitle: varchar("customer_title", { length: 255 }), rating: int("rating").notNull(), // 1-5 stars content: text("content").notNull(), verified: int("verified").default(0).notNull(), // 0 = false, 1 = true createdAt: timestamp("createdAt").defaultNow().notNull(), }); export type Testimonial = typeof testimonials.$inferSelect; export type InsertTestimonial = typeof testimonials.$inferInsert;