Spaces:
Running
Running
| -- nl2sql-bench/server/db/schema.sql | |
| -- E-commerce database schema for NL2SQL-Bench | |
| -- Designed for in-memory SQLite: realistic, universally understood domain. | |
| CREATE TABLE IF NOT EXISTS categories ( | |
| id INTEGER PRIMARY KEY, | |
| name TEXT NOT NULL UNIQUE | |
| ); | |
| CREATE TABLE IF NOT EXISTS products ( | |
| id INTEGER PRIMARY KEY, | |
| name TEXT NOT NULL, | |
| category_id INTEGER NOT NULL REFERENCES categories(id), | |
| price REAL NOT NULL CHECK(price >= 0), | |
| stock_quantity INTEGER NOT NULL DEFAULT 0 | |
| ); | |
| CREATE TABLE IF NOT EXISTS customers ( | |
| id INTEGER PRIMARY KEY, | |
| name TEXT NOT NULL, | |
| email TEXT NOT NULL UNIQUE, | |
| country TEXT NOT NULL, | |
| tier TEXT NOT NULL DEFAULT 'bronze' -- bronze | silver | gold | |
| CHECK(tier IN ('bronze', 'silver', 'gold')), | |
| created_at TEXT NOT NULL -- ISO-8601 date string | |
| ); | |
| CREATE TABLE IF NOT EXISTS orders ( | |
| id INTEGER PRIMARY KEY, | |
| customer_id INTEGER NOT NULL REFERENCES customers(id), | |
| status TEXT NOT NULL DEFAULT 'pending' | |
| CHECK(status IN ('pending','processing','shipped','delivered','cancelled')), | |
| created_at TEXT NOT NULL, | |
| total_amount REAL NOT NULL CHECK(total_amount >= 0) | |
| ); | |
| CREATE TABLE IF NOT EXISTS order_items ( | |
| id INTEGER PRIMARY KEY, | |
| order_id INTEGER NOT NULL REFERENCES orders(id), | |
| product_id INTEGER NOT NULL REFERENCES products(id), | |
| quantity INTEGER NOT NULL CHECK(quantity > 0), | |
| unit_price REAL NOT NULL CHECK(unit_price >= 0) | |
| ); | |
| CREATE TABLE IF NOT EXISTS reviews ( | |
| id INTEGER PRIMARY KEY, | |
| product_id INTEGER NOT NULL REFERENCES products(id), | |
| customer_id INTEGER NOT NULL REFERENCES customers(id), | |
| rating INTEGER NOT NULL CHECK(rating BETWEEN 1 AND 5), | |
| created_at TEXT NOT NULL | |
| ); | |
| -- Indexes for common join/filter patterns | |
| CREATE INDEX IF NOT EXISTS idx_products_category ON products(category_id); | |
| CREATE INDEX IF NOT EXISTS idx_orders_customer ON orders(customer_id); | |
| CREATE INDEX IF NOT EXISTS idx_orders_status ON orders(status); | |
| CREATE INDEX IF NOT EXISTS idx_orders_created ON orders(created_at); | |
| CREATE INDEX IF NOT EXISTS idx_order_items_order ON order_items(order_id); | |
| CREATE INDEX IF NOT EXISTS idx_order_items_product ON order_items(product_id); | |
| CREATE INDEX IF NOT EXISTS idx_reviews_product ON reviews(product_id); | |
| CREATE INDEX IF NOT EXISTS idx_customers_country ON customers(country); | |
| CREATE INDEX IF NOT EXISTS idx_customers_tier ON customers(tier); | |