E-commerce store schema in PostgreSQL
Backend developers get a normalized, production-ready DDL baseline so they can start building APIs instead of debating table structure.
Zobrazit náhled vstupu a výstupu
Vstup
- Requirements
- E-commerce platform: users register and place multiple orders. Each order has line items linked to products. Products belong to one or more categories and support variants (size, color) with independent SKUs and stock. Users leave verified reviews with a 1-5 star rating and optional photos. Track inventory levels per variant and order status history.
- Database Type
- postgresql
- Schema Style
- normalized
- Output Format
- sql-ddl
- Relationships
- many-to-many
Výstup (úryvek)
CREATE TABLE users (id BIGSERIAL PRIMARY KEY, email CITEXT UNIQUE NOT NULL, created_at TIMESTAMPTZ DEFAULT now()); CREATE TABLE products (id BIGSERIAL PRIMARY KEY, name TEXT NOT NULL, base_price NUMERIC(10,2)); CREATE TABLE product_variants (id BIGSERIAL PRIMARY KEY, product_id BIGINT REFERENCES products(id), sku TEXT UNIQUE, size TEXT, color TEXT, stock INT DEFAULT 0); CREATE TABLE product_categories (product_id BIGINT, category_id BIGINT, PRIMARY KEY (product_id, category_id)); -- junction table for many-to-many.