PostgreSQL의 이커머스 스토어 스키마
백엔드 개발자는 테이블 구조를 두고 논쟁하는 대신 API를 만들기 시작할 수 있도록 정규화된 프로덕션 준비 DDL 베이스라인을 얻습니다.
입력 및 출력 미리보기
입력
- 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
출력 (발췌)
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.