Fix Flyway migration
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,2 +1,5 @@
|
|||||||
*.zip
|
*.zip
|
||||||
.local/
|
.local/
|
||||||
|
commit-patches/
|
||||||
|
temp_photos/
|
||||||
|
uploads/
|
||||||
|
|||||||
@@ -35,13 +35,14 @@ public class FlywayContextInitializer implements ApplicationContextInitializer<C
|
|||||||
RuntimeException lastFailure = null;
|
RuntimeException lastFailure = null;
|
||||||
for (int attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
for (int attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
||||||
try {
|
try {
|
||||||
Flyway.configure()
|
Flyway flyway = Flyway.configure()
|
||||||
.dataSource(url, username, password)
|
.dataSource(url, username, password)
|
||||||
.locations(locations)
|
.locations(locations)
|
||||||
.baselineOnMigrate(environment.getProperty("spring.flyway.baseline-on-migrate", Boolean.class, false))
|
.baselineOnMigrate(environment.getProperty("spring.flyway.baseline-on-migrate", Boolean.class, false))
|
||||||
.baselineVersion(MigrationVersion.fromVersion(environment.getProperty("spring.flyway.baseline-version", "1")))
|
.baselineVersion(MigrationVersion.fromVersion(environment.getProperty("spring.flyway.baseline-version", "1")))
|
||||||
.load()
|
.load();
|
||||||
.migrate();
|
flyway.repair();
|
||||||
|
flyway.migrate();
|
||||||
return;
|
return;
|
||||||
} catch (RuntimeException ex) {
|
} catch (RuntimeException ex) {
|
||||||
lastFailure = ex;
|
lastFailure = ex;
|
||||||
|
|||||||
@@ -11,12 +11,18 @@ WHERE LOWER(appointmentStatus) = 'booked'
|
|||||||
);
|
);
|
||||||
|
|
||||||
-- Part 2: Resolve potential double-bookings caused by V15's simple backfill.
|
-- 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.
|
-- MySQL Error 1093 workaround: wrap same-table subqueries in derived tables.
|
||||||
-- 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.
|
|
||||||
UPDATE appointment a1
|
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 = (
|
SET a1.employeeId = (
|
||||||
SELECT es.employeeId
|
SELECT es.employeeId
|
||||||
FROM employeeStore es
|
FROM employeeStore es
|
||||||
@@ -25,21 +31,16 @@ SET a1.employeeId = (
|
|||||||
WHERE es.storeId = a1.storeId
|
WHERE es.storeId = a1.storeId
|
||||||
AND e.isActive = TRUE
|
AND e.isActive = TRUE
|
||||||
AND u.role = 'STAFF'
|
AND u.role = 'STAFF'
|
||||||
-- Find an employee who DOES NOT have an appointment at this exact time
|
|
||||||
AND NOT EXISTS (
|
AND NOT EXISTS (
|
||||||
SELECT 1 FROM appointment a2
|
SELECT 1 FROM (
|
||||||
WHERE a2.employeeId = es.employeeId
|
SELECT employeeId, appointmentDate, appointmentTime, appointmentId
|
||||||
AND a2.appointmentDate = a1.appointmentDate
|
FROM appointment
|
||||||
AND a2.appointmentTime = a1.appointmentTime
|
) snap
|
||||||
AND a2.appointmentId <> a1.appointmentId
|
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
|
ORDER BY es.employeeId ASC
|
||||||
LIMIT 1
|
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');
|
|
||||||
|
|||||||
Reference in New Issue
Block a user