diff --git a/database/init.sql b/database/init.sql new file mode 100644 index 0000000..1219589 --- /dev/null +++ b/database/init.sql @@ -0,0 +1,35 @@ +-- 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); diff --git a/docker-compose.yml b/docker-compose.yml index e20d74f..e9802a3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,6 +11,7 @@ services: POSTGRES_DB: priceghost volumes: - postgres_data:/var/lib/postgresql/data + - ./database/init.sql:/docker-entrypoint-initdb.d/init.sql:ro ports: - "5432:5432" healthcheck: