mirror of
https://github.com/clucraft/PriceGhost.git
synced 2026-04-25 16:56:23 +02:00
- Add database/init.sql with schema - Mount init.sql in docker-compose for auto-initialization - PostgreSQL will run this on first startup Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
35 lines
1,001 B
SQL
35 lines
1,001 B
SQL
-- PriceGhost Database Schema
|
|
|
|
-- Users table
|
|
CREATE TABLE IF NOT EXISTS users (
|
|
id SERIAL PRIMARY KEY,
|
|
email VARCHAR(255) UNIQUE NOT NULL,
|
|
password_hash VARCHAR(255) NOT NULL,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
-- Products table
|
|
CREATE TABLE IF NOT EXISTS products (
|
|
id SERIAL PRIMARY KEY,
|
|
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
|
|
url TEXT NOT NULL,
|
|
name VARCHAR(255),
|
|
image_url TEXT,
|
|
refresh_interval INTEGER DEFAULT 3600,
|
|
last_checked TIMESTAMP,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
UNIQUE(user_id, url)
|
|
);
|
|
|
|
-- Price history table
|
|
CREATE TABLE IF NOT EXISTS price_history (
|
|
id SERIAL PRIMARY KEY,
|
|
product_id INTEGER REFERENCES products(id) ON DELETE CASCADE,
|
|
price DECIMAL(10,2) NOT NULL,
|
|
currency VARCHAR(10) DEFAULT 'USD',
|
|
recorded_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
-- Index for faster price history queries
|
|
CREATE INDEX IF NOT EXISTS idx_price_history_product_date
|
|
ON price_history(product_id, recorded_at);
|