Files
route-commerce/supabase/migrations/.archived/208_stops_date_to_date.sql
T
openclaw 916ad39176
Deploy to route.crispygoat.com / deploy (push) Failing after 3m1s
feat(storage): MinIO object storage, Neon Auth, Supabase removal
- Add MinIO/S3-compatible storage client (src/lib/storage.ts) with uploadObject,
  deleteObject, presigned URL helpers, and BUCKETS constant
- Wire product images, brand logos, and water log photos to MinIO via the
  new storage client
- Migrate forgot-password to Neon Auth (remove Supabase /auth/v1/recover call)
- Migrate send-scheduled cron to direct Postgres + Resend (remove Supabase Edge
  Function proxy)
- Add logoUrl to email types (OrderReceipt, Welcome, PasswordReset) and pass
  brand_settings.logo_url from all call sites
- Update email templates to use dynamic logoUrl instead of hardcoded Supabase
  bucket URLs
- Remove hardcoded Supabase URLs from TuxedoVideoHero, TuxedoAboutPage,
  TimeTrackingFieldClient; use brand_settings props + local public/ fallback
- Download brand logos (3) and tuxedo-hero.mp4 (36MB) from Supabase bucket to
  public/ for local development
- Add MinIO env vars to .env.example (endpoint, access key, secret, buckets)
- Fix TimeTrackingFieldClient to destructure logoUrl and brandAccent props
- Fix admin/users.ts logoUrl type (null → undefined for optional string)
- Remove stale sb- cookie from wholesale-auth
- Migrate tuxedo/about page to remove supabase import and use pool query for
  wholesale_settings lookup
2026-06-09 12:23:37 -06:00

74 lines
2.3 KiB
PL/PgSQL

-- Migration 208: Change stops.date from TIMESTAMPTZ to DATE
--
-- Why
-- ---
-- The `stops.date` column was created as TIMESTAMPTZ but is used throughout
-- the app as a calendar date (no time-of-day component). The mismatch
-- forces every client consumer to do `new Date(s.date + "T00:00:00")` to
-- coerce the timestamp into a local-midnight Date — and that hack silently
-- produces an Invalid Date when Supabase returns a `2026-06-15 00:00:00+00`
-- style string, leaving the Stops & Routes calendar empty.
--
-- Storing the column as DATE makes Supabase return a clean `YYYY-MM-DD`
-- string, which the existing `+ "T00:00:00"` parsing handles correctly.
--
-- The `time` (TEXT, "HH:MM") and `cutoff_time` (TIMESTAMPTZ) columns are
-- unchanged — they legitimately carry time-of-day information.
--
-- Affected RPC
-- -------------
-- `get_public_stops_for_brand` declares `date TIMESTAMPTZ` in its
-- RETURNS TABLE. Recreate it with `date DATE` so the return type matches
-- the underlying column.
-- 1. Drop the existing RPC so we can recreate it with a new return type.
-- PostgreSQL refuses CREATE OR REPLACE when the OUT-parameter row type
-- changes (error 42P13).
DROP FUNCTION IF EXISTS get_public_stops_for_brand(TEXT);
-- 2. Convert the column. USING date::DATE truncates the time component,
-- which is what we want — all existing rows are stored at 00:00 anyway.
ALTER TABLE public.stops
ALTER COLUMN date TYPE DATE USING date::DATE;
-- 3. Recreate the public RPC with the corrected return type.
CREATE OR REPLACE FUNCTION get_public_stops_for_brand(p_brand_slug TEXT)
RETURNS TABLE (
id UUID,
city TEXT,
state TEXT,
date DATE,
"time" TEXT,
location TEXT,
address TEXT,
slug TEXT,
cutoff_time TIMESTAMPTZ
)
LANGUAGE plpgsql
SECURITY DEFINER
SET search_path = public
AS $$
BEGIN
RETURN QUERY
SELECT
s.id,
s.city,
s.state,
s.date,
s."time",
s.location,
s.address,
s.slug,
s.cutoff_time
FROM stops s
INNER JOIN brands b ON s.brand_id = b.id
WHERE s.active = true
AND b.slug = p_brand_slug
ORDER BY s.date ASC;
END;
$$;
GRANT EXECUTE ON FUNCTION get_public_stops_for_brand(TEXT) TO anon;
GRANT EXECUTE ON FUNCTION get_public_stops_for_brand(TEXT) TO authenticated;
GRANT EXECUTE ON FUNCTION get_public_stops_for_brand(TEXT) TO service_role;