
- Add Alembic for database migrations - Implement user authentication system - Update frontend styles and components - Add new test audio functionality - Update stream management and UI
2.1 KiB
2.1 KiB
Database Setup and Migrations
This document explains how to set up and manage the database for the dicta2stream application.
Prerequisites
- PostgreSQL database server
- Python 3.8+
- Required Python packages (install with
pip install -r requirements.txt
)
Initial Setup
-
Create a PostgreSQL database:
createdb dicta2stream
-
Set up the database URL in your environment:
echo "DATABASE_URL=postgresql://username:password@localhost/dicta2stream" > .env
Replace
username
andpassword
with your PostgreSQL credentials. -
Initialize the database:
python init_db.py
Running Migrations
After making changes to the database models, you can create and apply migrations:
-
Install the required dependencies:
pip install -r requirements.txt
-
Run the migrations:
python run_migrations.py
Database Models
The application uses the following database models:
User
- Stores user account information
- Fields: username, email, hashed_password, is_active, created_at, updated_at
Session
- Manages user sessions
- Fields: id, user_id, token, ip_address, user_agent, created_at, expires_at, last_used_at, is_active
PublicStream
- Tracks publicly available audio streams
- Fields: uid, filename, size, mtime, created_at, updated_at
UserQuota
- Tracks user storage quotas
- Fields: uid, storage_bytes, updated_at
UploadLog
- Logs file uploads
- Fields: id, uid, filename, size, ip_address, user_agent, created_at
Backing Up the Database
To create a backup of your database:
pg_dump -U username -d dicta2stream -f backup.sql
To restore from a backup:
psql -U username -d dicta2stream -f backup.sql
Troubleshooting
-
If you encounter connection issues, verify that:
- The PostgreSQL server is running
- The database URL in your .env file is correct
- The database user has the necessary permissions
-
If you need to reset the database:
dropdb dicta2stream createdb dicta2stream python init_db.py