Internal
Public Access
Add comprehensive database configuration documentation
Updated README with detailed instructions for: - SQLite3 (default/development) with pros/cons - PostgreSQL (recommended for production) with full setup - MariaDB/MySQL configuration and setup - Database migration between backends Each section includes: - Installation instructions for Ubuntu/Debian and macOS - Database and user creation commands - Python driver installation - Configuration examples (both .env and direct settings) - Migration steps Also added data export/import instructions for switching databases. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.5
parent
7f7ea3fef4
commit
87afc4e80c
@@ -118,6 +118,170 @@ Set via environment variable:
|
|||||||
export DJANGO_SETTINGS_MODULE=config.settings.development
|
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
|
### Environment Variables
|
||||||
|
|
||||||
Key environment variables (see `.env.example`):
|
Key environment variables (see `.env.example`):
|
||||||
@@ -125,7 +289,7 @@ Key environment variables (see `.env.example`):
|
|||||||
- `SECRET_KEY` - Django secret key (required in production)
|
- `SECRET_KEY` - Django secret key (required in production)
|
||||||
- `DEBUG` - Enable debug mode (True/False)
|
- `DEBUG` - Enable debug mode (True/False)
|
||||||
- `ALLOWED_HOSTS` - Comma-separated list of allowed hosts
|
- `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
|
- `REDIS_URL` - Redis connection for Celery
|
||||||
- `CSRF_TRUSTED_ORIGINS` - HTTPS origins for CSRF
|
- `CSRF_TRUSTED_ORIGINS` - HTTPS origins for CSRF
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user