From e1f6bd56b0727352ccd2afff591749036e81b611 Mon Sep 17 00:00:00 2001 From: Jose Lago Date: Sun, 17 May 2026 23:19:36 +0200 Subject: [PATCH] feat: add SQL migration to fix misclassified long rentals and update docker-compose configurations --- docker-compose.local.yml | 1 + docker-compose.yml | 12 ++++++++ .../16-rental-type-weekend-gap-fix.sql | 28 +++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 supabase/migrations/16-rental-type-weekend-gap-fix.sql diff --git a/docker-compose.local.yml b/docker-compose.local.yml index f07ec0d..af5b4e3 100644 --- a/docker-compose.local.yml +++ b/docker-compose.local.yml @@ -30,6 +30,7 @@ services: - ./supabase/migrations/13-rental-type-daily-and-email-guard.sql:/sql/13-rental-type-daily-and-email-guard.sql:ro - ./supabase/migrations/14-email-requested-trigger.sql:/sql/14-email-requested-trigger.sql:ro - ./supabase/migrations/15-individuell-vat-subtotal-fix.sql:/sql/15-individuell-vat-subtotal-fix.sql:ro + - ./supabase/migrations/16-rental-type-weekend-gap-fix.sql:/sql/16-rental-type-weekend-gap-fix.sql:ro kong: volumes: diff --git a/docker-compose.yml b/docker-compose.yml index 5d78910..60eaa29 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -218,6 +218,12 @@ services: - /mnt/user/appdata/mc-cars/supabase/migrations/08-backend-pricing-and-security.sql:/sql/08-backend-pricing-and-security.sql:ro - /mnt/user/appdata/mc-cars/supabase/migrations/09-site-settings.sql:/sql/09-site-settings.sql:ro - /mnt/user/appdata/mc-cars/supabase/migrations/10-mietvertrag-workflow.sql:/sql/10-mietvertrag-workflow.sql:ro + - /mnt/user/appdata/mc-cars/supabase/migrations/11-consolidate-km-rental.sql:/sql/11-consolidate-km-rental.sql:ro + - /mnt/user/appdata/mc-cars/supabase/migrations/12-email-sent-and-more.sql:/sql/12-email-sent-and-more.sql:ro + - /mnt/user/appdata/mc-cars/supabase/migrations/13-rental-type-daily-and-email-guard.sql:/sql/13-rental-type-daily-and-email-guard.sql:ro + - /mnt/user/appdata/mc-cars/supabase/migrations/14-email-requested-trigger.sql:/sql/14-email-requested-trigger.sql:ro + - /mnt/user/appdata/mc-cars/supabase/migrations/15-individuell-vat-subtotal-fix.sql:/sql/15-individuell-vat-subtotal-fix.sql:ro + - /mnt/user/appdata/mc-cars/supabase/migrations/16-rental-type-weekend-gap-fix.sql:/sql/16-rental-type-weekend-gap-fix.sql:ro entrypoint: ["sh","-c"] command: - | @@ -244,6 +250,12 @@ services: psql "postgresql://postgres:$$PGPASSWORD@db:5432/postgres" -v ON_ERROR_STOP=1 -f /sql/08-backend-pricing-and-security.sql psql "postgresql://postgres:$$PGPASSWORD@db:5432/postgres" -v ON_ERROR_STOP=1 -f /sql/09-site-settings.sql psql "postgresql://postgres:$$PGPASSWORD@db:5432/postgres" -v ON_ERROR_STOP=1 -f /sql/10-mietvertrag-workflow.sql + psql "postgresql://postgres:$$PGPASSWORD@db:5432/postgres" -v ON_ERROR_STOP=1 -f /sql/11-consolidate-km-rental.sql + psql "postgresql://postgres:$$PGPASSWORD@db:5432/postgres" -v ON_ERROR_STOP=1 -f /sql/12-email-sent-and-more.sql + psql "postgresql://postgres:$$PGPASSWORD@db:5432/postgres" -v ON_ERROR_STOP=1 -f /sql/13-rental-type-daily-and-email-guard.sql + psql "postgresql://postgres:$$PGPASSWORD@db:5432/postgres" -v ON_ERROR_STOP=1 -f /sql/14-email-requested-trigger.sql + psql "postgresql://postgres:$$PGPASSWORD@db:5432/postgres" -v ON_ERROR_STOP=1 -f /sql/15-individuell-vat-subtotal-fix.sql + psql "postgresql://postgres:$$PGPASSWORD@db:5432/postgres" -v ON_ERROR_STOP=1 -f /sql/16-rental-type-weekend-gap-fix.sql echo "post-init done." restart: "no" networks: [mccars] diff --git a/supabase/migrations/16-rental-type-weekend-gap-fix.sql b/supabase/migrations/16-rental-type-weekend-gap-fix.sql new file mode 100644 index 0000000..4608f3c --- /dev/null +++ b/supabase/migrations/16-rental-type-weekend-gap-fix.sql @@ -0,0 +1,28 @@ +-- 16-rental-type-weekend-gap-fix.sql +-- Fix misclassified long rentals that were stored as 'weekend'. +-- Business rule: only true weekend package may remain 'weekend'; long spans are 'individuell'. + +-- Leads: any weekend booking longer than 2 days must be individuell. +update public.leads + set rental_type = 'individuell' + where coalesce(lower(trim(rental_type)), 'weekend') = 'weekend' + and coalesce(total_days, 0) > 2; + +-- Sales orders: same correction. +update public.sales_orders + set rental_type = 'individuell' + where coalesce(lower(trim(rental_type)), 'weekend') = 'weekend' + and coalesce(total_days, 0) > 2; + +-- If old rows have unknown/legacy values and >2 days, normalize to individuell as well. +update public.leads + set rental_type = 'individuell' + where coalesce(total_days, 0) > 2 + and coalesce(lower(trim(rental_type)), '') not in ('individuell', 'weekend', 'single_day'); + +update public.sales_orders + set rental_type = 'individuell' + where coalesce(total_days, 0) > 2 + and coalesce(lower(trim(rental_type)), '') not in ('individuell', 'weekend', 'single_day'); + +notify pgrst, 'reload schema';