diff --git a/README.md b/README.md index b34a10f..0b8d62a 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,170 @@ Set via environment variable: export DJANGO_SETTINGS_MODULE=config.settings.development ``` +### Database Configuration + +The application supports multiple database backends. Choose the one that fits your needs. + +#### SQLite3 (Default - Development) + +SQLite3 is the default database and requires no additional setup. It's perfect for development and single-user scenarios. + +**Configuration in `config/settings/development.py`:** +```python +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} +``` + +**Pros:** +- Zero configuration +- No separate database server needed +- Perfect for development and testing + +**Cons:** +- Not recommended for production with multiple users +- Limited concurrent write operations +- No network access (local file only) + +#### PostgreSQL (Recommended for Production) + +PostgreSQL is the recommended database for production deployments. + +**1. Install PostgreSQL:** +```bash +# Ubuntu/Debian +sudo apt-get install postgresql postgresql-contrib libpq-dev + +# macOS +brew install postgresql +``` + +**2. Create database and user:** +```bash +sudo -u postgres psql +CREATE DATABASE keepitgoing; +CREATE USER keepitgoing_user WITH PASSWORD 'your_secure_password'; +ALTER ROLE keepitgoing_user SET client_encoding TO 'utf8'; +ALTER ROLE keepitgoing_user SET default_transaction_isolation TO 'read committed'; +ALTER ROLE keepitgoing_user SET timezone TO 'UTC'; +GRANT ALL PRIVILEGES ON DATABASE keepitgoing TO keepitgoing_user; +\q +``` + +**3. Install Python driver:** +```bash +pip install psycopg2-binary +``` + +**4. Update settings:** + +Add to your `.env` file: +```bash +DATABASE_URL=postgresql://keepitgoing_user:your_secure_password@localhost:5432/keepitgoing +``` + +Or configure directly in settings: +```python +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': 'keepitgoing', + 'USER': 'keepitgoing_user', + 'PASSWORD': 'your_secure_password', + 'HOST': 'localhost', + 'PORT': '5432', + } +} +``` + +**5. Run migrations:** +```bash +python manage.py migrate +``` + +#### MariaDB/MySQL + +MariaDB and MySQL are also supported for production use. + +**1. Install MariaDB:** +```bash +# Ubuntu/Debian +sudo apt-get install mariadb-server libmariadb-dev + +# macOS +brew install mariadb +``` + +**2. Create database and user:** +```bash +sudo mysql +CREATE DATABASE keepitgoing CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; +CREATE USER 'keepitgoing_user'@'localhost' IDENTIFIED BY 'your_secure_password'; +GRANT ALL PRIVILEGES ON keepitgoing.* TO 'keepitgoing_user'@'localhost'; +FLUSH PRIVILEGES; +EXIT; +``` + +**3. Install Python driver:** +```bash +pip install mysqlclient +``` + +**4. Update settings:** + +Add to your `.env` file: +```bash +DATABASE_URL=mysql://keepitgoing_user:your_secure_password@localhost:3306/keepitgoing +``` + +Or configure directly in settings: +```python +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.mysql', + 'NAME': 'keepitgoing', + 'USER': 'keepitgoing_user', + 'PASSWORD': 'your_secure_password', + 'HOST': 'localhost', + 'PORT': '3306', + 'OPTIONS': { + 'charset': 'utf8mb4', + 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'", + }, + } +} +``` + +**5. Run migrations:** +```bash +python manage.py migrate +``` + +#### Database Migration Between Backends + +To migrate data from one database to another: + +**1. Export data from current database:** +```bash +python manage.py dumpdata --natural-foreign --natural-primary \ + -e contenttypes -e auth.Permission --indent 4 > data.json +``` + +**2. Update database settings to new backend** + +**3. Run migrations on new database:** +```bash +python manage.py migrate --run-syncdb +``` + +**4. Import data:** +```bash +python manage.py loaddata data.json +``` + ### Environment Variables Key environment variables (see `.env.example`): @@ -125,7 +289,7 @@ Key environment variables (see `.env.example`): - `SECRET_KEY` - Django secret key (required in production) - `DEBUG` - Enable debug mode (True/False) - `ALLOWED_HOSTS` - Comma-separated list of allowed hosts -- `DATABASE_URL` - Database connection string +- `DATABASE_URL` - Database connection string (optional, overrides settings) - `REDIS_URL` - Redis connection for Celery - `CSRF_TRUSTED_ORIGINS` - HTTPS origins for CSRF