Fix Flyway migration

This commit is contained in:
2026-04-06 13:35:01 -06:00
parent d51b1b0ab7
commit 18407f8328
3 changed files with 27 additions and 22 deletions

3
.gitignore vendored
View File

@@ -1,2 +1,5 @@
*.zip
.local/
commit-patches/
temp_photos/
uploads/

View File

@@ -35,13 +35,14 @@ public class FlywayContextInitializer implements ApplicationContextInitializer<C
RuntimeException lastFailure = null;
for (int attempt = 1; attempt <= MAX_RETRIES; attempt++) {
try {
Flyway.configure()
Flyway flyway = Flyway.configure()
.dataSource(url, username, password)
.locations(locations)
.baselineOnMigrate(environment.getProperty("spring.flyway.baseline-on-migrate", Boolean.class, false))
.baselineVersion(MigrationVersion.fromVersion(environment.getProperty("spring.flyway.baseline-version", "1")))
.load()
.migrate();
.load();
flyway.repair();
flyway.migrate();
return;
} catch (RuntimeException ex) {
lastFailure = ex;

View File

@@ -11,12 +11,18 @@ WHERE LOWER(appointmentStatus) = 'booked'
);
-- Part 2: Resolve potential double-bookings caused by V15's simple backfill.
-- We try to spread overlapping appointments among other active staff in the same store.
-- This is a one-time cleanup for demo data integrity.
-- Temporary table to find conflicts (same employee, same date, overlapping time)
-- For simplicity in SQL, we just check exact same time for the demo data cleanup.
-- MySQL Error 1093 workaround: wrap same-table subqueries in derived tables.
UPDATE appointment a1
JOIN (
SELECT a3.appointmentId
FROM appointment a3
INNER JOIN appointment a4
ON a4.employeeId = a3.employeeId
AND a4.appointmentDate = a3.appointmentDate
AND a4.appointmentTime = a3.appointmentTime
AND a4.appointmentId < a3.appointmentId
WHERE LOWER(a3.appointmentStatus) NOT IN ('cancelled', 'missed')
) conflicting ON conflicting.appointmentId = a1.appointmentId
SET a1.employeeId = (
SELECT es.employeeId
FROM employeeStore es
@@ -25,21 +31,16 @@ SET a1.employeeId = (
WHERE es.storeId = a1.storeId
AND e.isActive = TRUE
AND u.role = 'STAFF'
-- Find an employee who DOES NOT have an appointment at this exact time
AND NOT EXISTS (
SELECT 1 FROM appointment a2
WHERE a2.employeeId = es.employeeId
AND a2.appointmentDate = a1.appointmentDate
AND a2.appointmentTime = a1.appointmentTime
AND a2.appointmentId <> a1.appointmentId
SELECT 1 FROM (
SELECT employeeId, appointmentDate, appointmentTime, appointmentId
FROM appointment
) snap
WHERE snap.employeeId = es.employeeId
AND snap.appointmentDate = a1.appointmentDate
AND snap.appointmentTime = a1.appointmentTime
AND snap.appointmentId <> a1.appointmentId
)
ORDER BY es.employeeId ASC
LIMIT 1
)
WHERE EXISTS (
SELECT 1 FROM appointment a3
WHERE a3.employeeId = a1.employeeId
AND a3.appointmentDate = a1.appointmentDate
AND a3.appointmentTime = a1.appointmentTime
AND a3.appointmentId < a1.appointmentId
) AND LOWER(a1.appointmentStatus) NOT IN ('cancelled', 'missed');
);