E-Commerce Schema
A full e-commerce schema demonstrating product catalog and order management.
Category Table
Section titled “Category Table”Self-referential parent allows nested category hierarchies.
export default table({ id: col.id(), name: col.name(), slug: col.slug().unique(), parent: col.belongs_to("catalog.category").optional(), description: col.text().optional(),}).timestamps();Product Table
Section titled “Product Table”export default table({ id: col.id(), name: col.name(), slug: col.slug().unique(), description: col.text().optional(), price: col.money(), stock: col.quantity(), category: col.belongs_to("catalog.category"), is_active: col.flag(true),}) .timestamps() .soft_delete();Order Table
Section titled “Order Table”export default table({ id: col.id(), user: col.belongs_to("auth.user"), status: col .enum(["pending", "paid", "shipped", "delivered", "cancelled"]) .default("pending"), total: col.money(), shipping_address: col.text(), notes: col.text().optional(),}).timestamps();Order Item Table
Section titled “Order Item Table”Line items join orders and products with quantity and price snapshot.
export default table({ id: col.id(), order: col.belongs_to("orders.order"), product: col.belongs_to("catalog.product"), quantity: col.quantity(), unit_price: col.money(), subtotal: col.money(),}).timestamps();