Files
route-commerce/supabase/migrations/148_public_stops_rpc.sql
tyler ba94d755fa chore: improve Supabase migrations via CLI after login and fix compatibility issues
- Update supabase/push-migrations.js:
  - Detect modern Supabase CLI link state (supabase/.temp/project-ref)
  - Prefer `supabase db query --linked --file` (works in this env where direct postgres connections fail with ENOTFOUND/network unreachable)
  - Updated docs/comments for `supabase login` + `supabase link --project-ref wnzkhezyhnfzhkhiflrp` workflow

- Add MEMORY.md capturing the Supabase login/link session, tooling changes, migration patches applied, and gotchas

- Patch migrations for current remote schema (column drift, syntax, idempotency, pre-existing tables):
  - 091_brand_plan_tier.sql: fix extra paren in get_brand_plan_info
  - 145_create_product_images_bucket.sql: allowed_mime_types + DROP POLICY IF EXISTS + safer bucket insert
  - 148_public_stops_rpc.sql: quote reserved "time" column in RETURNS TABLE + SELECT
  - 200_production_features.sql: add ALTER TABLE for user_activity_logs (originated in 036) so policies/indexes validate
  - 201_seed_data.sql: trim demo seeds with outdated column lists (products/stops/etc.); keep only compatible brands insert

- Include 202_fix_admin_create_stop.sql and related stop creation updates (src/actions/stops/create-stop.ts, 147_admin_create_stop_rpcs.sql, ADMIN_CREATE_STOP_FIX.sql)

- Update CLAUDE.md with pointer to MEMORY.md for recent migration work

Applied via the new flow (after supabase login + link): 084, 091, 142–148, 200–202 etc.

Refs: Supabase CLI now linked; use `node supabase/push-migrations.js <prefix>` or `npm run migrate:one NNN`
2026-06-03 15:11:42 +00:00

50 lines
1.3 KiB
PL/PgSQL

-- Migration: 148_public_stops_rpc.sql
-- Description: Public RPC to fetch active stops for a brand by slug.
-- Used by the /tuxedo and /indian-river-direct storefront stop pages
-- (refactored from client-side supabase.from() to server components).
--
-- SECURITY DEFINER bypasses RLS for a clean public read; the function
-- filters by brand slug + active=true so callers can't enumerate other
-- brands' stops. Granted to anon for public storefront access.
CREATE OR REPLACE FUNCTION get_public_stops_for_brand(p_brand_slug TEXT)
RETURNS TABLE (
id UUID,
city TEXT,
state TEXT,
date TIMESTAMPTZ,
"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;
$$;
-- Public storefront pages call this via the anon key.
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;