Documentation Index
Fetch the complete documentation index at: https://mintlify.com/aluxey/E-Commerce/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The Sabbels Handmade database is built on PostgreSQL with Supabase and implements a comprehensive e-commerce platform schema. The database uses Row Level Security (RLS) for fine-grained access control and includes automated triggers for timestamp management.Extensions
The schema requires the following PostgreSQL extension:Entity Relationship Overview
The database schema is organized into several logical domains:Product Catalog Domain
- categories - Hierarchical product categories with self-referencing parent-child relationships
- items - Core product definitions with pricing, status, and pattern types
- item_variants - Size-based product variants with individual SKUs and stock levels
- colors - Color definitions with hex codes for product customization
- item_colors - Many-to-many relationship between items and available colors
- item_images - Multiple images per product
- item_ratings - Customer reviews and ratings (1-5 stars)
Order Management Domain
- orders - Order headers with status tracking and shipping information
- order_items - Individual line items within orders, linking to variants
- payments - Payment transaction records (Stripe integration)
- stripe_events - Idempotency tracking for Stripe webhook events
User & Content Domain
- users - Customer and admin user accounts (extends auth.users)
- customer_photos - Customer-submitted photos for gallery/social proof
Key Relationships
Product Structure
Order Flow
Schema Diagram Description
Core Product Tables
items is the central table, connected to:- categories via
category_id(nullable, SET NULL on delete) - item_colors via many-to-many junction table
- item_variants via one-to-many relationship
- item_images via one-to-many relationship
- item_ratings via one-to-many relationship
Order Processing Chain
- users place orders
- orders contain multiple order_items
- Each order_item references a specific item_variant
- payments track financial transactions per order
- stripe_events prevent duplicate webhook processing
Important Constraints
All items must have at least one color assigned. This is enforced via deferred constraint triggers that execute after transaction commit.
Data Integrity Features
Check Constraints
- Price validation: All prices must be >= 0
- Stock validation: Stock levels must be >= 0
- Rating range: Ratings must be between 1 and 5
- Status enums: Strict status values for items, orders, and user roles
- Hex code format: Colors must match
^#([0-9A-Fa-f]{6})$pattern
Unique Constraints
- Category names must be unique per parent
- Color codes and hex codes are globally unique
- Users cannot rate the same item twice
- Item variants are unique per item+size combination
- Payment provider+provider_id combinations are unique
Cascade Behaviors
- Deleting a category cascades to child categories
- Deleting an item cascades to variants, images, colors, and ratings
- Deleting an order cascades to order_items and payments
- Deleting a user cascades to their orders and ratings
Automated Triggers
Timestamp Management
Theset_updated_at() trigger function automatically updates the updated_at field on:
- users
- items
- item_ratings
- orders
- payments
Color Requirement Enforcement
Deferred constraint triggers ensure items always have at least one color:These triggers are deferred, meaning they execute at transaction commit time, allowing you to insert an item and its colors in the same transaction.
Indexing Strategy
Foreign Key Indexes
All foreign key columns are indexed for optimal join performance:idx_categories_parentidx_items_categoryidx_item_colors_coloridx_item_images_itemidx_variants_itemidx_orders_useridx_order_items_order,idx_order_items_itemidx_payments_order
Functional Indexes
- Full-text search:
idx_items_nameuses GIN index onto_tsvectorfor fast product name searches - Visible photos:
idx_customer_photos_visiblefor efficient gallery queries
Unique Indexes
ux_categories_name_parent- Ensures category names are unique within parentux_item_variants_combo- Prevents duplicate item+size combinations usingcoalesce(size, '')
Next Steps
Tables Reference
Complete documentation of all table columns, types, and constraints
Row Level Security
RLS policies for access control and multi-tenant security