-- Data for Name: frigate_triggers; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.frigate_triggers (id, frigate_instance_id, camera, name, description, trigger_type, similarity_threshold, enabled, last_triggered_at, actions, created_at) FROM stdin;
\.


--
-- Data for Name: frigate_zones; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.frigate_zones (id, camera_id, name, coordinates, zone_type, enabled, color, created_at, updated_at) FROM stdin;
\.


--
-- Data for Name: health_alerts; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.health_alerts (id, student_id, alert_type, value, severity, note, detected_at, notified, resolved) FROM stdin;
c6afd3e5-353d-4fc9-b4f8-b4a22c5df1d2	cf21af24-b770-421a-bc5c-4b9f8bb5d34d	glucose_low	55	high	هبوط سكر خطر (55 mg/dL)	2026-07-05 03:53:32.271725+00	f	f
f30d6da1-b725-4d98-aa06-6414bcb8419d	cf21af24-b770-421a-bc5c-4b9f8bb5d34d	seizure	\N	high	اشتباه نوبة صرع — تدخّل فوري	2026-07-05 03:53:32.305759+00	f	f
979544b5-a7ed-4410-a8a1-8fb28f4f4020	cf21af24-b770-421a-bc5c-4b9f8bb5d34d	glucose_high	280	high	ارتفاع سكر خطر (280 mg/dL)	2026-07-05 04:20:19.4425+00	f	f
\.


--
-- Data for Name: industries; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.industries (id, name, name_ar, description, description_ar, icon, active, created_at, updated_at) FROM stdin;
6a5cf301-7d4a-47fe-b254-e50d99c7f0a8	Restaurant	مطعم	Restaurant and food service businesses	المطاعم وخدمات الطعام	utensils	t	2026-06-12 00:20:00.463156+00	2026-06-12 00:20:00.463156+00
a3615aa9-9fcf-4440-87fa-18e8b1fc03f4	Hospital	مستشفى	Healthcare and medical facilities	المرافق الصحية والطبية	heart-pulse	t	2026-06-12 00:20:00.463156+00	2026-06-12 00:20:00.463156+00
e17bdee2-b726-4117-9a83-36c8bd2d6933	Company	شركة	Corporate and business organizations	الشركات والمؤسسات التجارية	building-2	t	2026-06-12 00:20:00.463156+00	2026-06-12 00:20:00.463156+00
bc65c62b-f701-49c3-94bf-a561c988b4f1	Hotel	فندق	Hospitality and accommodation services	خدمات الضيافة والإقامة	bed	t	2026-06-12 00:20:00.463156+00	2026-06-12 00:20:00.463156+00
7aff7ce2-2963-45d0-971a-93d202f9d5dc	Retail	تجارة التجزئة	Retail stores and shopping centers	متاجر التجزئة ومراكز التسوق	shopping-cart	t	2026-06-12 00:20:00.463156+00	2026-06-12 00:20:00.463156+00
65168eb2-f74e-4e96-b7a1-8c95a9f155d1	Education	تعليم	Educational institutions and schools	المؤسسات التعليمية والمدارس	graduation-cap	t	2026-06-12 00:20:00.463156+00	2026-06-12 00:20:00.463156+00
02024d3c-beea-4ae7-91d6-17e157e15e32	Government	حكومة	Government agencies and public services	الوكالات الحكومية والخدمات العامة	landmark	t	2026-06-12 00:20:00.463156+00	2026-06-12 00:20:00.463156+00
dc988786-39ed-4966-9cbc-c440a37ee3f6	Sports	رياضة	Sports facilities and fitness centers	المرافق الرياضية ومراكز اللياقة	dumbbell	t	2026-06-12 00:20:00.463156+00	2026-06-12 00:20:00.463156+00
\.


--
-- Data for Name: legal_documents; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.legal_documents (id, document_type, title, content, version, effective_date, created_at, updated_at, created_by, updated_by) FROM stdin;
e041928f-7ea8-423d-b25f-ccff5539b7f3	terms_of_service	شروط الخدمة	محتوى شروط الخدمة سيتم تحديثه من قبل الإدارة.	1	2026-06-12 00:20:00.447043+00	2026-06-12 00:20:00.447043+00	2026-06-12 00:20:00.447043+00	\N	\N
db14ece6-4aae-4b7d-b5e9-e8a4ee020475	privacy_policy	سياسة الخصوصية	محتوى سياسة الخصوصية سيتم تحديثه من قبل الإدارة.	1	2026-06-12 00:20:00.447043+00	2026-06-12 00:20:00.447043+00	2026-06-12 00:20:00.447043+00	\N	\N
\.


--
-- Data for Name: network_scan_results; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.network_scan_results (id, ip_address, port, manufacturer, model, device_type, protocol, mac_address, hostname, discovered_at, scan_session_id, user_id) FROM stdin;
\.


--
-- Data for Name: notification_labels; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.notification_labels (id, type, name_ar, name_en, is_active, created_at, updated_at, created_by) FROM stdin;
\.


--
-- Data for Name: notification_methods; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.notification_methods (id, name_ar, name_en, type, icon, enabled, settings, created_at, updated_at, created_by) FROM stdin;
01e215ce-4741-412e-9727-23f055ce5830	واتساب	WhatsApp	whatsapp	message-circle	t	{}	2026-06-12 00:20:00.543969+00	2026-06-12 00:20:00.543969+00	\N
072d9533-0830-4ac9-9c2b-96572da8248e	البريد الإلكتروني	Email	email	mail	t	{}	2026-06-12 00:20:00.543969+00	2026-06-12 00:20:00.543969+00	\N
ce1bae39-a951-416a-8538-33c7e837b92b	الهاتف	Phone	phone	phone	t	{}	2026-06-12 00:20:00.543969+00	2026-06-12 00:20:00.543969+00	\N
8cedb059-51db-4412-b1b0-4bd5dd662e75	الرسائل النصية	SMS	sms	message-square	t	{}	2026-06-12 00:20:00.543969+00	2026-06-12 00:20:00.543969+00	\N
\.


--
-- Data for Name: organization_settings; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.organization_settings (id, organization_id, setting_key, setting_value, description, created_at, updated_at) FROM stdin;
\.


--
-- Data for Name: organizations; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.organizations (id, name, subscription_tier, max_cameras, active, created_at, updated_at, subscription_limits, max_branches, features, subscription_status, industry_id) FROM stdin;
67e83f81-01f6-4621-91dc-bc59048c7c17	Default Organization	basic	5	t	2026-06-12 00:22:09.682823+00	2026-06-12 00:22:09.682823+00	{"users": 3, "cameras": 5, "branches": 1, "storage_gb": 10, "ai_detections_per_month": 1000}	1	{"analytics": false, "recording": false, "ai_detection": true, "live_streaming": true}	pending	\N
e8352779-7fc5-4492-9672-7a07a779b25b	Default Organization	basic	5	t	2026-06-12 00:24:01.257248+00	2026-06-12 00:24:01.257248+00	{"users": 3, "cameras": 5, "branches": 1, "storage_gb": 10, "ai_detections_per_month": 1000}	1	{"analytics": false, "recording": false, "ai_detection": true, "live_streaming": true}	pending	\N
cb9e9cfe-03a8-44b1-adb3-854ce61fbe21	مطاعم الذواقة (تجريبي)	basic	100	t	2026-07-04 13:03:02.211031+00	2026-07-04 13:03:40.263831+00	{"users": 3, "cameras": 5, "branches": 1, "storage_gb": 10, "ai_detections_per_month": 1000}	1	{"analytics": false, "recording": false, "ai_detection": true, "live_streaming": true}	pending	\N
557d5fb7-b321-40ee-a074-9e847b4b8962	Default Organization	basic	5	t	2026-07-04 13:10:17.908345+00	2026-07-04 13:10:17.908345+00	{"users": 3, "cameras": 5, "branches": 1, "storage_gb": 10, "ai_detections_per_month": 1000}	1	{"analytics": false, "recording": false, "ai_detection": true, "live_streaming": true}	pending	\N
\.


--
-- Data for Name: pinned_dashboards; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.pinned_dashboards (id, user_id, instance_id, name, path, x, y, width, height, order_index, created_at, updated_at, zoom) FROM stdin;
\.


--
-- Data for Name: pinned_labels; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.pinned_labels (id, user_id, text, color, font_size, x, y, created_at, updated_at) FROM stdin;
\.


--
-- Data for Name: screen_permissions; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.screen_permissions (id, screen_key, path, title_en, title_ar, description_en, description_ar, allowed_roles, allow_super_admin, is_active, created_by, created_at, updated_at) FROM stdin;
\.


--
-- Data for Name: security_zones; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.security_zones (id, branch_id, name, description, coordinates, sensitivity_level, active_hours, created_at, updated_at, active) FROM stdin;
\.


--
-- Data for Name: storage_configs; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.storage_configs (id, name, type, config, is_active, created_at, updated_at, created_by) FROM stdin;
0346be93-d383-47c0-95cf-9c8fa296da86	Local Storage	local	{"path": "/uploads/models"}	t	2026-06-12 00:20:00.527808+00	2026-06-12 00:20:00.527808+00	\N
\.


--
-- Data for Name: students; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.students (id, organization_id, branch_id, name, condition, guardian_phone, clinic_phone, wearable_id, created_at) FROM stdin;
cf21af24-b770-421a-bc5c-4b9f8bb5d34d	cb9e9cfe-03a8-44b1-adb3-854ce61fbe21	0ab2ca49-ad88-4630-afb6-3ef008e1cef5	سالم أحمد (تجريبي)	diabetes	966500000001	966500000002	watch-demo-001	2026-07-05 03:53:26.725019+00
\.


--
-- Data for Name: subscribers; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.subscribers (id, user_id, email, stripe_customer_id, subscribed, subscription_tier, subscription_end, usage_analytics, billing_cycle, created_at, updated_at, subscription_status, approved_by, approved_at, last_activity, notes, organization_id) FROM stdin;
33cb19cb-1e5b-4295-969f-100fae681c17	8526382f-7ebb-4245-b8be-84c1f7a14e40	admin@admin.com	\N	f	basic	\N	{}	monthly	2026-06-12 00:24:01.257248+00	2026-06-12 00:24:13.097585+00	pending	\N	\N	2026-06-12 00:24:13.097585+00	\N	\N
f04a6b00-1988-4e61-8604-6d639684e3fe	a7b186ca-e6c3-4ece-9349-26a0dbf0defa	veedon.test@local.dev	\N	f	basic	\N	{}	monthly	2026-07-04 13:10:17.908345+00	2026-07-05 06:40:06.836696+00	pending	\N	\N	2026-07-05 06:40:06.836696+00	\N	\N
8ba08f08-8db0-48ce-8f28-c6ac01269ec1	f69c2370-64a4-467b-9be5-0262b271986a	ashraffarid@gmail.com	\N	f	basic	\N	{}	monthly	2026-06-12 00:22:09.682823+00	2026-07-05 07:09:16.27193+00	pending	\N	\N	2026-07-05 07:09:16.27193+00	\N	\N
\.


--
-- Data for Name: system_settings; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.system_settings (id, setting_key, setting_value, description, created_at, updated_at, updated_by) FROM stdin;
918eda42-5fbf-4279-9036-34edb0484630	default_storage_provider	{"type": "local"}	Default storage provider for model files	2026-06-12 00:20:00.527808+00	2026-06-12 00:20:00.527808+00	\N
c6f05119-0c3a-4524-8ed6-9c7dcd6a361b	max_file_size_mb	{"value": 100}	Maximum file size in MB for model uploads	2026-06-12 00:20:00.527808+00	2026-06-12 00:20:00.527808+00	\N
6f0f20c3-ddd5-4d3a-99a0-64cb84df447b	show_subscription_plans	{"enabled": false}	Control visibility of subscription plans on landing page	2026-06-12 00:20:00.570441+00	2026-06-12 00:20:00.582548+00	\N
8dffb3d7-cfd9-4a7b-91f1-47db832b74f8	messaging_global	{"twilio": {"enabled": false, "auth_token_secret": "TWILIO_AUTH_TOKEN", "from_phone_number": null, "account_sid_secret": "TWILIO_ACCOUNT_SID"}, "whatsapp_cloud": {"enabled": true, "business_phone_id": null, "from_phone_number": null, "access_token_secret": "WHATSAPP_CLOUD_ACCESS_TOKEN"}}	Global messaging providers configuration managed by system admin	2026-06-12 00:20:00.75604+00	2026-06-12 00:20:00.75604+00	\N
40627347-7203-476f-8160-0eaaadbcc87a	tts_global	{"free_tts": {"enabled": true, "default_voice": "auto"}, "elevenlabs": {"model": "eleven_turbo_v2_5", "enabled": false, "api_key_secret": "ELEVENLABS_API_KEY", "default_voice_id": "TX3LPaxmHKxFdv7VOQHJ"}, "default_provider": "free_tts"}	Global TTS providers configuration managed by system admin	2026-06-12 00:20:00.75604+00	2026-06-12 00:20:00.75604+00	\N
39fc8d5b-fb74-48aa-8fff-68a3d0c2ea74	ai_analysis_server_url	{"url": "https://203.161.35.97:11434"}	Server URL for AI analysis (e.g., Ollama server endpoint)	2026-06-12 00:20:00.785457+00	2026-06-12 00:20:00.785457+00	\N
a79c1308-5cba-4f6d-be0e-4078c7840937	mistral_ai_server_url	{"url": "https://a0415b97b37d.ngrok-free.app/v1/chat/completions"}	رابط خادم Mistral AI للتحليل الذكي للصور	2026-06-12 00:20:00.791515+00	2026-06-12 00:20:00.791515+00	\N
b69148bd-63b8-4cc7-ab7e-6c765dc5e663	frigate_sync_minutes	5	Minimum minutes between Frigate sync operations	2026-06-12 00:20:00.891752+00	2026-06-12 00:20:00.891752+00	\N
3f9f3e9c-3bbc-4c4a-95ac-4c1468d21ed2	frigate_last_sync_at	{"timestamp": "2026-06-12T23:02:46.740Z"}	Timestamp of last Frigate sync operation	2026-06-12 00:20:00.891752+00	2026-06-12 23:02:46.740636+00	\N
\.


--
-- Data for Name: user_branch_access; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.user_branch_access (id, user_id, branch_id, granted_by, granted_at) FROM stdin;
\.


--
-- Data for Name: user_group_members; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.user_group_members (id, group_id, user_role_id, added_by, added_at) FROM stdin;
\.


--
-- Data for Name: user_groups; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.user_groups (id, name, description, organization_id, group_type, metadata, created_by, created_at, updated_at) FROM stdin;
\.


--
-- Data for Name: user_preferences; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.user_preferences (id, user_id, language, timezone, theme, notifications, created_at, updated_at, ui_language, tts_language) FROM stdin;
3de40a8b-d677-4747-b22d-f14ed623ae09	8526382f-7ebb-4245-b8be-84c1f7a14e40	en	UTC	system	{"sms": false, "push": true, "email": true}	2026-06-12 00:24:01.257248+00	2026-06-12 00:24:01.257248+00	\N	\N
5457cbc0-4726-4a66-884d-57bf3f24c23a	a7b186ca-e6c3-4ece-9349-26a0dbf0defa	ar	UTC	system	{"sms": false, "push": true, "email": true}	2026-07-04 13:10:17.908345+00	2026-07-04 21:43:12.717901+00	ar	\N
563524ff-5c54-4cd9-95d8-9e98bf466331	f69c2370-64a4-467b-9be5-0262b271986a	ar	UTC	system	{"sms": false, "push": true, "email": true}	2026-06-12 00:22:09.682823+00	2026-07-05 06:10:42.906034+00	ar	\N
\.


--
-- Data for Name: user_roles; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.user_roles (id, user_id, organization_id, role, created_at, permissions, granted_by, granted_at, notification_type, notification_value, name) FROM stdin;
cad39fc8-3798-492f-8020-62e2129ef529	f69c2370-64a4-467b-9be5-0262b271986a	67e83f81-01f6-4621-91dc-bc59048c7c17	admin	2026-06-12 00:22:09.682823+00	{"manage_users": false, "view_cameras": true, "view_analytics": true, "manage_settings": false}	\N	2026-06-12 00:22:09.682823+00	\N	\N	\N
ebd9f75c-abf7-44e5-84b6-aa469698665f	8526382f-7ebb-4245-b8be-84c1f7a14e40	e8352779-7fc5-4492-9672-7a07a779b25b	admin	2026-06-12 00:24:01.257248+00	{"manage_users": false, "view_cameras": true, "view_analytics": true, "manage_settings": false}	\N	2026-06-12 00:24:01.257248+00	\N	\N	\N
40341238-0852-4e97-b5dd-cc38cd2bf1a9	a7b186ca-e6c3-4ece-9349-26a0dbf0defa	557d5fb7-b321-40ee-a074-9e847b4b8962	admin	2026-07-04 13:10:17.908345+00	{"manage_users": false, "view_cameras": true, "view_analytics": true, "manage_settings": false}	\N	2026-07-04 13:10:17.908345+00	\N	\N	\N
f622c8d6-b8ca-4dec-8739-3b6c236f280f	a7b186ca-e6c3-4ece-9349-26a0dbf0defa	\N	super_admin	2026-07-04 17:32:20.460025+00	{"manage_users": true, "view_cameras": true, "view_analytics": true, "manage_settings": true}	\N	2026-07-04 17:32:20.460025+00	\N	\N	\N
\.


--
-- Data for Name: workflow_forms; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.workflow_forms (id, name, name_ar, description, description_ar, activity_type, form_fields, is_active, created_by, created_at, updated_at, logo_url) FROM stdin;
\.


--
-- Data for Name: messages_2026_07_02; Type: TABLE DATA; Schema: realtime; Owner: supabase_admin
--

COPY realtime.messages_2026_07_02 (topic, extension, payload, event, private, updated_at, inserted_at, id, binary_payload) FROM stdin;
\.


--
-- Data for Name: messages_2026_07_03; Type: TABLE DATA; Schema: realtime; Owner: supabase_admin
--

COPY realtime.messages_2026_07_03 (topic, extension, payload, event, private, updated_at, inserted_at, id, binary_payload) FROM stdin;
\.


--
-- Data for Name: messages_2026_07_04; Type: TABLE DATA; Schema: realtime; Owner: supabase_admin
--

COPY realtime.messages_2026_07_04 (topic, extension, payload, event, private, updated_at, inserted_at, id, binary_payload) FROM stdin;
\.


--
-- Data for Name: messages_2026_07_05; Type: TABLE DATA; Schema: realtime; Owner: supabase_admin
--

COPY realtime.messages_2026_07_05 (topic, extension, payload, event, private, updated_at, inserted_at, id, binary_payload) FROM stdin;
\.


--
-- Data for Name: messages_2026_07_06; Type: TABLE DATA; Schema: realtime; Owner: supabase_admin
--

COPY realtime.messages_2026_07_06 (topic, extension, payload, event, private, updated_at, inserted_at, id, binary_payload) FROM stdin;
\.


--
-- Data for Name: messages_2026_07_07; Type: TABLE DATA; Schema: realtime; Owner: supabase_admin
--

COPY realtime.messages_2026_07_07 (topic, extension, payload, event, private, updated_at, inserted_at, id, binary_payload) FROM stdin;
\.


--
-- Data for Name: messages_2026_07_08; Type: TABLE DATA; Schema: realtime; Owner: supabase_admin
--

COPY realtime.messages_2026_07_08 (topic, extension, payload, event, private, updated_at, inserted_at, id, binary_payload) FROM stdin;
\.


--
-- Data for Name: schema_migrations; Type: TABLE DATA; Schema: realtime; Owner: supabase_admin
--

COPY realtime.schema_migrations (version, inserted_at) FROM stdin;
20211116024918	2026-06-12 00:19:50
20211116045059	2026-06-12 00:19:50
20211116050929	2026-06-12 00:19:50
20211116051442	2026-06-12 00:19:50
20211116212300	2026-06-12 00:19:50
20211116213355	2026-06-12 00:19:50
20211116213934	2026-06-12 00:19:50
20211116214523	2026-06-12 00:19:50
20211122062447	2026-06-12 00:19:50
20211124070109	2026-06-12 00:19:50
20211202204204	2026-06-12 00:19:50
20211202204605	2026-06-12 00:19:50
20211210212804	2026-06-12 00:19:50
20211228014915	2026-06-12 00:19:50
20220107221237	2026-06-12 00:19:50
20220228202821	2026-06-12 00:19:50
20220312004840	2026-06-12 00:19:50
20220603231003	2026-06-12 00:19:50
20220603232444	2026-06-12 00:19:50
20220615214548	2026-06-12 00:19:50
20220712093339	2026-06-12 00:19:50
20220908172859	2026-06-12 00:19:50
20220916233421	2026-06-12 00:19:50
20230119133233	2026-06-12 00:19:50
20230128025114	2026-06-12 00:19:50
20230128025212	2026-06-12 00:19:50
20230227211149	2026-06-12 00:19:50
20230228184745	2026-06-12 00:19:50
20230308225145	2026-06-12 00:19:50
20230328144023	2026-06-12 00:19:50
20231018144023	2026-06-12 00:19:50
20231204144023	2026-06-12 00:19:50
20231204144024	2026-06-12 00:19:50
20231204144025	2026-06-12 00:19:50
20240108234812	2026-06-12 00:19:50
20240109165339	2026-06-12 00:19:50
20240227174441	2026-06-12 00:19:50
20240311171622	2026-06-12 00:19:50
20240321100241	2026-06-12 00:19:50
20240401105812	2026-06-12 00:19:50
20240418121054	2026-06-12 00:19:50
20240523004032	2026-06-12 00:19:50
20240618124746	2026-06-12 00:19:50
20240801235015	2026-06-12 00:19:50
20240805133720	2026-06-12 00:19:50
20240827160934	2026-06-12 00:19:50
20240919163303	2026-06-12 00:19:50
20240919163305	2026-06-12 00:19:50
20241019105805	2026-06-12 00:19:50
20241030150047	2026-06-12 00:19:50
20241108114728	2026-06-12 00:19:50
20241121104152	2026-06-12 00:19:50
20241130184212	2026-06-12 00:19:50
20241220035512	2026-06-12 00:19:50
20241220123912	2026-06-12 00:19:50
20241224161212	2026-06-12 00:19:50
20250107150512	2026-06-12 00:19:50
20250110162412	2026-06-12 00:19:50
20250123174212	2026-06-12 00:19:50
20250128220012	2026-06-12 00:19:50
20250506224012	2026-06-12 00:19:50
20250523164012	2026-06-12 00:19:50
20250714121412	2026-06-12 00:19:50
20250905041441	2026-06-12 00:19:50
20251103001201	2026-06-12 00:19:50
20251120212548	2026-06-12 00:19:50
20251120215549	2026-06-12 00:19:50
20260218120000	2026-06-12 00:19:50
20260326120000	2026-06-12 00:19:50
20260514120000	2026-06-12 00:19:50
20260527120000	2026-06-12 00:19:50
20260528120000	2026-06-12 00:19:50
20260603120000	2026-06-12 00:19:50
\.


--
-- Data for Name: subscription; Type: TABLE DATA; Schema: realtime; Owner: supabase_admin
--

COPY realtime.subscription (id, subscription_id, entity, filters, claims, created_at, action_filter, selected_columns) FROM stdin;
\.


--
-- Data for Name: buckets; Type: TABLE DATA; Schema: storage; Owner: supabase_storage_admin
--

COPY storage.buckets (id, name, owner, created_at, updated_at, public, avif_autodetection, file_size_limit, allowed_mime_types, owner_id, type) FROM stdin;
form-logos	form-logos	\N	2026-06-12 00:20:00.557927+00	2026-06-12 00:20:00.557927+00	t	f	\N	\N	\N	STANDARD
model-files	model-files	\N	2026-06-12 00:20:00.527808+00	2026-06-12 00:20:00.527808+00	t	f	104857600	{application/octet-stream,application/x-pytorch,application/x-onnx,application/zip}	\N	STANDARD
form-attachments	form-attachments	\N	2026-06-12 00:20:00.743373+00	2026-06-12 00:20:00.743373+00	t	f	\N	\N	\N	STANDARD
test-uploads	test-uploads	\N	2026-06-12 00:20:00.869281+00	2026-06-12 00:20:00.869281+00	t	f	\N	\N	\N	STANDARD
frigate-models	frigate-models	\N	2026-06-14 02:48:56.510161+00	2026-06-14 02:48:56.510161+00	f	f	524288000	{application/octet-stream,application/x-yaml,text/yaml}	\N	STANDARD
\.


--
-- Data for Name: buckets_analytics; Type: TABLE DATA; Schema: storage; Owner: supabase_storage_admin
--

COPY storage.buckets_analytics (name, type, format, created_at, updated_at, id, deleted_at) FROM stdin;
\.


--
-- Data for Name: buckets_vectors; Type: TABLE DATA; Schema: storage; Owner: supabase_storage_admin
--

COPY storage.buckets_vectors (id, type, created_at, updated_at) FROM stdin;
\.


--
-- Data for Name: iceberg_namespaces; Type: TABLE DATA; Schema: storage; Owner: supabase_storage_admin
--

COPY storage.iceberg_namespaces (id, bucket_name, name, created_at, updated_at, metadata, catalog_id) FROM stdin;
\.


--
-- Data for Name: iceberg_tables; Type: TABLE DATA; Schema: storage; Owner: supabase_storage_admin
--

COPY storage.iceberg_tables (id, namespace_id, bucket_name, name, location, created_at, updated_at, remote_table_id, shard_key, shard_id, catalog_id) FROM stdin;
\.


--
-- Data for Name: migrations; Type: TABLE DATA; Schema: storage; Owner: supabase_storage_admin
--

COPY storage.migrations (id, name, hash, executed_at) FROM stdin;
0	create-migrations-table	e18db593bcde2aca2a408c4d1100f6abba2195df	2026-06-12 00:19:58.818121
1	initialmigration	6ab16121fbaa08bbd11b712d05f358f9b555d777	2026-06-12 00:19:58.825271
2	storage-schema	f6a1fa2c93cbcd16d4e487b362e45fca157a8dbd	2026-06-12 00:19:58.82768
3	pathtoken-column	2cb1b0004b817b29d5b0a971af16bafeede4b70d	2026-06-12 00:19:58.832408
4	add-migrations-rls	427c5b63fe1c5937495d9c635c263ee7a5905058	2026-06-12 00:19:58.836596
5	add-size-functions	79e081a1455b63666c1294a440f8ad4b1e6a7f84	2026-06-12 00:19:58.838726
6	change-column-name-in-get-size	ded78e2f1b5d7e616117897e6443a925965b30d2	2026-06-12 00:19:58.840908
7	add-rls-to-buckets	e7e7f86adbc51049f341dfe8d30256c1abca17aa	2026-06-12 00:19:58.843764
8	add-public-to-buckets	fd670db39ed65f9d08b01db09d6202503ca2bab3	2026-06-12 00:19:58.846996
9	fix-search-function	af597a1b590c70519b464a4ab3be54490712796b	2026-06-12 00:19:58.849419
10	search-files-search-function	b595f05e92f7e91211af1bbfe9c6a13bb3391e16	2026-06-12 00:19:58.851715
11	add-trigger-to-auto-update-updated_at-column	7425bdb14366d1739fa8a18c83100636d74dcaa2	2026-06-12 00:19:58.854047
12	add-automatic-avif-detection-flag	8e92e1266eb29518b6a4c5313ab8f29dd0d08df9	2026-06-12 00:19:58.857416
13	add-bucket-custom-limits	cce962054138135cd9a8c4bcd531598684b25e7d	2026-06-12 00:19:58.859845
14	use-bytes-for-max-size	941c41b346f9802b411f06f30e972ad4744dad27	2026-06-12 00:19:58.86226
15	add-can-insert-object-function	934146bc38ead475f4ef4b555c524ee5d66799e5	2026-06-12 00:19:58.869516
16	add-version	76debf38d3fd07dcfc747ca49096457d95b1221b	2026-06-12 00:19:58.872722
17	drop-owner-foreign-key	f1cbb288f1b7a4c1eb8c38504b80ae2a0153d101	2026-06-12 00:19:58.874951
18	add_owner_id_column_deprecate_owner	e7a511b379110b08e2f214be852c35414749fe66	2026-06-12 00:19:58.877223
19	alter-default-value-objects-id	02e5e22a78626187e00d173dc45f58fa66a4f043	2026-06-12 00:19:58.879499
20	list-objects-with-delimiter	cd694ae708e51ba82bf012bba00caf4f3b6393b7	2026-06-12 00:19:58.882616
21	s3-multipart-uploads	8c804d4a566c40cd1e4cc5b3725a664a9303657f	2026-06-12 00:19:58.885094
22	s3-multipart-uploads-big-ints	9737dc258d2397953c9953d9b86920b8be0cdb73	2026-06-12 00:19:58.889187
23	optimize-search-function	9d7e604cddc4b56a5422dc68c9313f4a1b6f132c	2026-06-12 00:19:58.892876
24	operation-function	8312e37c2bf9e76bbe841aa5fda889206d2bf8aa	2026-06-12 00:19:58.896207
25	custom-metadata	d974c6057c3db1c1f847afa0e291e6165693b990	2026-06-12 00:19:58.898344
26	objects-prefixes	215cabcb7f78121892a5a2037a09fedf9a1ae322	2026-06-12 00:19:58.900536
27	search-v2	859ba38092ac96eb3964d83bf53ccc0b141663a6	2026-06-12 00:19:58.90267
28	object-bucket-name-sorting	c73a2b5b5d4041e39705814fd3a1b95502d38ce4	2026-06-12 00:19:58.905846
29	create-prefixes	ad2c1207f76703d11a9f9007f821620017a66c21	2026-06-12 00:19:58.907808
30	update-object-levels	2be814ff05c8252fdfdc7cfb4b7f5c7e17f0bed6	2026-06-12 00:19:58.909886
31	objects-level-index	b40367c14c3440ec75f19bbce2d71e914ddd3da0	2026-06-12 00:19:58.911827
32	backward-compatible-index-on-objects	e0c37182b0f7aee3efd823298fb3c76f1042c0f7	2026-06-12 00:19:58.914946
33	backward-compatible-index-on-prefixes	b480e99ed951e0900f033ec4eb34b5bdcb4e3d49	2026-06-12 00:19:58.916805
34	optimize-search-function-v1	ca80a3dc7bfef894df17108785ce29a7fc8ee456	2026-06-12 00:19:58.918881
35	add-insert-trigger-prefixes	458fe0ffd07ec53f5e3ce9df51bfdf4861929ccc	2026-06-12 00:19:58.920802
36	optimise-existing-functions	6ae5fca6af5c55abe95369cd4f93985d1814ca8f	2026-06-12 00:19:58.923531
37	add-bucket-name-length-trigger	3944135b4e3e8b22d6d4cbb568fe3b0b51df15c1	2026-06-12 00:19:58.925604
38	iceberg-catalog-flag-on-buckets	02716b81ceec9705aed84aa1501657095b32e5c5	2026-06-12 00:19:58.928237
39	add-search-v2-sort-support	6706c5f2928846abee18461279799ad12b279b78	2026-06-12 00:19:58.935295
40	fix-prefix-race-conditions-optimized	7ad69982ae2d372b21f48fc4829ae9752c518f6b	2026-06-12 00:19:58.93853
41	add-object-level-update-trigger	07fcf1a22165849b7a029deed059ffcde08d1ae0	2026-06-12 00:19:58.940694
42	rollback-prefix-triggers	771479077764adc09e2ea2043eb627503c034cd4	2026-06-12 00:19:58.942816
43	fix-object-level	84b35d6caca9d937478ad8a797491f38b8c2979f	2026-06-12 00:19:58.944693
44	vector-bucket-type	99c20c0ffd52bb1ff1f32fb992f3b351e3ef8fb3	2026-06-12 00:19:58.947777
45	vector-buckets	049e27196d77a7cb76497a85afae669d8b230953	2026-06-12 00:19:58.950131
46	buckets-objects-grants	fedeb96d60fefd8e02ab3ded9fbde05632f84aed	2026-06-12 00:19:58.953717
47	iceberg-table-metadata	649df56855c24d8b36dd4cc1aeb8251aa9ad42c2	2026-06-12 00:19:58.956107
48	iceberg-catalog-ids	e0e8b460c609b9999ccd0df9ad14294613eed939	2026-06-12 00:19:58.959493
49	buckets-objects-grants-postgres	072b1195d0d5a2f888af6b2302a1938dd94b8b3d	2026-06-12 00:19:58.971156
50	search-v2-optimised	6323ac4f850aa14e7387eb32102869578b5bd478	2026-06-12 00:19:58.973692
51	index-backward-compatible-search	2ee395d433f76e38bcd3856debaf6e0e5b674011	2026-06-12 00:19:58.984124
52	drop-not-used-indexes-and-functions	5cc44c8696749ac11dd0dc37f2a3802075f3a171	2026-06-12 00:19:58.985607
53	drop-index-lower-name	d0cb18777d9e2a98ebe0bc5cc7a42e57ebe41854	2026-06-12 00:19:58.990738
54	drop-index-object-level	6289e048b1472da17c31a7eba1ded625a6457e67	2026-06-12 00:19:58.993342
55	prevent-direct-deletes	262a4798d5e0f2e7c8970232e03ce8be695d5819	2026-06-12 00:19:58.994969
56	fix-optimized-search-function	b823ed1e418101032fa01374edc9a436e54e3ed4	2026-06-12 00:19:58.997402
57	s3-multipart-uploads-metadata	f127886e00d1b374fadbc7c6b31e09336aad5287	2026-06-12 00:19:59.001483
58	operation-ergonomics	00ca5d483b3fe0d522133d9002ccc5df98365120	2026-06-12 00:19:59.004279
59	drop-unused-functions	38456f13e39691c2bbb4b5151d0d1cdbabd4a8c4	2026-06-12 00:19:59.0067
60	optimize-existing-functions-again	db35e1c91a9201e59f4fef8d972c2f277d68b157	2026-06-12 00:19:59.009075
\.


--
-- Data for Name: objects; Type: TABLE DATA; Schema: storage; Owner: supabase_storage_admin
--

COPY storage.objects (id, bucket_id, name, owner, created_at, updated_at, last_accessed_at, metadata, version, owner_id, user_metadata) FROM stdin;
a6648136-c7c7-4775-8f2e-d629fb81c94b	frigate-models	models/subh_firearm/best.pt	\N	2026-06-14 07:42:07.306196+00	2026-06-14 07:42:07.306196+00	2026-06-14 07:42:07.306196+00	{"eTag": "\\"a03b0c5aee7ad426fafd7265fa77ba5d\\"", "size": 6238307, "mimetype": "application/octet-stream", "cacheControl": "no-cache", "lastModified": "2026-06-14T07:42:07.288Z", "contentLength": 6238307, "httpStatusCode": 200}	9cdad23e-80c4-448d-95c3-af3eda16ce2e	\N	{}
07efc137-1275-44cb-9e91-c53898e4629f	frigate-models	models/abonai_fire_smoke/yolov8n.pt	\N	2026-06-14 02:58:57.155311+00	2026-06-14 07:41:53.730772+00	2026-06-14 02:58:57.155311+00	{"eTag": "\\"0305608151dd1725c9d7da6882ae52d5\\"", "size": 6534387, "mimetype": "application/octet-stream", "cacheControl": "no-cache", "lastModified": "2026-06-14T07:41:53.707Z", "contentLength": 6534387, "httpStatusCode": 200}	de25485e-250d-4c9f-8ee5-8ce42436a634	\N	{}
b4e6b7df-30f3-445f-aebb-f6835eafcb7e	frigate-models	models/hexmon_vyra_ppe/best.pt	\N	2026-06-14 02:58:58.291391+00	2026-06-14 07:41:59.286414+00	2026-06-14 02:58:58.291391+00	{"eTag": "\\"daa5a7a6561c78df9a5e141cbed65b8b\\"", "size": 52056210, "mimetype": "application/octet-stream", "cacheControl": "no-cache", "lastModified": "2026-06-14T07:41:59.207Z", "contentLength": 52056210, "httpStatusCode": 200}	162a2b88-a6dc-46ef-beee-14b06a1538d1	\N	{}
ca8b21bf-cea5-45f3-ae0d-95f094a41fa1	frigate-models	models/mkgoud_lpr/LP-detection.pt	\N	2026-06-14 07:47:28.525261+00	2026-06-14 07:47:28.525261+00	2026-06-14 07:47:28.525261+00	{"eTag": "\\"110481218c37bc27a963d1bbe85f78e6\\"", "size": 6239992, "mimetype": "application/octet-stream", "cacheControl": "no-cache", "lastModified": "2026-06-14T07:47:28.503Z", "contentLength": 6239992, "httpStatusCode": 200}	1a12d299-1c0a-4c9f-97eb-745e5bfbe06f	\N	{}
47222a8a-c97c-4689-b69e-87baae4318ac	frigate-models	models/keremberke_ppe/best.pt	\N	2026-06-14 02:58:58.724001+00	2026-06-14 07:42:01.358598+00	2026-06-14 02:58:58.724001+00	{"eTag": "\\"5f10a3f84dbc88b9d287a588c1f71f0c\\"", "size": 22500088, "mimetype": "application/octet-stream", "cacheControl": "no-cache", "lastModified": "2026-06-14T07:42:01.317Z", "contentLength": 22500088, "httpStatusCode": 200}	b5bd6ee2-506a-4331-a16a-ac9645db239f	\N	{}
225f3299-2729-43aa-8f41-81e0d7e41392	frigate-models	models/subh_threat/best.pt	\N	2026-06-14 07:42:04.451465+00	2026-06-14 07:42:04.451465+00	2026-06-14 07:42:04.451465+00	{"eTag": "\\"7453bb7a469f65e1eafa72df0f2da3fb\\"", "size": 6251747, "mimetype": "application/octet-stream", "cacheControl": "no-cache", "lastModified": "2026-06-14T07:42:04.428Z", "contentLength": 6251747, "httpStatusCode": 200}	79673a07-e690-4034-96e0-3d844bdec554	\N	{}
5a9a17dc-bdc3-4d8a-a649-6ab422f1e937	frigate-models	models/melih_fall/best.pt	\N	2026-06-14 02:59:00.496212+00	2026-06-14 07:42:11.703499+00	2026-06-14 02:59:00.496212+00	{"eTag": "\\"38436b66fc8bb3452ce7cf5efa667f8c\\"", "size": 5472282, "mimetype": "application/octet-stream", "cacheControl": "no-cache", "lastModified": "2026-06-14T07:42:11.688Z", "contentLength": 5472282, "httpStatusCode": 200}	97f22e16-fbe1-4859-a911-6ba5b6ba0899	\N	{}
ebb3efc4-d3dc-427e-bbc6-c5c5e4af79a8	frigate-models	models/keremberke_forklift/best.pt	\N	2026-06-14 02:59:02.486707+00	2026-06-14 07:42:15.667354+00	2026-06-14 02:59:02.486707+00	{"eTag": "\\"6f4fe49d71c67dfdf58db3554f12f109\\"", "size": 22485752, "mimetype": "application/octet-stream", "cacheControl": "no-cache", "lastModified": "2026-06-14T07:42:15.628Z", "contentLength": 22485752, "httpStatusCode": 200}	d6f8240d-845f-45bf-bb41-28a636fb6155	\N	{}
b545088f-8837-40ff-ae10-40c83e254602	frigate-models	models/enos_traffic_accident/epoch61.pt	\N	2026-06-14 07:47:20.522319+00	2026-06-14 07:47:20.522319+00	2026-06-14 07:47:20.522319+00	{"eTag": "\\"58c57cf390a31063eb225e8bc50c1fdf\\"", "size": 114368274, "mimetype": "application/octet-stream", "cacheControl": "no-cache", "lastModified": "2026-06-14T07:47:20.363Z", "contentLength": 114368274, "httpStatusCode": 200}	42c87340-8e5f-4050-8a49-aefdca695836	\N	{}
32b633a9-2429-4b1a-833e-e4b1fecd7099	frigate-models	models/risef_seatbelt/best.pt	\N	2026-06-14 07:47:24.000472+00	2026-06-14 07:47:24.000472+00	2026-06-14 07:47:24.000472+00	{"eTag": "\\"24b478871abf67604c9e22e67ea19363\\"", "size": 11024315, "mimetype": "application/octet-stream", "cacheControl": "no-cache", "lastModified": "2026-06-14T07:47:23.972Z", "contentLength": 11024315, "httpStatusCode": 200}	68acfd32-dc17-408c-a646-bccc770afe9c	\N	{}
9ebfc076-2886-487b-a205-d2be44fb39f0	frigate-models	models/musawer_fight/Yolo_nano_weights.pt	\N	2026-06-14 07:47:32.404846+00	2026-06-14 07:47:32.404846+00	2026-06-14 07:47:32.404846+00	{"eTag": "\\"71c7e339a30d2c583d2718009659c1c3\\"", "size": 6250147, "mimetype": "application/octet-stream", "cacheControl": "no-cache", "lastModified": "2026-06-14T07:47:32.383Z", "contentLength": 6250147, "httpStatusCode": 200}	7946c790-9910-492d-ab86-9d0efe58642b	\N	{}
\.


--
-- Data for Name: s3_multipart_uploads; Type: TABLE DATA; Schema: storage; Owner: supabase_storage_admin
--

COPY storage.s3_multipart_uploads (id, in_progress_size, upload_signature, bucket_id, key, version, owner_id, created_at, user_metadata, metadata) FROM stdin;
\.


--
-- Data for Name: s3_multipart_uploads_parts; Type: TABLE DATA; Schema: storage; Owner: supabase_storage_admin
--

COPY storage.s3_multipart_uploads_parts (id, upload_id, size, part_number, bucket_id, key, etag, owner_id, version, created_at) FROM stdin;
\.


--
-- Data for Name: vector_indexes; Type: TABLE DATA; Schema: storage; Owner: supabase_storage_admin
--

COPY storage.vector_indexes (id, name, bucket_id, data_type, dimension, distance_metric, metadata_configuration, created_at, updated_at) FROM stdin;
\.


--
-- Data for Name: hooks; Type: TABLE DATA; Schema: supabase_functions; Owner: supabase_functions_admin
--

COPY supabase_functions.hooks (id, hook_table_id, hook_name, created_at, request_id) FROM stdin;
\.


--
-- Data for Name: migrations; Type: TABLE DATA; Schema: supabase_functions; Owner: supabase_functions_admin
--

COPY supabase_functions.migrations (version, inserted_at) FROM stdin;
initial	2026-06-12 00:19:46.500688+00
20210809183423_update_grants	2026-06-12 00:19:46.500688+00
\.




--
-- Data for Name: secrets; Type: TABLE DATA; Schema: vault; Owner: supabase_admin
--

COPY vault.secrets (id, name, description, secret, key_id, nonce, created_at, updated_at) FROM stdin;
\.


--
-- Name: refresh_tokens_id_seq; Type: SEQUENCE SET; Schema: auth; Owner: supabase_auth_admin
--

SELECT pg_catalog.setval('auth.refresh_tokens_id_seq', 58, true);


--
-- Name: subscription_id_seq; Type: SEQUENCE SET; Schema: realtime; Owner: supabase_admin
--

SELECT pg_catalog.setval('realtime.subscription_id_seq', 296, true);


--
-- Name: hooks_id_seq; Type: SEQUENCE SET; Schema: supabase_functions; Owner: supabase_functions_admin
--

SELECT pg_catalog.setval('supabase_functions.hooks_id_seq', 1, false);


--
-- Name: extensions extensions_pkey; Type: CONSTRAINT; Schema: _realtime; Owner: supabase_admin
--

ALTER TABLE ONLY _realtime.extensions
    ADD CONSTRAINT extensions_pkey PRIMARY KEY (id);


--
-- Name: feature_flags feature_flags_pkey; Type: CONSTRAINT; Schema: _realtime; Owner: supabase_admin
--

ALTER TABLE ONLY _realtime.feature_flags
    ADD CONSTRAINT feature_flags_pkey PRIMARY KEY (id);


--
-- Name: schema_migrations schema_migrations_pkey; Type: CONSTRAINT; Schema: _realtime; Owner: supabase_admin
--

ALTER TABLE ONLY _realtime.schema_migrations
    ADD CONSTRAINT schema_migrations_pkey PRIMARY KEY (version);


--
-- Name: tenants tenants_pkey; Type: CONSTRAINT; Schema: _realtime; Owner: supabase_admin
--

ALTER TABLE ONLY _realtime.tenants
    ADD CONSTRAINT tenants_pkey PRIMARY KEY (id);


--
-- Name: mfa_amr_claims amr_id_pk; Type: CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.mfa_amr_claims
    ADD CONSTRAINT amr_id_pk PRIMARY KEY (id);


--
-- Name: audit_log_entries audit_log_entries_pkey; Type: CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.audit_log_entries
    ADD CONSTRAINT audit_log_entries_pkey PRIMARY KEY (id);


--
-- Name: custom_oauth_providers custom_oauth_providers_identifier_key; Type: CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.custom_oauth_providers
    ADD CONSTRAINT custom_oauth_providers_identifier_key UNIQUE (identifier);


--
-- Name: custom_oauth_providers custom_oauth_providers_pkey; Type: CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.custom_oauth_providers
    ADD CONSTRAINT custom_oauth_providers_pkey PRIMARY KEY (id);


--
-- Name: flow_state flow_state_pkey; Type: CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.flow_state
    ADD CONSTRAINT flow_state_pkey PRIMARY KEY (id);


--
-- Name: identities identities_pkey; Type: CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.identities
    ADD CONSTRAINT identities_pkey PRIMARY KEY (id);


--
-- Name: identities identities_provider_id_provider_unique; Type: CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.identities
    ADD CONSTRAINT identities_provider_id_provider_unique UNIQUE (provider_id, provider);


--
-- Name: instances instances_pkey; Type: CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.instances
    ADD CONSTRAINT instances_pkey PRIMARY KEY (id);


--
-- Name: mfa_amr_claims mfa_amr_claims_session_id_authentication_method_pkey; Type: CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.mfa_amr_claims
    ADD CONSTRAINT mfa_amr_claims_session_id_authentication_method_pkey UNIQUE (session_id, authentication_method);


--
-- Name: mfa_challenges mfa_challenges_pkey; Type: CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.mfa_challenges
    ADD CONSTRAINT mfa_challenges_pkey PRIMARY KEY (id);


--
-- Name: mfa_factors mfa_factors_last_challenged_at_key; Type: CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.mfa_factors
    ADD CONSTRAINT mfa_factors_last_challenged_at_key UNIQUE (last_challenged_at);


--
-- Name: mfa_factors mfa_factors_pkey; Type: CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.mfa_factors
    ADD CONSTRAINT mfa_factors_pkey PRIMARY KEY (id);


--
-- Name: oauth_authorizations oauth_authorizations_authorization_code_key; Type: CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.oauth_authorizations
    ADD CONSTRAINT oauth_authorizations_authorization_code_key UNIQUE (authorization_code);


--
-- Name: oauth_authorizations oauth_authorizations_authorization_id_key; Type: CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.oauth_authorizations
    ADD CONSTRAINT oauth_authorizations_authorization_id_key UNIQUE (authorization_id);


--
-- Name: oauth_authorizations oauth_authorizations_pkey; Type: CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.oauth_authorizations
    ADD CONSTRAINT oauth_authorizations_pkey PRIMARY KEY (id);


--
-- Name: oauth_client_states oauth_client_states_pkey; Type: CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.oauth_client_states
    ADD CONSTRAINT oauth_client_states_pkey PRIMARY KEY (id);


--
-- Name: oauth_clients oauth_clients_pkey; Type: CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.oauth_clients
    ADD CONSTRAINT oauth_clients_pkey PRIMARY KEY (id);


--
-- Name: oauth_consents oauth_consents_pkey; Type: CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.oauth_consents
    ADD CONSTRAINT oauth_consents_pkey PRIMARY KEY (id);


--
-- Name: oauth_consents oauth_consents_user_client_unique; Type: CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.oauth_consents
    ADD CONSTRAINT oauth_consents_user_client_unique UNIQUE (user_id, client_id);


--
-- Name: one_time_tokens one_time_tokens_pkey; Type: CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.one_time_tokens
    ADD CONSTRAINT one_time_tokens_pkey PRIMARY KEY (id);


--
-- Name: refresh_tokens refresh_tokens_pkey; Type: CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.refresh_tokens
    ADD CONSTRAINT refresh_tokens_pkey PRIMARY KEY (id);


--
-- Name: refresh_tokens refresh_tokens_token_unique; Type: CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.refresh_tokens
    ADD CONSTRAINT refresh_tokens_token_unique UNIQUE (token);


--
-- Name: saml_providers saml_providers_entity_id_key; Type: CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.saml_providers
    ADD CONSTRAINT saml_providers_entity_id_key UNIQUE (entity_id);


--
-- Name: saml_providers saml_providers_pkey; Type: CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.saml_providers
    ADD CONSTRAINT saml_providers_pkey PRIMARY KEY (id);


--
-- Name: saml_relay_states saml_relay_states_pkey; Type: CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.saml_relay_states
    ADD CONSTRAINT saml_relay_states_pkey PRIMARY KEY (id);


--
-- Name: schema_migrations schema_migrations_pkey; Type: CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.schema_migrations
    ADD CONSTRAINT schema_migrations_pkey PRIMARY KEY (version);


--
-- Name: sessions sessions_pkey; Type: CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.sessions
    ADD CONSTRAINT sessions_pkey PRIMARY KEY (id);


--
-- Name: sso_domains sso_domains_pkey; Type: CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.sso_domains
    ADD CONSTRAINT sso_domains_pkey PRIMARY KEY (id);


--
-- Name: sso_providers sso_providers_pkey; Type: CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.sso_providers
    ADD CONSTRAINT sso_providers_pkey PRIMARY KEY (id);


--
-- Name: users users_phone_key; Type: CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.users
    ADD CONSTRAINT users_phone_key UNIQUE (phone);


--
-- Name: users users_pkey; Type: CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.users
    ADD CONSTRAINT users_pkey PRIMARY KEY (id);


--
-- Name: webauthn_challenges webauthn_challenges_pkey; Type: CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.webauthn_challenges
    ADD CONSTRAINT webauthn_challenges_pkey PRIMARY KEY (id);


--
-- Name: webauthn_credentials webauthn_credentials_pkey; Type: CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.webauthn_credentials
    ADD CONSTRAINT webauthn_credentials_pkey PRIMARY KEY (id);


--
-- Name: ai_analysis_logs ai_analysis_logs_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.ai_analysis_logs
    ADD CONSTRAINT ai_analysis_logs_pkey PRIMARY KEY (id);


--
-- Name: ai_models ai_models_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.ai_models
    ADD CONSTRAINT ai_models_pkey PRIMARY KEY (id);


--
-- Name: alert_template_events alert_template_events_alert_template_id_event_type_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.alert_template_events
    ADD CONSTRAINT alert_template_events_alert_template_id_event_type_id_key UNIQUE (alert_template_id, event_type_id);


--
-- Name: alert_template_events alert_template_events_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.alert_template_events
    ADD CONSTRAINT alert_template_events_pkey PRIMARY KEY (id);


--
-- Name: alert_template_industries alert_template_industries_alert_template_id_industry_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.alert_template_industries
    ADD CONSTRAINT alert_template_industries_alert_template_id_industry_id_key UNIQUE (alert_template_id, industry_id);


--
-- Name: alert_template_industries alert_template_industries_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.alert_template_industries
    ADD CONSTRAINT alert_template_industries_pkey PRIMARY KEY (id);


--
-- Name: alert_templates alert_templates_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.alert_templates
    ADD CONSTRAINT alert_templates_pkey PRIMARY KEY (id);


--
-- Name: aman_instances aman_instances_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.aman_instances
    ADD CONSTRAINT aman_instances_pkey PRIMARY KEY (id);


--
-- Name: auto_sync_settings auto_sync_settings_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.auto_sync_settings
    ADD CONSTRAINT auto_sync_settings_pkey PRIMARY KEY (id);


--
-- Name: branch_roles branch_roles_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.branch_roles
    ADD CONSTRAINT branch_roles_pkey PRIMARY KEY (id);


--
-- Name: branches branches_device_token_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.branches
    ADD CONSTRAINT branches_device_token_key UNIQUE (device_token);


--
-- Name: branches branches_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.branches
    ADD CONSTRAINT branches_pkey PRIMARY KEY (id);


--
-- Name: camera_alert_assignments camera_alert_assignments_camera_id_alert_template_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.camera_alert_assignments
    ADD CONSTRAINT camera_alert_assignments_camera_id_alert_template_id_key UNIQUE (camera_id, alert_template_id);


--
-- Name: camera_alert_assignments camera_alert_assignments_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.camera_alert_assignments
    ADD CONSTRAINT camera_alert_assignments_pkey PRIMARY KEY (id);


--
-- Name: camera_event_assignments camera_event_assignments_camera_id_event_type_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.camera_event_assignments
    ADD CONSTRAINT camera_event_assignments_camera_id_event_type_id_key UNIQUE (camera_id, event_type_id);


--
-- Name: camera_event_assignments camera_event_assignments_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.camera_event_assignments
    ADD CONSTRAINT camera_event_assignments_pkey PRIMARY KEY (id);


--
-- Name: camera_sources camera_sources_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.camera_sources
    ADD CONSTRAINT camera_sources_pkey PRIMARY KEY (id);


--
-- Name: cameras cameras_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.cameras
    ADD CONSTRAINT cameras_pkey PRIMARY KEY (id);


--
-- Name: chat_messages chat_messages_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.chat_messages
    ADD CONSTRAINT chat_messages_pkey PRIMARY KEY (id);


--
-- Name: chat_thread_participants chat_thread_participants_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.chat_thread_participants
    ADD CONSTRAINT chat_thread_participants_pkey PRIMARY KEY (id);


--
-- Name: chat_thread_participants chat_thread_participants_thread_id_user_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.chat_thread_participants
    ADD CONSTRAINT chat_thread_participants_thread_id_user_id_key UNIQUE (thread_id, user_id);


--
-- Name: chat_threads chat_threads_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.chat_threads
    ADD CONSTRAINT chat_threads_pkey PRIMARY KEY (id);


--
-- Name: chatbot_knowledge_base chatbot_knowledge_base_language_content_type_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.chatbot_knowledge_base
    ADD CONSTRAINT chatbot_knowledge_base_language_content_type_key UNIQUE (language, content_type);


--
-- Name: chatbot_knowledge_base chatbot_knowledge_base_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.chatbot_knowledge_base
    ADD CONSTRAINT chatbot_knowledge_base_pkey PRIMARY KEY (id);


--
-- Name: detection_rules detection_rules_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.detection_rules
    ADD CONSTRAINT detection_rules_pkey PRIMARY KEY (id);


--
-- Name: event_types event_types_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.event_types
    ADD CONSTRAINT event_types_pkey PRIMARY KEY (id);


--
-- Name: events events_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.events
    ADD CONSTRAINT events_pkey PRIMARY KEY (id);


--
-- Name: form_assignments form_assignments_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.form_assignments
    ADD CONSTRAINT form_assignments_pkey PRIMARY KEY (id);


--
-- Name: form_distribution_settings form_distribution_settings_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.form_distribution_settings
    ADD CONSTRAINT form_distribution_settings_pkey PRIMARY KEY (id);


--
-- Name: form_submissions form_submissions_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.form_submissions
    ADD CONSTRAINT form_submissions_pkey PRIMARY KEY (id);


--
-- Name: frigate_alert_rules frigate_alert_rules_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_alert_rules
    ADD CONSTRAINT frigate_alert_rules_pkey PRIMARY KEY (id);


--
-- Name: frigate_deployed_models frigate_deployed_models_frigate_instance_id_model_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_deployed_models
    ADD CONSTRAINT frigate_deployed_models_frigate_instance_id_model_id_key UNIQUE (frigate_instance_id, model_id);


--
-- Name: frigate_deployed_models frigate_deployed_models_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_deployed_models
    ADD CONSTRAINT frigate_deployed_models_pkey PRIMARY KEY (id);


--
-- Name: frigate_exports frigate_exports_export_id_frigate_instance_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_exports
    ADD CONSTRAINT frigate_exports_export_id_frigate_instance_id_key UNIQUE (export_id, frigate_instance_id);


--
-- Name: frigate_exports frigate_exports_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_exports
    ADD CONSTRAINT frigate_exports_pkey PRIMARY KEY (id);


--
-- Name: frigate_faces frigate_faces_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_faces
    ADD CONSTRAINT frigate_faces_pkey PRIMARY KEY (id);


--
-- Name: frigate_instances frigate_instances_branch_id_name_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_instances
    ADD CONSTRAINT frigate_instances_branch_id_name_key UNIQUE (branch_id, name);


--
-- Name: frigate_instances frigate_instances_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_instances
    ADD CONSTRAINT frigate_instances_pkey PRIMARY KEY (id);


--
-- Name: frigate_license_plates frigate_license_plates_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_license_plates
    ADD CONSTRAINT frigate_license_plates_pkey PRIMARY KEY (id);


--
-- Name: frigate_model_deployments frigate_model_deployments_model_id_frigate_instance_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_model_deployments
    ADD CONSTRAINT frigate_model_deployments_model_id_frigate_instance_id_key UNIQUE (model_id, frigate_instance_id);


--
-- Name: frigate_model_deployments frigate_model_deployments_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_model_deployments
    ADD CONSTRAINT frigate_model_deployments_pkey PRIMARY KEY (id);


--
-- Name: frigate_model_registry frigate_model_registry_model_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_model_registry
    ADD CONSTRAINT frigate_model_registry_model_id_key UNIQUE (model_id);


--
-- Name: frigate_model_registry frigate_model_registry_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_model_registry
    ADD CONSTRAINT frigate_model_registry_pkey PRIMARY KEY (id);


--
-- Name: frigate_model_sync_log frigate_model_sync_log_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_model_sync_log
    ADD CONSTRAINT frigate_model_sync_log_pkey PRIMARY KEY (id);


--
-- Name: frigate_previews frigate_previews_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_previews
    ADD CONSTRAINT frigate_previews_pkey PRIMARY KEY (id);


--
-- Name: frigate_previews frigate_previews_preview_id_frigate_instance_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_previews
    ADD CONSTRAINT frigate_previews_preview_id_frigate_instance_id_key UNIQUE (preview_id, frigate_instance_id);


--
-- Name: frigate_recordings frigate_recordings_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_recordings
    ADD CONSTRAINT frigate_recordings_pkey PRIMARY KEY (id);


--
-- Name: frigate_recordings frigate_recordings_recording_id_frigate_instance_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_recordings
    ADD CONSTRAINT frigate_recordings_recording_id_frigate_instance_id_key UNIQUE (recording_id, frigate_instance_id);


--
-- Name: frigate_reviews frigate_reviews_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_reviews
    ADD CONSTRAINT frigate_reviews_pkey PRIMARY KEY (id);


--
-- Name: frigate_reviews frigate_reviews_review_id_frigate_instance_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_reviews
    ADD CONSTRAINT frigate_reviews_review_id_frigate_instance_id_key UNIQUE (review_id, frigate_instance_id);


--
-- Name: frigate_stats_history frigate_stats_history_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_stats_history
    ADD CONSTRAINT frigate_stats_history_pkey PRIMARY KEY (id);


--
-- Name: frigate_sync_logs frigate_sync_logs_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_sync_logs
    ADD CONSTRAINT frigate_sync_logs_pkey PRIMARY KEY (id);


--
-- Name: frigate_timeline frigate_timeline_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_timeline
    ADD CONSTRAINT frigate_timeline_pkey PRIMARY KEY (id);


--
-- Name: frigate_triggers frigate_triggers_frigate_instance_id_camera_name_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_triggers
    ADD CONSTRAINT frigate_triggers_frigate_instance_id_camera_name_key UNIQUE (frigate_instance_id, camera, name);


--
-- Name: frigate_triggers frigate_triggers_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_triggers
    ADD CONSTRAINT frigate_triggers_pkey PRIMARY KEY (id);


--
-- Name: frigate_zones frigate_zones_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_zones
    ADD CONSTRAINT frigate_zones_pkey PRIMARY KEY (id);


--
-- Name: health_alerts health_alerts_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.health_alerts
    ADD CONSTRAINT health_alerts_pkey PRIMARY KEY (id);


--
-- Name: industries industries_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.industries
    ADD CONSTRAINT industries_pkey PRIMARY KEY (id);


--
-- Name: legal_documents legal_documents_document_type_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.legal_documents
    ADD CONSTRAINT legal_documents_document_type_key UNIQUE (document_type);


--
-- Name: legal_documents legal_documents_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.legal_documents
    ADD CONSTRAINT legal_documents_pkey PRIMARY KEY (id);


--
-- Name: network_scan_results network_scan_results_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.network_scan_results
    ADD CONSTRAINT network_scan_results_pkey PRIMARY KEY (id);


--
-- Name: notification_labels notification_labels_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.notification_labels
    ADD CONSTRAINT notification_labels_pkey PRIMARY KEY (id);


--
-- Name: notification_methods notification_methods_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.notification_methods
    ADD CONSTRAINT notification_methods_pkey PRIMARY KEY (id);


--
-- Name: organization_settings organization_settings_organization_id_setting_key_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.organization_settings
    ADD CONSTRAINT organization_settings_organization_id_setting_key_key UNIQUE (organization_id, setting_key);


--
-- Name: organization_settings organization_settings_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.organization_settings
    ADD CONSTRAINT organization_settings_pkey PRIMARY KEY (id);


--
-- Name: organizations organizations_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.organizations
    ADD CONSTRAINT organizations_pkey PRIMARY KEY (id);


--
-- Name: pinned_dashboards pinned_dashboards_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.pinned_dashboards
    ADD CONSTRAINT pinned_dashboards_pkey PRIMARY KEY (id);


--
-- Name: pinned_labels pinned_labels_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.pinned_labels
    ADD CONSTRAINT pinned_labels_pkey PRIMARY KEY (id);


--
-- Name: screen_permissions screen_permissions_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.screen_permissions
    ADD CONSTRAINT screen_permissions_pkey PRIMARY KEY (id);


--
-- Name: screen_permissions screen_permissions_screen_key_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.screen_permissions
    ADD CONSTRAINT screen_permissions_screen_key_key UNIQUE (screen_key);


--
-- Name: security_zones security_zones_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.security_zones
    ADD CONSTRAINT security_zones_pkey PRIMARY KEY (id);


--
-- Name: storage_configs storage_configs_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.storage_configs
    ADD CONSTRAINT storage_configs_pkey PRIMARY KEY (id);


--
-- Name: students students_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.students
    ADD CONSTRAINT students_pkey PRIMARY KEY (id);


--
-- Name: students students_wearable_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.students
    ADD CONSTRAINT students_wearable_id_key UNIQUE (wearable_id);


--
-- Name: subscribers subscribers_email_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.subscribers
    ADD CONSTRAINT subscribers_email_key UNIQUE (email);


--
-- Name: subscribers subscribers_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.subscribers
    ADD CONSTRAINT subscribers_pkey PRIMARY KEY (id);


--
-- Name: system_settings system_settings_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.system_settings
    ADD CONSTRAINT system_settings_pkey PRIMARY KEY (id);


--
-- Name: system_settings system_settings_setting_key_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.system_settings
    ADD CONSTRAINT system_settings_setting_key_key UNIQUE (setting_key);


--
-- Name: user_branch_access user_branch_access_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.user_branch_access
    ADD CONSTRAINT user_branch_access_pkey PRIMARY KEY (id);


--
-- Name: user_branch_access user_branch_access_user_id_branch_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.user_branch_access
    ADD CONSTRAINT user_branch_access_user_id_branch_id_key UNIQUE (user_id, branch_id);


--
-- Name: user_group_members user_group_members_group_id_user_role_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.user_group_members
    ADD CONSTRAINT user_group_members_group_id_user_role_id_key UNIQUE (group_id, user_role_id);


--
-- Name: user_group_members user_group_members_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.user_group_members
    ADD CONSTRAINT user_group_members_pkey PRIMARY KEY (id);


--
-- Name: user_groups user_groups_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.user_groups
    ADD CONSTRAINT user_groups_pkey PRIMARY KEY (id);


--
-- Name: user_preferences user_preferences_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.user_preferences
    ADD CONSTRAINT user_preferences_pkey PRIMARY KEY (id);


--
-- Name: user_preferences user_preferences_user_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.user_preferences
    ADD CONSTRAINT user_preferences_user_id_key UNIQUE (user_id);


--
-- Name: user_roles user_roles_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.user_roles
    ADD CONSTRAINT user_roles_pkey PRIMARY KEY (id);


--
-- Name: user_roles user_roles_user_id_organization_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.user_roles
    ADD CONSTRAINT user_roles_user_id_organization_id_key UNIQUE (user_id, organization_id);


--
-- Name: workflow_forms workflow_forms_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.workflow_forms
    ADD CONSTRAINT workflow_forms_pkey PRIMARY KEY (id);


--
-- Name: messages messages_pkey; Type: CONSTRAINT; Schema: realtime; Owner: supabase_realtime_admin
--

ALTER TABLE ONLY realtime.messages
    ADD CONSTRAINT messages_pkey PRIMARY KEY (id, inserted_at);


--
-- Name: messages_2026_07_02 messages_2026_07_02_pkey; Type: CONSTRAINT; Schema: realtime; Owner: supabase_admin
--

ALTER TABLE ONLY realtime.messages_2026_07_02
    ADD CONSTRAINT messages_2026_07_02_pkey PRIMARY KEY (id, inserted_at);


--
-- Name: messages_2026_07_03 messages_2026_07_03_pkey; Type: CONSTRAINT; Schema: realtime; Owner: supabase_admin
--

ALTER TABLE ONLY realtime.messages_2026_07_03
    ADD CONSTRAINT messages_2026_07_03_pkey PRIMARY KEY (id, inserted_at);


--
-- Name: messages_2026_07_04 messages_2026_07_04_pkey; Type: CONSTRAINT; Schema: realtime; Owner: supabase_admin
--

ALTER TABLE ONLY realtime.messages_2026_07_04
    ADD CONSTRAINT messages_2026_07_04_pkey PRIMARY KEY (id, inserted_at);


--
-- Name: messages_2026_07_05 messages_2026_07_05_pkey; Type: CONSTRAINT; Schema: realtime; Owner: supabase_admin
--

ALTER TABLE ONLY realtime.messages_2026_07_05
    ADD CONSTRAINT messages_2026_07_05_pkey PRIMARY KEY (id, inserted_at);


--
-- Name: messages_2026_07_06 messages_2026_07_06_pkey; Type: CONSTRAINT; Schema: realtime; Owner: supabase_admin
--

ALTER TABLE ONLY realtime.messages_2026_07_06
    ADD CONSTRAINT messages_2026_07_06_pkey PRIMARY KEY (id, inserted_at);


--
-- Name: messages_2026_07_07 messages_2026_07_07_pkey; Type: CONSTRAINT; Schema: realtime; Owner: supabase_admin
--

ALTER TABLE ONLY realtime.messages_2026_07_07
    ADD CONSTRAINT messages_2026_07_07_pkey PRIMARY KEY (id, inserted_at);


--
-- Name: messages_2026_07_08 messages_2026_07_08_pkey; Type: CONSTRAINT; Schema: realtime; Owner: supabase_admin
--

ALTER TABLE ONLY realtime.messages_2026_07_08
    ADD CONSTRAINT messages_2026_07_08_pkey PRIMARY KEY (id, inserted_at);


--
-- Name: messages messages_payload_exclusive; Type: CHECK CONSTRAINT; Schema: realtime; Owner: supabase_realtime_admin
--

ALTER TABLE realtime.messages
    ADD CONSTRAINT messages_payload_exclusive CHECK (((payload IS NULL) OR (binary_payload IS NULL))) NOT VALID;


--
-- Name: subscription pk_subscription; Type: CONSTRAINT; Schema: realtime; Owner: supabase_admin
--

ALTER TABLE ONLY realtime.subscription
    ADD CONSTRAINT pk_subscription PRIMARY KEY (id);


--
-- Name: schema_migrations schema_migrations_pkey; Type: CONSTRAINT; Schema: realtime; Owner: supabase_admin
--

ALTER TABLE ONLY realtime.schema_migrations
    ADD CONSTRAINT schema_migrations_pkey PRIMARY KEY (version);


--
-- Name: buckets_analytics buckets_analytics_pkey; Type: CONSTRAINT; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE ONLY storage.buckets_analytics
    ADD CONSTRAINT buckets_analytics_pkey PRIMARY KEY (id);


--
-- Name: buckets buckets_pkey; Type: CONSTRAINT; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE ONLY storage.buckets
    ADD CONSTRAINT buckets_pkey PRIMARY KEY (id);


--
-- Name: buckets_vectors buckets_vectors_pkey; Type: CONSTRAINT; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE ONLY storage.buckets_vectors
    ADD CONSTRAINT buckets_vectors_pkey PRIMARY KEY (id);


--
-- Name: iceberg_namespaces iceberg_namespaces_pkey; Type: CONSTRAINT; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE ONLY storage.iceberg_namespaces
    ADD CONSTRAINT iceberg_namespaces_pkey PRIMARY KEY (id);


--
-- Name: iceberg_tables iceberg_tables_pkey; Type: CONSTRAINT; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE ONLY storage.iceberg_tables
    ADD CONSTRAINT iceberg_tables_pkey PRIMARY KEY (id);


--
-- Name: migrations migrations_name_key; Type: CONSTRAINT; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE ONLY storage.migrations
    ADD CONSTRAINT migrations_name_key UNIQUE (name);


--
-- Name: migrations migrations_pkey; Type: CONSTRAINT; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE ONLY storage.migrations
    ADD CONSTRAINT migrations_pkey PRIMARY KEY (id);


--
-- Name: objects objects_pkey; Type: CONSTRAINT; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE ONLY storage.objects
    ADD CONSTRAINT objects_pkey PRIMARY KEY (id);


--
-- Name: s3_multipart_uploads_parts s3_multipart_uploads_parts_pkey; Type: CONSTRAINT; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE ONLY storage.s3_multipart_uploads_parts
    ADD CONSTRAINT s3_multipart_uploads_parts_pkey PRIMARY KEY (id);


--
-- Name: s3_multipart_uploads s3_multipart_uploads_pkey; Type: CONSTRAINT; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE ONLY storage.s3_multipart_uploads
    ADD CONSTRAINT s3_multipart_uploads_pkey PRIMARY KEY (id);


--
-- Name: vector_indexes vector_indexes_pkey; Type: CONSTRAINT; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE ONLY storage.vector_indexes
    ADD CONSTRAINT vector_indexes_pkey PRIMARY KEY (id);


--
-- Name: hooks hooks_pkey; Type: CONSTRAINT; Schema: supabase_functions; Owner: supabase_functions_admin
--

ALTER TABLE ONLY supabase_functions.hooks
    ADD CONSTRAINT hooks_pkey PRIMARY KEY (id);


--
-- Name: migrations migrations_pkey; Type: CONSTRAINT; Schema: supabase_functions; Owner: supabase_functions_admin
--

ALTER TABLE ONLY supabase_functions.migrations
    ADD CONSTRAINT migrations_pkey PRIMARY KEY (version);


--
-- Name: schema_migrations schema_migrations_pkey; Type: CONSTRAINT; Schema: supabase_migrations; Owner: postgres
--

ALTER TABLE ONLY supabase_migrations.schema_migrations
    ADD CONSTRAINT schema_migrations_pkey PRIMARY KEY (version);


--
-- Name: extensions_tenant_external_id_index; Type: INDEX; Schema: _realtime; Owner: supabase_admin
--

CREATE INDEX extensions_tenant_external_id_index ON _realtime.extensions USING btree (tenant_external_id);


--
-- Name: extensions_tenant_external_id_type_index; Type: INDEX; Schema: _realtime; Owner: supabase_admin
--

CREATE UNIQUE INDEX extensions_tenant_external_id_type_index ON _realtime.extensions USING btree (tenant_external_id, type);


--
-- Name: feature_flags_name_index; Type: INDEX; Schema: _realtime; Owner: supabase_admin
--

CREATE UNIQUE INDEX feature_flags_name_index ON _realtime.feature_flags USING btree (name);


--
-- Name: tenants_external_id_index; Type: INDEX; Schema: _realtime; Owner: supabase_admin
--

CREATE UNIQUE INDEX tenants_external_id_index ON _realtime.tenants USING btree (external_id);


--
-- Name: audit_logs_instance_id_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX audit_logs_instance_id_idx ON auth.audit_log_entries USING btree (instance_id);


--
-- Name: confirmation_token_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE UNIQUE INDEX confirmation_token_idx ON auth.users USING btree (confirmation_token) WHERE ((confirmation_token)::text !~ '^[0-9 ]*$'::text);


--
-- Name: custom_oauth_providers_created_at_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX custom_oauth_providers_created_at_idx ON auth.custom_oauth_providers USING btree (created_at);


--
-- Name: custom_oauth_providers_enabled_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX custom_oauth_providers_enabled_idx ON auth.custom_oauth_providers USING btree (enabled);


--
-- Name: custom_oauth_providers_identifier_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX custom_oauth_providers_identifier_idx ON auth.custom_oauth_providers USING btree (identifier);


--
-- Name: custom_oauth_providers_provider_type_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX custom_oauth_providers_provider_type_idx ON auth.custom_oauth_providers USING btree (provider_type);


--
-- Name: email_change_token_current_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE UNIQUE INDEX email_change_token_current_idx ON auth.users USING btree (email_change_token_current) WHERE ((email_change_token_current)::text !~ '^[0-9 ]*$'::text);


--
-- Name: email_change_token_new_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE UNIQUE INDEX email_change_token_new_idx ON auth.users USING btree (email_change_token_new) WHERE ((email_change_token_new)::text !~ '^[0-9 ]*$'::text);


--
-- Name: factor_id_created_at_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX factor_id_created_at_idx ON auth.mfa_factors USING btree (user_id, created_at);


--
-- Name: flow_state_created_at_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX flow_state_created_at_idx ON auth.flow_state USING btree (created_at DESC);


--
-- Name: identities_email_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX identities_email_idx ON auth.identities USING btree (email text_pattern_ops);


--
-- Name: INDEX identities_email_idx; Type: COMMENT; Schema: auth; Owner: supabase_auth_admin
--

COMMENT ON INDEX auth.identities_email_idx IS 'Auth: Ensures indexed queries on the email column';


--
-- Name: identities_user_id_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX identities_user_id_idx ON auth.identities USING btree (user_id);


--
-- Name: idx_auth_code; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX idx_auth_code ON auth.flow_state USING btree (auth_code);


--
-- Name: idx_oauth_client_states_created_at; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX idx_oauth_client_states_created_at ON auth.oauth_client_states USING btree (created_at);


--
-- Name: idx_user_id_auth_method; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX idx_user_id_auth_method ON auth.flow_state USING btree (user_id, authentication_method);


--
-- Name: mfa_challenge_created_at_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX mfa_challenge_created_at_idx ON auth.mfa_challenges USING btree (created_at DESC);


--
-- Name: mfa_factors_user_friendly_name_unique; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE UNIQUE INDEX mfa_factors_user_friendly_name_unique ON auth.mfa_factors USING btree (friendly_name, user_id) WHERE (TRIM(BOTH FROM friendly_name) <> ''::text);


--
-- Name: mfa_factors_user_id_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX mfa_factors_user_id_idx ON auth.mfa_factors USING btree (user_id);


--
-- Name: oauth_auth_pending_exp_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX oauth_auth_pending_exp_idx ON auth.oauth_authorizations USING btree (expires_at) WHERE (status = 'pending'::auth.oauth_authorization_status);


--
-- Name: oauth_clients_deleted_at_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX oauth_clients_deleted_at_idx ON auth.oauth_clients USING btree (deleted_at);


--
-- Name: oauth_consents_active_client_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX oauth_consents_active_client_idx ON auth.oauth_consents USING btree (client_id) WHERE (revoked_at IS NULL);


--
-- Name: oauth_consents_active_user_client_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX oauth_consents_active_user_client_idx ON auth.oauth_consents USING btree (user_id, client_id) WHERE (revoked_at IS NULL);


--
-- Name: oauth_consents_user_order_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX oauth_consents_user_order_idx ON auth.oauth_consents USING btree (user_id, granted_at DESC);


--
-- Name: one_time_tokens_relates_to_hash_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX one_time_tokens_relates_to_hash_idx ON auth.one_time_tokens USING hash (relates_to);


--
-- Name: one_time_tokens_token_hash_hash_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX one_time_tokens_token_hash_hash_idx ON auth.one_time_tokens USING hash (token_hash);


--
-- Name: one_time_tokens_user_id_token_type_key; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE UNIQUE INDEX one_time_tokens_user_id_token_type_key ON auth.one_time_tokens USING btree (user_id, token_type);


--
-- Name: reauthentication_token_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE UNIQUE INDEX reauthentication_token_idx ON auth.users USING btree (reauthentication_token) WHERE ((reauthentication_token)::text !~ '^[0-9 ]*$'::text);


--
-- Name: recovery_token_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE UNIQUE INDEX recovery_token_idx ON auth.users USING btree (recovery_token) WHERE ((recovery_token)::text !~ '^[0-9 ]*$'::text);


--
-- Name: refresh_tokens_instance_id_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX refresh_tokens_instance_id_idx ON auth.refresh_tokens USING btree (instance_id);


--
-- Name: refresh_tokens_instance_id_user_id_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX refresh_tokens_instance_id_user_id_idx ON auth.refresh_tokens USING btree (instance_id, user_id);


--
-- Name: refresh_tokens_parent_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX refresh_tokens_parent_idx ON auth.refresh_tokens USING btree (parent);


--
-- Name: refresh_tokens_session_id_revoked_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX refresh_tokens_session_id_revoked_idx ON auth.refresh_tokens USING btree (session_id, revoked);


--
-- Name: refresh_tokens_updated_at_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX refresh_tokens_updated_at_idx ON auth.refresh_tokens USING btree (updated_at DESC);


--
-- Name: saml_providers_sso_provider_id_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX saml_providers_sso_provider_id_idx ON auth.saml_providers USING btree (sso_provider_id);


--
-- Name: saml_relay_states_created_at_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX saml_relay_states_created_at_idx ON auth.saml_relay_states USING btree (created_at DESC);


--
-- Name: saml_relay_states_for_email_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX saml_relay_states_for_email_idx ON auth.saml_relay_states USING btree (for_email);


--
-- Name: saml_relay_states_sso_provider_id_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX saml_relay_states_sso_provider_id_idx ON auth.saml_relay_states USING btree (sso_provider_id);


--
-- Name: sessions_not_after_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX sessions_not_after_idx ON auth.sessions USING btree (not_after DESC);


--
-- Name: sessions_oauth_client_id_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX sessions_oauth_client_id_idx ON auth.sessions USING btree (oauth_client_id);


--
-- Name: sessions_user_id_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX sessions_user_id_idx ON auth.sessions USING btree (user_id);


--
-- Name: sso_domains_domain_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE UNIQUE INDEX sso_domains_domain_idx ON auth.sso_domains USING btree (lower(domain));


--
-- Name: sso_domains_sso_provider_id_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX sso_domains_sso_provider_id_idx ON auth.sso_domains USING btree (sso_provider_id);


--
-- Name: sso_providers_resource_id_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE UNIQUE INDEX sso_providers_resource_id_idx ON auth.sso_providers USING btree (lower(resource_id));


--
-- Name: sso_providers_resource_id_pattern_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX sso_providers_resource_id_pattern_idx ON auth.sso_providers USING btree (resource_id text_pattern_ops);


--
-- Name: unique_phone_factor_per_user; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE UNIQUE INDEX unique_phone_factor_per_user ON auth.mfa_factors USING btree (user_id, phone);


--
-- Name: user_id_created_at_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX user_id_created_at_idx ON auth.sessions USING btree (user_id, created_at);


--
-- Name: users_email_partial_key; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE UNIQUE INDEX users_email_partial_key ON auth.users USING btree (email) WHERE (is_sso_user = false);


--
-- Name: INDEX users_email_partial_key; Type: COMMENT; Schema: auth; Owner: supabase_auth_admin
--

COMMENT ON INDEX auth.users_email_partial_key IS 'Auth: A partial unique index that applies only when is_sso_user is false';


--
-- Name: users_instance_id_email_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX users_instance_id_email_idx ON auth.users USING btree (instance_id, lower((email)::text));


--
-- Name: users_instance_id_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX users_instance_id_idx ON auth.users USING btree (instance_id);


--
-- Name: users_is_anonymous_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX users_is_anonymous_idx ON auth.users USING btree (is_anonymous);


--
-- Name: webauthn_challenges_expires_at_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX webauthn_challenges_expires_at_idx ON auth.webauthn_challenges USING btree (expires_at);


--
-- Name: webauthn_challenges_user_id_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX webauthn_challenges_user_id_idx ON auth.webauthn_challenges USING btree (user_id);


--
-- Name: webauthn_credentials_credential_id_key; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE UNIQUE INDEX webauthn_credentials_credential_id_key ON auth.webauthn_credentials USING btree (credential_id);


--
-- Name: webauthn_credentials_user_id_idx; Type: INDEX; Schema: auth; Owner: supabase_auth_admin
--

CREATE INDEX webauthn_credentials_user_id_idx ON auth.webauthn_credentials USING btree (user_id);


--
-- Name: idx_aman_instances_branch; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_aman_instances_branch ON public.aman_instances USING btree (branch_id);


--
-- Name: idx_aman_instances_org; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_aman_instances_org ON public.aman_instances USING btree (organization_id);


--
-- Name: idx_cameras_branch_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_cameras_branch_id ON public.cameras USING btree (branch_id);


--
-- Name: idx_chat_messages_thread_created; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_chat_messages_thread_created ON public.chat_messages USING btree (thread_id, created_at);


--
-- Name: idx_chat_participants_thread; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_chat_participants_thread ON public.chat_thread_participants USING btree (thread_id);


--
-- Name: idx_chat_participants_user; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_chat_participants_user ON public.chat_thread_participants USING btree (user_id);


--
-- Name: idx_chat_threads_org; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_chat_threads_org ON public.chat_threads USING btree (organization_id);


--
-- Name: idx_chatbot_knowledge_active; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_chatbot_knowledge_active ON public.chatbot_knowledge_base USING btree (is_active);


--
-- Name: idx_chatbot_knowledge_language_type; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_chatbot_knowledge_language_type ON public.chatbot_knowledge_base USING btree (language, content_type);


--
-- Name: idx_event_types_feature_key; Type: INDEX; Schema: public; Owner: postgres
--

CREATE UNIQUE INDEX idx_event_types_feature_key ON public.event_types USING btree (feature_key) WHERE (feature_key IS NOT NULL);


--
-- Name: idx_events_camera_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_events_camera_id ON public.events USING btree (camera_id);


--
-- Name: idx_events_detected_at; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_events_detected_at ON public.events USING btree (detected_at);


--
-- Name: idx_events_face_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_events_face_id ON public.events USING btree (face_id) WHERE (face_id IS NOT NULL);


--
-- Name: idx_events_frigate_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_events_frigate_id ON public.events USING btree (frigate_id) WHERE (frigate_id IS NOT NULL);


--
-- Name: idx_events_license_plate; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_events_license_plate ON public.events USING btree (license_plate) WHERE (license_plate IS NOT NULL);


--
-- Name: idx_frigate_deployed_models_category; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_frigate_deployed_models_category ON public.frigate_deployed_models USING btree (category);


--
-- Name: idx_frigate_deployed_models_instance; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_frigate_deployed_models_instance ON public.frigate_deployed_models USING btree (frigate_instance_id);


--
-- Name: idx_frigate_deployed_models_status; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_frigate_deployed_models_status ON public.frigate_deployed_models USING btree (status);


--
-- Name: idx_frigate_exports_instance_camera; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_frigate_exports_instance_camera ON public.frigate_exports USING btree (frigate_instance_id, camera);


--
-- Name: idx_frigate_exports_status; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_frigate_exports_status ON public.frigate_exports USING btree (status);


--
-- Name: idx_frigate_faces_camera_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_frigate_faces_camera_id ON public.frigate_faces USING btree (camera_id);


--
-- Name: idx_frigate_faces_label; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_frigate_faces_label ON public.frigate_faces USING btree (label);


--
-- Name: idx_frigate_license_plates_camera_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_frigate_license_plates_camera_id ON public.frigate_license_plates USING btree (camera_id);


--
-- Name: idx_frigate_license_plates_instance; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_frigate_license_plates_instance ON public.frigate_license_plates USING btree (frigate_instance_id) WHERE (frigate_instance_id IS NOT NULL);


--
-- Name: idx_frigate_license_plates_plate_number; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_frigate_license_plates_plate_number ON public.frigate_license_plates USING btree (plate_number);


--
-- Name: idx_frigate_license_plates_watch; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_frigate_license_plates_watch ON public.frigate_license_plates USING btree (is_watchlisted) WHERE (is_watchlisted = true);


--
-- Name: idx_frigate_previews_instance_camera; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_frigate_previews_instance_camera ON public.frigate_previews USING btree (frigate_instance_id, camera);


--
-- Name: idx_frigate_previews_time; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_frigate_previews_time ON public.frigate_previews USING btree (start_time, end_time);


--
-- Name: idx_frigate_recordings_instance_camera; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_frigate_recordings_instance_camera ON public.frigate_recordings USING btree (frigate_instance_id, camera);


--
-- Name: idx_frigate_recordings_time; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_frigate_recordings_time ON public.frigate_recordings USING btree (start_time, end_time);


--
-- Name: idx_frigate_reviews_instance_camera; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_frigate_reviews_instance_camera ON public.frigate_reviews USING btree (frigate_instance_id, camera);


--
-- Name: idx_frigate_reviews_reviewed; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_frigate_reviews_reviewed ON public.frigate_reviews USING btree (has_been_reviewed);


--
-- Name: idx_frigate_reviews_reviewed_new; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_frigate_reviews_reviewed_new ON public.frigate_reviews USING btree (reviewed);


--
-- Name: idx_frigate_reviews_severity; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_frigate_reviews_severity ON public.frigate_reviews USING btree (severity);


--
-- Name: idx_frigate_stats_history_instance; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_frigate_stats_history_instance ON public.frigate_stats_history USING btree (frigate_instance_id);


--
-- Name: idx_frigate_stats_history_recorded; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_frigate_stats_history_recorded ON public.frigate_stats_history USING btree (recorded_at DESC);


--
-- Name: idx_frigate_sync_logs_instance; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_frigate_sync_logs_instance ON public.frigate_sync_logs USING btree (frigate_instance_id);


--
-- Name: idx_frigate_sync_logs_started; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_frigate_sync_logs_started ON public.frigate_sync_logs USING btree (started_at DESC);


--
-- Name: idx_frigate_timeline_camera_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_frigate_timeline_camera_id ON public.frigate_timeline USING btree (camera_id);


--
-- Name: idx_frigate_timeline_time; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_frigate_timeline_time ON public.frigate_timeline USING btree (start_time, end_time);


--
-- Name: idx_frigate_triggers_instance; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_frigate_triggers_instance ON public.frigate_triggers USING btree (frigate_instance_id);


--
-- Name: idx_frigate_zones_camera_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_frigate_zones_camera_id ON public.frigate_zones USING btree (camera_id);


--
-- Name: idx_health_alerts_student; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_health_alerts_student ON public.health_alerts USING btree (student_id);


--
-- Name: idx_health_alerts_time; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_health_alerts_time ON public.health_alerts USING btree (detected_at DESC);


--
-- Name: idx_model_deployments_instance; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_model_deployments_instance ON public.frigate_model_deployments USING btree (frigate_instance_id);


--
-- Name: idx_model_deployments_model; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_model_deployments_model ON public.frigate_model_deployments USING btree (model_id);


--
-- Name: idx_model_deployments_status; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_model_deployments_status ON public.frigate_model_deployments USING btree (deployment_status);


--
-- Name: idx_model_registry_category; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_model_registry_category ON public.frigate_model_registry USING btree (category);


--
-- Name: idx_model_registry_status; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_model_registry_status ON public.frigate_model_registry USING btree (status);


--
-- Name: idx_org_settings_org_key; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_org_settings_org_key ON public.organization_settings USING btree (organization_id, setting_key);


--
-- Name: idx_pinned_dashboards_user_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_pinned_dashboards_user_id ON public.pinned_dashboards USING btree (user_id);


--
-- Name: idx_pinned_labels_user_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_pinned_labels_user_id ON public.pinned_labels USING btree (user_id);


--
-- Name: idx_security_zones_active; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_security_zones_active ON public.security_zones USING btree (active);


--
-- Name: idx_sync_log_instance; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_sync_log_instance ON public.frigate_model_sync_log USING btree (frigate_instance_id);


--
-- Name: idx_sync_log_started; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_sync_log_started ON public.frigate_model_sync_log USING btree (started_at DESC);


--
-- Name: idx_system_settings_key; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_system_settings_key ON public.system_settings USING btree (setting_key);


--
-- Name: ix_realtime_subscription_entity; Type: INDEX; Schema: realtime; Owner: supabase_admin
--

CREATE INDEX ix_realtime_subscription_entity ON realtime.subscription USING btree (entity);


--
-- Name: messages_inserted_at_topic_index; Type: INDEX; Schema: realtime; Owner: supabase_realtime_admin
--

CREATE INDEX messages_inserted_at_topic_index ON ONLY realtime.messages USING btree (inserted_at DESC, topic) WHERE ((extension = 'broadcast'::text) AND (private IS TRUE));


--
-- Name: messages_2026_07_02_inserted_at_topic_idx; Type: INDEX; Schema: realtime; Owner: supabase_admin
--

CREATE INDEX messages_2026_07_02_inserted_at_topic_idx ON realtime.messages_2026_07_02 USING btree (inserted_at DESC, topic) WHERE ((extension = 'broadcast'::text) AND (private IS TRUE));


--
-- Name: messages_2026_07_03_inserted_at_topic_idx; Type: INDEX; Schema: realtime; Owner: supabase_admin
--

CREATE INDEX messages_2026_07_03_inserted_at_topic_idx ON realtime.messages_2026_07_03 USING btree (inserted_at DESC, topic) WHERE ((extension = 'broadcast'::text) AND (private IS TRUE));


--
-- Name: messages_2026_07_04_inserted_at_topic_idx; Type: INDEX; Schema: realtime; Owner: supabase_admin
--

CREATE INDEX messages_2026_07_04_inserted_at_topic_idx ON realtime.messages_2026_07_04 USING btree (inserted_at DESC, topic) WHERE ((extension = 'broadcast'::text) AND (private IS TRUE));


--
-- Name: messages_2026_07_05_inserted_at_topic_idx; Type: INDEX; Schema: realtime; Owner: supabase_admin
--

CREATE INDEX messages_2026_07_05_inserted_at_topic_idx ON realtime.messages_2026_07_05 USING btree (inserted_at DESC, topic) WHERE ((extension = 'broadcast'::text) AND (private IS TRUE));


--
-- Name: messages_2026_07_06_inserted_at_topic_idx; Type: INDEX; Schema: realtime; Owner: supabase_admin
--

CREATE INDEX messages_2026_07_06_inserted_at_topic_idx ON realtime.messages_2026_07_06 USING btree (inserted_at DESC, topic) WHERE ((extension = 'broadcast'::text) AND (private IS TRUE));


--
-- Name: messages_2026_07_07_inserted_at_topic_idx; Type: INDEX; Schema: realtime; Owner: supabase_admin
--

CREATE INDEX messages_2026_07_07_inserted_at_topic_idx ON realtime.messages_2026_07_07 USING btree (inserted_at DESC, topic) WHERE ((extension = 'broadcast'::text) AND (private IS TRUE));


--
-- Name: messages_2026_07_08_inserted_at_topic_idx; Type: INDEX; Schema: realtime; Owner: supabase_admin
--

CREATE INDEX messages_2026_07_08_inserted_at_topic_idx ON realtime.messages_2026_07_08 USING btree (inserted_at DESC, topic) WHERE ((extension = 'broadcast'::text) AND (private IS TRUE));


--
-- Name: subscription_subscription_id_entity_filters_action_filter_selec; Type: INDEX; Schema: realtime; Owner: supabase_admin
--

CREATE UNIQUE INDEX subscription_subscription_id_entity_filters_action_filter_selec ON realtime.subscription USING btree (subscription_id, entity, filters, action_filter, COALESCE(selected_columns, '{}'::text[]));


--
-- Name: bname; Type: INDEX; Schema: storage; Owner: supabase_storage_admin
--

CREATE UNIQUE INDEX bname ON storage.buckets USING btree (name);


--
-- Name: bucketid_objname; Type: INDEX; Schema: storage; Owner: supabase_storage_admin
--

CREATE UNIQUE INDEX bucketid_objname ON storage.objects USING btree (bucket_id, name);


--
-- Name: buckets_analytics_unique_name_idx; Type: INDEX; Schema: storage; Owner: supabase_storage_admin
--

CREATE UNIQUE INDEX buckets_analytics_unique_name_idx ON storage.buckets_analytics USING btree (name) WHERE (deleted_at IS NULL);


--
-- Name: idx_iceberg_namespaces_bucket_id; Type: INDEX; Schema: storage; Owner: supabase_storage_admin
--

CREATE UNIQUE INDEX idx_iceberg_namespaces_bucket_id ON storage.iceberg_namespaces USING btree (catalog_id, name);


--
-- Name: idx_iceberg_tables_location; Type: INDEX; Schema: storage; Owner: supabase_storage_admin
--

CREATE UNIQUE INDEX idx_iceberg_tables_location ON storage.iceberg_tables USING btree (location);


--
-- Name: idx_iceberg_tables_namespace_id; Type: INDEX; Schema: storage; Owner: supabase_storage_admin
--

CREATE UNIQUE INDEX idx_iceberg_tables_namespace_id ON storage.iceberg_tables USING btree (catalog_id, namespace_id, name);


--
-- Name: idx_multipart_uploads_list; Type: INDEX; Schema: storage; Owner: supabase_storage_admin
--

CREATE INDEX idx_multipart_uploads_list ON storage.s3_multipart_uploads USING btree (bucket_id, key, created_at);


--
-- Name: idx_objects_bucket_id_name; Type: INDEX; Schema: storage; Owner: supabase_storage_admin
--

CREATE INDEX idx_objects_bucket_id_name ON storage.objects USING btree (bucket_id, name COLLATE "C");


--
-- Name: idx_objects_bucket_id_name_lower; Type: INDEX; Schema: storage; Owner: supabase_storage_admin
--

CREATE INDEX idx_objects_bucket_id_name_lower ON storage.objects USING btree (bucket_id, lower(name) COLLATE "C");


--
-- Name: name_prefix_search; Type: INDEX; Schema: storage; Owner: supabase_storage_admin
--

CREATE INDEX name_prefix_search ON storage.objects USING btree (name text_pattern_ops);


--
-- Name: vector_indexes_name_bucket_id_idx; Type: INDEX; Schema: storage; Owner: supabase_storage_admin
--

CREATE UNIQUE INDEX vector_indexes_name_bucket_id_idx ON storage.vector_indexes USING btree (name, bucket_id);


--
-- Name: supabase_functions_hooks_h_table_id_h_name_idx; Type: INDEX; Schema: supabase_functions; Owner: supabase_functions_admin
--

CREATE INDEX supabase_functions_hooks_h_table_id_h_name_idx ON supabase_functions.hooks USING btree (hook_table_id, hook_name);


--
-- Name: supabase_functions_hooks_request_id_idx; Type: INDEX; Schema: supabase_functions; Owner: supabase_functions_admin
--

CREATE INDEX supabase_functions_hooks_request_id_idx ON supabase_functions.hooks USING btree (request_id);


--
-- Name: messages_2026_07_02_inserted_at_topic_idx; Type: INDEX ATTACH; Schema: realtime; Owner: supabase_realtime_admin
--

ALTER INDEX realtime.messages_inserted_at_topic_index ATTACH PARTITION realtime.messages_2026_07_02_inserted_at_topic_idx;


--
-- Name: messages_2026_07_02_pkey; Type: INDEX ATTACH; Schema: realtime; Owner: supabase_realtime_admin
--

ALTER INDEX realtime.messages_pkey ATTACH PARTITION realtime.messages_2026_07_02_pkey;


--
-- Name: messages_2026_07_03_inserted_at_topic_idx; Type: INDEX ATTACH; Schema: realtime; Owner: supabase_realtime_admin
--

ALTER INDEX realtime.messages_inserted_at_topic_index ATTACH PARTITION realtime.messages_2026_07_03_inserted_at_topic_idx;


--
-- Name: messages_2026_07_03_pkey; Type: INDEX ATTACH; Schema: realtime; Owner: supabase_realtime_admin
--

ALTER INDEX realtime.messages_pkey ATTACH PARTITION realtime.messages_2026_07_03_pkey;


--
-- Name: messages_2026_07_04_inserted_at_topic_idx; Type: INDEX ATTACH; Schema: realtime; Owner: supabase_realtime_admin
--

ALTER INDEX realtime.messages_inserted_at_topic_index ATTACH PARTITION realtime.messages_2026_07_04_inserted_at_topic_idx;


--
-- Name: messages_2026_07_04_pkey; Type: INDEX ATTACH; Schema: realtime; Owner: supabase_realtime_admin
--

ALTER INDEX realtime.messages_pkey ATTACH PARTITION realtime.messages_2026_07_04_pkey;


--
-- Name: messages_2026_07_05_inserted_at_topic_idx; Type: INDEX ATTACH; Schema: realtime; Owner: supabase_realtime_admin
--

ALTER INDEX realtime.messages_inserted_at_topic_index ATTACH PARTITION realtime.messages_2026_07_05_inserted_at_topic_idx;


--
-- Name: messages_2026_07_05_pkey; Type: INDEX ATTACH; Schema: realtime; Owner: supabase_realtime_admin
--

ALTER INDEX realtime.messages_pkey ATTACH PARTITION realtime.messages_2026_07_05_pkey;


--
-- Name: messages_2026_07_06_inserted_at_topic_idx; Type: INDEX ATTACH; Schema: realtime; Owner: supabase_realtime_admin
--

ALTER INDEX realtime.messages_inserted_at_topic_index ATTACH PARTITION realtime.messages_2026_07_06_inserted_at_topic_idx;


--
-- Name: messages_2026_07_06_pkey; Type: INDEX ATTACH; Schema: realtime; Owner: supabase_realtime_admin
--

ALTER INDEX realtime.messages_pkey ATTACH PARTITION realtime.messages_2026_07_06_pkey;


--
-- Name: messages_2026_07_07_inserted_at_topic_idx; Type: INDEX ATTACH; Schema: realtime; Owner: supabase_realtime_admin
--

ALTER INDEX realtime.messages_inserted_at_topic_index ATTACH PARTITION realtime.messages_2026_07_07_inserted_at_topic_idx;


--
-- Name: messages_2026_07_07_pkey; Type: INDEX ATTACH; Schema: realtime; Owner: supabase_realtime_admin
--

ALTER INDEX realtime.messages_pkey ATTACH PARTITION realtime.messages_2026_07_07_pkey;


--
-- Name: messages_2026_07_08_inserted_at_topic_idx; Type: INDEX ATTACH; Schema: realtime; Owner: supabase_realtime_admin
--

ALTER INDEX realtime.messages_inserted_at_topic_index ATTACH PARTITION realtime.messages_2026_07_08_inserted_at_topic_idx;


--
-- Name: messages_2026_07_08_pkey; Type: INDEX ATTACH; Schema: realtime; Owner: supabase_realtime_admin
--

ALTER INDEX realtime.messages_pkey ATTACH PARTITION realtime.messages_2026_07_08_pkey;


--
-- Name: users on_auth_user_created; Type: TRIGGER; Schema: auth; Owner: supabase_auth_admin
--

CREATE TRIGGER on_auth_user_created AFTER INSERT ON auth.users FOR EACH ROW EXECUTE FUNCTION public.handle_new_user();


--
-- Name: sessions update_subscriber_activity_trigger; Type: TRIGGER; Schema: auth; Owner: supabase_auth_admin
--

CREATE TRIGGER update_subscriber_activity_trigger AFTER INSERT OR UPDATE ON auth.sessions FOR EACH ROW EXECUTE FUNCTION public.update_subscriber_activity();


--
-- Name: screen_permissions handle_screen_permissions_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER handle_screen_permissions_updated_at BEFORE UPDATE ON public.screen_permissions FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: frigate_alert_rules set_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER set_updated_at BEFORE UPDATE ON public.frigate_alert_rules FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: frigate_faces set_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER set_updated_at BEFORE UPDATE ON public.frigate_faces FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: frigate_license_plates set_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER set_updated_at BEFORE UPDATE ON public.frigate_license_plates FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: frigate_zones set_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER set_updated_at BEFORE UPDATE ON public.frigate_zones FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: chat_threads set_updated_at_chat_threads; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER set_updated_at_chat_threads BEFORE UPDATE ON public.chat_threads FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: chat_messages touch_thread_on_message_insert; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER touch_thread_on_message_insert AFTER INSERT ON public.chat_messages FOR EACH ROW EXECUTE FUNCTION public.touch_chat_thread();


--
-- Name: chat_threads trg_chat_threads_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER trg_chat_threads_updated_at BEFORE UPDATE ON public.chat_threads FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: frigate_model_deployments trg_deployments_updated; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER trg_deployments_updated BEFORE UPDATE ON public.frigate_model_deployments FOR EACH ROW EXECUTE FUNCTION public.trg_touch_updated_at();


--
-- Name: pinned_labels trg_pinned_labels_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER trg_pinned_labels_updated_at BEFORE UPDATE ON public.pinned_labels FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: frigate_model_registry trg_registry_updated; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER trg_registry_updated BEFORE UPDATE ON public.frigate_model_registry FOR EACH ROW EXECUTE FUNCTION public.trg_touch_updated_at();


--
-- Name: events trg_restrict_events_update; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER trg_restrict_events_update BEFORE UPDATE ON public.events FOR EACH ROW EXECUTE FUNCTION public.restrict_events_update();


--
-- Name: chat_messages trg_touch_thread_after_message_insert; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER trg_touch_thread_after_message_insert AFTER INSERT ON public.chat_messages FOR EACH ROW EXECUTE FUNCTION public.touch_chat_thread();


--
-- Name: camera_event_assignments trg_veedon_bump_assignments; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER trg_veedon_bump_assignments AFTER INSERT OR DELETE OR UPDATE ON public.camera_event_assignments FOR EACH ROW EXECUTE FUNCTION public.veedon_bump_branch_config();


--
-- Name: cameras trg_veedon_bump_cameras; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER trg_veedon_bump_cameras AFTER INSERT OR DELETE OR UPDATE ON public.cameras FOR EACH ROW EXECUTE FUNCTION public.veedon_bump_branch_config();


--
-- Name: alert_templates update_alert_templates_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER update_alert_templates_updated_at BEFORE UPDATE ON public.alert_templates FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: aman_instances update_aman_instances_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER update_aman_instances_updated_at BEFORE UPDATE ON public.aman_instances FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: auto_sync_settings update_auto_sync_settings_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER update_auto_sync_settings_updated_at BEFORE UPDATE ON public.auto_sync_settings FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: camera_sources update_camera_sources_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER update_camera_sources_updated_at BEFORE UPDATE ON public.camera_sources FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: cameras update_cameras_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER update_cameras_updated_at BEFORE UPDATE ON public.cameras FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: chatbot_knowledge_base update_chatbot_knowledge_base_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER update_chatbot_knowledge_base_updated_at BEFORE UPDATE ON public.chatbot_knowledge_base FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: event_types update_event_types_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER update_event_types_updated_at BEFORE UPDATE ON public.event_types FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: form_assignments update_form_assignments_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER update_form_assignments_updated_at BEFORE UPDATE ON public.form_assignments FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: form_distribution_settings update_form_distribution_settings_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER update_form_distribution_settings_updated_at BEFORE UPDATE ON public.form_distribution_settings FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: frigate_exports update_frigate_exports_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER update_frigate_exports_updated_at BEFORE UPDATE ON public.frigate_exports FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: frigate_instances update_frigate_instances_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER update_frigate_instances_updated_at BEFORE UPDATE ON public.frigate_instances FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: frigate_previews update_frigate_previews_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER update_frigate_previews_updated_at BEFORE UPDATE ON public.frigate_previews FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: frigate_recordings update_frigate_recordings_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER update_frigate_recordings_updated_at BEFORE UPDATE ON public.frigate_recordings FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: frigate_reviews update_frigate_reviews_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER update_frigate_reviews_updated_at BEFORE UPDATE ON public.frigate_reviews FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: industries update_industries_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER update_industries_updated_at BEFORE UPDATE ON public.industries FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: legal_documents update_legal_documents_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER update_legal_documents_updated_at BEFORE UPDATE ON public.legal_documents FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: notification_labels update_notification_labels_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER update_notification_labels_updated_at BEFORE UPDATE ON public.notification_labels FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: notification_methods update_notification_methods_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER update_notification_methods_updated_at BEFORE UPDATE ON public.notification_methods FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: organization_settings update_organization_settings_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER update_organization_settings_updated_at BEFORE UPDATE ON public.organization_settings FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: organizations update_organizations_modtime; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER update_organizations_modtime BEFORE UPDATE ON public.organizations FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: pinned_dashboards update_pinned_dashboards_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER update_pinned_dashboards_updated_at BEFORE UPDATE ON public.pinned_dashboards FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: security_zones update_security_zones_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER update_security_zones_updated_at BEFORE UPDATE ON public.security_zones FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: storage_configs update_storage_configs_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER update_storage_configs_updated_at BEFORE UPDATE ON public.storage_configs FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: subscribers update_subscribers_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER update_subscribers_updated_at BEFORE UPDATE ON public.subscribers FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: system_settings update_system_settings_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER update_system_settings_updated_at BEFORE UPDATE ON public.system_settings FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: user_groups update_user_groups_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER update_user_groups_updated_at BEFORE UPDATE ON public.user_groups FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: user_preferences update_user_preferences_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER update_user_preferences_updated_at BEFORE UPDATE ON public.user_preferences FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: workflow_forms update_workflow_forms_updated_at; Type: TRIGGER; Schema: public; Owner: postgres
--

CREATE TRIGGER update_workflow_forms_updated_at BEFORE UPDATE ON public.workflow_forms FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();


--
-- Name: subscription tr_check_filters; Type: TRIGGER; Schema: realtime; Owner: supabase_admin
--

CREATE TRIGGER tr_check_filters BEFORE INSERT OR UPDATE ON realtime.subscription FOR EACH ROW EXECUTE FUNCTION realtime.subscription_check_filters();


--
-- Name: buckets enforce_bucket_name_length_trigger; Type: TRIGGER; Schema: storage; Owner: supabase_storage_admin
--

CREATE TRIGGER enforce_bucket_name_length_trigger BEFORE INSERT OR UPDATE OF name ON storage.buckets FOR EACH ROW EXECUTE FUNCTION storage.enforce_bucket_name_length();


--
-- Name: buckets protect_buckets_delete; Type: TRIGGER; Schema: storage; Owner: supabase_storage_admin
--

CREATE TRIGGER protect_buckets_delete BEFORE DELETE ON storage.buckets FOR EACH STATEMENT EXECUTE FUNCTION storage.protect_delete();


--
-- Name: objects protect_objects_delete; Type: TRIGGER; Schema: storage; Owner: supabase_storage_admin
--

CREATE TRIGGER protect_objects_delete BEFORE DELETE ON storage.objects FOR EACH STATEMENT EXECUTE FUNCTION storage.protect_delete();


--
-- Name: objects update_objects_updated_at; Type: TRIGGER; Schema: storage; Owner: supabase_storage_admin
--

CREATE TRIGGER update_objects_updated_at BEFORE UPDATE ON storage.objects FOR EACH ROW EXECUTE FUNCTION storage.update_updated_at_column();


--
-- Name: extensions extensions_tenant_external_id_fkey; Type: FK CONSTRAINT; Schema: _realtime; Owner: supabase_admin
--

ALTER TABLE ONLY _realtime.extensions
    ADD CONSTRAINT extensions_tenant_external_id_fkey FOREIGN KEY (tenant_external_id) REFERENCES _realtime.tenants(external_id) ON DELETE CASCADE;


--
-- Name: identities identities_user_id_fkey; Type: FK CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.identities
    ADD CONSTRAINT identities_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth.users(id) ON DELETE CASCADE;


--
-- Name: mfa_amr_claims mfa_amr_claims_session_id_fkey; Type: FK CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.mfa_amr_claims
    ADD CONSTRAINT mfa_amr_claims_session_id_fkey FOREIGN KEY (session_id) REFERENCES auth.sessions(id) ON DELETE CASCADE;


--
-- Name: mfa_challenges mfa_challenges_auth_factor_id_fkey; Type: FK CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.mfa_challenges
    ADD CONSTRAINT mfa_challenges_auth_factor_id_fkey FOREIGN KEY (factor_id) REFERENCES auth.mfa_factors(id) ON DELETE CASCADE;


--
-- Name: mfa_factors mfa_factors_user_id_fkey; Type: FK CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.mfa_factors
    ADD CONSTRAINT mfa_factors_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth.users(id) ON DELETE CASCADE;


--
-- Name: oauth_authorizations oauth_authorizations_client_id_fkey; Type: FK CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.oauth_authorizations
    ADD CONSTRAINT oauth_authorizations_client_id_fkey FOREIGN KEY (client_id) REFERENCES auth.oauth_clients(id) ON DELETE CASCADE;


--
-- Name: oauth_authorizations oauth_authorizations_user_id_fkey; Type: FK CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.oauth_authorizations
    ADD CONSTRAINT oauth_authorizations_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth.users(id) ON DELETE CASCADE;


--
-- Name: oauth_consents oauth_consents_client_id_fkey; Type: FK CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.oauth_consents
    ADD CONSTRAINT oauth_consents_client_id_fkey FOREIGN KEY (client_id) REFERENCES auth.oauth_clients(id) ON DELETE CASCADE;


--
-- Name: oauth_consents oauth_consents_user_id_fkey; Type: FK CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.oauth_consents
    ADD CONSTRAINT oauth_consents_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth.users(id) ON DELETE CASCADE;


--
-- Name: one_time_tokens one_time_tokens_user_id_fkey; Type: FK CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.one_time_tokens
    ADD CONSTRAINT one_time_tokens_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth.users(id) ON DELETE CASCADE;


--
-- Name: refresh_tokens refresh_tokens_session_id_fkey; Type: FK CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.refresh_tokens
    ADD CONSTRAINT refresh_tokens_session_id_fkey FOREIGN KEY (session_id) REFERENCES auth.sessions(id) ON DELETE CASCADE;


--
-- Name: saml_providers saml_providers_sso_provider_id_fkey; Type: FK CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.saml_providers
    ADD CONSTRAINT saml_providers_sso_provider_id_fkey FOREIGN KEY (sso_provider_id) REFERENCES auth.sso_providers(id) ON DELETE CASCADE;


--
-- Name: saml_relay_states saml_relay_states_flow_state_id_fkey; Type: FK CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.saml_relay_states
    ADD CONSTRAINT saml_relay_states_flow_state_id_fkey FOREIGN KEY (flow_state_id) REFERENCES auth.flow_state(id) ON DELETE CASCADE;


--
-- Name: saml_relay_states saml_relay_states_sso_provider_id_fkey; Type: FK CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.saml_relay_states
    ADD CONSTRAINT saml_relay_states_sso_provider_id_fkey FOREIGN KEY (sso_provider_id) REFERENCES auth.sso_providers(id) ON DELETE CASCADE;


--
-- Name: sessions sessions_oauth_client_id_fkey; Type: FK CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.sessions
    ADD CONSTRAINT sessions_oauth_client_id_fkey FOREIGN KEY (oauth_client_id) REFERENCES auth.oauth_clients(id) ON DELETE CASCADE;


--
-- Name: sessions sessions_user_id_fkey; Type: FK CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.sessions
    ADD CONSTRAINT sessions_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth.users(id) ON DELETE CASCADE;


--
-- Name: sso_domains sso_domains_sso_provider_id_fkey; Type: FK CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.sso_domains
    ADD CONSTRAINT sso_domains_sso_provider_id_fkey FOREIGN KEY (sso_provider_id) REFERENCES auth.sso_providers(id) ON DELETE CASCADE;


--
-- Name: webauthn_challenges webauthn_challenges_user_id_fkey; Type: FK CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.webauthn_challenges
    ADD CONSTRAINT webauthn_challenges_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth.users(id) ON DELETE CASCADE;


--
-- Name: webauthn_credentials webauthn_credentials_user_id_fkey; Type: FK CONSTRAINT; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE ONLY auth.webauthn_credentials
    ADD CONSTRAINT webauthn_credentials_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth.users(id) ON DELETE CASCADE;


--
-- Name: ai_analysis_logs ai_analysis_logs_alert_template_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.ai_analysis_logs
    ADD CONSTRAINT ai_analysis_logs_alert_template_id_fkey FOREIGN KEY (alert_template_id) REFERENCES public.alert_templates(id) ON DELETE SET NULL;


--
-- Name: ai_analysis_logs ai_analysis_logs_camera_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.ai_analysis_logs
    ADD CONSTRAINT ai_analysis_logs_camera_id_fkey FOREIGN KEY (camera_id) REFERENCES public.cameras(id) ON DELETE CASCADE;


--
-- Name: alert_template_events alert_template_events_alert_template_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.alert_template_events
    ADD CONSTRAINT alert_template_events_alert_template_id_fkey FOREIGN KEY (alert_template_id) REFERENCES public.alert_templates(id) ON DELETE CASCADE;


--
-- Name: alert_template_events alert_template_events_event_type_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.alert_template_events
    ADD CONSTRAINT alert_template_events_event_type_id_fkey FOREIGN KEY (event_type_id) REFERENCES public.event_types(id) ON DELETE CASCADE;


--
-- Name: alert_template_industries alert_template_industries_alert_template_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.alert_template_industries
    ADD CONSTRAINT alert_template_industries_alert_template_id_fkey FOREIGN KEY (alert_template_id) REFERENCES public.alert_templates(id) ON DELETE CASCADE;


--
-- Name: alert_template_industries alert_template_industries_industry_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.alert_template_industries
    ADD CONSTRAINT alert_template_industries_industry_id_fkey FOREIGN KEY (industry_id) REFERENCES public.industries(id) ON DELETE CASCADE;


--
-- Name: alert_templates alert_templates_created_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.alert_templates
    ADD CONSTRAINT alert_templates_created_by_fkey FOREIGN KEY (created_by) REFERENCES auth.users(id);


--
-- Name: branch_roles branch_roles_branch_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.branch_roles
    ADD CONSTRAINT branch_roles_branch_id_fkey FOREIGN KEY (branch_id) REFERENCES public.branches(id) ON DELETE CASCADE;


--
-- Name: branch_roles branch_roles_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.branch_roles
    ADD CONSTRAINT branch_roles_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth.users(id) ON DELETE CASCADE;


--
-- Name: branches branches_organization_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.branches
    ADD CONSTRAINT branches_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES public.organizations(id) ON DELETE CASCADE;


--
-- Name: camera_alert_assignments camera_alert_assignments_alert_template_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.camera_alert_assignments
    ADD CONSTRAINT camera_alert_assignments_alert_template_id_fkey FOREIGN KEY (alert_template_id) REFERENCES public.alert_templates(id) ON DELETE CASCADE;


--
-- Name: camera_sources camera_sources_created_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.camera_sources
    ADD CONSTRAINT camera_sources_created_by_fkey FOREIGN KEY (created_by) REFERENCES auth.users(id);


--
-- Name: cameras cameras_branch_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.cameras
    ADD CONSTRAINT cameras_branch_id_fkey FOREIGN KEY (branch_id) REFERENCES public.branches(id) ON DELETE CASCADE;


--
-- Name: cameras cameras_frigate_instance_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.cameras
    ADD CONSTRAINT cameras_frigate_instance_id_fkey FOREIGN KEY (frigate_instance_id) REFERENCES public.frigate_instances(id);


--
-- Name: cameras cameras_security_zone_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.cameras
    ADD CONSTRAINT cameras_security_zone_id_fkey FOREIGN KEY (security_zone_id) REFERENCES public.security_zones(id);


--
-- Name: chat_messages chat_messages_thread_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.chat_messages
    ADD CONSTRAINT chat_messages_thread_id_fkey FOREIGN KEY (thread_id) REFERENCES public.chat_threads(id) ON DELETE CASCADE;


--
-- Name: chat_thread_participants chat_thread_participants_thread_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.chat_thread_participants
    ADD CONSTRAINT chat_thread_participants_thread_id_fkey FOREIGN KEY (thread_id) REFERENCES public.chat_threads(id) ON DELETE CASCADE;


--
-- Name: chat_threads chat_threads_organization_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.chat_threads
    ADD CONSTRAINT chat_threads_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES public.organizations(id) ON DELETE CASCADE;


--
-- Name: detection_rules detection_rules_organization_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.detection_rules
    ADD CONSTRAINT detection_rules_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES public.organizations(id) ON DELETE CASCADE;


--
-- Name: events events_camera_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.events
    ADD CONSTRAINT events_camera_id_fkey FOREIGN KEY (camera_id) REFERENCES public.cameras(id) ON DELETE CASCADE;


--
-- Name: frigate_exports fk_frigate_exports_instance; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_exports
    ADD CONSTRAINT fk_frigate_exports_instance FOREIGN KEY (frigate_instance_id) REFERENCES public.frigate_instances(id) ON DELETE CASCADE;


--
-- Name: frigate_previews fk_frigate_previews_instance; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_previews
    ADD CONSTRAINT fk_frigate_previews_instance FOREIGN KEY (frigate_instance_id) REFERENCES public.frigate_instances(id) ON DELETE CASCADE;


--
-- Name: frigate_recordings fk_frigate_recordings_instance; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_recordings
    ADD CONSTRAINT fk_frigate_recordings_instance FOREIGN KEY (frigate_instance_id) REFERENCES public.frigate_instances(id) ON DELETE CASCADE;


--
-- Name: frigate_reviews fk_frigate_reviews_instance; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_reviews
    ADD CONSTRAINT fk_frigate_reviews_instance FOREIGN KEY (frigate_instance_id) REFERENCES public.frigate_instances(id) ON DELETE CASCADE;


--
-- Name: frigate_timeline fk_frigate_timeline_instance; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_timeline
    ADD CONSTRAINT fk_frigate_timeline_instance FOREIGN KEY (frigate_instance_id) REFERENCES public.frigate_instances(id) ON DELETE CASCADE;


--
-- Name: form_assignments form_assignments_workflow_form_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.form_assignments
    ADD CONSTRAINT form_assignments_workflow_form_id_fkey FOREIGN KEY (workflow_form_id) REFERENCES public.workflow_forms(id) ON DELETE CASCADE;


--
-- Name: form_distribution_settings form_distribution_settings_workflow_form_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.form_distribution_settings
    ADD CONSTRAINT form_distribution_settings_workflow_form_id_fkey FOREIGN KEY (workflow_form_id) REFERENCES public.workflow_forms(id) ON DELETE CASCADE;


--
-- Name: form_submissions form_submissions_form_assignment_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.form_submissions
    ADD CONSTRAINT form_submissions_form_assignment_id_fkey FOREIGN KEY (form_assignment_id) REFERENCES public.form_assignments(id) ON DELETE CASCADE;


--
-- Name: frigate_alert_rules frigate_alert_rules_camera_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_alert_rules
    ADD CONSTRAINT frigate_alert_rules_camera_id_fkey FOREIGN KEY (camera_id) REFERENCES public.cameras(id) ON DELETE CASCADE;


--
-- Name: frigate_deployed_models frigate_deployed_models_frigate_instance_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_deployed_models
    ADD CONSTRAINT frigate_deployed_models_frigate_instance_id_fkey FOREIGN KEY (frigate_instance_id) REFERENCES public.frigate_instances(id) ON DELETE CASCADE;


--
-- Name: frigate_faces frigate_faces_camera_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_faces
    ADD CONSTRAINT frigate_faces_camera_id_fkey FOREIGN KEY (camera_id) REFERENCES public.cameras(id) ON DELETE CASCADE;


--
-- Name: frigate_instances frigate_instances_branch_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_instances
    ADD CONSTRAINT frigate_instances_branch_id_fkey FOREIGN KEY (branch_id) REFERENCES public.branches(id) ON DELETE SET NULL;


--
-- Name: frigate_license_plates frigate_license_plates_camera_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_license_plates
    ADD CONSTRAINT frigate_license_plates_camera_id_fkey FOREIGN KEY (camera_id) REFERENCES public.cameras(id) ON DELETE CASCADE;


--
-- Name: frigate_license_plates frigate_license_plates_frigate_instance_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_license_plates
    ADD CONSTRAINT frigate_license_plates_frigate_instance_id_fkey FOREIGN KEY (frigate_instance_id) REFERENCES public.frigate_instances(id) ON DELETE SET NULL;


--
-- Name: frigate_model_deployments frigate_model_deployments_deployed_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_model_deployments
    ADD CONSTRAINT frigate_model_deployments_deployed_by_fkey FOREIGN KEY (deployed_by) REFERENCES auth.users(id);


--
-- Name: frigate_model_deployments frigate_model_deployments_frigate_instance_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_model_deployments
    ADD CONSTRAINT frigate_model_deployments_frigate_instance_id_fkey FOREIGN KEY (frigate_instance_id) REFERENCES public.frigate_instances(id) ON DELETE CASCADE;


--
-- Name: frigate_model_sync_log frigate_model_sync_log_frigate_instance_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_model_sync_log
    ADD CONSTRAINT frigate_model_sync_log_frigate_instance_id_fkey FOREIGN KEY (frigate_instance_id) REFERENCES public.frigate_instances(id) ON DELETE CASCADE;


--
-- Name: frigate_stats_history frigate_stats_history_frigate_instance_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_stats_history
    ADD CONSTRAINT frigate_stats_history_frigate_instance_id_fkey FOREIGN KEY (frigate_instance_id) REFERENCES public.frigate_instances(id) ON DELETE CASCADE;


--
-- Name: frigate_sync_logs frigate_sync_logs_frigate_instance_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_sync_logs
    ADD CONSTRAINT frigate_sync_logs_frigate_instance_id_fkey FOREIGN KEY (frigate_instance_id) REFERENCES public.frigate_instances(id) ON DELETE CASCADE;


--
-- Name: frigate_timeline frigate_timeline_camera_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_timeline
    ADD CONSTRAINT frigate_timeline_camera_id_fkey FOREIGN KEY (camera_id) REFERENCES public.cameras(id) ON DELETE CASCADE;


--
-- Name: frigate_triggers frigate_triggers_frigate_instance_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_triggers
    ADD CONSTRAINT frigate_triggers_frigate_instance_id_fkey FOREIGN KEY (frigate_instance_id) REFERENCES public.frigate_instances(id) ON DELETE CASCADE;


--
-- Name: frigate_zones frigate_zones_camera_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.frigate_zones
    ADD CONSTRAINT frigate_zones_camera_id_fkey FOREIGN KEY (camera_id) REFERENCES public.cameras(id) ON DELETE CASCADE;


--
-- Name: health_alerts health_alerts_student_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.health_alerts
    ADD CONSTRAINT health_alerts_student_id_fkey FOREIGN KEY (student_id) REFERENCES public.students(id) ON DELETE CASCADE;


--
-- Name: legal_documents legal_documents_created_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.legal_documents
    ADD CONSTRAINT legal_documents_created_by_fkey FOREIGN KEY (created_by) REFERENCES auth.users(id);


--
-- Name: legal_documents legal_documents_updated_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.legal_documents
    ADD CONSTRAINT legal_documents_updated_by_fkey FOREIGN KEY (updated_by) REFERENCES auth.users(id);


--
-- Name: network_scan_results network_scan_results_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.network_scan_results
    ADD CONSTRAINT network_scan_results_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth.users(id);


--
-- Name: notification_methods notification_methods_created_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.notification_methods
    ADD CONSTRAINT notification_methods_created_by_fkey FOREIGN KEY (created_by) REFERENCES auth.users(id);


--
-- Name: organization_settings organization_settings_organization_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.organization_settings
    ADD CONSTRAINT organization_settings_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES public.organizations(id) ON DELETE CASCADE;


--
-- Name: organizations organizations_industry_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.organizations
    ADD CONSTRAINT organizations_industry_id_fkey FOREIGN KEY (industry_id) REFERENCES public.industries(id);


--
-- Name: security_zones security_zones_branch_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.security_zones
    ADD CONSTRAINT security_zones_branch_id_fkey FOREIGN KEY (branch_id) REFERENCES public.branches(id) ON DELETE CASCADE;


--
-- Name: storage_configs storage_configs_created_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.storage_configs
    ADD CONSTRAINT storage_configs_created_by_fkey FOREIGN KEY (created_by) REFERENCES auth.users(id);


--
-- Name: students students_branch_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.students
    ADD CONSTRAINT students_branch_id_fkey FOREIGN KEY (branch_id) REFERENCES public.branches(id) ON DELETE SET NULL;


--
-- Name: students students_organization_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.students
    ADD CONSTRAINT students_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES public.organizations(id) ON DELETE CASCADE;


--
-- Name: subscribers subscribers_approved_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.subscribers
    ADD CONSTRAINT subscribers_approved_by_fkey FOREIGN KEY (approved_by) REFERENCES auth.users(id);


--
-- Name: subscribers subscribers_organization_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.subscribers
    ADD CONSTRAINT subscribers_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES public.organizations(id);


--
-- Name: subscribers subscribers_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.subscribers
    ADD CONSTRAINT subscribers_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth.users(id) ON DELETE CASCADE;


--
-- Name: system_settings system_settings_updated_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.system_settings
    ADD CONSTRAINT system_settings_updated_by_fkey FOREIGN KEY (updated_by) REFERENCES auth.users(id);


--
-- Name: user_branch_access user_branch_access_branch_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.user_branch_access
    ADD CONSTRAINT user_branch_access_branch_id_fkey FOREIGN KEY (branch_id) REFERENCES public.branches(id) ON DELETE CASCADE;


--
-- Name: user_branch_access user_branch_access_granted_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.user_branch_access
    ADD CONSTRAINT user_branch_access_granted_by_fkey FOREIGN KEY (granted_by) REFERENCES auth.users(id);


--
-- Name: user_branch_access user_branch_access_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.user_branch_access
    ADD CONSTRAINT user_branch_access_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth.users(id) ON DELETE CASCADE;


--
-- Name: user_group_members user_group_members_group_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.user_group_members
    ADD CONSTRAINT user_group_members_group_id_fkey FOREIGN KEY (group_id) REFERENCES public.user_groups(id) ON DELETE CASCADE;


--
-- Name: user_group_members user_group_members_user_role_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.user_group_members
    ADD CONSTRAINT user_group_members_user_role_id_fkey FOREIGN KEY (user_role_id) REFERENCES public.user_roles(id) ON DELETE CASCADE;


--
-- Name: user_groups user_groups_organization_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.user_groups
    ADD CONSTRAINT user_groups_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES public.organizations(id) ON DELETE CASCADE;


--
-- Name: user_preferences user_preferences_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.user_preferences
    ADD CONSTRAINT user_preferences_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth.users(id) ON DELETE CASCADE;


--
-- Name: user_roles user_roles_granted_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.user_roles
    ADD CONSTRAINT user_roles_granted_by_fkey FOREIGN KEY (granted_by) REFERENCES auth.users(id);


--
-- Name: user_roles user_roles_organization_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.user_roles
    ADD CONSTRAINT user_roles_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES public.organizations(id) ON DELETE CASCADE;


--
-- Name: user_roles user_roles_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.user_roles
    ADD CONSTRAINT user_roles_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth.users(id) ON DELETE CASCADE;


--
-- Name: iceberg_namespaces iceberg_namespaces_catalog_id_fkey; Type: FK CONSTRAINT; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE ONLY storage.iceberg_namespaces
    ADD CONSTRAINT iceberg_namespaces_catalog_id_fkey FOREIGN KEY (catalog_id) REFERENCES storage.buckets_analytics(id) ON DELETE CASCADE;


--
-- Name: iceberg_tables iceberg_tables_catalog_id_fkey; Type: FK CONSTRAINT; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE ONLY storage.iceberg_tables
    ADD CONSTRAINT iceberg_tables_catalog_id_fkey FOREIGN KEY (catalog_id) REFERENCES storage.buckets_analytics(id) ON DELETE CASCADE;


--
-- Name: iceberg_tables iceberg_tables_namespace_id_fkey; Type: FK CONSTRAINT; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE ONLY storage.iceberg_tables
    ADD CONSTRAINT iceberg_tables_namespace_id_fkey FOREIGN KEY (namespace_id) REFERENCES storage.iceberg_namespaces(id) ON DELETE CASCADE;


--
-- Name: objects objects_bucketId_fkey; Type: FK CONSTRAINT; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE ONLY storage.objects
    ADD CONSTRAINT "objects_bucketId_fkey" FOREIGN KEY (bucket_id) REFERENCES storage.buckets(id);


--
-- Name: s3_multipart_uploads s3_multipart_uploads_bucket_id_fkey; Type: FK CONSTRAINT; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE ONLY storage.s3_multipart_uploads
    ADD CONSTRAINT s3_multipart_uploads_bucket_id_fkey FOREIGN KEY (bucket_id) REFERENCES storage.buckets(id);


--
-- Name: s3_multipart_uploads_parts s3_multipart_uploads_parts_bucket_id_fkey; Type: FK CONSTRAINT; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE ONLY storage.s3_multipart_uploads_parts
    ADD CONSTRAINT s3_multipart_uploads_parts_bucket_id_fkey FOREIGN KEY (bucket_id) REFERENCES storage.buckets(id);


--
-- Name: s3_multipart_uploads_parts s3_multipart_uploads_parts_upload_id_fkey; Type: FK CONSTRAINT; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE ONLY storage.s3_multipart_uploads_parts
    ADD CONSTRAINT s3_multipart_uploads_parts_upload_id_fkey FOREIGN KEY (upload_id) REFERENCES storage.s3_multipart_uploads(id) ON DELETE CASCADE;


--
-- Name: vector_indexes vector_indexes_bucket_id_fkey; Type: FK CONSTRAINT; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE ONLY storage.vector_indexes
    ADD CONSTRAINT vector_indexes_bucket_id_fkey FOREIGN KEY (bucket_id) REFERENCES storage.buckets_vectors(id);


--
-- Name: audit_log_entries; Type: ROW SECURITY; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE auth.audit_log_entries ENABLE ROW LEVEL SECURITY;

--
-- Name: flow_state; Type: ROW SECURITY; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE auth.flow_state ENABLE ROW LEVEL SECURITY;

--
-- Name: identities; Type: ROW SECURITY; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE auth.identities ENABLE ROW LEVEL SECURITY;

--
-- Name: instances; Type: ROW SECURITY; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE auth.instances ENABLE ROW LEVEL SECURITY;

--
-- Name: mfa_amr_claims; Type: ROW SECURITY; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE auth.mfa_amr_claims ENABLE ROW LEVEL SECURITY;

--
-- Name: mfa_challenges; Type: ROW SECURITY; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE auth.mfa_challenges ENABLE ROW LEVEL SECURITY;

--
-- Name: mfa_factors; Type: ROW SECURITY; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE auth.mfa_factors ENABLE ROW LEVEL SECURITY;

--
-- Name: one_time_tokens; Type: ROW SECURITY; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE auth.one_time_tokens ENABLE ROW LEVEL SECURITY;

--
-- Name: refresh_tokens; Type: ROW SECURITY; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE auth.refresh_tokens ENABLE ROW LEVEL SECURITY;

--
-- Name: saml_providers; Type: ROW SECURITY; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE auth.saml_providers ENABLE ROW LEVEL SECURITY;

--
-- Name: saml_relay_states; Type: ROW SECURITY; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE auth.saml_relay_states ENABLE ROW LEVEL SECURITY;

--
-- Name: schema_migrations; Type: ROW SECURITY; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE auth.schema_migrations ENABLE ROW LEVEL SECURITY;

--
-- Name: sessions; Type: ROW SECURITY; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE auth.sessions ENABLE ROW LEVEL SECURITY;

--
-- Name: sso_domains; Type: ROW SECURITY; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE auth.sso_domains ENABLE ROW LEVEL SECURITY;

--
-- Name: sso_providers; Type: ROW SECURITY; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE auth.sso_providers ENABLE ROW LEVEL SECURITY;

--
-- Name: users; Type: ROW SECURITY; Schema: auth; Owner: supabase_auth_admin
--

ALTER TABLE auth.users ENABLE ROW LEVEL SECURITY;

--
-- Name: cameras Admins and managers can delete cameras; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Admins and managers can delete cameras" ON public.cameras FOR DELETE USING ((EXISTS ( SELECT 1
   FROM (public.user_roles ur
     JOIN public.branches b ON ((ur.organization_id = b.organization_id)))
  WHERE ((ur.user_id = auth.uid()) AND (b.id = cameras.branch_id) AND (ur.role = ANY (ARRAY['admin'::public.user_role, 'manager'::public.user_role]))))));


--
-- Name: security_zones Admins and managers can delete security zones; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Admins and managers can delete security zones" ON public.security_zones FOR DELETE USING ((public.is_current_user_super_admin() OR (EXISTS ( SELECT 1
   FROM (public.user_roles ur
     JOIN public.branches b ON ((security_zones.branch_id = b.id)))
  WHERE ((ur.user_id = auth.uid()) AND (ur.organization_id = b.organization_id) AND (ur.role = ANY (ARRAY['company_admin'::public.user_role, 'branch_manager'::public.user_role]))))) OR (EXISTS ( SELECT 1
   FROM public.user_branch_access uba
  WHERE ((uba.user_id = auth.uid()) AND (uba.branch_id = security_zones.branch_id))))));


--
-- Name: aman_instances Admins and managers can manage Aman instances; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Admins and managers can manage Aman instances" ON public.aman_instances USING ((EXISTS ( SELECT 1
   FROM public.user_roles ur
  WHERE ((ur.user_id = auth.uid()) AND (ur.organization_id = aman_instances.organization_id) AND (ur.role = ANY (ARRAY['admin'::public.user_role, 'manager'::public.user_role])))))) WITH CHECK ((EXISTS ( SELECT 1
   FROM public.user_roles ur
  WHERE ((ur.user_id = auth.uid()) AND (ur.organization_id = aman_instances.organization_id) AND (ur.role = ANY (ARRAY['admin'::public.user_role, 'manager'::public.user_role]))))));


--
-- Name: camera_event_assignments Admins and managers can manage camera event assignments; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Admins and managers can manage camera event assignments" ON public.camera_event_assignments TO authenticated USING ((EXISTS ( SELECT 1
   FROM ((public.cameras c
     JOIN public.branches b ON ((c.branch_id = b.id)))
     JOIN public.user_roles ur ON ((ur.organization_id = b.organization_id)))
  WHERE ((c.id = camera_event_assignments.camera_id) AND (ur.user_id = auth.uid()) AND (ur.role = ANY (ARRAY['admin'::public.user_role, 'manager'::public.user_role]))))));


--
-- Name: detection_rules Admins and managers can manage detection rules; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Admins and managers can manage detection rules" ON public.detection_rules USING ((EXISTS ( SELECT 1
   FROM public.user_roles ur
  WHERE ((ur.user_id = auth.uid()) AND (ur.organization_id = detection_rules.organization_id) AND (ur.role = ANY (ARRAY['admin'::public.user_role, 'manager'::public.user_role]))))));


--
-- Name: form_assignments Admins and managers can manage form assignments; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Admins and managers can manage form assignments" ON public.form_assignments USING ((EXISTS ( SELECT 1
   FROM public.user_roles ur
  WHERE ((ur.user_id = auth.uid()) AND (ur.organization_id = form_assignments.organization_id) AND (ur.role = ANY (ARRAY['admin'::public.user_role, 'manager'::public.user_role]))))));


--
-- Name: user_group_members Admins and managers can manage group members; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Admins and managers can manage group members" ON public.user_group_members USING ((EXISTS ( SELECT 1
   FROM (public.user_groups ug
     JOIN public.user_roles ur ON ((ur.organization_id = ug.organization_id)))
  WHERE ((ug.id = user_group_members.group_id) AND (ur.user_id = auth.uid()) AND (ur.role = ANY (ARRAY['admin'::public.user_role, 'manager'::public.user_role]))))));


--
-- Name: user_groups Admins and managers can manage groups; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Admins and managers can manage groups" ON public.user_groups USING ((EXISTS ( SELECT 1
   FROM public.user_roles ur
  WHERE ((ur.user_id = auth.uid()) AND (ur.organization_id = user_groups.organization_id) AND (ur.role = ANY (ARRAY['admin'::public.user_role, 'manager'::public.user_role]))))));


--
-- Name: cameras Admins and managers can update cameras; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Admins and managers can update cameras" ON public.cameras FOR UPDATE USING ((EXISTS ( SELECT 1
   FROM (public.user_roles ur
     JOIN public.branches b ON ((ur.organization_id = b.organization_id)))
  WHERE ((ur.user_id = auth.uid()) AND (b.id = cameras.branch_id) AND (ur.role = ANY (ARRAY['admin'::public.user_role, 'manager'::public.user_role]))))));


--
-- Name: security_zones Admins and managers can update security zones; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Admins and managers can update security zones" ON public.security_zones FOR UPDATE USING ((public.is_current_user_super_admin() OR (EXISTS ( SELECT 1
   FROM (public.user_roles ur
     JOIN public.branches b ON ((security_zones.branch_id = b.id)))
  WHERE ((ur.user_id = auth.uid()) AND (ur.organization_id = b.organization_id) AND (ur.role = ANY (ARRAY['company_admin'::public.user_role, 'branch_manager'::public.user_role]))))) OR (EXISTS ( SELECT 1
   FROM public.user_branch_access uba
  WHERE ((uba.user_id = auth.uid()) AND (uba.branch_id = security_zones.branch_id))))));


--
-- Name: form_submissions Admins and managers can view submissions in their organization; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Admins and managers can view submissions in their organization" ON public.form_submissions FOR SELECT USING ((EXISTS ( SELECT 1
   FROM (public.form_assignments fa
     JOIN public.user_roles ur ON ((ur.organization_id = fa.organization_id)))
  WHERE ((fa.id = form_submissions.form_assignment_id) AND (ur.user_id = auth.uid()) AND (ur.role = ANY (ARRAY['admin'::public.user_role, 'manager'::public.user_role]))))));


--
-- Name: ai_models Admins can manage AI models; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Admins can manage AI models" ON public.ai_models USING ((EXISTS ( SELECT 1
   FROM public.user_roles ur
  WHERE ((ur.user_id = auth.uid()) AND (ur.role = 'admin'::public.user_role)))));


--
-- Name: frigate_alert_rules Admins can manage alert rules in their organization cameras; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Admins can manage alert rules in their organization cameras" ON public.frigate_alert_rules USING ((EXISTS ( SELECT 1
   FROM ((public.cameras c
     JOIN public.branches b ON ((c.branch_id = b.id)))
     JOIN public.user_roles ur ON ((ur.organization_id = b.organization_id)))
  WHERE ((c.id = frigate_alert_rules.camera_id) AND (ur.user_id = auth.uid()) AND (ur.role = ANY (ARRAY['admin'::public.user_role, 'manager'::public.user_role]))))));


--
-- Name: frigate_faces Admins can manage faces in their organization; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Admins can manage faces in their organization" ON public.frigate_faces USING ((EXISTS ( SELECT 1
   FROM ((public.cameras c
     JOIN public.branches b ON ((c.branch_id = b.id)))
     JOIN public.user_roles ur ON ((ur.organization_id = b.organization_id)))
  WHERE ((c.id = frigate_faces.camera_id) AND (ur.user_id = auth.uid()) AND (ur.role = ANY (ARRAY['admin'::public.user_role, 'manager'::public.user_role]))))));


--
-- Name: frigate_zones Admins can manage zones in their organization cameras; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Admins can manage zones in their organization cameras" ON public.frigate_zones USING ((EXISTS ( SELECT 1
   FROM ((public.cameras c
     JOIN public.branches b ON ((c.branch_id = b.id)))
     JOIN public.user_roles ur ON ((ur.organization_id = b.organization_id)))
  WHERE ((c.id = frigate_zones.camera_id) AND (ur.user_id = auth.uid()) AND (ur.role = ANY (ARRAY['admin'::public.user_role, 'manager'::public.user_role]))))));


--
-- Name: chatbot_knowledge_base Anyone can view active knowledge base; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Anyone can view active knowledge base" ON public.chatbot_knowledge_base FOR SELECT USING ((is_active = true));


--
-- Name: legal_documents Anyone can view legal documents; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Anyone can view legal documents" ON public.legal_documents FOR SELECT USING (true);


--
-- Name: screen_permissions Authenticated users can view active screen permissions; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Authenticated users can view active screen permissions" ON public.screen_permissions FOR SELECT USING ((COALESCE(is_active, true) = true));


--
-- Name: form_submissions Branch managers can update branch form submissions; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Branch managers can update branch form submissions" ON public.form_submissions FOR UPDATE USING (public.branch_manager_can_view_submission(id)) WITH CHECK (public.branch_manager_can_view_submission(id));


--
-- Name: form_submissions Branch managers can view branch form submissions; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Branch managers can view branch form submissions" ON public.form_submissions FOR SELECT USING (public.branch_manager_can_view_submission(id));


--
-- Name: pinned_dashboards Branch managers can view branch pinned dashboards; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Branch managers can view branch pinned dashboards" ON public.pinned_dashboards FOR SELECT USING ((EXISTS ( SELECT 1
   FROM (public.aman_instances ai
     JOIN public.branch_roles br ON ((br.branch_id = ai.branch_id)))
  WHERE ((ai.id = pinned_dashboards.instance_id) AND (br.user_id = auth.uid()) AND (br.role = 'branch_manager'::text)))));


--
-- Name: user_roles Branch managers can view branch user roles; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Branch managers can view branch user roles" ON public.user_roles FOR SELECT USING (public.current_user_is_branch_manager_for_user(user_id));


--
-- Name: user_branch_access Company admins can manage branch access in their organization; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Company admins can manage branch access in their organization" ON public.user_branch_access USING ((EXISTS ( SELECT 1
   FROM (public.user_roles ur
     JOIN public.branches b ON ((user_branch_access.branch_id = b.id)))
  WHERE ((ur.user_id = auth.uid()) AND (ur.organization_id = b.organization_id) AND (ur.role = ANY (ARRAY['super_admin'::public.user_role, 'company_admin'::public.user_role]))))));


--
-- Name: pinned_labels Labels: users can delete their own; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Labels: users can delete their own" ON public.pinned_labels FOR DELETE USING ((auth.uid() = user_id));


--
-- Name: pinned_labels Labels: users can insert their own; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Labels: users can insert their own" ON public.pinned_labels FOR INSERT WITH CHECK ((auth.uid() = user_id));


--
-- Name: pinned_labels Labels: users can update their own; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Labels: users can update their own" ON public.pinned_labels FOR UPDATE USING ((auth.uid() = user_id));


--
-- Name: pinned_labels Labels: users can view their own; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Labels: users can view their own" ON public.pinned_labels FOR SELECT USING ((auth.uid() = user_id));


--
-- Name: pinned_dashboards Org admins and managers can view org pinned dashboards; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Org admins and managers can view org pinned dashboards" ON public.pinned_dashboards FOR SELECT USING ((EXISTS ( SELECT 1
   FROM (public.aman_instances ai
     JOIN public.user_roles ur ON ((ur.organization_id = ai.organization_id)))
  WHERE ((ai.id = pinned_dashboards.instance_id) AND (ur.user_id = auth.uid()) AND (ur.role = ANY (ARRAY['admin'::public.user_role, 'manager'::public.user_role]))))));


--
-- Name: frigate_instances Org admins can manage frigate instances in their organization; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Org admins can manage frigate instances in their organization" ON public.frigate_instances USING ((EXISTS ( SELECT 1
   FROM (public.branches b
     JOIN public.user_roles ur ON ((ur.organization_id = b.organization_id)))
  WHERE ((b.id = frigate_instances.branch_id) AND (ur.user_id = auth.uid()) AND (ur.role = ANY (ARRAY['admin'::public.user_role, 'manager'::public.user_role]))))));


--
-- Name: subscribers Org admins can update subscribers; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Org admins can update subscribers" ON public.subscribers FOR UPDATE USING ((public.is_current_user_super_admin() OR (EXISTS ( SELECT 1
   FROM public.user_roles ur
  WHERE ((ur.user_id = auth.uid()) AND (ur.role = ANY (ARRAY['admin'::public.user_role, 'manager'::public.user_role]))))))) WITH CHECK ((public.is_current_user_super_admin() OR (EXISTS ( SELECT 1
   FROM public.user_roles ur
  WHERE ((ur.user_id = auth.uid()) AND (ur.role = ANY (ARRAY['admin'::public.user_role, 'manager'::public.user_role])))))));


--
-- Name: subscribers Org admins can view all subscribers; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Org admins can view all subscribers" ON public.subscribers FOR SELECT USING ((public.is_current_user_super_admin() OR (EXISTS ( SELECT 1
   FROM public.user_roles ur
  WHERE ((ur.user_id = auth.uid()) AND (ur.role = ANY (ARRAY['admin'::public.user_role, 'manager'::public.user_role])))))));


--
-- Name: subscribers Org admins can view org subscribers; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Org admins can view org subscribers" ON public.subscribers FOR SELECT USING ((EXISTS ( SELECT 1
   FROM public.user_roles ur
  WHERE ((ur.user_id = auth.uid()) AND (ur.organization_id = subscribers.organization_id) AND (ur.role = 'admin'::public.user_role)))));


--
-- Name: form_distribution_settings Org admins/managers can manage form distribution settings; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Org admins/managers can manage form distribution settings" ON public.form_distribution_settings TO authenticated USING ((EXISTS ( SELECT 1
   FROM (public.form_assignments fa
     JOIN public.user_roles ur ON ((ur.organization_id = fa.organization_id)))
  WHERE ((fa.workflow_form_id = form_distribution_settings.workflow_form_id) AND (ur.user_id = auth.uid()) AND (ur.role = ANY (ARRAY['admin'::public.user_role, 'manager'::public.user_role])))))) WITH CHECK ((EXISTS ( SELECT 1
   FROM (public.form_assignments fa
     JOIN public.user_roles ur ON ((ur.organization_id = fa.organization_id)))
  WHERE ((fa.workflow_form_id = form_distribution_settings.workflow_form_id) AND (ur.user_id = auth.uid()) AND (ur.role = ANY (ARRAY['admin'::public.user_role, 'manager'::public.user_role]))))));


--
-- Name: form_submissions Org admins/managers can update submissions; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Org admins/managers can update submissions" ON public.form_submissions FOR UPDATE USING ((EXISTS ( SELECT 1
   FROM (public.form_assignments fa
     JOIN public.user_roles ur ON ((ur.organization_id = fa.organization_id)))
  WHERE ((fa.id = form_submissions.form_assignment_id) AND (ur.user_id = auth.uid()) AND (ur.role = ANY (ARRAY['admin'::public.user_role, 'manager'::public.user_role])))))) WITH CHECK ((EXISTS ( SELECT 1
   FROM (public.form_assignments fa
     JOIN public.user_roles ur ON ((ur.organization_id = fa.organization_id)))
  WHERE ((fa.id = form_submissions.form_assignment_id) AND (ur.user_id = auth.uid()) AND (ur.role = ANY (ARRAY['admin'::public.user_role, 'manager'::public.user_role]))))));


--
-- Name: user_roles Org admins/managers can view org user roles; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Org admins/managers can view org user roles" ON public.user_roles FOR SELECT USING (public.current_user_is_org_admin_or_manager(organization_id));


--
-- Name: chat_thread_participants Org members can add participants to their org threads; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Org members can add participants to their org threads" ON public.chat_thread_participants FOR INSERT WITH CHECK ((EXISTS ( SELECT 1
   FROM (public.chat_threads t
     JOIN public.user_roles ur ON ((ur.organization_id = t.organization_id)))
  WHERE ((t.id = chat_thread_participants.thread_id) AND (ur.user_id = auth.uid())))));


--
-- Name: chat_threads Org members can create threads in their org; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Org members can create threads in their org" ON public.chat_threads FOR INSERT WITH CHECK ((organization_id IN ( SELECT user_roles.organization_id
   FROM public.user_roles
  WHERE (user_roles.user_id = auth.uid()))));


--
-- Name: chat_threads Org members can update org threads; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Org members can update org threads" ON public.chat_threads FOR UPDATE USING ((EXISTS ( SELECT 1
   FROM public.user_roles ur
  WHERE ((ur.user_id = auth.uid()) AND (ur.organization_id = chat_threads.organization_id)))));


--
-- Name: form_distribution_settings Org members can view form distribution settings; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Org members can view form distribution settings" ON public.form_distribution_settings FOR SELECT TO authenticated USING ((EXISTS ( SELECT 1
   FROM (public.form_assignments fa
     JOIN public.user_roles ur ON ((ur.organization_id = fa.organization_id)))
  WHERE ((fa.workflow_form_id = form_distribution_settings.workflow_form_id) AND (ur.user_id = auth.uid())))));


--
-- Name: chat_threads Org members can view org threads; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Org members can view org threads" ON public.chat_threads FOR SELECT USING ((EXISTS ( SELECT 1
   FROM public.user_roles ur
  WHERE ((ur.user_id = auth.uid()) AND (ur.organization_id = chat_threads.organization_id)))));


--
-- Name: chat_thread_participants Org members can view participants for org threads; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Org members can view participants for org threads" ON public.chat_thread_participants FOR SELECT USING ((EXISTS ( SELECT 1
   FROM (public.chat_threads t
     JOIN public.user_roles ur ON ((ur.organization_id = t.organization_id)))
  WHERE ((t.id = chat_thread_participants.thread_id) AND (ur.user_id = auth.uid())))));


--
-- Name: chat_messages Participants can send messages to their threads; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Participants can send messages to their threads" ON public.chat_messages FOR INSERT WITH CHECK (((sender_id = auth.uid()) AND (EXISTS ( SELECT 1
   FROM public.chat_thread_participants p
  WHERE ((p.thread_id = chat_messages.thread_id) AND (p.user_id = auth.uid())))) AND (organization_id = ( SELECT t.organization_id
   FROM public.chat_threads t
  WHERE (t.id = chat_messages.thread_id)))));


--
-- Name: chat_messages Participants can view messages in their threads; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Participants can view messages in their threads" ON public.chat_messages FOR SELECT USING ((EXISTS ( SELECT 1
   FROM public.chat_thread_participants p
  WHERE ((p.thread_id = chat_messages.thread_id) AND (p.user_id = auth.uid())))));


--
-- Name: form_submissions Representatives can manage their own submissions; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Representatives can manage their own submissions" ON public.form_submissions USING ((EXISTS ( SELECT 1
   FROM (public.form_assignments fa
     JOIN public.user_roles ur ON ((ur.id = fa.representative_id)))
  WHERE ((fa.id = form_submissions.form_assignment_id) AND (ur.user_id = auth.uid())))));


--
-- Name: form_assignments Representatives can view their assignments; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Representatives can view their assignments" ON public.form_assignments FOR SELECT USING ((representative_id IN ( SELECT user_roles.id
   FROM public.user_roles
  WHERE (user_roles.user_id = auth.uid()))));


--
-- Name: ai_analysis_logs Super admin can manage AI analysis logs; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can manage AI analysis logs" ON public.ai_analysis_logs USING (public.is_current_user_super_admin()) WITH CHECK (public.is_current_user_super_admin());


--
-- Name: alert_template_events Super admin can manage alert template events; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can manage alert template events" ON public.alert_template_events TO authenticated USING (public.is_current_user_super_admin());


--
-- Name: alert_template_industries Super admin can manage alert template industries; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can manage alert template industries" ON public.alert_template_industries USING (public.is_current_user_super_admin());


--
-- Name: aman_instances Super admin can manage all Aman instances; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can manage all Aman instances" ON public.aman_instances USING (public.is_current_user_super_admin()) WITH CHECK (public.is_current_user_super_admin());


--
-- Name: alert_templates Super admin can manage all alert templates; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can manage all alert templates" ON public.alert_templates TO authenticated USING (public.is_current_user_super_admin());


--
-- Name: user_branch_access Super admin can manage all branch access; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can manage all branch access" ON public.user_branch_access USING (public.is_current_user_super_admin());


--
-- Name: camera_alert_assignments Super admin can manage all camera alert assignments; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can manage all camera alert assignments" ON public.camera_alert_assignments TO authenticated USING (public.is_current_user_super_admin());


--
-- Name: chat_threads Super admin can manage all chat threads; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can manage all chat threads" ON public.chat_threads USING (public.is_current_user_super_admin()) WITH CHECK (public.is_current_user_super_admin());


--
-- Name: event_types Super admin can manage all event types; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can manage all event types" ON public.event_types TO authenticated USING (public.is_current_user_super_admin());


--
-- Name: form_distribution_settings Super admin can manage all form distribution settings; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can manage all form distribution settings" ON public.form_distribution_settings TO authenticated USING (public.is_current_user_super_admin()) WITH CHECK (public.is_current_user_super_admin());


--
-- Name: form_submissions Super admin can manage all form submissions; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can manage all form submissions" ON public.form_submissions USING (public.is_current_user_super_admin()) WITH CHECK (public.is_current_user_super_admin());


--
-- Name: frigate_alert_rules Super admin can manage all frigate alert rules; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can manage all frigate alert rules" ON public.frigate_alert_rules USING (public.is_current_user_super_admin());


--
-- Name: frigate_faces Super admin can manage all frigate faces; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can manage all frigate faces" ON public.frigate_faces USING (public.is_current_user_super_admin());


--
-- Name: frigate_instances Super admin can manage all frigate instances; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can manage all frigate instances" ON public.frigate_instances USING (public.is_current_user_super_admin());


--
-- Name: frigate_license_plates Super admin can manage all frigate license plates; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can manage all frigate license plates" ON public.frigate_license_plates USING (public.is_current_user_super_admin());


--
-- Name: frigate_timeline Super admin can manage all frigate timeline; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can manage all frigate timeline" ON public.frigate_timeline USING (public.is_current_user_super_admin());


--
-- Name: frigate_zones Super admin can manage all frigate zones; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can manage all frigate zones" ON public.frigate_zones USING (public.is_current_user_super_admin());


--
-- Name: industries Super admin can manage all industries; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can manage all industries" ON public.industries USING (public.is_current_user_super_admin());


--
-- Name: organizations Super admin can manage all organizations; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can manage all organizations" ON public.organizations USING (public.is_current_user_super_admin());


--
-- Name: chat_thread_participants Super admin can manage all participants; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can manage all participants" ON public.chat_thread_participants USING (public.is_current_user_super_admin()) WITH CHECK (public.is_current_user_super_admin());


--
-- Name: subscribers Super admin can manage all subscribers; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can manage all subscribers" ON public.subscribers USING (public.is_current_user_super_admin()) WITH CHECK (public.is_current_user_super_admin());


--
-- Name: user_roles Super admin can manage all user roles; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can manage all user roles" ON public.user_roles USING (public.is_current_user_super_admin());


--
-- Name: branch_roles Super admin can manage branch roles; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can manage branch roles" ON public.branch_roles USING (public.is_current_user_super_admin()) WITH CHECK (public.is_current_user_super_admin());


--
-- Name: camera_sources Super admin can manage camera sources; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can manage camera sources" ON public.camera_sources USING (public.is_current_user_super_admin());


--
-- Name: form_distribution_settings Super admin can manage form distribution; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can manage form distribution" ON public.form_distribution_settings USING (public.is_current_user_super_admin());


--
-- Name: chatbot_knowledge_base Super admin can manage knowledge base; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can manage knowledge base" ON public.chatbot_knowledge_base USING (public.is_current_user_super_admin());


--
-- Name: notification_labels Super admin can manage notification labels; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can manage notification labels" ON public.notification_labels USING (public.is_current_user_super_admin()) WITH CHECK (public.is_current_user_super_admin());


--
-- Name: notification_methods Super admin can manage notification methods; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can manage notification methods" ON public.notification_methods USING (public.is_current_user_super_admin());


--
-- Name: screen_permissions Super admin can manage screen permissions; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can manage screen permissions" ON public.screen_permissions USING (public.is_current_user_super_admin()) WITH CHECK (public.is_current_user_super_admin());


--
-- Name: storage_configs Super admin can manage storage configs; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can manage storage configs" ON public.storage_configs TO authenticated USING (public.is_current_user_super_admin());


--
-- Name: workflow_forms Super admin can manage workflow forms; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can manage workflow forms" ON public.workflow_forms USING (public.is_current_user_super_admin());


--
-- Name: branches Super admin can view all branches; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can view all branches" ON public.branches FOR SELECT USING (public.is_current_user_super_admin());


--
-- Name: form_assignments Super admin can view all form assignments; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can view all form assignments" ON public.form_assignments FOR SELECT USING (public.is_current_user_super_admin());


--
-- Name: pinned_dashboards Super admin can view all pinned dashboards; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can view all pinned dashboards" ON public.pinned_dashboards FOR SELECT USING (public.is_current_user_super_admin());


--
-- Name: chat_messages Super admin can view and manage all messages; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admin can view and manage all messages" ON public.chat_messages USING (public.is_current_user_super_admin()) WITH CHECK (public.is_current_user_super_admin());


--
-- Name: legal_documents Super admins can manage legal documents; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Super admins can manage legal documents" ON public.legal_documents USING ((EXISTS ( SELECT 1
   FROM public.user_roles ur
  WHERE ((ur.user_id = auth.uid()) AND (ur.role = 'admin'::public.user_role)))));


--
-- Name: cameras System can insert cameras during sync; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "System can insert cameras during sync" ON public.cameras FOR INSERT WITH CHECK ((((auth.jwt() ->> 'sub'::text) IS NOT NULL) AND (branch_id IS NOT NULL)));


--
-- Name: events System can insert events during sync; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "System can insert events during sync" ON public.events FOR INSERT WITH CHECK ((((auth.jwt() ->> 'sub'::text) IS NOT NULL) AND ((metadata ->> 'frigate_instance_id'::text) IS NOT NULL)));


--
-- Name: frigate_previews System can insert frigate_previews; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "System can insert frigate_previews" ON public.frigate_previews FOR INSERT WITH CHECK (((auth.jwt() ->> 'sub'::text) IS NOT NULL));


--
-- Name: frigate_recordings System can insert frigate_recordings; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "System can insert frigate_recordings" ON public.frigate_recordings FOR INSERT WITH CHECK (((auth.jwt() ->> 'sub'::text) IS NOT NULL));


--
-- Name: frigate_reviews System can insert frigate_reviews; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "System can insert frigate_reviews" ON public.frigate_reviews FOR INSERT WITH CHECK (((auth.jwt() ->> 'sub'::text) IS NOT NULL));


--
-- Name: frigate_timeline System can insert frigate_timeline; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "System can insert frigate_timeline" ON public.frigate_timeline FOR INSERT WITH CHECK (((auth.jwt() ->> 'sub'::text) IS NOT NULL));


--
-- Name: subscribers System can insert new subscribers; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "System can insert new subscribers" ON public.subscribers FOR INSERT WITH CHECK ((auth.uid() = user_id));


--
-- Name: security_zones Users can create security zones in their organization; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can create security zones in their organization" ON public.security_zones FOR INSERT WITH CHECK ((public.is_current_user_super_admin() OR (EXISTS ( SELECT 1
   FROM (public.user_roles ur
     JOIN public.branches b ON ((security_zones.branch_id = b.id)))
  WHERE ((ur.user_id = auth.uid()) AND (ur.organization_id = b.organization_id) AND (ur.role = ANY (ARRAY['company_admin'::public.user_role, 'branch_manager'::public.user_role]))))) OR (EXISTS ( SELECT 1
   FROM public.user_branch_access uba
  WHERE ((uba.user_id = auth.uid()) AND (uba.branch_id = security_zones.branch_id))))));


--
-- Name: subscribers Users can create their own subscriptions; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can create their own subscriptions" ON public.subscribers FOR INSERT WITH CHECK ((user_id = auth.uid()));


--
-- Name: frigate_exports Users can delete frigate_exports; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can delete frigate_exports" ON public.frigate_exports FOR DELETE USING ((auth.role() = 'authenticated'::text));


--
-- Name: frigate_previews Users can delete frigate_previews; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can delete frigate_previews" ON public.frigate_previews FOR DELETE USING ((auth.role() = 'authenticated'::text));


--
-- Name: frigate_recordings Users can delete frigate_recordings; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can delete frigate_recordings" ON public.frigate_recordings FOR DELETE USING ((auth.role() = 'authenticated'::text));


--
-- Name: frigate_reviews Users can delete frigate_reviews; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can delete frigate_reviews" ON public.frigate_reviews FOR DELETE USING ((auth.role() = 'authenticated'::text));


--
-- Name: frigate_exports Users can insert frigate_exports; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can insert frigate_exports" ON public.frigate_exports FOR INSERT WITH CHECK ((auth.role() = 'authenticated'::text));


--
-- Name: frigate_previews Users can insert frigate_previews; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can insert frigate_previews" ON public.frigate_previews FOR INSERT WITH CHECK ((auth.role() = 'authenticated'::text));


--
-- Name: frigate_recordings Users can insert frigate_recordings; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can insert frigate_recordings" ON public.frigate_recordings FOR INSERT WITH CHECK ((auth.role() = 'authenticated'::text));


--
-- Name: frigate_reviews Users can insert frigate_reviews; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can insert frigate_reviews" ON public.frigate_reviews FOR INSERT WITH CHECK ((auth.role() = 'authenticated'::text));


--
-- Name: network_scan_results Users can insert their own scan results; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can insert their own scan results" ON public.network_scan_results FOR INSERT WITH CHECK ((user_id = auth.uid()));


--
-- Name: user_preferences Users can manage their own preferences; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can manage their own preferences" ON public.user_preferences USING ((user_id = auth.uid()));


--
-- Name: events Users can update event reviewed; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can update event reviewed" ON public.events FOR UPDATE USING ((EXISTS ( SELECT 1
   FROM ((public.cameras c
     JOIN public.branches b ON ((c.branch_id = b.id)))
     JOIN public.user_roles ur ON ((ur.organization_id = b.organization_id)))
  WHERE ((c.id = events.camera_id) AND (ur.user_id = auth.uid()))))) WITH CHECK ((reviewed = true));


--
-- Name: frigate_exports Users can update frigate_exports; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can update frigate_exports" ON public.frigate_exports FOR UPDATE USING ((auth.role() = 'authenticated'::text));


--
-- Name: frigate_previews Users can update frigate_previews; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can update frigate_previews" ON public.frigate_previews FOR UPDATE USING ((auth.role() = 'authenticated'::text));


--
-- Name: frigate_recordings Users can update frigate_recordings; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can update frigate_recordings" ON public.frigate_recordings FOR UPDATE USING ((auth.role() = 'authenticated'::text));


--
-- Name: frigate_reviews Users can update frigate_reviews; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can update frigate_reviews" ON public.frigate_reviews FOR UPDATE USING ((auth.role() = 'authenticated'::text));


--
-- Name: subscribers Users can update their own subscription; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can update their own subscription" ON public.subscribers FOR UPDATE USING ((user_id = auth.uid()));


--
-- Name: subscribers Users can update their own subscriptions; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can update their own subscriptions" ON public.subscribers FOR UPDATE USING ((user_id = auth.uid())) WITH CHECK ((user_id = auth.uid()));


--
-- Name: ai_analysis_logs Users can view AI analysis logs in their org; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view AI analysis logs in their org" ON public.ai_analysis_logs FOR SELECT USING ((EXISTS ( SELECT 1
   FROM ((public.cameras c
     JOIN public.branches b ON ((c.branch_id = b.id)))
     JOIN public.user_roles ur ON ((ur.organization_id = b.organization_id)))
  WHERE ((c.id = ai_analysis_logs.camera_id) AND (ur.user_id = auth.uid())))));


--
-- Name: ai_models Users can view AI models in their organization; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view AI models in their organization" ON public.ai_models FOR SELECT USING ((EXISTS ( SELECT 1
   FROM public.user_roles ur
  WHERE ((ur.user_id = auth.uid()) AND (ur.organization_id IS NOT NULL)))));


--
-- Name: aman_instances Users can view Aman instances in their organization; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view Aman instances in their organization" ON public.aman_instances FOR SELECT USING ((EXISTS ( SELECT 1
   FROM public.user_roles ur
  WHERE ((ur.user_id = auth.uid()) AND (ur.organization_id = aman_instances.organization_id)))));


--
-- Name: notification_labels Users can view active notification labels; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view active notification labels" ON public.notification_labels FOR SELECT USING ((is_active = true));


--
-- Name: workflow_forms Users can view active workflow forms; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view active workflow forms" ON public.workflow_forms FOR SELECT USING ((is_active = true));


--
-- Name: frigate_alert_rules Users can view alert rules in their organization cameras; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view alert rules in their organization cameras" ON public.frigate_alert_rules FOR SELECT USING ((EXISTS ( SELECT 1
   FROM ((public.cameras c
     JOIN public.branches b ON ((c.branch_id = b.id)))
     JOIN public.user_roles ur ON ((ur.organization_id = b.organization_id)))
  WHERE ((c.id = frigate_alert_rules.camera_id) AND (ur.user_id = auth.uid())))));


--
-- Name: alert_template_events Users can view alert template events; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view alert template events" ON public.alert_template_events FOR SELECT TO authenticated USING (true);


--
-- Name: alert_template_industries Users can view alert template industries in their organization; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view alert template industries in their organization" ON public.alert_template_industries FOR SELECT USING ((EXISTS ( SELECT 1
   FROM (public.user_roles ur
     JOIN public.organizations o ON ((o.id = ur.organization_id)))
  WHERE ((ur.user_id = auth.uid()) AND (o.industry_id = alert_template_industries.industry_id)))));


--
-- Name: alert_templates Users can view alert templates for their industry; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view alert templates for their industry" ON public.alert_templates FOR SELECT USING ((public.is_current_user_super_admin() OR (EXISTS ( SELECT 1
   FROM ((public.alert_template_industries ati
     JOIN public.user_roles ur ON ((ur.user_id = auth.uid())))
     JOIN public.organizations o ON ((o.id = ur.organization_id)))
  WHERE ((ati.alert_template_id = alert_templates.id) AND (ati.industry_id = o.industry_id))))));


--
-- Name: frigate_exports Users can view all frigate_exports; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view all frigate_exports" ON public.frigate_exports FOR SELECT USING ((auth.role() = 'authenticated'::text));


--
-- Name: frigate_previews Users can view all frigate_previews; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view all frigate_previews" ON public.frigate_previews FOR SELECT USING ((auth.role() = 'authenticated'::text));


--
-- Name: frigate_recordings Users can view all frigate_recordings; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view all frigate_recordings" ON public.frigate_recordings FOR SELECT USING ((auth.role() = 'authenticated'::text));


--
-- Name: frigate_reviews Users can view all frigate_reviews; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view all frigate_reviews" ON public.frigate_reviews FOR SELECT USING ((auth.role() = 'authenticated'::text));


--
-- Name: industries Users can view all industries; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view all industries" ON public.industries FOR SELECT USING (true);


--
-- Name: branches Users can view branches in their organization; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view branches in their organization" ON public.branches FOR SELECT USING ((public.is_current_user_super_admin() OR (EXISTS ( SELECT 1
   FROM public.user_roles ur
  WHERE ((ur.user_id = auth.uid()) AND (ur.organization_id = branches.organization_id)))) OR (EXISTS ( SELECT 1
   FROM public.user_branch_access uba
  WHERE ((uba.user_id = auth.uid()) AND (uba.branch_id = branches.id))))));


--
-- Name: camera_alert_assignments Users can view camera alert assignments in their organization; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view camera alert assignments in their organization" ON public.camera_alert_assignments FOR SELECT TO authenticated USING ((EXISTS ( SELECT 1
   FROM ((public.cameras c
     JOIN public.branches b ON ((c.branch_id = b.id)))
     JOIN public.user_roles ur ON ((ur.organization_id = b.organization_id)))
  WHERE ((c.id = camera_alert_assignments.camera_id) AND (ur.user_id = auth.uid())))));


--
-- Name: camera_event_assignments Users can view camera event assignments in their organization; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view camera event assignments in their organization" ON public.camera_event_assignments FOR SELECT TO authenticated USING ((EXISTS ( SELECT 1
   FROM ((public.cameras c
     JOIN public.branches b ON ((c.branch_id = b.id)))
     JOIN public.user_roles ur ON ((ur.organization_id = b.organization_id)))
  WHERE ((c.id = camera_event_assignments.camera_id) AND (ur.user_id = auth.uid())))));


--
-- Name: camera_sources Users can view camera sources; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view camera sources" ON public.camera_sources FOR SELECT USING (((auth.role() = 'authenticated'::text) AND (active = true)));


--
-- Name: cameras Users can view cameras in their organization; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view cameras in their organization" ON public.cameras FOR SELECT TO authenticated USING ((public.is_current_user_super_admin() OR (EXISTS ( SELECT 1
   FROM (public.branches b
     JOIN public.user_roles ur ON ((ur.organization_id = b.organization_id)))
  WHERE ((b.id = cameras.branch_id) AND (ur.user_id = auth.uid()))))));


--
-- Name: detection_rules Users can view detection rules in their organization; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view detection rules in their organization" ON public.detection_rules FOR SELECT USING ((EXISTS ( SELECT 1
   FROM public.user_roles ur
  WHERE ((ur.user_id = auth.uid()) AND (ur.organization_id = detection_rules.organization_id)))));


--
-- Name: event_types Users can view event types; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view event types" ON public.event_types FOR SELECT TO authenticated USING ((enabled = true));


--
-- Name: events Users can view events in their organization; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view events in their organization" ON public.events FOR SELECT USING ((EXISTS ( SELECT 1
   FROM (((public.user_roles ur
     JOIN public.cameras c ON ((events.camera_id = c.id)))
     JOIN public.branches b ON ((c.branch_id = b.id)))
     JOIN public.organizations o ON ((b.organization_id = o.id)))
  WHERE ((ur.user_id = auth.uid()) AND (ur.organization_id = o.id)))));


--
-- Name: frigate_faces Users can view faces in their organization cameras; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view faces in their organization cameras" ON public.frigate_faces FOR SELECT USING ((EXISTS ( SELECT 1
   FROM ((public.cameras c
     JOIN public.branches b ON ((c.branch_id = b.id)))
     JOIN public.user_roles ur ON ((ur.organization_id = b.organization_id)))
  WHERE ((c.id = frigate_faces.camera_id) AND (ur.user_id = auth.uid())))));


--
-- Name: form_distribution_settings Users can view form distribution in their organization; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view form distribution in their organization" ON public.form_distribution_settings FOR SELECT USING ((EXISTS ( SELECT 1
   FROM public.workflow_forms wf
  WHERE (wf.id = form_distribution_settings.workflow_form_id))));


--
-- Name: frigate_instances Users can view frigate instances in their organization; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view frigate instances in their organization" ON public.frigate_instances FOR SELECT USING ((EXISTS ( SELECT 1
   FROM (public.branches b
     JOIN public.user_roles ur ON ((ur.organization_id = b.organization_id)))
  WHERE ((b.id = frigate_instances.branch_id) AND (ur.user_id = auth.uid())))));


--
-- Name: user_group_members Users can view group members in their organization; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view group members in their organization" ON public.user_group_members FOR SELECT USING ((EXISTS ( SELECT 1
   FROM (public.user_groups ug
     JOIN public.user_roles ur ON ((ur.organization_id = ug.organization_id)))
  WHERE ((ug.id = user_group_members.group_id) AND (ur.user_id = auth.uid())))));


--
-- Name: user_groups Users can view groups in their organization; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view groups in their organization" ON public.user_groups FOR SELECT USING ((EXISTS ( SELECT 1
   FROM public.user_roles ur
  WHERE ((ur.user_id = auth.uid()) AND (ur.organization_id = user_groups.organization_id)))));


--
-- Name: frigate_license_plates Users can view license plates in their organization cameras; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view license plates in their organization cameras" ON public.frigate_license_plates FOR SELECT USING ((EXISTS ( SELECT 1
   FROM ((public.cameras c
     JOIN public.branches b ON ((c.branch_id = b.id)))
     JOIN public.user_roles ur ON ((ur.organization_id = b.organization_id)))
  WHERE ((c.id = frigate_license_plates.camera_id) AND (ur.user_id = auth.uid())))));


--
-- Name: notification_methods Users can view notification methods; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view notification methods" ON public.notification_methods FOR SELECT USING ((enabled = true));


--
-- Name: security_zones Users can view security zones in their organization; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view security zones in their organization" ON public.security_zones FOR SELECT USING ((public.is_current_user_super_admin() OR (EXISTS ( SELECT 1
   FROM (public.user_roles ur
     JOIN public.branches b ON ((security_zones.branch_id = b.id)))
  WHERE ((ur.user_id = auth.uid()) AND (ur.organization_id = b.organization_id)))) OR (EXISTS ( SELECT 1
   FROM public.user_branch_access uba
  WHERE ((uba.user_id = auth.uid()) AND (uba.branch_id = security_zones.branch_id))))));


--
-- Name: organizations Users can view their organization; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view their organization" ON public.organizations FOR SELECT USING ((public.is_current_user_super_admin() OR (EXISTS ( SELECT 1
   FROM public.user_roles
  WHERE ((user_roles.user_id = auth.uid()) AND (user_roles.organization_id = organizations.id))))));


--
-- Name: user_branch_access Users can view their own branch access; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view their own branch access" ON public.user_branch_access FOR SELECT USING ((user_id = auth.uid()));


--
-- Name: branch_roles Users can view their own branch roles; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view their own branch roles" ON public.branch_roles FOR SELECT USING ((user_id = auth.uid()));


--
-- Name: user_roles Users can view their own roles; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view their own roles" ON public.user_roles FOR SELECT USING ((user_id = auth.uid()));


--
-- Name: network_scan_results Users can view their own scan results; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view their own scan results" ON public.network_scan_results FOR SELECT USING ((user_id = auth.uid()));


--
-- Name: subscribers Users can view their own subscription; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view their own subscription" ON public.subscribers FOR SELECT USING ((user_id = auth.uid()));


--
-- Name: subscribers Users can view their own subscriptions; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view their own subscriptions" ON public.subscribers FOR SELECT USING ((user_id = auth.uid()));


--
-- Name: frigate_timeline Users can view timeline in their organization cameras; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view timeline in their organization cameras" ON public.frigate_timeline FOR SELECT USING ((EXISTS ( SELECT 1
   FROM ((public.cameras c
     JOIN public.branches b ON ((c.branch_id = b.id)))
     JOIN public.user_roles ur ON ((ur.organization_id = b.organization_id)))
  WHERE ((c.id = frigate_timeline.camera_id) AND (ur.user_id = auth.uid())))));


--
-- Name: frigate_zones Users can view zones in their organization cameras; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users can view zones in their organization cameras" ON public.frigate_zones FOR SELECT USING ((EXISTS ( SELECT 1
   FROM ((public.cameras c
     JOIN public.branches b ON ((c.branch_id = b.id)))
     JOIN public.user_roles ur ON ((ur.organization_id = b.organization_id)))
  WHERE ((c.id = frigate_zones.camera_id) AND (ur.user_id = auth.uid())))));


--
-- Name: cameras Users with admin/manager role can insert cameras; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY "Users with admin/manager role can insert cameras" ON public.cameras FOR INSERT TO authenticated WITH CHECK ((public.is_current_user_super_admin() OR (EXISTS ( SELECT 1
   FROM (public.user_roles ur
     JOIN public.branches b ON ((b.organization_id = ur.organization_id)))
  WHERE ((ur.user_id = auth.uid()) AND (ur.role = ANY (ARRAY['admin'::public.user_role, 'manager'::public.user_role])) AND (b.id = cameras.branch_id))))));


--
-- Name: aman_instances aman_delete_org; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY aman_delete_org ON public.aman_instances FOR DELETE TO authenticated USING ((organization_id IN ( SELECT user_roles.organization_id
   FROM public.user_roles
  WHERE ((user_roles.user_id = auth.uid()) AND (user_roles.role = ANY (ARRAY['admin'::public.user_role, 'manager'::public.user_role]))))));


--
-- Name: aman_instances aman_delete_super; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY aman_delete_super ON public.aman_instances FOR DELETE TO authenticated USING ((EXISTS ( SELECT 1
   FROM public.user_roles
  WHERE ((user_roles.user_id = auth.uid()) AND (user_roles.role = 'super_admin'::public.user_role)))));


--
-- Name: aman_instances aman_insert_org; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY aman_insert_org ON public.aman_instances FOR INSERT TO authenticated WITH CHECK ((organization_id IN ( SELECT user_roles.organization_id
   FROM public.user_roles
  WHERE ((user_roles.user_id = auth.uid()) AND (user_roles.role = ANY (ARRAY['admin'::public.user_role, 'manager'::public.user_role]))))));


--
-- Name: aman_instances aman_insert_super; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY aman_insert_super ON public.aman_instances FOR INSERT TO authenticated WITH CHECK ((EXISTS ( SELECT 1
   FROM public.user_roles
  WHERE ((user_roles.user_id = auth.uid()) AND (user_roles.role = 'super_admin'::public.user_role)))));


--
-- Name: aman_instances aman_update_org; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY aman_update_org ON public.aman_instances FOR UPDATE TO authenticated USING ((organization_id IN ( SELECT user_roles.organization_id
   FROM public.user_roles
  WHERE ((user_roles.user_id = auth.uid()) AND (user_roles.role = ANY (ARRAY['admin'::public.user_role, 'manager'::public.user_role]))))));


--
-- Name: aman_instances aman_update_super; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY aman_update_super ON public.aman_instances FOR UPDATE TO authenticated USING ((EXISTS ( SELECT 1
   FROM public.user_roles
  WHERE ((user_roles.user_id = auth.uid()) AND (user_roles.role = 'super_admin'::public.user_role)))));


--
-- Name: aman_instances aman_view_org_admin; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY aman_view_org_admin ON public.aman_instances FOR SELECT TO authenticated USING ((organization_id IN ( SELECT user_roles.organization_id
   FROM public.user_roles
  WHERE ((user_roles.user_id = auth.uid()) AND (user_roles.role = ANY (ARRAY['admin'::public.user_role, 'manager'::public.user_role]))))));


--
-- Name: aman_instances aman_view_rep; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY aman_view_rep ON public.aman_instances FOR SELECT TO authenticated USING ((branch_id IN ( SELECT aman_instances.branch_id
   FROM public.user_roles
  WHERE ((user_roles.user_id = auth.uid()) AND (user_roles.role = 'representative'::public.user_role)))));


--
-- Name: aman_instances aman_view_super_admin; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY aman_view_super_admin ON public.aman_instances FOR SELECT TO authenticated USING ((EXISTS ( SELECT 1
   FROM public.user_roles
  WHERE ((user_roles.user_id = auth.uid()) AND (user_roles.role = 'super_admin'::public.user_role)))));


--
-- Name: auto_sync_settings autosync_update; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY autosync_update ON public.auto_sync_settings FOR UPDATE USING (public.is_current_user_super_admin());


--
-- Name: auto_sync_settings autosync_view; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY autosync_view ON public.auto_sync_settings FOR SELECT USING (public.is_current_user_super_admin());


--
-- Name: frigate_deployed_models; Type: ROW SECURITY; Schema: public; Owner: postgres
--

ALTER TABLE public.frigate_deployed_models ENABLE ROW LEVEL SECURITY;

--
-- Name: frigate_deployed_models frigate_deployed_models_all; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY frigate_deployed_models_all ON public.frigate_deployed_models USING (true) WITH CHECK (true);


--
-- Name: frigate_model_deployments; Type: ROW SECURITY; Schema: public; Owner: postgres
--

ALTER TABLE public.frigate_model_deployments ENABLE ROW LEVEL SECURITY;

--
-- Name: frigate_model_deployments frigate_model_deployments_all; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY frigate_model_deployments_all ON public.frigate_model_deployments USING (true) WITH CHECK (true);


--
-- Name: frigate_model_registry; Type: ROW SECURITY; Schema: public; Owner: postgres
--

ALTER TABLE public.frigate_model_registry ENABLE ROW LEVEL SECURITY;

--
-- Name: frigate_model_registry frigate_model_registry_all; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY frigate_model_registry_all ON public.frigate_model_registry USING (true) WITH CHECK (true);


--
-- Name: frigate_model_sync_log; Type: ROW SECURITY; Schema: public; Owner: postgres
--

ALTER TABLE public.frigate_model_sync_log ENABLE ROW LEVEL SECURITY;

--
-- Name: frigate_model_sync_log frigate_model_sync_log_all; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY frigate_model_sync_log_all ON public.frigate_model_sync_log USING (true) WITH CHECK (true);


--
-- Name: frigate_stats_history; Type: ROW SECURITY; Schema: public; Owner: postgres
--

ALTER TABLE public.frigate_stats_history ENABLE ROW LEVEL SECURITY;

--
-- Name: frigate_stats_history frigate_stats_history_all; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY frigate_stats_history_all ON public.frigate_stats_history USING (true) WITH CHECK (true);


--
-- Name: frigate_sync_logs; Type: ROW SECURITY; Schema: public; Owner: postgres
--

ALTER TABLE public.frigate_sync_logs ENABLE ROW LEVEL SECURITY;

--
-- Name: frigate_sync_logs frigate_sync_logs_all; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY frigate_sync_logs_all ON public.frigate_sync_logs USING (true) WITH CHECK (true);


--
-- Name: frigate_triggers; Type: ROW SECURITY; Schema: public; Owner: postgres
--

ALTER TABLE public.frigate_triggers ENABLE ROW LEVEL SECURITY;

--
-- Name: frigate_triggers frigate_triggers_all; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY frigate_triggers_all ON public.frigate_triggers USING (true) WITH CHECK (true);


--
-- Name: organization_settings org_settings_manage; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY org_settings_manage ON public.organization_settings USING ((public.is_current_user_super_admin() OR (organization_id IN ( SELECT user_roles.organization_id
   FROM public.user_roles
  WHERE ((user_roles.user_id = auth.uid()) AND (user_roles.role = ANY (ARRAY['admin'::public.user_role, 'manager'::public.user_role]))))))) WITH CHECK ((public.is_current_user_super_admin() OR (organization_id IN ( SELECT user_roles.organization_id
   FROM public.user_roles
  WHERE ((user_roles.user_id = auth.uid()) AND (user_roles.role = ANY (ARRAY['admin'::public.user_role, 'manager'::public.user_role])))))));


--
-- Name: organization_settings org_settings_view; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY org_settings_view ON public.organization_settings FOR SELECT USING ((public.is_current_user_super_admin() OR (organization_id IN ( SELECT user_roles.organization_id
   FROM public.user_roles
  WHERE (user_roles.user_id = auth.uid())))));


--
-- Name: system_settings super_admin_system_settings_policy; Type: POLICY; Schema: public; Owner: postgres
--

CREATE POLICY super_admin_system_settings_policy ON public.system_settings TO authenticated USING (public.is_current_user_super_admin());


--
-- Name: messages; Type: ROW SECURITY; Schema: realtime; Owner: supabase_realtime_admin
--

ALTER TABLE realtime.messages ENABLE ROW LEVEL SECURITY;

--
-- Name: objects Anyone can view form logos; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY "Anyone can view form logos" ON storage.objects FOR SELECT USING ((bucket_id = 'form-logos'::text));


--
-- Name: objects Authenticated users can delete model-files; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY "Authenticated users can delete model-files" ON storage.objects FOR DELETE TO authenticated USING ((bucket_id = 'model-files'::text));


--
-- Name: objects Authenticated users can update model-files; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY "Authenticated users can update model-files" ON storage.objects FOR UPDATE TO authenticated USING ((bucket_id = 'model-files'::text)) WITH CHECK ((bucket_id = 'model-files'::text));


--
-- Name: objects Authenticated users can upload form logos; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY "Authenticated users can upload form logos" ON storage.objects FOR INSERT WITH CHECK (((bucket_id = 'form-logos'::text) AND (auth.role() = 'authenticated'::text)));


--
-- Name: objects Authenticated users can upload to model-files; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY "Authenticated users can upload to model-files" ON storage.objects FOR INSERT TO authenticated WITH CHECK ((bucket_id = 'model-files'::text));


--
-- Name: objects Enable delete for authenticated users on model files; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY "Enable delete for authenticated users on model files" ON storage.objects FOR DELETE TO authenticated USING ((bucket_id = 'model-files'::text));


--
-- Name: objects Enable delete for authenticated users on test uploads; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY "Enable delete for authenticated users on test uploads" ON storage.objects FOR DELETE TO authenticated USING ((bucket_id = 'test-uploads'::text));


--
-- Name: objects Enable read for all users on model files; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY "Enable read for all users on model files" ON storage.objects FOR SELECT USING ((bucket_id = 'model-files'::text));


--
-- Name: objects Enable read for all users on test uploads; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY "Enable read for all users on test uploads" ON storage.objects FOR SELECT USING ((bucket_id = 'test-uploads'::text));


--
-- Name: objects Enable update for authenticated users on model files; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY "Enable update for authenticated users on model files" ON storage.objects FOR UPDATE TO authenticated USING ((bucket_id = 'model-files'::text)) WITH CHECK ((bucket_id = 'model-files'::text));


--
-- Name: objects Enable update for authenticated users on test uploads; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY "Enable update for authenticated users on test uploads" ON storage.objects FOR UPDATE TO authenticated USING ((bucket_id = 'test-uploads'::text)) WITH CHECK ((bucket_id = 'test-uploads'::text));


--
-- Name: objects Enable upload for authenticated users on model files; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY "Enable upload for authenticated users on model files" ON storage.objects FOR INSERT TO authenticated WITH CHECK ((bucket_id = 'model-files'::text));


--
-- Name: objects Enable upload for authenticated users on test uploads; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY "Enable upload for authenticated users on test uploads" ON storage.objects FOR INSERT TO authenticated WITH CHECK ((bucket_id = 'test-uploads'::text));


--
-- Name: objects Public can read model-files; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY "Public can read model-files" ON storage.objects FOR SELECT USING ((bucket_id = 'model-files'::text));


--
-- Name: objects Public can view form attachments; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY "Public can view form attachments" ON storage.objects FOR SELECT USING ((bucket_id = 'form-attachments'::text));


--
-- Name: objects Super admin can manage model files; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY "Super admin can manage model files" ON storage.objects TO authenticated USING (((bucket_id = 'model-files'::text) AND public.is_current_user_super_admin()));


--
-- Name: objects Users can delete their form logos; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY "Users can delete their form logos" ON storage.objects FOR DELETE USING (((bucket_id = 'form-logos'::text) AND (auth.role() = 'authenticated'::text)));


--
-- Name: objects Users can delete their own files (form-attachments); Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY "Users can delete their own files (form-attachments)" ON storage.objects FOR DELETE USING (((bucket_id = 'form-attachments'::text) AND ((auth.uid())::text = (storage.foldername(name))[1])));


--
-- Name: objects Users can update their form logos; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY "Users can update their form logos" ON storage.objects FOR UPDATE USING (((bucket_id = 'form-logos'::text) AND (auth.role() = 'authenticated'::text)));


--
-- Name: objects Users can update their own files (form-attachments); Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY "Users can update their own files (form-attachments)" ON storage.objects FOR UPDATE USING (((bucket_id = 'form-attachments'::text) AND ((auth.uid())::text = (storage.foldername(name))[1])));


--
-- Name: objects Users can upload to their folder (form-attachments); Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY "Users can upload to their folder (form-attachments)" ON storage.objects FOR INSERT WITH CHECK (((bucket_id = 'form-attachments'::text) AND ((auth.uid())::text = (storage.foldername(name))[1])));


--
-- Name: objects Users can view model files; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY "Users can view model files" ON storage.objects FOR SELECT TO authenticated USING ((bucket_id = 'model-files'::text));


--
-- Name: buckets; Type: ROW SECURITY; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE storage.buckets ENABLE ROW LEVEL SECURITY;

--
-- Name: buckets_analytics; Type: ROW SECURITY; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE storage.buckets_analytics ENABLE ROW LEVEL SECURITY;

--
-- Name: buckets_vectors; Type: ROW SECURITY; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE storage.buckets_vectors ENABLE ROW LEVEL SECURITY;

--
-- Name: objects frigate_models_delete; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY frigate_models_delete ON storage.objects FOR DELETE USING ((bucket_id = 'frigate-models'::text));


--
-- Name: objects frigate_models_insert; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY frigate_models_insert ON storage.objects FOR INSERT WITH CHECK ((bucket_id = 'frigate-models'::text));


--
-- Name: objects frigate_models_select; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY frigate_models_select ON storage.objects FOR SELECT USING ((bucket_id = 'frigate-models'::text));


--
-- Name: objects frigate_models_update; Type: POLICY; Schema: storage; Owner: supabase_storage_admin
--

CREATE POLICY frigate_models_update ON storage.objects FOR UPDATE USING ((bucket_id = 'frigate-models'::text));


--
-- Name: iceberg_namespaces; Type: ROW SECURITY; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE storage.iceberg_namespaces ENABLE ROW LEVEL SECURITY;

--
-- Name: iceberg_tables; Type: ROW SECURITY; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE storage.iceberg_tables ENABLE ROW LEVEL SECURITY;

--
-- Name: migrations; Type: ROW SECURITY; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE storage.migrations ENABLE ROW LEVEL SECURITY;

--
-- Name: objects; Type: ROW SECURITY; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE storage.objects ENABLE ROW LEVEL SECURITY;

--
-- Name: s3_multipart_uploads; Type: ROW SECURITY; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE storage.s3_multipart_uploads ENABLE ROW LEVEL SECURITY;

--
-- Name: s3_multipart_uploads_parts; Type: ROW SECURITY; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE storage.s3_multipart_uploads_parts ENABLE ROW LEVEL SECURITY;

--
-- Name: vector_indexes; Type: ROW SECURITY; Schema: storage; Owner: supabase_storage_admin
--

ALTER TABLE storage.vector_indexes ENABLE ROW LEVEL SECURITY;

--
-- Name: supabase_realtime; Type: PUBLICATION; Schema: -; Owner: postgres
--

CREATE PUBLICATION supabase_realtime WITH (publish = 'insert, update, delete, truncate');


ALTER PUBLICATION supabase_realtime OWNER TO postgres;

--
-- Name: supabase_realtime_messages_publication; Type: PUBLICATION; Schema: -; Owner: supabase_admin
--

CREATE PUBLICATION supabase_realtime_messages_publication WITH (publish = 'insert, update, delete, truncate');


ALTER PUBLICATION supabase_realtime_messages_publication OWNER TO supabase_admin;

--
-- Name: supabase_realtime aman_instances; Type: PUBLICATION TABLE; Schema: public; Owner: postgres
--

ALTER PUBLICATION supabase_realtime ADD TABLE ONLY public.aman_instances;


--
-- Name: supabase_realtime branches; Type: PUBLICATION TABLE; Schema: public; Owner: postgres
--

ALTER PUBLICATION supabase_realtime ADD TABLE ONLY public.branches;


--
-- Name: supabase_realtime events; Type: PUBLICATION TABLE; Schema: public; Owner: postgres
--

ALTER PUBLICATION supabase_realtime ADD TABLE ONLY public.events;


--
-- Name: supabase_realtime health_alerts; Type: PUBLICATION TABLE; Schema: public; Owner: postgres
--

ALTER PUBLICATION supabase_realtime ADD TABLE ONLY public.health_alerts;


--
-- Name: supabase_realtime_messages_publication messages; Type: PUBLICATION TABLE; Schema: realtime; Owner: supabase_admin
--

ALTER PUBLICATION supabase_realtime_messages_publication ADD TABLE ONLY realtime.messages;


--
-- Name: SCHEMA auth; Type: ACL; Schema: -; Owner: supabase_admin
--

GRANT USAGE ON SCHEMA auth TO anon;
GRANT USAGE ON SCHEMA auth TO authenticated;
GRANT USAGE ON SCHEMA auth TO service_role;
GRANT ALL ON SCHEMA auth TO supabase_auth_admin;
GRANT ALL ON SCHEMA auth TO dashboard_user;
GRANT USAGE ON SCHEMA auth TO postgres;


--
-- Name: SCHEMA extensions; Type: ACL; Schema: -; Owner: postgres
--

GRANT USAGE ON SCHEMA extensions TO anon;
GRANT USAGE ON SCHEMA extensions TO authenticated;
GRANT USAGE ON SCHEMA extensions TO service_role;
GRANT ALL ON SCHEMA extensions TO dashboard_user;


--
-- Name: SCHEMA net; Type: ACL; Schema: -; Owner: supabase_admin
--

GRANT USAGE ON SCHEMA net TO supabase_functions_admin;
GRANT USAGE ON SCHEMA net TO postgres;
GRANT USAGE ON SCHEMA net TO anon;
GRANT USAGE ON SCHEMA net TO authenticated;
GRANT USAGE ON SCHEMA net TO service_role;


--
-- Name: SCHEMA public; Type: ACL; Schema: -; Owner: pg_database_owner
--

GRANT USAGE ON SCHEMA public TO postgres;
GRANT USAGE ON SCHEMA public TO anon;
GRANT USAGE ON SCHEMA public TO authenticated;
GRANT USAGE ON SCHEMA public TO service_role;


--
-- Name: SCHEMA realtime; Type: ACL; Schema: -; Owner: supabase_admin
--

GRANT USAGE ON SCHEMA realtime TO postgres;
GRANT USAGE ON SCHEMA realtime TO anon;
GRANT USAGE ON SCHEMA realtime TO authenticated;
GRANT USAGE ON SCHEMA realtime TO service_role;
GRANT ALL ON SCHEMA realtime TO supabase_realtime_admin;


--
-- Name: SCHEMA storage; Type: ACL; Schema: -; Owner: supabase_admin
--

GRANT USAGE ON SCHEMA storage TO postgres WITH GRANT OPTION;
GRANT USAGE ON SCHEMA storage TO anon;
GRANT USAGE ON SCHEMA storage TO authenticated;
GRANT USAGE ON SCHEMA storage TO service_role;
GRANT ALL ON SCHEMA storage TO supabase_storage_admin WITH GRANT OPTION;
GRANT ALL ON SCHEMA storage TO dashboard_user;


--
-- Name: SCHEMA supabase_functions; Type: ACL; Schema: -; Owner: supabase_admin
--

GRANT USAGE ON SCHEMA supabase_functions TO postgres;
GRANT USAGE ON SCHEMA supabase_functions TO anon;
GRANT USAGE ON SCHEMA supabase_functions TO authenticated;
GRANT USAGE ON SCHEMA supabase_functions TO service_role;
GRANT ALL ON SCHEMA supabase_functions TO supabase_functions_admin;


--
-- Name: SCHEMA vault; Type: ACL; Schema: -; Owner: supabase_admin
--

GRANT USAGE ON SCHEMA vault TO postgres WITH GRANT OPTION;
GRANT USAGE ON SCHEMA vault TO service_role;


--
-- Name: FUNCTION email(); Type: ACL; Schema: auth; Owner: supabase_auth_admin
--

GRANT ALL ON FUNCTION auth.email() TO dashboard_user;


--
-- Name: FUNCTION jwt(); Type: ACL; Schema: auth; Owner: supabase_auth_admin
--

GRANT ALL ON FUNCTION auth.jwt() TO postgres;
GRANT ALL ON FUNCTION auth.jwt() TO dashboard_user;


--
-- Name: FUNCTION role(); Type: ACL; Schema: auth; Owner: supabase_auth_admin
--

GRANT ALL ON FUNCTION auth.role() TO dashboard_user;


--
-- Name: FUNCTION uid(); Type: ACL; Schema: auth; Owner: supabase_auth_admin
--

GRANT ALL ON FUNCTION auth.uid() TO dashboard_user;


--
-- Name: FUNCTION armor(bytea); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.armor(bytea) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.armor(bytea) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION armor(bytea, text[], text[]); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.armor(bytea, text[], text[]) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.armor(bytea, text[], text[]) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION crypt(text, text); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.crypt(text, text) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.crypt(text, text) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION dearmor(text); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.dearmor(text) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.dearmor(text) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION decrypt(bytea, bytea, text); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.decrypt(bytea, bytea, text) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.decrypt(bytea, bytea, text) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION decrypt_iv(bytea, bytea, bytea, text); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.decrypt_iv(bytea, bytea, bytea, text) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.decrypt_iv(bytea, bytea, bytea, text) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION digest(bytea, text); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.digest(bytea, text) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.digest(bytea, text) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION digest(text, text); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.digest(text, text) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.digest(text, text) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION encrypt(bytea, bytea, text); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.encrypt(bytea, bytea, text) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.encrypt(bytea, bytea, text) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION encrypt_iv(bytea, bytea, bytea, text); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.encrypt_iv(bytea, bytea, bytea, text) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.encrypt_iv(bytea, bytea, bytea, text) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION gen_random_bytes(integer); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.gen_random_bytes(integer) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.gen_random_bytes(integer) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION gen_random_uuid(); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.gen_random_uuid() TO dashboard_user;
GRANT ALL ON FUNCTION extensions.gen_random_uuid() TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION gen_salt(text); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.gen_salt(text) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.gen_salt(text) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION gen_salt(text, integer); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.gen_salt(text, integer) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.gen_salt(text, integer) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION grant_pg_cron_access(); Type: ACL; Schema: extensions; Owner: supabase_admin
--

REVOKE ALL ON FUNCTION extensions.grant_pg_cron_access() FROM supabase_admin;
GRANT ALL ON FUNCTION extensions.grant_pg_cron_access() TO supabase_admin WITH GRANT OPTION;
GRANT ALL ON FUNCTION extensions.grant_pg_cron_access() TO dashboard_user;


--
-- Name: FUNCTION grant_pg_graphql_access(); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.grant_pg_graphql_access() TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION grant_pg_net_access(); Type: ACL; Schema: extensions; Owner: supabase_admin
--

REVOKE ALL ON FUNCTION extensions.grant_pg_net_access() FROM supabase_admin;
GRANT ALL ON FUNCTION extensions.grant_pg_net_access() TO supabase_admin WITH GRANT OPTION;
GRANT ALL ON FUNCTION extensions.grant_pg_net_access() TO dashboard_user;


--
-- Name: FUNCTION hmac(bytea, bytea, text); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.hmac(bytea, bytea, text) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.hmac(bytea, bytea, text) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION hmac(text, text, text); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.hmac(text, text, text) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.hmac(text, text, text) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION pg_stat_statements(showtext boolean, OUT userid oid, OUT dbid oid, OUT toplevel boolean, OUT queryid bigint, OUT query text, OUT plans bigint, OUT total_plan_time double precision, OUT min_plan_time double precision, OUT max_plan_time double precision, OUT mean_plan_time double precision, OUT stddev_plan_time double precision, OUT calls bigint, OUT total_exec_time double precision, OUT min_exec_time double precision, OUT max_exec_time double precision, OUT mean_exec_time double precision, OUT stddev_exec_time double precision, OUT rows bigint, OUT shared_blks_hit bigint, OUT shared_blks_read bigint, OUT shared_blks_dirtied bigint, OUT shared_blks_written bigint, OUT local_blks_hit bigint, OUT local_blks_read bigint, OUT local_blks_dirtied bigint, OUT local_blks_written bigint, OUT temp_blks_read bigint, OUT temp_blks_written bigint, OUT shared_blk_read_time double precision, OUT shared_blk_write_time double precision, OUT local_blk_read_time double precision, OUT local_blk_write_time double precision, OUT temp_blk_read_time double precision, OUT temp_blk_write_time double precision, OUT wal_records bigint, OUT wal_fpi bigint, OUT wal_bytes numeric, OUT jit_functions bigint, OUT jit_generation_time double precision, OUT jit_inlining_count bigint, OUT jit_inlining_time double precision, OUT jit_optimization_count bigint, OUT jit_optimization_time double precision, OUT jit_emission_count bigint, OUT jit_emission_time double precision, OUT jit_deform_count bigint, OUT jit_deform_time double precision, OUT stats_since timestamp with time zone, OUT minmax_stats_since timestamp with time zone); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.pg_stat_statements(showtext boolean, OUT userid oid, OUT dbid oid, OUT toplevel boolean, OUT queryid bigint, OUT query text, OUT plans bigint, OUT total_plan_time double precision, OUT min_plan_time double precision, OUT max_plan_time double precision, OUT mean_plan_time double precision, OUT stddev_plan_time double precision, OUT calls bigint, OUT total_exec_time double precision, OUT min_exec_time double precision, OUT max_exec_time double precision, OUT mean_exec_time double precision, OUT stddev_exec_time double precision, OUT rows bigint, OUT shared_blks_hit bigint, OUT shared_blks_read bigint, OUT shared_blks_dirtied bigint, OUT shared_blks_written bigint, OUT local_blks_hit bigint, OUT local_blks_read bigint, OUT local_blks_dirtied bigint, OUT local_blks_written bigint, OUT temp_blks_read bigint, OUT temp_blks_written bigint, OUT shared_blk_read_time double precision, OUT shared_blk_write_time double precision, OUT local_blk_read_time double precision, OUT local_blk_write_time double precision, OUT temp_blk_read_time double precision, OUT temp_blk_write_time double precision, OUT wal_records bigint, OUT wal_fpi bigint, OUT wal_bytes numeric, OUT jit_functions bigint, OUT jit_generation_time double precision, OUT jit_inlining_count bigint, OUT jit_inlining_time double precision, OUT jit_optimization_count bigint, OUT jit_optimization_time double precision, OUT jit_emission_count bigint, OUT jit_emission_time double precision, OUT jit_deform_count bigint, OUT jit_deform_time double precision, OUT stats_since timestamp with time zone, OUT minmax_stats_since timestamp with time zone) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION pg_stat_statements_info(OUT dealloc bigint, OUT stats_reset timestamp with time zone); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.pg_stat_statements_info(OUT dealloc bigint, OUT stats_reset timestamp with time zone) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION pg_stat_statements_reset(userid oid, dbid oid, queryid bigint, minmax_only boolean); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.pg_stat_statements_reset(userid oid, dbid oid, queryid bigint, minmax_only boolean) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION pgp_armor_headers(text, OUT key text, OUT value text); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.pgp_armor_headers(text, OUT key text, OUT value text) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.pgp_armor_headers(text, OUT key text, OUT value text) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION pgp_key_id(bytea); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.pgp_key_id(bytea) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.pgp_key_id(bytea) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION pgp_pub_decrypt(bytea, bytea); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.pgp_pub_decrypt(bytea, bytea) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.pgp_pub_decrypt(bytea, bytea) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION pgp_pub_decrypt(bytea, bytea, text); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.pgp_pub_decrypt(bytea, bytea, text) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.pgp_pub_decrypt(bytea, bytea, text) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION pgp_pub_decrypt(bytea, bytea, text, text); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.pgp_pub_decrypt(bytea, bytea, text, text) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.pgp_pub_decrypt(bytea, bytea, text, text) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION pgp_pub_decrypt_bytea(bytea, bytea); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.pgp_pub_decrypt_bytea(bytea, bytea) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.pgp_pub_decrypt_bytea(bytea, bytea) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION pgp_pub_decrypt_bytea(bytea, bytea, text); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.pgp_pub_decrypt_bytea(bytea, bytea, text) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.pgp_pub_decrypt_bytea(bytea, bytea, text) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION pgp_pub_decrypt_bytea(bytea, bytea, text, text); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.pgp_pub_decrypt_bytea(bytea, bytea, text, text) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.pgp_pub_decrypt_bytea(bytea, bytea, text, text) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION pgp_pub_encrypt(text, bytea); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.pgp_pub_encrypt(text, bytea) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.pgp_pub_encrypt(text, bytea) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION pgp_pub_encrypt(text, bytea, text); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.pgp_pub_encrypt(text, bytea, text) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.pgp_pub_encrypt(text, bytea, text) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION pgp_pub_encrypt_bytea(bytea, bytea); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.pgp_pub_encrypt_bytea(bytea, bytea) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.pgp_pub_encrypt_bytea(bytea, bytea) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION pgp_pub_encrypt_bytea(bytea, bytea, text); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.pgp_pub_encrypt_bytea(bytea, bytea, text) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.pgp_pub_encrypt_bytea(bytea, bytea, text) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION pgp_sym_decrypt(bytea, text); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.pgp_sym_decrypt(bytea, text) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.pgp_sym_decrypt(bytea, text) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION pgp_sym_decrypt(bytea, text, text); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.pgp_sym_decrypt(bytea, text, text) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.pgp_sym_decrypt(bytea, text, text) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION pgp_sym_decrypt_bytea(bytea, text); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.pgp_sym_decrypt_bytea(bytea, text) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.pgp_sym_decrypt_bytea(bytea, text) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION pgp_sym_decrypt_bytea(bytea, text, text); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.pgp_sym_decrypt_bytea(bytea, text, text) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.pgp_sym_decrypt_bytea(bytea, text, text) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION pgp_sym_encrypt(text, text); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.pgp_sym_encrypt(text, text) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.pgp_sym_encrypt(text, text) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION pgp_sym_encrypt(text, text, text); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.pgp_sym_encrypt(text, text, text) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.pgp_sym_encrypt(text, text, text) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION pgp_sym_encrypt_bytea(bytea, text); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.pgp_sym_encrypt_bytea(bytea, text) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.pgp_sym_encrypt_bytea(bytea, text) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION pgp_sym_encrypt_bytea(bytea, text, text); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.pgp_sym_encrypt_bytea(bytea, text, text) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.pgp_sym_encrypt_bytea(bytea, text, text) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION pgrst_ddl_watch(); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.pgrst_ddl_watch() TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION pgrst_drop_watch(); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.pgrst_drop_watch() TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION set_graphql_placeholder(); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.set_graphql_placeholder() TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION uuid_generate_v1(); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.uuid_generate_v1() TO dashboard_user;
GRANT ALL ON FUNCTION extensions.uuid_generate_v1() TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION uuid_generate_v1mc(); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.uuid_generate_v1mc() TO dashboard_user;
GRANT ALL ON FUNCTION extensions.uuid_generate_v1mc() TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION uuid_generate_v3(namespace uuid, name text); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.uuid_generate_v3(namespace uuid, name text) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.uuid_generate_v3(namespace uuid, name text) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION uuid_generate_v4(); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.uuid_generate_v4() TO dashboard_user;
GRANT ALL ON FUNCTION extensions.uuid_generate_v4() TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION uuid_generate_v5(namespace uuid, name text); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.uuid_generate_v5(namespace uuid, name text) TO dashboard_user;
GRANT ALL ON FUNCTION extensions.uuid_generate_v5(namespace uuid, name text) TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION uuid_nil(); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.uuid_nil() TO dashboard_user;
GRANT ALL ON FUNCTION extensions.uuid_nil() TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION uuid_ns_dns(); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.uuid_ns_dns() TO dashboard_user;
GRANT ALL ON FUNCTION extensions.uuid_ns_dns() TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION uuid_ns_oid(); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.uuid_ns_oid() TO dashboard_user;
GRANT ALL ON FUNCTION extensions.uuid_ns_oid() TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION uuid_ns_url(); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.uuid_ns_url() TO dashboard_user;
GRANT ALL ON FUNCTION extensions.uuid_ns_url() TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION uuid_ns_x500(); Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON FUNCTION extensions.uuid_ns_x500() TO dashboard_user;
GRANT ALL ON FUNCTION extensions.uuid_ns_x500() TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION graphql("operationName" text, query text, variables jsonb, extensions jsonb); Type: ACL; Schema: graphql_public; Owner: supabase_admin
--

GRANT ALL ON FUNCTION graphql_public.graphql("operationName" text, query text, variables jsonb, extensions jsonb) TO postgres;
GRANT ALL ON FUNCTION graphql_public.graphql("operationName" text, query text, variables jsonb, extensions jsonb) TO anon;
GRANT ALL ON FUNCTION graphql_public.graphql("operationName" text, query text, variables jsonb, extensions jsonb) TO authenticated;
GRANT ALL ON FUNCTION graphql_public.graphql("operationName" text, query text, variables jsonb, extensions jsonb) TO service_role;


--
-- Name: FUNCTION http_get(url text, params jsonb, headers jsonb, timeout_milliseconds integer); Type: ACL; Schema: net; Owner: supabase_admin
--

REVOKE ALL ON FUNCTION net.http_get(url text, params jsonb, headers jsonb, timeout_milliseconds integer) FROM PUBLIC;
GRANT ALL ON FUNCTION net.http_get(url text, params jsonb, headers jsonb, timeout_milliseconds integer) TO supabase_functions_admin;
GRANT ALL ON FUNCTION net.http_get(url text, params jsonb, headers jsonb, timeout_milliseconds integer) TO postgres;
GRANT ALL ON FUNCTION net.http_get(url text, params jsonb, headers jsonb, timeout_milliseconds integer) TO anon;
GRANT ALL ON FUNCTION net.http_get(url text, params jsonb, headers jsonb, timeout_milliseconds integer) TO authenticated;
GRANT ALL ON FUNCTION net.http_get(url text, params jsonb, headers jsonb, timeout_milliseconds integer) TO service_role;


--
-- Name: FUNCTION http_post(url text, body jsonb, params jsonb, headers jsonb, timeout_milliseconds integer); Type: ACL; Schema: net; Owner: supabase_admin
--

REVOKE ALL ON FUNCTION net.http_post(url text, body jsonb, params jsonb, headers jsonb, timeout_milliseconds integer) FROM PUBLIC;
GRANT ALL ON FUNCTION net.http_post(url text, body jsonb, params jsonb, headers jsonb, timeout_milliseconds integer) TO supabase_functions_admin;
GRANT ALL ON FUNCTION net.http_post(url text, body jsonb, params jsonb, headers jsonb, timeout_milliseconds integer) TO postgres;
GRANT ALL ON FUNCTION net.http_post(url text, body jsonb, params jsonb, headers jsonb, timeout_milliseconds integer) TO anon;
GRANT ALL ON FUNCTION net.http_post(url text, body jsonb, params jsonb, headers jsonb, timeout_milliseconds integer) TO authenticated;
GRANT ALL ON FUNCTION net.http_post(url text, body jsonb, params jsonb, headers jsonb, timeout_milliseconds integer) TO service_role;


--
-- Name: FUNCTION pg_reload_conf(); Type: ACL; Schema: pg_catalog; Owner: supabase_admin
--

GRANT ALL ON FUNCTION pg_catalog.pg_reload_conf() TO postgres WITH GRANT OPTION;


--
-- Name: FUNCTION get_auth(p_usename text); Type: ACL; Schema: pgbouncer; Owner: supabase_admin
--

REVOKE ALL ON FUNCTION pgbouncer.get_auth(p_usename text) FROM PUBLIC;
GRANT ALL ON FUNCTION pgbouncer.get_auth(p_usename text) TO pgbouncer;


--
-- Name: FUNCTION branch_manager_can_view_submission(_submission_id uuid); Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON FUNCTION public.branch_manager_can_view_submission(_submission_id uuid) TO anon;
GRANT ALL ON FUNCTION public.branch_manager_can_view_submission(_submission_id uuid) TO authenticated;
GRANT ALL ON FUNCTION public.branch_manager_can_view_submission(_submission_id uuid) TO service_role;


--
-- Name: FUNCTION current_user_is_branch_manager_for_user(target_user_id uuid); Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON FUNCTION public.current_user_is_branch_manager_for_user(target_user_id uuid) TO anon;
GRANT ALL ON FUNCTION public.current_user_is_branch_manager_for_user(target_user_id uuid) TO authenticated;
GRANT ALL ON FUNCTION public.current_user_is_branch_manager_for_user(target_user_id uuid) TO service_role;


--
-- Name: FUNCTION current_user_is_org_admin_or_manager(org_id uuid); Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON FUNCTION public.current_user_is_org_admin_or_manager(org_id uuid) TO anon;
GRANT ALL ON FUNCTION public.current_user_is_org_admin_or_manager(org_id uuid) TO authenticated;
GRANT ALL ON FUNCTION public.current_user_is_org_admin_or_manager(org_id uuid) TO service_role;


--
-- Name: FUNCTION get_user_role(user_id uuid); Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON FUNCTION public.get_user_role(user_id uuid) TO anon;
GRANT ALL ON FUNCTION public.get_user_role(user_id uuid) TO authenticated;
GRANT ALL ON FUNCTION public.get_user_role(user_id uuid) TO service_role;


--
-- Name: FUNCTION handle_new_user(); Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON FUNCTION public.handle_new_user() TO anon;
GRANT ALL ON FUNCTION public.handle_new_user() TO authenticated;
GRANT ALL ON FUNCTION public.handle_new_user() TO service_role;


--
-- Name: FUNCTION inc_download_count(mid text); Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON FUNCTION public.inc_download_count(mid text) TO anon;
GRANT ALL ON FUNCTION public.inc_download_count(mid text) TO authenticated;
GRANT ALL ON FUNCTION public.inc_download_count(mid text) TO service_role;


--
-- Name: FUNCTION is_current_user_super_admin(); Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON FUNCTION public.is_current_user_super_admin() TO anon;
GRANT ALL ON FUNCTION public.is_current_user_super_admin() TO authenticated;
GRANT ALL ON FUNCTION public.is_current_user_super_admin() TO service_role;


--
-- Name: FUNCTION is_super_admin(user_email text); Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON FUNCTION public.is_super_admin(user_email text) TO anon;
GRANT ALL ON FUNCTION public.is_super_admin(user_email text) TO authenticated;
GRANT ALL ON FUNCTION public.is_super_admin(user_email text) TO service_role;


--
-- Name: FUNCTION manage_auto_sync_schedule(enabled boolean, interval_minutes integer); Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON FUNCTION public.manage_auto_sync_schedule(enabled boolean, interval_minutes integer) TO anon;
GRANT ALL ON FUNCTION public.manage_auto_sync_schedule(enabled boolean, interval_minutes integer) TO authenticated;
GRANT ALL ON FUNCTION public.manage_auto_sync_schedule(enabled boolean, interval_minutes integer) TO service_role;


--
-- Name: FUNCTION restrict_events_update(); Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON FUNCTION public.restrict_events_update() TO anon;
GRANT ALL ON FUNCTION public.restrict_events_update() TO authenticated;
GRANT ALL ON FUNCTION public.restrict_events_update() TO service_role;


--
-- Name: FUNCTION touch_chat_thread(); Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON FUNCTION public.touch_chat_thread() TO anon;
GRANT ALL ON FUNCTION public.touch_chat_thread() TO authenticated;
GRANT ALL ON FUNCTION public.touch_chat_thread() TO service_role;


--
-- Name: FUNCTION trg_touch_updated_at(); Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON FUNCTION public.trg_touch_updated_at() TO anon;
GRANT ALL ON FUNCTION public.trg_touch_updated_at() TO authenticated;
GRANT ALL ON FUNCTION public.trg_touch_updated_at() TO service_role;


--
-- Name: FUNCTION trigger_auto_sync(); Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON FUNCTION public.trigger_auto_sync() TO anon;
GRANT ALL ON FUNCTION public.trigger_auto_sync() TO authenticated;
GRANT ALL ON FUNCTION public.trigger_auto_sync() TO service_role;


--
-- Name: FUNCTION update_modified_column(); Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON FUNCTION public.update_modified_column() TO anon;
GRANT ALL ON FUNCTION public.update_modified_column() TO authenticated;
GRANT ALL ON FUNCTION public.update_modified_column() TO service_role;


--
-- Name: FUNCTION update_subscriber_activity(); Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON FUNCTION public.update_subscriber_activity() TO anon;
GRANT ALL ON FUNCTION public.update_subscriber_activity() TO authenticated;
GRANT ALL ON FUNCTION public.update_subscriber_activity() TO service_role;


--
-- Name: FUNCTION user_is_org_member_for_thread(thread_id uuid); Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON FUNCTION public.user_is_org_member_for_thread(thread_id uuid) TO anon;
GRANT ALL ON FUNCTION public.user_is_org_member_for_thread(thread_id uuid) TO authenticated;
GRANT ALL ON FUNCTION public.user_is_org_member_for_thread(thread_id uuid) TO service_role;


--
-- Name: FUNCTION user_is_thread_participant(thread_id uuid); Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON FUNCTION public.user_is_thread_participant(thread_id uuid) TO anon;
GRANT ALL ON FUNCTION public.user_is_thread_participant(thread_id uuid) TO authenticated;
GRANT ALL ON FUNCTION public.user_is_thread_participant(thread_id uuid) TO service_role;


--
-- Name: FUNCTION veedon_bump_branch_config(); Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON FUNCTION public.veedon_bump_branch_config() TO anon;
GRANT ALL ON FUNCTION public.veedon_bump_branch_config() TO authenticated;
GRANT ALL ON FUNCTION public.veedon_bump_branch_config() TO service_role;


--
-- Name: FUNCTION apply_rls(wal jsonb, max_record_bytes integer); Type: ACL; Schema: realtime; Owner: supabase_admin
--

GRANT ALL ON FUNCTION realtime.apply_rls(wal jsonb, max_record_bytes integer) TO postgres;
GRANT ALL ON FUNCTION realtime.apply_rls(wal jsonb, max_record_bytes integer) TO dashboard_user;
GRANT ALL ON FUNCTION realtime.apply_rls(wal jsonb, max_record_bytes integer) TO anon;
GRANT ALL ON FUNCTION realtime.apply_rls(wal jsonb, max_record_bytes integer) TO authenticated;
GRANT ALL ON FUNCTION realtime.apply_rls(wal jsonb, max_record_bytes integer) TO service_role;
GRANT ALL ON FUNCTION realtime.apply_rls(wal jsonb, max_record_bytes integer) TO supabase_realtime_admin;


--
-- Name: FUNCTION broadcast_changes(topic_name text, event_name text, operation text, table_name text, table_schema text, new record, old record, level text); Type: ACL; Schema: realtime; Owner: supabase_admin
--

GRANT ALL ON FUNCTION realtime.broadcast_changes(topic_name text, event_name text, operation text, table_name text, table_schema text, new record, old record, level text) TO postgres;
GRANT ALL ON FUNCTION realtime.broadcast_changes(topic_name text, event_name text, operation text, table_name text, table_schema text, new record, old record, level text) TO dashboard_user;


--
-- Name: FUNCTION build_prepared_statement_sql(prepared_statement_name text, entity regclass, columns realtime.wal_column[]); Type: ACL; Schema: realtime; Owner: supabase_admin
--

GRANT ALL ON FUNCTION realtime.build_prepared_statement_sql(prepared_statement_name text, entity regclass, columns realtime.wal_column[]) TO postgres;
GRANT ALL ON FUNCTION realtime.build_prepared_statement_sql(prepared_statement_name text, entity regclass, columns realtime.wal_column[]) TO dashboard_user;
GRANT ALL ON FUNCTION realtime.build_prepared_statement_sql(prepared_statement_name text, entity regclass, columns realtime.wal_column[]) TO anon;
GRANT ALL ON FUNCTION realtime.build_prepared_statement_sql(prepared_statement_name text, entity regclass, columns realtime.wal_column[]) TO authenticated;
GRANT ALL ON FUNCTION realtime.build_prepared_statement_sql(prepared_statement_name text, entity regclass, columns realtime.wal_column[]) TO service_role;
GRANT ALL ON FUNCTION realtime.build_prepared_statement_sql(prepared_statement_name text, entity regclass, columns realtime.wal_column[]) TO supabase_realtime_admin;


--
-- Name: FUNCTION "cast"(val text, type_ regtype); Type: ACL; Schema: realtime; Owner: supabase_admin
--

GRANT ALL ON FUNCTION realtime."cast"(val text, type_ regtype) TO postgres;
GRANT ALL ON FUNCTION realtime."cast"(val text, type_ regtype) TO dashboard_user;
GRANT ALL ON FUNCTION realtime."cast"(val text, type_ regtype) TO anon;
GRANT ALL ON FUNCTION realtime."cast"(val text, type_ regtype) TO authenticated;
GRANT ALL ON FUNCTION realtime."cast"(val text, type_ regtype) TO service_role;
GRANT ALL ON FUNCTION realtime."cast"(val text, type_ regtype) TO supabase_realtime_admin;


--
-- Name: FUNCTION check_equality_op(op realtime.equality_op, type_ regtype, val_1 text, val_2 text); Type: ACL; Schema: realtime; Owner: supabase_admin
--

GRANT ALL ON FUNCTION realtime.check_equality_op(op realtime.equality_op, type_ regtype, val_1 text, val_2 text) TO postgres;
GRANT ALL ON FUNCTION realtime.check_equality_op(op realtime.equality_op, type_ regtype, val_1 text, val_2 text) TO dashboard_user;
GRANT ALL ON FUNCTION realtime.check_equality_op(op realtime.equality_op, type_ regtype, val_1 text, val_2 text) TO anon;
GRANT ALL ON FUNCTION realtime.check_equality_op(op realtime.equality_op, type_ regtype, val_1 text, val_2 text) TO authenticated;
GRANT ALL ON FUNCTION realtime.check_equality_op(op realtime.equality_op, type_ regtype, val_1 text, val_2 text) TO service_role;
GRANT ALL ON FUNCTION realtime.check_equality_op(op realtime.equality_op, type_ regtype, val_1 text, val_2 text) TO supabase_realtime_admin;


--
-- Name: FUNCTION is_visible_through_filters(columns realtime.wal_column[], filters realtime.user_defined_filter[]); Type: ACL; Schema: realtime; Owner: supabase_admin
--

GRANT ALL ON FUNCTION realtime.is_visible_through_filters(columns realtime.wal_column[], filters realtime.user_defined_filter[]) TO postgres;
GRANT ALL ON FUNCTION realtime.is_visible_through_filters(columns realtime.wal_column[], filters realtime.user_defined_filter[]) TO dashboard_user;
GRANT ALL ON FUNCTION realtime.is_visible_through_filters(columns realtime.wal_column[], filters realtime.user_defined_filter[]) TO anon;
GRANT ALL ON FUNCTION realtime.is_visible_through_filters(columns realtime.wal_column[], filters realtime.user_defined_filter[]) TO authenticated;
GRANT ALL ON FUNCTION realtime.is_visible_through_filters(columns realtime.wal_column[], filters realtime.user_defined_filter[]) TO service_role;
GRANT ALL ON FUNCTION realtime.is_visible_through_filters(columns realtime.wal_column[], filters realtime.user_defined_filter[]) TO supabase_realtime_admin;


--
-- Name: FUNCTION list_changes(publication name, slot_name name, max_changes integer, max_record_bytes integer); Type: ACL; Schema: realtime; Owner: supabase_admin
--

GRANT ALL ON FUNCTION realtime.list_changes(publication name, slot_name name, max_changes integer, max_record_bytes integer) TO postgres;
GRANT ALL ON FUNCTION realtime.list_changes(publication name, slot_name name, max_changes integer, max_record_bytes integer) TO dashboard_user;


--
-- Name: FUNCTION quote_wal2json(entity regclass); Type: ACL; Schema: realtime; Owner: supabase_admin
--

GRANT ALL ON FUNCTION realtime.quote_wal2json(entity regclass) TO postgres;
GRANT ALL ON FUNCTION realtime.quote_wal2json(entity regclass) TO dashboard_user;
GRANT ALL ON FUNCTION realtime.quote_wal2json(entity regclass) TO anon;
GRANT ALL ON FUNCTION realtime.quote_wal2json(entity regclass) TO authenticated;
GRANT ALL ON FUNCTION realtime.quote_wal2json(entity regclass) TO service_role;
GRANT ALL ON FUNCTION realtime.quote_wal2json(entity regclass) TO supabase_realtime_admin;


--
-- Name: FUNCTION send(payload jsonb, event text, topic text, private boolean); Type: ACL; Schema: realtime; Owner: supabase_admin
--

GRANT ALL ON FUNCTION realtime.send(payload jsonb, event text, topic text, private boolean) TO postgres;
GRANT ALL ON FUNCTION realtime.send(payload jsonb, event text, topic text, private boolean) TO dashboard_user;


--
-- Name: FUNCTION send_binary(payload bytea, event text, topic text, private boolean); Type: ACL; Schema: realtime; Owner: supabase_admin
--

GRANT ALL ON FUNCTION realtime.send_binary(payload bytea, event text, topic text, private boolean) TO postgres;
GRANT ALL ON FUNCTION realtime.send_binary(payload bytea, event text, topic text, private boolean) TO dashboard_user;


--
-- Name: FUNCTION subscription_check_filters(); Type: ACL; Schema: realtime; Owner: supabase_admin
--

GRANT ALL ON FUNCTION realtime.subscription_check_filters() TO postgres;
GRANT ALL ON FUNCTION realtime.subscription_check_filters() TO dashboard_user;
GRANT ALL ON FUNCTION realtime.subscription_check_filters() TO anon;
GRANT ALL ON FUNCTION realtime.subscription_check_filters() TO authenticated;
GRANT ALL ON FUNCTION realtime.subscription_check_filters() TO service_role;
GRANT ALL ON FUNCTION realtime.subscription_check_filters() TO supabase_realtime_admin;


--
-- Name: FUNCTION to_regrole(role_name text); Type: ACL; Schema: realtime; Owner: supabase_admin
--

GRANT ALL ON FUNCTION realtime.to_regrole(role_name text) TO postgres;
GRANT ALL ON FUNCTION realtime.to_regrole(role_name text) TO dashboard_user;
GRANT ALL ON FUNCTION realtime.to_regrole(role_name text) TO anon;
GRANT ALL ON FUNCTION realtime.to_regrole(role_name text) TO authenticated;
GRANT ALL ON FUNCTION realtime.to_regrole(role_name text) TO service_role;
GRANT ALL ON FUNCTION realtime.to_regrole(role_name text) TO supabase_realtime_admin;


--
-- Name: FUNCTION topic(); Type: ACL; Schema: realtime; Owner: supabase_realtime_admin
--

GRANT ALL ON FUNCTION realtime.topic() TO postgres;
GRANT ALL ON FUNCTION realtime.topic() TO dashboard_user;


--
-- Name: FUNCTION wal2json_escape_identifier(name text); Type: ACL; Schema: realtime; Owner: supabase_admin
--

GRANT ALL ON FUNCTION realtime.wal2json_escape_identifier(name text) TO postgres;
GRANT ALL ON FUNCTION realtime.wal2json_escape_identifier(name text) TO dashboard_user;


--
-- Name: FUNCTION http_request(); Type: ACL; Schema: supabase_functions; Owner: supabase_functions_admin
--

REVOKE ALL ON FUNCTION supabase_functions.http_request() FROM PUBLIC;
GRANT ALL ON FUNCTION supabase_functions.http_request() TO postgres;
GRANT ALL ON FUNCTION supabase_functions.http_request() TO anon;
GRANT ALL ON FUNCTION supabase_functions.http_request() TO authenticated;
GRANT ALL ON FUNCTION supabase_functions.http_request() TO service_role;


--
-- Name: FUNCTION _crypto_aead_det_decrypt(message bytea, additional bytea, key_id bigint, context bytea, nonce bytea); Type: ACL; Schema: vault; Owner: supabase_admin
--

GRANT ALL ON FUNCTION vault._crypto_aead_det_decrypt(message bytea, additional bytea, key_id bigint, context bytea, nonce bytea) TO postgres WITH GRANT OPTION;
GRANT ALL ON FUNCTION vault._crypto_aead_det_decrypt(message bytea, additional bytea, key_id bigint, context bytea, nonce bytea) TO service_role;


--
-- Name: FUNCTION create_secret(new_secret text, new_name text, new_description text, new_key_id uuid); Type: ACL; Schema: vault; Owner: supabase_admin
--

GRANT ALL ON FUNCTION vault.create_secret(new_secret text, new_name text, new_description text, new_key_id uuid) TO postgres WITH GRANT OPTION;
GRANT ALL ON FUNCTION vault.create_secret(new_secret text, new_name text, new_description text, new_key_id uuid) TO service_role;


--
-- Name: FUNCTION update_secret(secret_id uuid, new_secret text, new_name text, new_description text, new_key_id uuid); Type: ACL; Schema: vault; Owner: supabase_admin
--

GRANT ALL ON FUNCTION vault.update_secret(secret_id uuid, new_secret text, new_name text, new_description text, new_key_id uuid) TO postgres WITH GRANT OPTION;
GRANT ALL ON FUNCTION vault.update_secret(secret_id uuid, new_secret text, new_name text, new_description text, new_key_id uuid) TO service_role;


--
-- Name: TABLE audit_log_entries; Type: ACL; Schema: auth; Owner: supabase_auth_admin
--

GRANT ALL ON TABLE auth.audit_log_entries TO dashboard_user;
GRANT INSERT,REFERENCES,DELETE,TRIGGER,TRUNCATE,MAINTAIN,UPDATE ON TABLE auth.audit_log_entries TO postgres;
GRANT SELECT ON TABLE auth.audit_log_entries TO postgres WITH GRANT OPTION;


--
-- Name: TABLE custom_oauth_providers; Type: ACL; Schema: auth; Owner: supabase_auth_admin
--

GRANT ALL ON TABLE auth.custom_oauth_providers TO postgres;
GRANT ALL ON TABLE auth.custom_oauth_providers TO dashboard_user;


--
-- Name: TABLE flow_state; Type: ACL; Schema: auth; Owner: supabase_auth_admin
--

GRANT INSERT,REFERENCES,DELETE,TRIGGER,TRUNCATE,MAINTAIN,UPDATE ON TABLE auth.flow_state TO postgres;
GRANT SELECT ON TABLE auth.flow_state TO postgres WITH GRANT OPTION;
GRANT ALL ON TABLE auth.flow_state TO dashboard_user;


--
-- Name: TABLE identities; Type: ACL; Schema: auth; Owner: supabase_auth_admin
--

GRANT INSERT,REFERENCES,DELETE,TRIGGER,TRUNCATE,MAINTAIN,UPDATE ON TABLE auth.identities TO postgres;
GRANT SELECT ON TABLE auth.identities TO postgres WITH GRANT OPTION;
GRANT ALL ON TABLE auth.identities TO dashboard_user;


--
-- Name: TABLE instances; Type: ACL; Schema: auth; Owner: supabase_auth_admin
--

GRANT ALL ON TABLE auth.instances TO dashboard_user;
GRANT INSERT,REFERENCES,DELETE,TRIGGER,TRUNCATE,MAINTAIN,UPDATE ON TABLE auth.instances TO postgres;
GRANT SELECT ON TABLE auth.instances TO postgres WITH GRANT OPTION;


--
-- Name: TABLE mfa_amr_claims; Type: ACL; Schema: auth; Owner: supabase_auth_admin
--

GRANT INSERT,REFERENCES,DELETE,TRIGGER,TRUNCATE,MAINTAIN,UPDATE ON TABLE auth.mfa_amr_claims TO postgres;
GRANT SELECT ON TABLE auth.mfa_amr_claims TO postgres WITH GRANT OPTION;
GRANT ALL ON TABLE auth.mfa_amr_claims TO dashboard_user;


--
-- Name: TABLE mfa_challenges; Type: ACL; Schema: auth; Owner: supabase_auth_admin
--

GRANT INSERT,REFERENCES,DELETE,TRIGGER,TRUNCATE,MAINTAIN,UPDATE ON TABLE auth.mfa_challenges TO postgres;
GRANT SELECT ON TABLE auth.mfa_challenges TO postgres WITH GRANT OPTION;
GRANT ALL ON TABLE auth.mfa_challenges TO dashboard_user;


--
-- Name: TABLE mfa_factors; Type: ACL; Schema: auth; Owner: supabase_auth_admin
--

GRANT INSERT,REFERENCES,DELETE,TRIGGER,TRUNCATE,MAINTAIN,UPDATE ON TABLE auth.mfa_factors TO postgres;
GRANT SELECT ON TABLE auth.mfa_factors TO postgres WITH GRANT OPTION;
GRANT ALL ON TABLE auth.mfa_factors TO dashboard_user;


--
-- Name: TABLE oauth_authorizations; Type: ACL; Schema: auth; Owner: supabase_auth_admin
--

GRANT ALL ON TABLE auth.oauth_authorizations TO postgres;
GRANT ALL ON TABLE auth.oauth_authorizations TO dashboard_user;


--
-- Name: TABLE oauth_client_states; Type: ACL; Schema: auth; Owner: supabase_auth_admin
--

GRANT ALL ON TABLE auth.oauth_client_states TO postgres;
GRANT ALL ON TABLE auth.oauth_client_states TO dashboard_user;


--
-- Name: TABLE oauth_clients; Type: ACL; Schema: auth; Owner: supabase_auth_admin
--

GRANT ALL ON TABLE auth.oauth_clients TO postgres;
GRANT ALL ON TABLE auth.oauth_clients TO dashboard_user;


--
-- Name: TABLE oauth_consents; Type: ACL; Schema: auth; Owner: supabase_auth_admin
--

GRANT ALL ON TABLE auth.oauth_consents TO postgres;
GRANT ALL ON TABLE auth.oauth_consents TO dashboard_user;


--
-- Name: TABLE one_time_tokens; Type: ACL; Schema: auth; Owner: supabase_auth_admin
--

GRANT INSERT,REFERENCES,DELETE,TRIGGER,TRUNCATE,MAINTAIN,UPDATE ON TABLE auth.one_time_tokens TO postgres;
GRANT SELECT ON TABLE auth.one_time_tokens TO postgres WITH GRANT OPTION;
GRANT ALL ON TABLE auth.one_time_tokens TO dashboard_user;


--
-- Name: TABLE refresh_tokens; Type: ACL; Schema: auth; Owner: supabase_auth_admin
--

GRANT ALL ON TABLE auth.refresh_tokens TO dashboard_user;
GRANT INSERT,REFERENCES,DELETE,TRIGGER,TRUNCATE,MAINTAIN,UPDATE ON TABLE auth.refresh_tokens TO postgres;
GRANT SELECT ON TABLE auth.refresh_tokens TO postgres WITH GRANT OPTION;


--
-- Name: SEQUENCE refresh_tokens_id_seq; Type: ACL; Schema: auth; Owner: supabase_auth_admin
--

GRANT ALL ON SEQUENCE auth.refresh_tokens_id_seq TO dashboard_user;
GRANT ALL ON SEQUENCE auth.refresh_tokens_id_seq TO postgres;


--
-- Name: TABLE saml_providers; Type: ACL; Schema: auth; Owner: supabase_auth_admin
--

GRANT INSERT,REFERENCES,DELETE,TRIGGER,TRUNCATE,MAINTAIN,UPDATE ON TABLE auth.saml_providers TO postgres;
GRANT SELECT ON TABLE auth.saml_providers TO postgres WITH GRANT OPTION;
GRANT ALL ON TABLE auth.saml_providers TO dashboard_user;


--
-- Name: TABLE saml_relay_states; Type: ACL; Schema: auth; Owner: supabase_auth_admin
--

GRANT INSERT,REFERENCES,DELETE,TRIGGER,TRUNCATE,MAINTAIN,UPDATE ON TABLE auth.saml_relay_states TO postgres;
GRANT SELECT ON TABLE auth.saml_relay_states TO postgres WITH GRANT OPTION;
GRANT ALL ON TABLE auth.saml_relay_states TO dashboard_user;


--
-- Name: TABLE schema_migrations; Type: ACL; Schema: auth; Owner: supabase_auth_admin
--

GRANT SELECT ON TABLE auth.schema_migrations TO postgres WITH GRANT OPTION;


--
-- Name: TABLE sessions; Type: ACL; Schema: auth; Owner: supabase_auth_admin
--

GRANT INSERT,REFERENCES,DELETE,TRIGGER,TRUNCATE,MAINTAIN,UPDATE ON TABLE auth.sessions TO postgres;
GRANT SELECT ON TABLE auth.sessions TO postgres WITH GRANT OPTION;
GRANT ALL ON TABLE auth.sessions TO dashboard_user;


--
-- Name: TABLE sso_domains; Type: ACL; Schema: auth; Owner: supabase_auth_admin
--

GRANT INSERT,REFERENCES,DELETE,TRIGGER,TRUNCATE,MAINTAIN,UPDATE ON TABLE auth.sso_domains TO postgres;
GRANT SELECT ON TABLE auth.sso_domains TO postgres WITH GRANT OPTION;
GRANT ALL ON TABLE auth.sso_domains TO dashboard_user;


--
-- Name: TABLE sso_providers; Type: ACL; Schema: auth; Owner: supabase_auth_admin
--

GRANT INSERT,REFERENCES,DELETE,TRIGGER,TRUNCATE,MAINTAIN,UPDATE ON TABLE auth.sso_providers TO postgres;
GRANT SELECT ON TABLE auth.sso_providers TO postgres WITH GRANT OPTION;
GRANT ALL ON TABLE auth.sso_providers TO dashboard_user;


--
-- Name: TABLE users; Type: ACL; Schema: auth; Owner: supabase_auth_admin
--

GRANT ALL ON TABLE auth.users TO dashboard_user;
GRANT INSERT,REFERENCES,DELETE,TRIGGER,TRUNCATE,MAINTAIN,UPDATE ON TABLE auth.users TO postgres;
GRANT SELECT ON TABLE auth.users TO postgres WITH GRANT OPTION;


--
-- Name: TABLE webauthn_challenges; Type: ACL; Schema: auth; Owner: supabase_auth_admin
--

GRANT ALL ON TABLE auth.webauthn_challenges TO postgres;
GRANT ALL ON TABLE auth.webauthn_challenges TO dashboard_user;


--
-- Name: TABLE webauthn_credentials; Type: ACL; Schema: auth; Owner: supabase_auth_admin
--

GRANT ALL ON TABLE auth.webauthn_credentials TO postgres;
GRANT ALL ON TABLE auth.webauthn_credentials TO dashboard_user;


--
-- Name: TABLE pg_stat_statements; Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON TABLE extensions.pg_stat_statements TO postgres WITH GRANT OPTION;


--
-- Name: TABLE pg_stat_statements_info; Type: ACL; Schema: extensions; Owner: supabase_admin
--

GRANT ALL ON TABLE extensions.pg_stat_statements_info TO postgres WITH GRANT OPTION;


--
-- Name: TABLE ai_analysis_logs; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.ai_analysis_logs TO anon;
GRANT ALL ON TABLE public.ai_analysis_logs TO authenticated;
GRANT ALL ON TABLE public.ai_analysis_logs TO service_role;


--
-- Name: TABLE ai_models; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.ai_models TO anon;
GRANT ALL ON TABLE public.ai_models TO authenticated;
GRANT ALL ON TABLE public.ai_models TO service_role;


--
-- Name: TABLE alert_template_events; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.alert_template_events TO anon;
GRANT ALL ON TABLE public.alert_template_events TO authenticated;
GRANT ALL ON TABLE public.alert_template_events TO service_role;


--
-- Name: TABLE alert_template_industries; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.alert_template_industries TO anon;
GRANT ALL ON TABLE public.alert_template_industries TO authenticated;
GRANT ALL ON TABLE public.alert_template_industries TO service_role;


--
-- Name: TABLE alert_templates; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.alert_templates TO anon;
GRANT ALL ON TABLE public.alert_templates TO authenticated;
GRANT ALL ON TABLE public.alert_templates TO service_role;


--
-- Name: TABLE aman_instances; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.aman_instances TO service_role;
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE public.aman_instances TO authenticated;


--
-- Name: COLUMN aman_instances.id; Type: ACL; Schema: public; Owner: postgres
--

GRANT SELECT(id) ON TABLE public.aman_instances TO authenticated;


--
-- Name: COLUMN aman_instances.organization_id; Type: ACL; Schema: public; Owner: postgres
--

GRANT SELECT(organization_id) ON TABLE public.aman_instances TO authenticated;


--
-- Name: COLUMN aman_instances.branch_id; Type: ACL; Schema: public; Owner: postgres
--

GRANT SELECT(branch_id) ON TABLE public.aman_instances TO authenticated;


--
-- Name: COLUMN aman_instances.name; Type: ACL; Schema: public; Owner: postgres
--

GRANT SELECT(name) ON TABLE public.aman_instances TO authenticated;


--
-- Name: COLUMN aman_instances.base_url; Type: ACL; Schema: public; Owner: postgres
--

GRANT SELECT(base_url) ON TABLE public.aman_instances TO authenticated;


--
-- Name: COLUMN aman_instances.active; Type: ACL; Schema: public; Owner: postgres
--

GRANT SELECT(active) ON TABLE public.aman_instances TO authenticated;


--
-- Name: COLUMN aman_instances.created_by; Type: ACL; Schema: public; Owner: postgres
--

GRANT SELECT(created_by) ON TABLE public.aman_instances TO authenticated;


--
-- Name: COLUMN aman_instances.created_at; Type: ACL; Schema: public; Owner: postgres
--

GRANT SELECT(created_at) ON TABLE public.aman_instances TO authenticated;


--
-- Name: COLUMN aman_instances.updated_at; Type: ACL; Schema: public; Owner: postgres
--

GRANT SELECT(updated_at) ON TABLE public.aman_instances TO authenticated;


--
-- Name: TABLE auto_sync_settings; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.auto_sync_settings TO anon;
GRANT ALL ON TABLE public.auto_sync_settings TO authenticated;
GRANT ALL ON TABLE public.auto_sync_settings TO service_role;


--
-- Name: TABLE branch_roles; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.branch_roles TO anon;
GRANT ALL ON TABLE public.branch_roles TO authenticated;
GRANT ALL ON TABLE public.branch_roles TO service_role;


--
-- Name: TABLE branches; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.branches TO anon;
GRANT ALL ON TABLE public.branches TO authenticated;
GRANT ALL ON TABLE public.branches TO service_role;


--
-- Name: TABLE camera_alert_assignments; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.camera_alert_assignments TO anon;
GRANT ALL ON TABLE public.camera_alert_assignments TO authenticated;
GRANT ALL ON TABLE public.camera_alert_assignments TO service_role;


--
-- Name: TABLE camera_event_assignments; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.camera_event_assignments TO anon;
GRANT ALL ON TABLE public.camera_event_assignments TO authenticated;
GRANT ALL ON TABLE public.camera_event_assignments TO service_role;


--
-- Name: TABLE camera_sources; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.camera_sources TO anon;
GRANT ALL ON TABLE public.camera_sources TO authenticated;
GRANT ALL ON TABLE public.camera_sources TO service_role;


--
-- Name: TABLE cameras; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.cameras TO anon;
GRANT ALL ON TABLE public.cameras TO authenticated;
GRANT ALL ON TABLE public.cameras TO service_role;


--
-- Name: TABLE chat_messages; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.chat_messages TO anon;
GRANT ALL ON TABLE public.chat_messages TO authenticated;
GRANT ALL ON TABLE public.chat_messages TO service_role;


--
-- Name: TABLE chat_thread_participants; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.chat_thread_participants TO anon;
GRANT ALL ON TABLE public.chat_thread_participants TO authenticated;
GRANT ALL ON TABLE public.chat_thread_participants TO service_role;


--
-- Name: TABLE chat_threads; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.chat_threads TO anon;
GRANT ALL ON TABLE public.chat_threads TO authenticated;
GRANT ALL ON TABLE public.chat_threads TO service_role;


--
-- Name: TABLE chatbot_knowledge_base; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.chatbot_knowledge_base TO anon;
GRANT ALL ON TABLE public.chatbot_knowledge_base TO authenticated;
GRANT ALL ON TABLE public.chatbot_knowledge_base TO service_role;


--
-- Name: TABLE detection_rules; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.detection_rules TO anon;
GRANT ALL ON TABLE public.detection_rules TO authenticated;
GRANT ALL ON TABLE public.detection_rules TO service_role;


--
-- Name: TABLE event_types; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.event_types TO anon;
GRANT ALL ON TABLE public.event_types TO authenticated;
GRANT ALL ON TABLE public.event_types TO service_role;


--
-- Name: TABLE events; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.events TO anon;
GRANT ALL ON TABLE public.events TO authenticated;
GRANT ALL ON TABLE public.events TO service_role;


--
-- Name: TABLE form_assignments; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.form_assignments TO anon;
GRANT ALL ON TABLE public.form_assignments TO authenticated;
GRANT ALL ON TABLE public.form_assignments TO service_role;


--
-- Name: TABLE form_distribution_settings; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.form_distribution_settings TO anon;
GRANT ALL ON TABLE public.form_distribution_settings TO authenticated;
GRANT ALL ON TABLE public.form_distribution_settings TO service_role;


--
-- Name: TABLE form_submissions; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.form_submissions TO anon;
GRANT ALL ON TABLE public.form_submissions TO authenticated;
GRANT ALL ON TABLE public.form_submissions TO service_role;


--
-- Name: TABLE frigate_alert_rules; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.frigate_alert_rules TO anon;
GRANT ALL ON TABLE public.frigate_alert_rules TO authenticated;
GRANT ALL ON TABLE public.frigate_alert_rules TO service_role;


--
-- Name: TABLE frigate_deployed_models; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.frigate_deployed_models TO anon;
GRANT ALL ON TABLE public.frigate_deployed_models TO authenticated;
GRANT ALL ON TABLE public.frigate_deployed_models TO service_role;


--
-- Name: TABLE frigate_exports; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.frigate_exports TO anon;
GRANT ALL ON TABLE public.frigate_exports TO authenticated;
GRANT ALL ON TABLE public.frigate_exports TO service_role;


--
-- Name: TABLE frigate_faces; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.frigate_faces TO anon;
GRANT ALL ON TABLE public.frigate_faces TO authenticated;
GRANT ALL ON TABLE public.frigate_faces TO service_role;


--
-- Name: TABLE frigate_instances; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.frigate_instances TO anon;
GRANT ALL ON TABLE public.frigate_instances TO authenticated;
GRANT ALL ON TABLE public.frigate_instances TO service_role;


--
-- Name: TABLE frigate_license_plates; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.frigate_license_plates TO anon;
GRANT ALL ON TABLE public.frigate_license_plates TO authenticated;
GRANT ALL ON TABLE public.frigate_license_plates TO service_role;


--
-- Name: TABLE frigate_model_deployments; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.frigate_model_deployments TO anon;
GRANT ALL ON TABLE public.frigate_model_deployments TO authenticated;
GRANT ALL ON TABLE public.frigate_model_deployments TO service_role;


--
-- Name: TABLE frigate_model_registry; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.frigate_model_registry TO anon;
GRANT ALL ON TABLE public.frigate_model_registry TO authenticated;
GRANT ALL ON TABLE public.frigate_model_registry TO service_role;


--
-- Name: TABLE frigate_model_sync_log; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.frigate_model_sync_log TO anon;
GRANT ALL ON TABLE public.frigate_model_sync_log TO authenticated;
GRANT ALL ON TABLE public.frigate_model_sync_log TO service_role;


--
-- Name: TABLE frigate_previews; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.frigate_previews TO anon;
GRANT ALL ON TABLE public.frigate_previews TO authenticated;
GRANT ALL ON TABLE public.frigate_previews TO service_role;


--
-- Name: TABLE frigate_recordings; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.frigate_recordings TO anon;
GRANT ALL ON TABLE public.frigate_recordings TO authenticated;
GRANT ALL ON TABLE public.frigate_recordings TO service_role;


--
-- Name: TABLE frigate_reviews; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.frigate_reviews TO anon;
GRANT ALL ON TABLE public.frigate_reviews TO authenticated;
GRANT ALL ON TABLE public.frigate_reviews TO service_role;


--
-- Name: TABLE frigate_stats_history; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.frigate_stats_history TO anon;
GRANT ALL ON TABLE public.frigate_stats_history TO authenticated;
GRANT ALL ON TABLE public.frigate_stats_history TO service_role;


--
-- Name: TABLE frigate_sync_logs; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.frigate_sync_logs TO anon;
GRANT ALL ON TABLE public.frigate_sync_logs TO authenticated;
GRANT ALL ON TABLE public.frigate_sync_logs TO service_role;


--
-- Name: TABLE frigate_timeline; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.frigate_timeline TO anon;
GRANT ALL ON TABLE public.frigate_timeline TO authenticated;
GRANT ALL ON TABLE public.frigate_timeline TO service_role;


--
-- Name: TABLE frigate_triggers; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.frigate_triggers TO anon;
GRANT ALL ON TABLE public.frigate_triggers TO authenticated;
GRANT ALL ON TABLE public.frigate_triggers TO service_role;


--
-- Name: TABLE frigate_zones; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.frigate_zones TO anon;
GRANT ALL ON TABLE public.frigate_zones TO authenticated;
GRANT ALL ON TABLE public.frigate_zones TO service_role;


--
-- Name: TABLE health_alerts; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.health_alerts TO anon;
GRANT ALL ON TABLE public.health_alerts TO authenticated;
GRANT ALL ON TABLE public.health_alerts TO service_role;


--
-- Name: TABLE industries; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.industries TO anon;
GRANT ALL ON TABLE public.industries TO authenticated;
GRANT ALL ON TABLE public.industries TO service_role;


--
-- Name: TABLE legal_documents; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.legal_documents TO anon;
GRANT ALL ON TABLE public.legal_documents TO authenticated;
GRANT ALL ON TABLE public.legal_documents TO service_role;


--
-- Name: TABLE network_scan_results; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.network_scan_results TO anon;
GRANT ALL ON TABLE public.network_scan_results TO authenticated;
GRANT ALL ON TABLE public.network_scan_results TO service_role;


--
-- Name: TABLE notification_labels; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.notification_labels TO anon;
GRANT ALL ON TABLE public.notification_labels TO authenticated;
GRANT ALL ON TABLE public.notification_labels TO service_role;


--
-- Name: TABLE notification_methods; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.notification_methods TO anon;
GRANT ALL ON TABLE public.notification_methods TO authenticated;
GRANT ALL ON TABLE public.notification_methods TO service_role;


--
-- Name: TABLE organization_settings; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.organization_settings TO anon;
GRANT ALL ON TABLE public.organization_settings TO authenticated;
GRANT ALL ON TABLE public.organization_settings TO service_role;


--
-- Name: TABLE organizations; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.organizations TO anon;
GRANT ALL ON TABLE public.organizations TO authenticated;
GRANT ALL ON TABLE public.organizations TO service_role;


--
-- Name: TABLE pinned_dashboards; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.pinned_dashboards TO anon;
GRANT ALL ON TABLE public.pinned_dashboards TO authenticated;
GRANT ALL ON TABLE public.pinned_dashboards TO service_role;


--
-- Name: TABLE pinned_labels; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.pinned_labels TO anon;
GRANT ALL ON TABLE public.pinned_labels TO authenticated;
GRANT ALL ON TABLE public.pinned_labels TO service_role;


--
-- Name: TABLE screen_permissions; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.screen_permissions TO anon;
GRANT ALL ON TABLE public.screen_permissions TO authenticated;
GRANT ALL ON TABLE public.screen_permissions TO service_role;


--
-- Name: TABLE security_zones; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.security_zones TO anon;
GRANT ALL ON TABLE public.security_zones TO authenticated;
GRANT ALL ON TABLE public.security_zones TO service_role;


--
-- Name: TABLE storage_configs; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.storage_configs TO anon;
GRANT ALL ON TABLE public.storage_configs TO authenticated;
GRANT ALL ON TABLE public.storage_configs TO service_role;


--
-- Name: TABLE students; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.students TO anon;
GRANT ALL ON TABLE public.students TO authenticated;
GRANT ALL ON TABLE public.students TO service_role;


--
-- Name: TABLE subscribers; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.subscribers TO anon;
GRANT ALL ON TABLE public.subscribers TO authenticated;
GRANT ALL ON TABLE public.subscribers TO service_role;


--
-- Name: TABLE system_settings; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.system_settings TO anon;
GRANT ALL ON TABLE public.system_settings TO authenticated;
GRANT ALL ON TABLE public.system_settings TO service_role;


--
-- Name: TABLE user_branch_access; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.user_branch_access TO anon;
GRANT ALL ON TABLE public.user_branch_access TO authenticated;
GRANT ALL ON TABLE public.user_branch_access TO service_role;


--
-- Name: TABLE user_group_members; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.user_group_members TO anon;
GRANT ALL ON TABLE public.user_group_members TO authenticated;
GRANT ALL ON TABLE public.user_group_members TO service_role;


--
-- Name: TABLE user_groups; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.user_groups TO anon;
GRANT ALL ON TABLE public.user_groups TO authenticated;
GRANT ALL ON TABLE public.user_groups TO service_role;


--
-- Name: TABLE user_preferences; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.user_preferences TO anon;
GRANT ALL ON TABLE public.user_preferences TO authenticated;
GRANT ALL ON TABLE public.user_preferences TO service_role;


--
-- Name: TABLE user_roles; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.user_roles TO anon;
GRANT ALL ON TABLE public.user_roles TO authenticated;
GRANT ALL ON TABLE public.user_roles TO service_role;


--
-- Name: TABLE workflow_forms; Type: ACL; Schema: public; Owner: postgres
--

GRANT ALL ON TABLE public.workflow_forms TO anon;
GRANT ALL ON TABLE public.workflow_forms TO authenticated;
GRANT ALL ON TABLE public.workflow_forms TO service_role;


--
-- Name: TABLE messages; Type: ACL; Schema: realtime; Owner: supabase_realtime_admin
--

GRANT ALL ON TABLE realtime.messages TO postgres;
GRANT ALL ON TABLE realtime.messages TO dashboard_user;
GRANT SELECT,INSERT,UPDATE ON TABLE realtime.messages TO anon;
GRANT SELECT,INSERT,UPDATE ON TABLE realtime.messages TO authenticated;
GRANT SELECT,INSERT,UPDATE ON TABLE realtime.messages TO service_role;


--
-- Name: TABLE messages_2026_07_02; Type: ACL; Schema: realtime; Owner: supabase_admin
--

GRANT ALL ON TABLE realtime.messages_2026_07_02 TO postgres;
GRANT ALL ON TABLE realtime.messages_2026_07_02 TO dashboard_user;


--
-- Name: TABLE messages_2026_07_03; Type: ACL; Schema: realtime; Owner: supabase_admin
--

GRANT ALL ON TABLE realtime.messages_2026_07_03 TO postgres;
GRANT ALL ON TABLE realtime.messages_2026_07_03 TO dashboard_user;


--
-- Name: TABLE messages_2026_07_04; Type: ACL; Schema: realtime; Owner: supabase_admin
--

GRANT ALL ON TABLE realtime.messages_2026_07_04 TO postgres;
GRANT ALL ON TABLE realtime.messages_2026_07_04 TO dashboard_user;


--
-- Name: TABLE messages_2026_07_05; Type: ACL; Schema: realtime; Owner: supabase_admin
--

GRANT ALL ON TABLE realtime.messages_2026_07_05 TO postgres;
GRANT ALL ON TABLE realtime.messages_2026_07_05 TO dashboard_user;


--
-- Name: TABLE messages_2026_07_06; Type: ACL; Schema: realtime; Owner: supabase_admin
--

GRANT ALL ON TABLE realtime.messages_2026_07_06 TO postgres;
GRANT ALL ON TABLE realtime.messages_2026_07_06 TO dashboard_user;


--
-- Name: TABLE messages_2026_07_07; Type: ACL; Schema: realtime; Owner: supabase_admin
--

GRANT ALL ON TABLE realtime.messages_2026_07_07 TO postgres;
GRANT ALL ON TABLE realtime.messages_2026_07_07 TO dashboard_user;


--
-- Name: TABLE messages_2026_07_08; Type: ACL; Schema: realtime; Owner: supabase_admin
--

GRANT ALL ON TABLE realtime.messages_2026_07_08 TO postgres;
GRANT ALL ON TABLE realtime.messages_2026_07_08 TO dashboard_user;


--
-- Name: TABLE schema_migrations; Type: ACL; Schema: realtime; Owner: supabase_admin
--

GRANT ALL ON TABLE realtime.schema_migrations TO postgres;
GRANT ALL ON TABLE realtime.schema_migrations TO dashboard_user;
GRANT SELECT ON TABLE realtime.schema_migrations TO anon;
GRANT SELECT ON TABLE realtime.schema_migrations TO authenticated;
GRANT SELECT ON TABLE realtime.schema_migrations TO service_role;
GRANT ALL ON TABLE realtime.schema_migrations TO supabase_realtime_admin;


--
-- Name: TABLE subscription; Type: ACL; Schema: realtime; Owner: supabase_admin
--

GRANT ALL ON TABLE realtime.subscription TO postgres;
GRANT ALL ON TABLE realtime.subscription TO dashboard_user;
GRANT SELECT ON TABLE realtime.subscription TO anon;
GRANT SELECT ON TABLE realtime.subscription TO authenticated;
GRANT SELECT ON TABLE realtime.subscription TO service_role;
GRANT ALL ON TABLE realtime.subscription TO supabase_realtime_admin;


--
-- Name: SEQUENCE subscription_id_seq; Type: ACL; Schema: realtime; Owner: supabase_admin
--

GRANT ALL ON SEQUENCE realtime.subscription_id_seq TO postgres;
GRANT ALL ON SEQUENCE realtime.subscription_id_seq TO dashboard_user;
GRANT USAGE ON SEQUENCE realtime.subscription_id_seq TO anon;
GRANT USAGE ON SEQUENCE realtime.subscription_id_seq TO authenticated;
GRANT USAGE ON SEQUENCE realtime.subscription_id_seq TO service_role;
GRANT ALL ON SEQUENCE realtime.subscription_id_seq TO supabase_realtime_admin;


--
-- Name: TABLE buckets; Type: ACL; Schema: storage; Owner: supabase_storage_admin
--

GRANT ALL ON TABLE storage.buckets TO postgres WITH GRANT OPTION;
GRANT ALL ON TABLE storage.buckets TO service_role;
GRANT ALL ON TABLE storage.buckets TO authenticated;
GRANT ALL ON TABLE storage.buckets TO anon;


--
-- Name: TABLE buckets_analytics; Type: ACL; Schema: storage; Owner: supabase_storage_admin
--

GRANT ALL ON TABLE storage.buckets_analytics TO service_role;
GRANT ALL ON TABLE storage.buckets_analytics TO authenticated;
GRANT ALL ON TABLE storage.buckets_analytics TO anon;


--
-- Name: TABLE buckets_vectors; Type: ACL; Schema: storage; Owner: supabase_storage_admin
--

GRANT SELECT ON TABLE storage.buckets_vectors TO service_role;
GRANT SELECT ON TABLE storage.buckets_vectors TO authenticated;
GRANT SELECT ON TABLE storage.buckets_vectors TO anon;


--
-- Name: TABLE iceberg_namespaces; Type: ACL; Schema: storage; Owner: supabase_storage_admin
--

GRANT ALL ON TABLE storage.iceberg_namespaces TO service_role;
GRANT SELECT ON TABLE storage.iceberg_namespaces TO authenticated;
GRANT SELECT ON TABLE storage.iceberg_namespaces TO anon;


--
-- Name: TABLE iceberg_tables; Type: ACL; Schema: storage; Owner: supabase_storage_admin
--

GRANT ALL ON TABLE storage.iceberg_tables TO service_role;
GRANT SELECT ON TABLE storage.iceberg_tables TO authenticated;
GRANT SELECT ON TABLE storage.iceberg_tables TO anon;


--
-- Name: TABLE objects; Type: ACL; Schema: storage; Owner: supabase_storage_admin
--

GRANT ALL ON TABLE storage.objects TO postgres WITH GRANT OPTION;
GRANT ALL ON TABLE storage.objects TO service_role;
GRANT ALL ON TABLE storage.objects TO authenticated;
GRANT ALL ON TABLE storage.objects TO anon;


--
-- Name: TABLE s3_multipart_uploads; Type: ACL; Schema: storage; Owner: supabase_storage_admin
--

GRANT ALL ON TABLE storage.s3_multipart_uploads TO service_role;
GRANT SELECT ON TABLE storage.s3_multipart_uploads TO authenticated;
GRANT SELECT ON TABLE storage.s3_multipart_uploads TO anon;


--
-- Name: TABLE s3_multipart_uploads_parts; Type: ACL; Schema: storage; Owner: supabase_storage_admin
--

GRANT ALL ON TABLE storage.s3_multipart_uploads_parts TO service_role;
GRANT SELECT ON TABLE storage.s3_multipart_uploads_parts TO authenticated;
GRANT SELECT ON TABLE storage.s3_multipart_uploads_parts TO anon;


--
-- Name: TABLE vector_indexes; Type: ACL; Schema: storage; Owner: supabase_storage_admin
--

GRANT SELECT ON TABLE storage.vector_indexes TO service_role;
GRANT SELECT ON TABLE storage.vector_indexes TO authenticated;
GRANT SELECT ON TABLE storage.vector_indexes TO anon;


--
-- Name: TABLE hooks; Type: ACL; Schema: supabase_functions; Owner: supabase_functions_admin
--

GRANT ALL ON TABLE supabase_functions.hooks TO postgres;
GRANT ALL ON TABLE supabase_functions.hooks TO anon;
GRANT ALL ON TABLE supabase_functions.hooks TO authenticated;
GRANT ALL ON TABLE supabase_functions.hooks TO service_role;


--
-- Name: SEQUENCE hooks_id_seq; Type: ACL; Schema: supabase_functions; Owner: supabase_functions_admin
--

GRANT ALL ON SEQUENCE supabase_functions.hooks_id_seq TO postgres;
GRANT ALL ON SEQUENCE supabase_functions.hooks_id_seq TO anon;
GRANT ALL ON SEQUENCE supabase_functions.hooks_id_seq TO authenticated;
GRANT ALL ON SEQUENCE supabase_functions.hooks_id_seq TO service_role;


--
-- Name: TABLE migrations; Type: ACL; Schema: supabase_functions; Owner: supabase_functions_admin
--

GRANT ALL ON TABLE supabase_functions.migrations TO postgres;
GRANT ALL ON TABLE supabase_functions.migrations TO anon;
GRANT ALL ON TABLE supabase_functions.migrations TO authenticated;
GRANT ALL ON TABLE supabase_functions.migrations TO service_role;


--
-- Name: TABLE secrets; Type: ACL; Schema: vault; Owner: supabase_admin
--

GRANT SELECT,REFERENCES,DELETE,TRUNCATE ON TABLE vault.secrets TO postgres WITH GRANT OPTION;
GRANT SELECT,DELETE ON TABLE vault.secrets TO service_role;


--
-- Name: TABLE decrypted_secrets; Type: ACL; Schema: vault; Owner: supabase_admin
--

GRANT SELECT,REFERENCES,DELETE,TRUNCATE ON TABLE vault.decrypted_secrets TO postgres WITH GRANT OPTION;
GRANT SELECT,DELETE ON TABLE vault.decrypted_secrets TO service_role;


--
-- Name: DEFAULT PRIVILEGES FOR SEQUENCES; Type: DEFAULT ACL; Schema: auth; Owner: supabase_auth_admin
--

ALTER DEFAULT PRIVILEGES FOR ROLE supabase_auth_admin IN SCHEMA auth GRANT ALL ON SEQUENCES TO postgres;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_auth_admin IN SCHEMA auth GRANT ALL ON SEQUENCES TO dashboard_user;


--
-- Name: DEFAULT PRIVILEGES FOR FUNCTIONS; Type: DEFAULT ACL; Schema: auth; Owner: supabase_auth_admin
--

ALTER DEFAULT PRIVILEGES FOR ROLE supabase_auth_admin IN SCHEMA auth GRANT ALL ON FUNCTIONS TO postgres;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_auth_admin IN SCHEMA auth GRANT ALL ON FUNCTIONS TO dashboard_user;


--
-- Name: DEFAULT PRIVILEGES FOR TABLES; Type: DEFAULT ACL; Schema: auth; Owner: supabase_auth_admin
--

ALTER DEFAULT PRIVILEGES FOR ROLE supabase_auth_admin IN SCHEMA auth GRANT ALL ON TABLES TO postgres;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_auth_admin IN SCHEMA auth GRANT ALL ON TABLES TO dashboard_user;


--
-- Name: DEFAULT PRIVILEGES FOR SEQUENCES; Type: DEFAULT ACL; Schema: extensions; Owner: supabase_admin
--

ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA extensions GRANT ALL ON SEQUENCES TO postgres WITH GRANT OPTION;


--
-- Name: DEFAULT PRIVILEGES FOR FUNCTIONS; Type: DEFAULT ACL; Schema: extensions; Owner: supabase_admin
--

ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA extensions GRANT ALL ON FUNCTIONS TO postgres WITH GRANT OPTION;


--
-- Name: DEFAULT PRIVILEGES FOR TABLES; Type: DEFAULT ACL; Schema: extensions; Owner: supabase_admin
--

ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA extensions GRANT ALL ON TABLES TO postgres WITH GRANT OPTION;


--
-- Name: DEFAULT PRIVILEGES FOR SEQUENCES; Type: DEFAULT ACL; Schema: graphql; Owner: supabase_admin
--

ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA graphql GRANT ALL ON SEQUENCES TO postgres;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA graphql GRANT ALL ON SEQUENCES TO anon;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA graphql GRANT ALL ON SEQUENCES TO authenticated;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA graphql GRANT ALL ON SEQUENCES TO service_role;


--
-- Name: DEFAULT PRIVILEGES FOR FUNCTIONS; Type: DEFAULT ACL; Schema: graphql; Owner: supabase_admin
--

ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA graphql GRANT ALL ON FUNCTIONS TO postgres;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA graphql GRANT ALL ON FUNCTIONS TO anon;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA graphql GRANT ALL ON FUNCTIONS TO authenticated;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA graphql GRANT ALL ON FUNCTIONS TO service_role;


--
-- Name: DEFAULT PRIVILEGES FOR TABLES; Type: DEFAULT ACL; Schema: graphql; Owner: supabase_admin
--

ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA graphql GRANT ALL ON TABLES TO postgres;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA graphql GRANT ALL ON TABLES TO anon;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA graphql GRANT ALL ON TABLES TO authenticated;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA graphql GRANT ALL ON TABLES TO service_role;


--
-- Name: DEFAULT PRIVILEGES FOR SEQUENCES; Type: DEFAULT ACL; Schema: graphql_public; Owner: supabase_admin
--

ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA graphql_public GRANT ALL ON SEQUENCES TO postgres;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA graphql_public GRANT ALL ON SEQUENCES TO anon;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA graphql_public GRANT ALL ON SEQUENCES TO authenticated;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA graphql_public GRANT ALL ON SEQUENCES TO service_role;


--
-- Name: DEFAULT PRIVILEGES FOR FUNCTIONS; Type: DEFAULT ACL; Schema: graphql_public; Owner: supabase_admin
--

ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA graphql_public GRANT ALL ON FUNCTIONS TO postgres;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA graphql_public GRANT ALL ON FUNCTIONS TO anon;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA graphql_public GRANT ALL ON FUNCTIONS TO authenticated;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA graphql_public GRANT ALL ON FUNCTIONS TO service_role;


--
-- Name: DEFAULT PRIVILEGES FOR TABLES; Type: DEFAULT ACL; Schema: graphql_public; Owner: supabase_admin
--

ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA graphql_public GRANT ALL ON TABLES TO postgres;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA graphql_public GRANT ALL ON TABLES TO anon;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA graphql_public GRANT ALL ON TABLES TO authenticated;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA graphql_public GRANT ALL ON TABLES TO service_role;


--
-- Name: DEFAULT PRIVILEGES FOR SEQUENCES; Type: DEFAULT ACL; Schema: public; Owner: postgres
--

ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON SEQUENCES TO postgres;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON SEQUENCES TO anon;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON SEQUENCES TO authenticated;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON SEQUENCES TO service_role;


--
-- Name: DEFAULT PRIVILEGES FOR SEQUENCES; Type: DEFAULT ACL; Schema: public; Owner: supabase_admin
--

ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON SEQUENCES TO postgres;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON SEQUENCES TO anon;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON SEQUENCES TO authenticated;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON SEQUENCES TO service_role;


--
-- Name: DEFAULT PRIVILEGES FOR FUNCTIONS; Type: DEFAULT ACL; Schema: public; Owner: postgres
--

ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON FUNCTIONS TO postgres;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON FUNCTIONS TO anon;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON FUNCTIONS TO authenticated;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON FUNCTIONS TO service_role;


--
-- Name: DEFAULT PRIVILEGES FOR FUNCTIONS; Type: DEFAULT ACL; Schema: public; Owner: supabase_admin
--

ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON FUNCTIONS TO postgres;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON FUNCTIONS TO anon;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON FUNCTIONS TO authenticated;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON FUNCTIONS TO service_role;


--
-- Name: DEFAULT PRIVILEGES FOR TABLES; Type: DEFAULT ACL; Schema: public; Owner: postgres
--

ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON TABLES TO postgres;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON TABLES TO anon;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON TABLES TO authenticated;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON TABLES TO service_role;


--
-- Name: DEFAULT PRIVILEGES FOR TABLES; Type: DEFAULT ACL; Schema: public; Owner: supabase_admin
--

ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON TABLES TO postgres;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON TABLES TO anon;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON TABLES TO authenticated;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON TABLES TO service_role;


--
-- Name: DEFAULT PRIVILEGES FOR SEQUENCES; Type: DEFAULT ACL; Schema: realtime; Owner: supabase_admin
--

ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA realtime GRANT ALL ON SEQUENCES TO postgres;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA realtime GRANT ALL ON SEQUENCES TO dashboard_user;


--
-- Name: DEFAULT PRIVILEGES FOR FUNCTIONS; Type: DEFAULT ACL; Schema: realtime; Owner: supabase_admin
--

ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA realtime GRANT ALL ON FUNCTIONS TO postgres;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA realtime GRANT ALL ON FUNCTIONS TO dashboard_user;


--
-- Name: DEFAULT PRIVILEGES FOR TABLES; Type: DEFAULT ACL; Schema: realtime; Owner: supabase_admin
--

ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA realtime GRANT ALL ON TABLES TO postgres;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA realtime GRANT ALL ON TABLES TO dashboard_user;


--
-- Name: DEFAULT PRIVILEGES FOR SEQUENCES; Type: DEFAULT ACL; Schema: storage; Owner: postgres
--

ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA storage GRANT ALL ON SEQUENCES TO postgres;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA storage GRANT ALL ON SEQUENCES TO anon;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA storage GRANT ALL ON SEQUENCES TO authenticated;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA storage GRANT ALL ON SEQUENCES TO service_role;


--
-- Name: DEFAULT PRIVILEGES FOR FUNCTIONS; Type: DEFAULT ACL; Schema: storage; Owner: postgres
--

ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA storage GRANT ALL ON FUNCTIONS TO postgres;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA storage GRANT ALL ON FUNCTIONS TO anon;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA storage GRANT ALL ON FUNCTIONS TO authenticated;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA storage GRANT ALL ON FUNCTIONS TO service_role;


--
-- Name: DEFAULT PRIVILEGES FOR TABLES; Type: DEFAULT ACL; Schema: storage; Owner: postgres
--

ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA storage GRANT ALL ON TABLES TO postgres;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA storage GRANT ALL ON TABLES TO anon;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA storage GRANT ALL ON TABLES TO authenticated;
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA storage GRANT ALL ON TABLES TO service_role;


--
-- Name: DEFAULT PRIVILEGES FOR SEQUENCES; Type: DEFAULT ACL; Schema: supabase_functions; Owner: supabase_admin
--

ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA supabase_functions GRANT ALL ON SEQUENCES TO postgres;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA supabase_functions GRANT ALL ON SEQUENCES TO anon;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA supabase_functions GRANT ALL ON SEQUENCES TO authenticated;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA supabase_functions GRANT ALL ON SEQUENCES TO service_role;


--
-- Name: DEFAULT PRIVILEGES FOR FUNCTIONS; Type: DEFAULT ACL; Schema: supabase_functions; Owner: supabase_admin
--

ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA supabase_functions GRANT ALL ON FUNCTIONS TO postgres;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA supabase_functions GRANT ALL ON FUNCTIONS TO anon;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA supabase_functions GRANT ALL ON FUNCTIONS TO authenticated;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA supabase_functions GRANT ALL ON FUNCTIONS TO service_role;


--
-- Name: DEFAULT PRIVILEGES FOR TABLES; Type: DEFAULT ACL; Schema: supabase_functions; Owner: supabase_admin
--

ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA supabase_functions GRANT ALL ON TABLES TO postgres;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA supabase_functions GRANT ALL ON TABLES TO anon;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA supabase_functions GRANT ALL ON TABLES TO authenticated;
ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA supabase_functions GRANT ALL ON TABLES TO service_role;


--
-- Name: issue_graphql_placeholder; Type: EVENT TRIGGER; Schema: -; Owner: supabase_admin
--

CREATE EVENT TRIGGER issue_graphql_placeholder ON sql_drop
         WHEN TAG IN ('DROP EXTENSION')
   EXECUTE FUNCTION extensions.set_graphql_placeholder();


ALTER EVENT TRIGGER issue_graphql_placeholder OWNER TO supabase_admin;

--
-- Name: issue_pg_cron_access; Type: EVENT TRIGGER; Schema: -; Owner: supabase_admin
--

CREATE EVENT TRIGGER issue_pg_cron_access ON ddl_command_end
         WHEN TAG IN ('CREATE EXTENSION')
   EXECUTE FUNCTION extensions.grant_pg_cron_access();


ALTER EVENT TRIGGER issue_pg_cron_access OWNER TO supabase_admin;

--
-- Name: issue_pg_graphql_access; Type: EVENT TRIGGER; Schema: -; Owner: supabase_admin
--

CREATE EVENT TRIGGER issue_pg_graphql_access ON ddl_command_end
         WHEN TAG IN ('CREATE EXTENSION')
   EXECUTE FUNCTION extensions.grant_pg_graphql_access();


ALTER EVENT TRIGGER issue_pg_graphql_access OWNER TO supabase_admin;

--
-- Name: issue_pg_net_access; Type: EVENT TRIGGER; Schema: -; Owner: supabase_admin
--

CREATE EVENT TRIGGER issue_pg_net_access ON ddl_command_end
         WHEN TAG IN ('CREATE EXTENSION')
   EXECUTE FUNCTION extensions.grant_pg_net_access();


ALTER EVENT TRIGGER issue_pg_net_access OWNER TO supabase_admin;

--
-- Name: pgrst_ddl_watch; Type: EVENT TRIGGER; Schema: -; Owner: supabase_admin
--

CREATE EVENT TRIGGER pgrst_ddl_watch ON ddl_command_end
   EXECUTE FUNCTION extensions.pgrst_ddl_watch();


ALTER EVENT TRIGGER pgrst_ddl_watch OWNER TO supabase_admin;

--
-- Name: pgrst_drop_watch; Type: EVENT TRIGGER; Schema: -; Owner: supabase_admin
--

CREATE EVENT TRIGGER pgrst_drop_watch ON sql_drop
   EXECUTE FUNCTION extensions.pgrst_drop_watch();


ALTER EVENT TRIGGER pgrst_drop_watch OWNER TO supabase_admin;

--
--

\unrestrict LV0qnjUH3SWL0aBPGm6cy1ZkmlSzDJdVUfB9wNeKmjDM3b1Te6x9rqoVJJo161S

