Files
route-commerce/supabase/migrations/.archived/059_order_status_delete.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

64 lines
2.1 KiB
PL/PgSQL

-- Migration 059: Order status update + delete RPCs
-- Needed by the redesigned Actions column dropdown in WholesaleClient.tsx
BEGIN;
-- ── update_wholesale_order_status ───────────────────────────────────────────
DROP FUNCTION IF EXISTS public.update_wholesale_order_status(UUID, TEXT);
CREATE OR REPLACE FUNCTION public.update_wholesale_order_status(
p_order_id UUID,
p_status TEXT DEFAULT 'pending'
)
RETURNS JSONB
LANGUAGE plpgsql SECURITY DEFINER SET search_path = public
AS $$
DECLARE
v_order RECORD;
BEGIN
SELECT id, status INTO v_order FROM wholesale_orders WHERE id = p_order_id FOR UPDATE;
IF NOT FOUND THEN
RETURN jsonb_build_object('success', false, 'error', 'Order not found');
END IF;
IF v_order.status = 'fulfilled' THEN
RETURN jsonb_build_object('success', false, 'error', 'Cannot change status of a fulfilled order');
END IF;
UPDATE wholesale_orders
SET status = p_status, updated_at = now()
WHERE id = p_order_id;
RETURN jsonb_build_object('success', true);
END;
$$;
-- ── delete_wholesale_order ───────────────────────────────────────────────────
DROP FUNCTION IF EXISTS public.delete_wholesale_order(UUID);
CREATE OR REPLACE FUNCTION public.delete_wholesale_order(p_order_id UUID)
RETURNS JSONB
LANGUAGE plpgsql SECURITY DEFINER SET search_path = public
AS $$
DECLARE
v_order RECORD;
BEGIN
SELECT id, status INTO v_order FROM wholesale_orders WHERE id = p_order_id FOR UPDATE;
IF NOT FOUND THEN
RETURN jsonb_build_object('success', false, 'error', 'Order not found');
END IF;
IF v_order.status = 'fulfilled' THEN
RETURN jsonb_build_object('success', false, 'error', 'Cannot delete a fulfilled order');
END IF;
DELETE FROM wholesale_order_items WHERE wholesale_order_id = p_order_id;
DELETE FROM wholesale_notifications WHERE order_id = p_order_id;
DELETE FROM wholesale_orders WHERE id = p_order_id;
RETURN jsonb_build_object('success', true);
END;
$$;
COMMIT;
NOTIFY pgrst, 'reload schema';