# With confirmation./scrapai db query "UPDATE spider_settings SET value='3' WHERE key='DOWNLOAD_DELAY'"# Skip confirmation./scrapai db query "UPDATE spiders SET active=false WHERE project='archive'" --yes
INSERT, DROP, ALTER, and TRUNCATE are blocked for safety:
$ ./scrapai db query "DROP TABLE spiders"❌ Only SELECT, UPDATE, and DELETE queries are allowed INSERT, DROP, ALTER, and TRUNCATE are blocked for safety
Joins, aggregations, and subqueries are supported:
# Count items per spider./scrapai db query "SELECT s.name, COUNT(si.id) as item_count FROM spiders s LEFT JOIN scraped_items si ON s.id = si.spider_id GROUP BY s.name ORDER BY item_count DESC"# Find spiders with no items./scrapai db query "SELECT name FROM spiders WHERE id NOT IN (SELECT DISTINCT spider_id FROM scraped_items)"# Queue statistics by project./scrapai db query "SELECT project_name, status, COUNT(*) as count FROM crawl_queue GROUP BY project_name, status ORDER BY project_name, status"
# 1. Update .envDATABASE_URL=postgresql://user:pass@localhost:5432/scrapai# 2. Run migrations./scrapai db migrate# 3. Transfer from SQLite./scrapai db transfer sqlite:///scrapai.db
# 1. Update .env to new databaseDATABASE_URL=postgresql://user:pass@new-host:5432/scrapai# 2. Run migrations./scrapai db migrate# 3. Transfer from old database./scrapai db transfer postgresql://user:pass@old-host:5432/scrapai
$ ./scrapai db transfer postgresql://localhost:5432/scrapai❌ Source is the same as current database. Update DATABASE_URL in .env to your new database first.
$ ./scrapai db transfer postgresql://bad-host:5432/db❌ Transfer failed: connection to server at "bad-host" failed
All operations are transactional. If transfer fails, target database is rolled back.
# In .envDATABASE_URL=postgresql://user:password@localhost:5432/scrapai# Run migrations./scrapai db migrate# Transfer from SQLite./scrapai db transfer sqlite:///scrapai.db
# Spiders by item count./scrapai db query "SELECT s.name, s.project, COUNT(si.id) as itemsFROM spiders sLEFT JOIN scraped_items si ON s.id = si.spider_idGROUP BY s.name, s.projectORDER BY items DESC" --format table# Recent spiders./scrapai db query "SELECT name, project, created_at FROM spiders ORDER BY created_at DESC LIMIT 10"
# Queue status summary./scrapai db query "SELECT status, COUNT(*) as count FROM crawl_queue GROUP BY status"# Failed items with errors./scrapai db query "SELECT website_url, error_message, updated_at FROM crawl_queue WHERE status='failed' ORDER BY updated_at DESC" --format json
# Items by date./scrapai db query "SELECT DATE(scraped_at) as date, COUNT(*) as count FROM scraped_items GROUP BY DATE(scraped_at) ORDER BY date DESC LIMIT 7"# Search content./scrapai db query "SELECT title, url FROM scraped_items WHERE content LIKE '%climate change%' LIMIT 10"