Skip to main content

Part 3: Database Setup

For Everyone 5 min read
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:

.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
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

olytix-core serve --reload

The --reload flag enables hot-reloading for development.

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:

URLDescription
http://localhost:8000/healthHealth check endpoint
http://localhost:8000/docsSwagger UI (interactive API docs)
http://localhost:8000/redocReDoc (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

Next Step