Part 3: Database Setup
What you'll learn
- Configure environment variables
- Set up warehouse connection
- Test the database connection
- Start the API server
Step 1: Create Environment File
Copy the example environment file:
cp .env.example .env
Step 2: Configure Connection
Edit the .env file with your warehouse credentials:
- PostgreSQL
- Snowflake
- BigQuery
.env
# Environment
OLYTIX_ENVIRONMENT=development
# Warehouse Connection
OLYTIX_WAREHOUSE_DB__ADAPTER=postgresql
OLYTIX_WAREHOUSE_DB__HOST=your-warehouse-host
OLYTIX_WAREHOUSE_DB__PORT=5432
OLYTIX_WAREHOUSE_DB__DATABASE=your-database
OLYTIX_WAREHOUSE_DB__USERNAME=your-username
OLYTIX_WAREHOUSE_DB__PASSWORD=your-password
# API Configuration
OLYTIX_API__HOST=0.0.0.0
OLYTIX_API__PORT=8000
OLYTIX_API__DEBUG=true
.env
# Environment
OLYTIX_ENVIRONMENT=development
# Warehouse Connection
OLYTIX_WAREHOUSE_DB__ADAPTER=snowflake
OLYTIX_WAREHOUSE_DB__ACCOUNT=your-account.region
OLYTIX_WAREHOUSE_DB__DATABASE=your-database
OLYTIX_WAREHOUSE_DB__WAREHOUSE=your-warehouse
OLYTIX_WAREHOUSE_DB__USERNAME=your-username
OLYTIX_WAREHOUSE_DB__PASSWORD=your-password
OLYTIX_WAREHOUSE_DB__SCHEMA=PUBLIC
# API Configuration
OLYTIX_API__HOST=0.0.0.0
OLYTIX_API__PORT=8000
OLYTIX_API__DEBUG=true
.env
# Environment
OLYTIX_ENVIRONMENT=development
# Warehouse Connection
OLYTIX_WAREHOUSE_DB__ADAPTER=bigquery
OLYTIX_WAREHOUSE_DB__PROJECT=your-gcp-project
OLYTIX_WAREHOUSE_DB__DATASET=your-dataset
OLYTIX_WAREHOUSE_DB__CREDENTIALS_PATH=/path/to/service-account.json
# API Configuration
OLYTIX_API__HOST=0.0.0.0
OLYTIX_API__PORT=8000
OLYTIX_API__DEBUG=true
Environment Variable Format
Olytix uses __ (double underscore) as a nested delimiter. So OLYTIX_WAREHOUSE_DB__HOST maps to warehouse_db.host in the configuration.
Step 3: Test Connection
Verify your database connection before starting the server:
olytix-core test-connection
Expected output:
Testing connection to warehouse...
✓ Connection successful!
Adapter: postgresql
Host: your-warehouse-host
Database: your-database
Tables found: 47
Connection Issues?
If the connection fails:
# Check your configuration
olytix-core config show
# Common issues:
# - Firewall blocking port 5432
# - Incorrect credentials
# - Database server not running
Step 4: Start the Server
- Using CLI (Recommended)
- Using Uvicorn Directly
olytix-core serve --reload
The --reload flag enables hot-reloading for development.
uvicorn src.olytix_core.api.app:create_app --factory --reload --port 8000
Expected output:
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
INFO: Started reloader process [12345]
INFO: Started server process [12346]
INFO: Waiting for application startup.
INFO: Application startup complete.
Step 5: Verify Server
Open your browser to verify the server is running:
| URL | Description |
|---|---|
| http://localhost:8000/health | Health check endpoint |
| http://localhost:8000/docs | Swagger UI (interactive API docs) |
| http://localhost:8000/redoc | ReDoc (alternative API docs) |
Or use curl:
# Health check
curl http://localhost:8000/health
Expected response:
{
"status": "healthy",
"version": "0.1.0",
"project_loaded": false
}
Troubleshooting
Server Won't Start
# Check if port 8000 is already in use
lsof -i :8000
# Use a different port
olytix-core serve --port 8001
Environment Variables Not Loading
# Verify .env file exists
ls -la .env
# Check variable values
olytix-core config show
Database Connection Timeout
# Test basic connectivity
nc -zv your-warehouse-host 5432
# Check DNS resolution
nslookup your-warehouse-host