# Local Development Setup ## PostgreSQL Only (Recommended for Local Development) Voor lokale development heb je alleen PostgreSQL nodig. De backend en frontend draaien lokaal op je MacBook. ### Start PostgreSQL ```bash # Start alleen PostgreSQL docker-compose -f docker-compose.dev.yml up -d # Check status docker-compose -f docker-compose.dev.yml ps # Check logs docker-compose -f docker-compose.dev.yml logs -f postgres ``` ### Connection String ```env DATABASE_TYPE=postgres DATABASE_URL=postgresql://cmdb:cmdb-dev@localhost:5432/cmdb_cache ``` Of individuele variabelen: ```env DATABASE_TYPE=postgres DATABASE_HOST=localhost DATABASE_PORT=5432 DATABASE_NAME=cmdb_cache DATABASE_USER=cmdb DATABASE_PASSWORD=cmdb-dev ``` ### Stop PostgreSQL ```bash docker-compose -f docker-compose.dev.yml down ``` ### Reset Database ```bash # Stop en verwijder volume docker-compose -f docker-compose.dev.yml down -v # Start opnieuw docker-compose -f docker-compose.dev.yml up -d ``` ### Connect to Database ```bash # Via psql docker-compose -f docker-compose.dev.yml exec postgres psql -U cmdb -d cmdb_cache # Of direct psql postgresql://cmdb:cmdb-dev@localhost:5432/cmdb_cache ``` ### Useful Commands ```bash # List databases docker-compose -f docker-compose.dev.yml exec postgres psql -U cmdb -c "\l" # List tables docker-compose -f docker-compose.dev.yml exec postgres psql -U cmdb -d cmdb_cache -c "\dt" # Check database size docker-compose -f docker-compose.dev.yml exec postgres psql -U cmdb -d cmdb_cache -c " SELECT pg_size_pretty(pg_database_size('cmdb_cache')) as size; " # Count objects docker-compose -f docker-compose.dev.yml exec postgres psql -U cmdb -d cmdb_cache -c " SELECT object_type_name, COUNT(*) FROM objects GROUP BY object_type_name; " ``` ## Full Stack (Alternative) Als je de hele stack in Docker wilt draaien: ```bash docker-compose up -d ``` Dit start: - PostgreSQL - Backend (in Docker) - Frontend (in Docker) ## Backend Development Met alleen PostgreSQL draaiend: ```bash # In backend directory cd backend npm install npm run dev ``` Backend draait op `http://localhost:3001` ## Frontend Development ```bash # In frontend directory cd frontend npm install npm run dev ``` Frontend draait op `http://localhost:5173` ## Environment Variables Maak een `.env` bestand in de root: ```env # Database (voor backend) DATABASE_TYPE=postgres DATABASE_URL=postgresql://cmdb:cmdb-dev@localhost:5432/cmdb_cache # Jira (optioneel) JIRA_HOST=https://jira.zuyderland.nl JIRA_PAT=your_token JIRA_SCHEMA_ID=your_schema_id # AI (optioneel) ANTHROPIC_API_KEY=your_key ``` ## Troubleshooting ### Port Already in Use Als poort 5432 al in gebruik is: ```yaml # In docker-compose.dev.yml, wijzig: ports: - "5433:5432" # Gebruik 5433 lokaal ``` En update je `.env`: ```env DATABASE_PORT=5433 ``` ### Connection Refused ```bash # Check of container draait docker ps | grep postgres # Check logs docker-compose -f docker-compose.dev.yml logs postgres # Test connection docker-compose -f docker-compose.dev.yml exec postgres pg_isready -U cmdb ``` ### Database Not Found De database wordt automatisch aangemaakt bij eerste start van de backend. Of maak handmatig: ```bash docker-compose -f docker-compose.dev.yml exec postgres psql -U cmdb -c "CREATE DATABASE cmdb_cache;" ```