Refactor SQL scripts for index creation in sick and vacation tables; implement checks to prevent duplicate index creation and streamline execution process. Update TimeEntryService to remove obsolete overtime calculation method for cleaner code.
This commit is contained in:
@@ -1,9 +1,22 @@
|
||||
-- Füge Index für vacation Tabelle hinzu
|
||||
-- Optimiert die Abfrage: WHERE user_id = ? AND first_day >= ? ORDER BY first_day DESC
|
||||
-- Ausführen mit: mysql -u root -p timeclock < add-vacation-index.sql
|
||||
|
||||
CREATE INDEX idx_vacation_user_first_day
|
||||
ON vacation (user_id, first_day DESC);
|
||||
-- Prüfe zuerst ob der Index bereits existiert
|
||||
SELECT COUNT(*) INTO @index_exists
|
||||
FROM information_schema.statistics
|
||||
WHERE table_schema = DATABASE()
|
||||
AND table_name = 'vacation'
|
||||
AND index_name = 'idx_vacation_user_first_day';
|
||||
|
||||
-- Prüfe ob der Index erstellt wurde
|
||||
SHOW INDEX FROM vacation WHERE Key_name = 'idx_vacation_user_first_day';
|
||||
SET @sql = IF(@index_exists = 0,
|
||||
'CREATE INDEX idx_vacation_user_first_day ON vacation (user_id, first_day DESC)',
|
||||
'SELECT "Index idx_vacation_user_first_day existiert bereits" AS Info'
|
||||
);
|
||||
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
SELECT 'Index idx_vacation_user_first_day erfolgreich erstellt oder bereits vorhanden.' AS Status;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user