# Database Scripts **Simplified database initialization system for Interactive Brokers data.** ## Quick Start ```bash # Initialize everything (recommended) bun run db:init # Or run Interactive Brokers setup directly: bun run db:setup-ib # Create schema and populate IB data ``` ## What We Built ✅ **Simplified from complex multi-table schema to exchanges-only** ✅ **Single script setup** - `setup-ib.ts` handles both schema and data ✅ **Structured logging** with `@stock-bot/logger` ✅ **184 exchanges populated** from JSON data ✅ **Proper error handling** with helpful troubleshooting messages ## Scripts ### `setup-ib.ts` - Interactive Brokers Complete Setup **Main script for IB setup** - Sets up schema and populates exchange data in one go. ### `init.ts` Main initialization script that orchestrates setup for all providers. ## Database Schema ### IB Data (`ib_data` schema) - `exchanges` - Trading exchanges with metadata - `upsert_exchange()` - Function to insert/update exchanges ## Package.json Commands ```json { "db:init": "Run complete database initialization", "db:setup-ib": "Complete IB setup (schema + data)" } ``` ## Adding New Providers 1. Create `{provider}.sql` in `database/postgres/providers/` 2. Create `{provider}.ts` script 3. Add to `init.ts` and `package.json` ## Requirements - PostgreSQL running - Database configured in `.env` - `ib-exchanges.json` file in `apps/data-service/src/setup/`