Files
HRM-System/docs/PLAN-data-migration.md
2026-04-23 10:15:50 +08:00

3.0 KiB

Data Migration Plan: Employee, Shift, and Attendance

Executive Summary

This document outlines a structured plan to import historical Employee, Shift, and Attendance records from the legacy data dump (rame_seb.sql) into the current HRM system. Based on user directives, we will replicate the legacy data as closely as possible to the new relational structure.

Architectural Approach & Data Mapping

1. Employee Details

  • Source: Legacy users table.
  • Target: Current users and employees tables.
  • Approach:
    • We will read the legacy users rows.
    • For each row, create a User identity for authentication.
    • Password Rule: Explicitly set all imported users' passwords to 123456 (hashed using Laravel's Hash::make('123456')) to ensure smooth initial access.
    • Create the related Employee profile using the legacy HR details (phone, address, etc.), maintaining the mapping via user_id.

2. Shifts (The 48-Shift Strategy)

  • Source: Legacy shifts table (contains ~48 half-hour interval shifts covering the 24-hour cycle, e.g., OPS 12:00AM-09:00AM).
  • Target: Current shifts table.
  • Approach:
    • Direct Replication: We will import all 48 distinct shift templates exactly as they are defined in the legacy system.
    • Scheduling: Since the legacy shifts are universally enabled for all 7 days (sunday through saturday = 1), we do not need complex roster logic. We will simply migrate the start_time, end_time, and is_night_shift logic into our new Shift templates, making them immediately available for assignment to Employees.

3. Attendance

  • Source: Legacy attendances table.
  • Target: Current attendance_records table.
  • Approach:
    • Read the raw check_in_time, check_out_time, and working_hours from the legacy database.
    • Link them to the newly generated Employee ID rather than the old legacy User ID.
    • Map legacy attendance statuses (present, leave, etc.) to the new system's properties.
    • "Just Copy" strategy: Orphaned records (if any) will still be imported if the related user exists, preserving historical attendance integrity.

Task Breakdown / Execution Plan

  1. Database Preparation:
    • Load rame_seb.sql into a temporary secondary database connection in Laravel (e.g., legacy_db).
  2. Shift Importer:
    • Write a Seeder/Command to insert the 48 shifts into the shifts table.
    • Retain legacy id mappings to properly link attendance records later.
  3. Employee Importer:
    • Write a Command to stream legacy users.
    • Insert into users (password: 123456).
    • Insert into employees (associate with their legacy default shift_id).
  4. Attendance Importer:
    • Write a Command to fetch all legacy attendances.
    • Remap IDs to the new structure and insert them sequentially into attendance_records.

This plan is ready for execution. Run /create or confirm to proceed with writing the import scripts.