erp-cicd/my-access-hub-main/supabase/migrations/20250810140119_ddc25fa9-f5d1-442d-8466-f661fa3d8265.sql
Ali 20e95c2fb6
Some checks failed
Build & Deploy Frontend / build-push-deploy (push) Failing after 15s
pushing all
2025-08-30 11:51:11 +05:30

40 lines
1.2 KiB
SQL

-- Create page_layouts table for storing drag-and-drop page layouts
CREATE TABLE public.page_layouts (
id UUID NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY,
user_id UUID NOT NULL,
name TEXT NOT NULL,
nodes JSONB NOT NULL DEFAULT '[]'::jsonb,
edges JSONB NOT NULL DEFAULT '[]'::jsonb,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now()
);
-- Enable Row Level Security
ALTER TABLE public.page_layouts ENABLE ROW LEVEL SECURITY;
-- Create policies for user access
CREATE POLICY "Users can view their own page layouts"
ON public.page_layouts
FOR SELECT
USING (auth.uid() = user_id);
CREATE POLICY "Users can create their own page layouts"
ON public.page_layouts
FOR INSERT
WITH CHECK (auth.uid() = user_id);
CREATE POLICY "Users can update their own page layouts"
ON public.page_layouts
FOR UPDATE
USING (auth.uid() = user_id);
CREATE POLICY "Users can delete their own page layouts"
ON public.page_layouts
FOR DELETE
USING (auth.uid() = user_id);
-- Create trigger for automatic timestamp updates
CREATE TRIGGER update_page_layouts_updated_at
BEFORE UPDATE ON public.page_layouts
FOR EACH ROW
EXECUTE FUNCTION public.update_updated_at_column();