# ThrillWiki Development Scripts

## Development Server Script

The `dev_server.sh` script sets up all necessary environment variables and starts the Django development server with proper configuration.

### Usage

```bash
# From the project root directory
./scripts/dev_server.sh

# Or from anywhere
/path/to/thrillwiki_django_no_react/scripts/dev_server.sh
```

### What the script does

1. **Environment Setup**: Sets all required environment variables for local development
2. **Directory Creation**: Creates necessary directories (logs, profiles, media, etc.)
3. **Database Migrations**: Runs pending migrations automatically
4. **Superuser Creation**: Creates a development superuser (admin/admin) if none exists
5. **Static Files**: Collects static files for the application
6. **Tailwind CSS**: Builds Tailwind CSS if npm is available
7. **System Checks**: Runs Django system checks
8. **Server Start**: Starts the Django development server on `http://localhost:8000`

### Environment Variables Set

The script automatically sets these environment variables:

- `DJANGO_SETTINGS_MODULE=config.django.local`
- `DEBUG=True`
- `SECRET_KEY=<generated-dev-key>`
- `ALLOWED_HOSTS=localhost,127.0.0.1,0.0.0.0`
- `DATABASE_URL=postgis://thrillwiki_user:thrillwiki_pass@localhost:5432/thrillwiki_db`
- `CACHE_URL=locmemcache://`
- `CORS_ALLOW_ALL_ORIGINS=True`
- GeoDjango library paths for macOS
- And many more...

### Prerequisites

1. **PostgreSQL with PostGIS**: Make sure PostgreSQL with PostGIS extension is running
2. **Database**: Create the database `thrillwiki_db` with user `thrillwiki_user`
3. **uv**: The script uses `uv` to run Django commands
4. **Virtual Environment**: The script will activate `.venv` if it exists

### Database Setup

If you need to set up the database:

```bash
# Install PostgreSQL and PostGIS (macOS with Homebrew)
brew install postgresql postgis

# Start PostgreSQL
brew services start postgresql

# Create database and user
psql postgres -c "CREATE USER thrillwiki_user WITH PASSWORD 'thrillwiki_pass';"
psql postgres -c "CREATE DATABASE thrillwiki_db OWNER thrillwiki_user;"
psql -d thrillwiki_db -c "CREATE EXTENSION postgis;"
psql -d thrillwiki_db -c "GRANT ALL PRIVILEGES ON DATABASE thrillwiki_db TO thrillwiki_user;"
```

### Access Points

Once the server is running, you can access:

- **Main Application**: http://localhost:8000
- **Admin Interface**: http://localhost:8000/admin/ (admin/admin)
- **Django Silk Profiler**: http://localhost:8000/silk/
- **API Documentation**: http://localhost:8000/api/docs/
- **API Redoc**: http://localhost:8000/api/redoc/

### Stopping the Server

Press `Ctrl+C` to stop the development server.

### Troubleshooting

1. **Database Connection Issues**: Ensure PostgreSQL is running and the database exists
2. **GeoDjango Library Issues**: Adjust `GDAL_LIBRARY_PATH` and `GEOS_LIBRARY_PATH` if needed
3. **Permission Issues**: Make sure the script is executable with `chmod +x scripts/dev_server.sh`
4. **Virtual Environment**: Ensure your virtual environment is set up with all dependencies

### Customization

You can modify the script to:
- Change default database credentials
- Adjust library paths for your system
- Add additional environment variables
- Modify the development server port or host
