mirror of
https://github.com/clucraft/PriceGhost.git
synced 2026-04-26 01:06:23 +02:00
Add database initialization script
- 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>
This commit is contained in:
parent
93b6338e99
commit
5263ac93a9
2 changed files with 36 additions and 0 deletions
35
database/init.sql
Normal file
35
database/init.sql
Normal file
|
|
@ -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);
|
||||
Loading…
Add table
Add a link
Reference in a new issue