commit cb82580f868b629902ba96c7f09f885b7d9c24dc Author: Jens Luedicke <jens.luedicke@gmail.com> Date: Thu Jul 3 22:42:49 2025 +0200 Fix for postgres db migration. #5 commit 6a4505e2db1cdb2cec65e630b63535ba08c02fc4 Author: Jens Luedicke <jens.luedicke@gmail.com> Date: Thu Jul 3 22:39:58 2025 +0200 Fix for postgres db migration. #4 commit 7d9a5bb12c591182e67d7d52f90d6b1a45260d9f Author: Jens Luedicke <jens.luedicke@gmail.com> Date: Thu Jul 3 22:38:02 2025 +0200 Fix for postgres db migration. #3 commit 29dbb8b62d873dfbc4901b21e637a7181d545ec7 Author: Jens Luedicke <jens.luedicke@gmail.com> Date: Thu Jul 3 22:35:08 2025 +0200 Fix for postgres db migration. #2 commit d5afc56290d05f53e06a77366214c605d0989c1d Author: Jens Luedicke <jens.luedicke@gmail.com> Date: Thu Jul 3 22:33:09 2025 +0200 Fix for postgres db migration. commit 936008fe1c56b6e699c4a45b503507b6423e15eb Author: Jens Luedicke <jens.luedicke@gmail.com> Date: Thu Jul 3 21:46:32 2025 +0200 Add changes for gunicorn. commit 464c71e5102117f35d05e1504165299ffa50c70c Author: Jens Luedicke <jens.luedicke@gmail.com> Date: Thu Jul 3 20:30:29 2025 +0200 Add changes for Postgres migration.
5.3 KiB
TimeTrack Database Migration Guide
This guide explains how to migrate your TimeTrack application from SQLite to PostgreSQL using Docker.
Overview
TimeTrack now supports both SQLite and PostgreSQL databases. The migration process automatically converts your existing SQLite database to PostgreSQL while preserving all your data.
Prerequisites
- Docker and Docker Compose installed
- Existing TimeTrack SQLite database
- Basic understanding of command line operations
Quick Start (Automatic Migration)
-
Set up environment variables:
cp .env.example .env # Edit .env file with your configuration -
Start the services:
docker-compose up -d
The migration will happen automatically when you first start the application with PostgreSQL configured.
Manual Migration Process
If you prefer to control the migration process manually:
-
Prepare your environment:
cp .env.example .env # Edit .env file with your database credentials -
Start PostgreSQL and pgAdmin:
docker-compose up -d postgres pgadmin -
Run the migration script:
./scripts/migrate.sh -
Start the application:
docker-compose up -d timetrack
Configuration
Environment Variables (.env)
# Database Configuration
POSTGRES_DB=timetrack
POSTGRES_USER=timetrack
POSTGRES_PASSWORD=timetrack_password
POSTGRES_PORT=5432
# pgAdmin Configuration
PGADMIN_EMAIL=admin@timetrack.com
PGADMIN_PASSWORD=admin
PGADMIN_PORT=5050
# TimeTrack App Configuration
TIMETRACK_PORT=5000
FLASK_ENV=production
SECRET_KEY=your-secret-key-here
DATABASE_URL=postgresql://timetrack:timetrack_password@postgres:5432/timetrack
# Mail Configuration
MAIL_SERVER=smtp.example.com
MAIL_PORT=587
MAIL_USE_TLS=true
MAIL_USERNAME=your-email@example.com
MAIL_PASSWORD=your-password
MAIL_DEFAULT_SENDER=TimeTrack <noreply@timetrack.com>
SQLite Path
By default, the migration looks for your SQLite database at /data/timetrack.db. If your database is located elsewhere, set the SQLITE_PATH environment variable:
SQLITE_PATH=/path/to/your/timetrack.db
Migration Process Details
The migration process includes:
- Database Connection: Connects to both SQLite and PostgreSQL
- Backup Creation: Creates a backup of existing PostgreSQL data (if any)
- Schema Creation: Creates PostgreSQL tables using SQLAlchemy models
- Data Migration: Transfers all data from SQLite to PostgreSQL
- Sequence Updates: Updates PostgreSQL auto-increment sequences
- Verification: Verifies that all data was migrated correctly
Tables Migrated
- Companies and multi-tenancy data
- Users and authentication information
- Teams and project assignments
- Projects and categories
- Tasks and subtasks
- Time entries and work logs
- Work configurations and user preferences
- System settings
Post-Migration
After successful migration:
- SQLite Database: Renamed to
.migratedto indicate completion - Backup Files: Created with timestamp for rollback if needed
- Application: Automatically uses PostgreSQL for all operations
- Verification: Check
migration.logfor detailed migration results
Accessing pgAdmin
After starting the services, you can access pgAdmin at:
- URL: http://localhost:5050
- Email: admin@timetrack.com (or your configured email)
- Password: admin (or your configured password)
Server Connection in pgAdmin:
- Host: postgres
- Port: 5432
- Database: timetrack
- Username: timetrack
- Password: timetrack_password
Troubleshooting
Common Issues
-
PostgreSQL Connection Failed
- Ensure PostgreSQL container is running:
docker-compose ps postgres - Check connection settings in .env file
- Ensure PostgreSQL container is running:
-
SQLite Database Not Found
- Verify the SQLite database path
- Ensure the database file is accessible from the container
-
Migration Fails
- Check
migration.logfor detailed error messages - Verify PostgreSQL has sufficient permissions
- Ensure no data conflicts exist
- Check
-
Data Verification Failed
- Compare row counts between SQLite and PostgreSQL
- Check for foreign key constraint violations
- Review migration.log for specific table issues
Manual Recovery
If migration fails, you can:
-
Restore from backup:
# Restore PostgreSQL from backup docker-compose exec postgres psql -U timetrack -d timetrack < postgres_backup_TIMESTAMP.sql -
Revert to SQLite:
# Rename migrated database back mv /data/timetrack.db.migrated /data/timetrack.db # Update .env to use SQLite DATABASE_URL=sqlite:////data/timetrack.db
Performance Considerations
- Migration time depends on database size
- Large databases may take several minutes
- Migration runs in batches to optimize memory usage
- All operations are logged for monitoring
Security Notes
- Change default passwords before production use
- Use strong, unique passwords for database access
- Ensure .env file is not committed to version control
- Regularly backup your PostgreSQL database
Support
For issues or questions about the migration process:
- Check the migration.log file for detailed error messages
- Review this documentation for common solutions
- Ensure all prerequisites are met
- Verify environment configuration