#!/usr/bin/env python3 """ Initialize SQLite database for crawl queue. """ import sqlite3 from pathlib import Path DB_PATH = Path(__file__).parent.parent / 'data' / 'crawl_queue.db' def init_database(): """Create database and tables if they don't exist.""" DB_PATH.parent.mkdir(parents=True, exist_ok=True) conn = sqlite3.connect(DB_PATH) cursor = conn.cursor() # Create jobs table cursor.execute(""" CREATE TABLE IF NOT EXISTS jobs ( job_id TEXT PRIMARY KEY, domain TEXT NOT NULL, status TEXT NOT NULL DEFAULT 'queued', progress INTEGER DEFAULT 0, current_step TEXT, products_processed INTEGER DEFAULT 0, products_total INTEGER DEFAULT 0, file_path TEXT, products_count INTEGER, error TEXT, config TEXT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, started_at TIMESTAMP, completed_at TIMESTAMP ) """) # Create indexes cursor.execute(""" CREATE INDEX IF NOT EXISTS idx_status ON jobs(status) """) cursor.execute(""" CREATE INDEX IF NOT EXISTS idx_domain ON jobs(domain) """) cursor.execute(""" CREATE INDEX IF NOT EXISTS idx_created_at ON jobs(created_at) """) conn.commit() conn.close() print(f"✅ Database initialized at: {DB_PATH}") if __name__ == '__main__': init_database()