-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathschema.sql
More file actions
90 lines (80 loc) · 3.96 KB
/
Copy pathschema.sql
File metadata and controls
90 lines (80 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
-- Supabase Schema for Solana Garden
-- 1. Create Crops Table
CREATE TABLE IF NOT EXISTS public.crops (
"id" TEXT PRIMARY KEY,
"name" TEXT NOT NULL,
"scientificName" TEXT,
"origin" TEXT,
"uses" TEXT,
"description" TEXT,
"difficulty" TEXT,
"image" TEXT,
"priceSol" NUMERIC,
"priceUsdc" NUMERIC,
"priceUsdt" NUMERIC,
"stock" INTEGER,
"isForSale" BOOLEAN DEFAULT false,
"category" TEXT,
"watering" TEXT,
"sunlight" TEXT,
"idealSowingSeason" TEXT,
"harvestTimeDays" TEXT,
"soilType" TEXT,
"phRecommended" TEXT,
"companionPlants" TEXT,
"pestPrevention" TEXT,
"detectedElement" TEXT
);
-- 2. Create Ledger Table
CREATE TABLE IF NOT EXISTS public.ledger (
"id" TEXT PRIMARY KEY,
"timestamp" TEXT NOT NULL,
"cropName" TEXT NOT NULL,
"quantity" INTEGER DEFAULT 1,
"amount" NUMERIC NOT NULL,
"currency" TEXT NOT NULL,
"signature" TEXT,
"status" TEXT
);
-- 3. Create Store Metrics Table
CREATE TABLE IF NOT EXISTS public.store_metrics (
"id" TEXT PRIMARY KEY,
"totalSalesUsd" NUMERIC NOT NULL DEFAULT 0
);
-- 4. Enable Row Level Security (RLS) but allow anonymous access for development
ALTER TABLE public.crops ENABLE ROW LEVEL SECURITY;
ALTER TABLE public.ledger ENABLE ROW LEVEL SECURITY;
ALTER TABLE public.store_metrics ENABLE ROW LEVEL SECURITY;
-- 5. Create policies to allow all actions for anonymous users (for development)
DROP POLICY IF EXISTS "Allow anonymous read crops" ON public.crops;
CREATE POLICY "Allow anonymous read crops" ON public.crops FOR SELECT USING (true);
DROP POLICY IF EXISTS "Allow anonymous insert crops" ON public.crops;
CREATE POLICY "Allow anonymous insert crops" ON public.crops FOR INSERT WITH CHECK (true);
DROP POLICY IF EXISTS "Allow anonymous update crops" ON public.crops;
CREATE POLICY "Allow anonymous update crops" ON public.crops FOR UPDATE USING (true);
DROP POLICY IF EXISTS "Allow anonymous delete crops" ON public.crops;
CREATE POLICY "Allow anonymous delete crops" ON public.crops FOR DELETE USING (true);
DROP POLICY IF EXISTS "Allow anonymous read ledger" ON public.ledger;
CREATE POLICY "Allow anonymous read ledger" ON public.ledger FOR SELECT USING (true);
DROP POLICY IF EXISTS "Allow anonymous insert ledger" ON public.ledger;
CREATE POLICY "Allow anonymous insert ledger" ON public.ledger FOR INSERT WITH CHECK (true);
DROP POLICY IF EXISTS "Allow anonymous delete ledger" ON public.ledger;
CREATE POLICY "Allow anonymous delete ledger" ON public.ledger FOR DELETE USING (true);
DROP POLICY IF EXISTS "Allow anonymous read metrics" ON public.store_metrics;
CREATE POLICY "Allow anonymous read metrics" ON public.store_metrics FOR SELECT USING (true);
DROP POLICY IF EXISTS "Allow anonymous insert metrics" ON public.store_metrics;
CREATE POLICY "Allow anonymous insert metrics" ON public.store_metrics FOR INSERT WITH CHECK (true);
DROP POLICY IF EXISTS "Allow anonymous update metrics" ON public.store_metrics;
CREATE POLICY "Allow anonymous update metrics" ON public.store_metrics FOR UPDATE USING (true);
-- 6. Storage Bucket setup for 'imagenes'
-- Important: You must run this in the Supabase SQL Editor
INSERT INTO storage.buckets (id, name, public) VALUES ('imagenes', 'imagenes', true) ON CONFLICT DO NOTHING;
-- Storage RLS Policies
DROP POLICY IF EXISTS "Allow public read imagenes" ON storage.objects;
CREATE POLICY "Allow public read imagenes" ON storage.objects FOR SELECT USING (bucket_id = 'imagenes');
DROP POLICY IF EXISTS "Allow public insert imagenes" ON storage.objects;
CREATE POLICY "Allow public insert imagenes" ON storage.objects FOR INSERT WITH CHECK (bucket_id = 'imagenes');
DROP POLICY IF EXISTS "Allow public update imagenes" ON storage.objects;
CREATE POLICY "Allow public update imagenes" ON storage.objects FOR UPDATE USING (bucket_id = 'imagenes');
DROP POLICY IF EXISTS "Allow public delete imagenes" ON storage.objects;
CREATE POLICY "Allow public delete imagenes" ON storage.objects FOR DELETE USING (bucket_id = 'imagenes');