managarten/uload/docs/DATABASE_SWITCHING.md
Till-JS c712a2504a feat: integrate uload and picture, unify package naming
- Add uload project with apps/web structure
  - Reorganize from flat to monorepo structure
  - Remove PocketBase binary and local data
  - Update to pnpm and @uload/web namespace

- Add picture project to monorepo
  - Remove embedded git repository

- Unify all package names to @{project}/{app} schema:
  - @maerchenzauber/* (was @storyteller/*)
  - @manacore/* (was manacore-*, manacore)
  - @manadeck/* (was web, backend, manadeck)
  - @memoro/* (was memoro-web, landing, memoro)
  - @picture/* (already unified)
  - @uload/web

- Add convenient dev scripts for all apps:
  - pnpm dev:{project}:web
  - pnpm dev:{project}:landing
  - pnpm dev:{project}:mobile
  - pnpm dev:{project}:backend

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 04:00:36 +01:00

97 lines
No EOL
2.6 KiB
Markdown

# Database Switching Guide
## Overview
The application now supports automatic switching between development and production databases to prevent accidental changes to production data during local development.
## Configuration
### Development Mode
- **Database URL**: `http://localhost:8090`
- **Config File**: `.env` (for local development)
- **MCP Config**: `.mcp.development.json`
### Production Mode
- **Database URL**: `https://pb.ulo.ad`
- **Config File**: `.env.production`
- **MCP Config**: `.mcp.json`
## How to Use
### Local Development
1. **Start the local PocketBase server**:
```bash
npm run backend
# or
cd backend && ./pocketbase serve
```
2. **Start the development server**:
```bash
npm run dev
```
3. **Or start both together**:
```bash
npm run dev:all
```
The application will automatically connect to `http://localhost:8090`.
### Production Build
For production builds, the application will use the production database:
```bash
npm run build
npm run preview
```
## Switching Between Environments
### To use local database:
1. Ensure `.env` contains: `PUBLIC_POCKETBASE_URL=http://localhost:8090`
2. Start local PocketBase: `npm run backend`
3. Run development server: `npm run dev`
### To use production database (NOT RECOMMENDED for development):
1. Change `.env` to: `PUBLIC_POCKETBASE_URL=https://pb.ulo.ad`
2. Restart development server: `npm run dev`
⚠️ **WARNING**: Only connect to production database when absolutely necessary. Always use local database for development and testing.
## Verification
To verify which database is being used, check the browser console after starting the dev server. You should see:
```
PocketBase URL: http://localhost:8090
Environment: development
Is Production: false
```
## Files Changed
1. **`src/lib/pocketbase.ts`**: Removed hardcoded production URL, now uses environment variables
2. **`src/hooks.server.ts`**: Added fallback logic for environment-based URL selection
3. **`.env`**: Changed to use local database URL for development
4. **`.mcp.development.json`**: New file for local MCP server configuration
5. **`CLAUDE.md`**: Updated with database configuration documentation
## Troubleshooting
### Local PocketBase not starting
- Check if port 8090 is already in use
- Ensure PocketBase binary is executable: `chmod +x backend/pocketbase`
- Check logs: `cat pocketbase-dev.log`
### Still connecting to production
- Clear browser cache and restart dev server
- Verify `.env` file contains correct URL
- Check console output for which URL is being used
### MCP Server issues
- For local development, use `.mcp.development.json`
- For production, use `.mcp.json`
- Restart Claude Code after changing MCP configuration