Today I continued the migration process, focusing specifically on converting the shift management system from Google Apps Script to our new PHP framework. This module is particularly complex due to its interconnected nature and real-time requirements.
I began by designing the database schema for shift-related tables. Moving from our previous flat structure to a relational model required careful consideration of entity relationships. I created migrations for several tables including shifts
, shift_types
, employee_shifts
, and shift_statuses
, establishing appropriate foreign key relationships between them. This normalization eliminates much of the data redundancy we experienced in our Google Sheets implementation while enabling more sophisticated queries than were previously possible.
One particularly challenging aspect was converting our time-based logic for shift status updates. In the Apps Script environment, we relied heavily on time-driven triggers to automatically update shift statuses based on current time. The PHP environment requires a different approach, so I implemented a combination of scheduled tasks using Laravel’s task scheduler and event listeners that respond to status change conditions. This new implementation actually improves reliability by removing dependencies on Google’s trigger execution timing, which occasionally had delays.
I spent considerable time rebuilding the shift assignment algorithm that matches employees to open shifts. This logic was previously embedded in client-side JavaScript with server-side validation in Apps Script. I refactored it into proper service classes in Laravel, implementing more sophisticated validation rules and business logic constraints. The new implementation properly separates concerns between the data layer, business logic, and presentation, making the code significantly more maintainable.
Another critical component was recreating the conflict detection system that prevents scheduling conflicts. The original implementation had numerous edge cases and special conditions scattered throughout the code. I consolidated these into a dedicated ConflictDetectionService that systematically checks for various conflict types (double-booking, leave conflicts, rest period violations) using clean, testable methods. This refactoring not only preserves the original functionality but makes it easier to modify or extend the conflict rules in the future.
By late afternoon, I had made significant progress on the shift management migration but still have components remaining to complete. Tomorrow I’ll focus on finalizing the shift display functionality and implementing the calendar views using a PHP-compatible approach instead of our previous implementation.