Files
TimeTrack/MIGRATION_PROJECTS.md
Jens Luedicke be111a4bed Implement comprehensive project time logging feature
Add complete project management system with role-based access control:

**Core Features:**
- Project creation and management for Admins/Supervisors
- Time tracking with optional project selection and notes
- Project-based filtering and reporting in history
- Enhanced export functionality with project data
- Team-specific project assignments

**Database Changes:**
- New Project model with full relationships
- Enhanced TimeEntry model with project_id and notes
- Updated migration scripts with rollback support
- Sample project creation for testing

**User Interface:**
- Project management templates (create, edit, list)
- Enhanced time tracking with project dropdown
- Project filtering in history page
- Updated navigation for role-based access
- Modern styling with hover effects and responsive design

**API Enhancements:**
- Project validation and access control
- Updated arrive endpoint with project support
- Enhanced export functions with project data
- Role-based route protection

**Migration Support:**
- Comprehensive migration scripts (migrate_projects.py)
- Updated main migration script (migrate_db.py)
- Detailed migration documentation
- Rollback functionality for safe deployment

**Role-Based Access:**
- Admins: Full project CRUD operations
- Supervisors: Project creation and management
- Team Leaders: View team hours with projects
- Team Members: Select projects when tracking time

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-29 17:18:10 +02:00

5.0 KiB

Project Time Logging Migration Guide

This document explains how to migrate your TimeTrack database to support the new Project Time Logging feature.

Overview

The Project Time Logging feature adds the ability to:

  • Track time against specific projects
  • Manage projects with role-based access control
  • Filter and report on project-based time entries
  • Export data with project information

Database Changes

New Tables

  • project: Stores project information including name, code, description, team assignment, and dates

Modified Tables

  • time_entry: Added project_id (foreign key) and notes (text) columns
  • Existing data: All existing time entries remain unchanged and will show as "No project assigned"

Migration Options

The main migration script has been updated to include project functionality:

python migrate_db.py

This will:

  • Create the project table
  • Add project_id and notes columns to time_entry
  • Create 3 sample projects (if no admin user exists)
  • Maintain all existing data

Option 2: Run Project-Specific Migration

For existing installations, you can run the project-specific migration:

python migrate_projects.py

Option 3: Manual Migration

If you prefer to handle the migration manually, execute these SQL commands:

-- Create project table
CREATE TABLE project (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name VARCHAR(100) NOT NULL,
    description TEXT,
    code VARCHAR(20) NOT NULL UNIQUE,
    is_active BOOLEAN DEFAULT 1,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    created_by_id INTEGER NOT NULL,
    team_id INTEGER,
    start_date DATE,
    end_date DATE,
    FOREIGN KEY (created_by_id) REFERENCES user (id),
    FOREIGN KEY (team_id) REFERENCES team (id)
);

-- Add columns to time_entry table
ALTER TABLE time_entry ADD COLUMN project_id INTEGER;
ALTER TABLE time_entry ADD COLUMN notes TEXT;

Sample Projects

The migration creates these sample projects (if admin user exists):

  1. ADMIN001 - General Administration
  2. DEV001 - Development Project
  3. SUPPORT001 - Customer Support

These can be modified or deleted after migration.

Rollback

To rollback the project functionality (removes projects but keeps time entry columns):

python migrate_projects.py rollback

Note: Due to SQLite limitations, the project_id and notes columns cannot be removed from the time_entry table during rollback.

Post-Migration Steps

  1. Verify Migration: Check that the migration completed successfully
  2. Create Projects: Admin/Supervisor users can create projects via the web interface
  3. Assign Teams: Optionally assign projects to specific teams
  4. User Training: Inform users about the new project selection feature

Migration Verification

After running the migration, verify it worked by:

  1. Check Tables:

    .tables  -- Should show 'project' table
    .schema project  -- Verify project table structure
    .schema time_entry  -- Verify project_id and notes columns
    
  2. Check Web Interface:

    • Admin/Supervisor users should see "Manage Projects" in their dropdown menu
    • Time tracking interface should show project selection dropdown
    • History page should have project filtering
  3. Check Sample Projects:

    SELECT * FROM project;  -- Should show 3 sample projects
    

Troubleshooting

Migration Fails

  • Ensure no active connections to the database
  • Check file permissions
  • Verify admin user exists in the database
  • Clear browser cache
  • Verify user has Admin or Supervisor role
  • Check that the templates have been updated

Project Selection Not Available

  • Verify migration completed successfully
  • Check that active projects exist in the database
  • Ensure user has permission to access projects

Feature Access

Admin Users

  • Create, edit, delete, and manage all projects
  • Access project management interface
  • View all project reports

Supervisor Users

  • Create, edit, and manage projects
  • Access project management interface
  • View project reports

Team Leader Users

  • View team hours with project breakdown
  • No project creation/management access

Team Member Users

  • Select projects when tracking time
  • View personal history with project filtering
  • No project management access

File Changes

The migration affects these files:

  • migrate_db.py - Updated main migration script
  • migrate_projects.py - New project-specific migration
  • models.py - Added Project model and updated TimeEntry
  • app.py - Added project routes and updated existing routes
  • Templates - Updated with project functionality
  • static/js/script.js - Updated time tracking JavaScript

Backup Recommendation

Before running any migration, it's recommended to backup your database:

cp timetrack.db timetrack.db.backup

This allows you to restore the original database if needed.