File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 11-- ============================================================
22-- LMXEngine · DINA COSMETIC · PHASE 2 SCHEMA EXPANSION
33-- Run this in Supabase SQL Editor → New Query
4+ -- SELF-CONTAINED: Works even if DATABASE.sql was not run first.
45-- Safe to run multiple times (uses IF NOT EXISTS / ON CONFLICT)
56-- ============================================================
67
8+ -- ─────────────────────────────────────────────
9+ -- 0. PREREQUISITES — ensure core helpers exist
10+ -- ─────────────────────────────────────────────
11+
12+ -- is_admin() helper (idempotent)
13+ CREATE OR REPLACE FUNCTION public .is_admin()
14+ RETURNS boolean
15+ LANGUAGE sql
16+ SECURITY DEFINER
17+ STABLE
18+ SET search_path = public
19+ AS $$
20+ SELECT EXISTS (
21+ SELECT 1 FROM public .profiles
22+ WHERE id = auth .uid () AND role = ' admin'
23+ );
24+ $$;
25+
26+ -- updated_at trigger function (idempotent)
27+ CREATE OR REPLACE FUNCTION public .handle_updated_at()
28+ RETURNS TRIGGER
29+ LANGUAGE plpgsql
30+ SECURITY DEFINER
31+ SET search_path = public
32+ AS $$
33+ BEGIN
34+ NEW .updated_at = now();
35+ RETURN NEW;
36+ END;
37+ $$;
38+
739-- ─────────────────────────────────────────────
840-- 1. FIX ORDERS TABLE (add missing user_id column)
941-- ─────────────────────────────────────────────
You can’t perform that action at this time.
0 commit comments