refactor: flatten monorepo structure to backend/ frontend/ devops/
Rename subdirectories for a cleaner single-repo layout: - website-monitoring-backend/ → backend/ - website-monitoring-frontend/ → frontend/ - website-monitoring-devops/ → devops/ Update all references in package.json scripts, CI workflows, docker-compose, pre-commit hooks, and documentation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,424 @@
|
||||
revoke delete on table "auth"."audit_log_entries" from "postgres";
|
||||
|
||||
revoke insert on table "auth"."audit_log_entries" from "postgres";
|
||||
|
||||
revoke references on table "auth"."audit_log_entries" from "postgres";
|
||||
|
||||
revoke select on table "auth"."audit_log_entries" from "postgres";
|
||||
|
||||
revoke trigger on table "auth"."audit_log_entries" from "postgres";
|
||||
|
||||
revoke truncate on table "auth"."audit_log_entries" from "postgres";
|
||||
|
||||
revoke update on table "auth"."audit_log_entries" from "postgres";
|
||||
|
||||
revoke delete on table "auth"."flow_state" from "postgres";
|
||||
|
||||
revoke insert on table "auth"."flow_state" from "postgres";
|
||||
|
||||
revoke references on table "auth"."flow_state" from "postgres";
|
||||
|
||||
revoke select on table "auth"."flow_state" from "postgres";
|
||||
|
||||
revoke trigger on table "auth"."flow_state" from "postgres";
|
||||
|
||||
revoke truncate on table "auth"."flow_state" from "postgres";
|
||||
|
||||
revoke update on table "auth"."flow_state" from "postgres";
|
||||
|
||||
revoke delete on table "auth"."identities" from "postgres";
|
||||
|
||||
revoke insert on table "auth"."identities" from "postgres";
|
||||
|
||||
revoke references on table "auth"."identities" from "postgres";
|
||||
|
||||
revoke select on table "auth"."identities" from "postgres";
|
||||
|
||||
revoke trigger on table "auth"."identities" from "postgres";
|
||||
|
||||
revoke truncate on table "auth"."identities" from "postgres";
|
||||
|
||||
revoke update on table "auth"."identities" from "postgres";
|
||||
|
||||
revoke delete on table "auth"."instances" from "postgres";
|
||||
|
||||
revoke insert on table "auth"."instances" from "postgres";
|
||||
|
||||
revoke references on table "auth"."instances" from "postgres";
|
||||
|
||||
revoke select on table "auth"."instances" from "postgres";
|
||||
|
||||
revoke trigger on table "auth"."instances" from "postgres";
|
||||
|
||||
revoke truncate on table "auth"."instances" from "postgres";
|
||||
|
||||
revoke update on table "auth"."instances" from "postgres";
|
||||
|
||||
revoke delete on table "auth"."mfa_amr_claims" from "postgres";
|
||||
|
||||
revoke insert on table "auth"."mfa_amr_claims" from "postgres";
|
||||
|
||||
revoke references on table "auth"."mfa_amr_claims" from "postgres";
|
||||
|
||||
revoke select on table "auth"."mfa_amr_claims" from "postgres";
|
||||
|
||||
revoke trigger on table "auth"."mfa_amr_claims" from "postgres";
|
||||
|
||||
revoke truncate on table "auth"."mfa_amr_claims" from "postgres";
|
||||
|
||||
revoke update on table "auth"."mfa_amr_claims" from "postgres";
|
||||
|
||||
revoke delete on table "auth"."mfa_challenges" from "postgres";
|
||||
|
||||
revoke insert on table "auth"."mfa_challenges" from "postgres";
|
||||
|
||||
revoke references on table "auth"."mfa_challenges" from "postgres";
|
||||
|
||||
revoke select on table "auth"."mfa_challenges" from "postgres";
|
||||
|
||||
revoke trigger on table "auth"."mfa_challenges" from "postgres";
|
||||
|
||||
revoke truncate on table "auth"."mfa_challenges" from "postgres";
|
||||
|
||||
revoke update on table "auth"."mfa_challenges" from "postgres";
|
||||
|
||||
revoke delete on table "auth"."mfa_factors" from "postgres";
|
||||
|
||||
revoke insert on table "auth"."mfa_factors" from "postgres";
|
||||
|
||||
revoke references on table "auth"."mfa_factors" from "postgres";
|
||||
|
||||
revoke select on table "auth"."mfa_factors" from "postgres";
|
||||
|
||||
revoke trigger on table "auth"."mfa_factors" from "postgres";
|
||||
|
||||
revoke truncate on table "auth"."mfa_factors" from "postgres";
|
||||
|
||||
revoke update on table "auth"."mfa_factors" from "postgres";
|
||||
|
||||
revoke delete on table "auth"."one_time_tokens" from "postgres";
|
||||
|
||||
revoke insert on table "auth"."one_time_tokens" from "postgres";
|
||||
|
||||
revoke references on table "auth"."one_time_tokens" from "postgres";
|
||||
|
||||
revoke select on table "auth"."one_time_tokens" from "postgres";
|
||||
|
||||
revoke trigger on table "auth"."one_time_tokens" from "postgres";
|
||||
|
||||
revoke truncate on table "auth"."one_time_tokens" from "postgres";
|
||||
|
||||
revoke update on table "auth"."one_time_tokens" from "postgres";
|
||||
|
||||
revoke delete on table "auth"."refresh_tokens" from "postgres";
|
||||
|
||||
revoke insert on table "auth"."refresh_tokens" from "postgres";
|
||||
|
||||
revoke references on table "auth"."refresh_tokens" from "postgres";
|
||||
|
||||
revoke select on table "auth"."refresh_tokens" from "postgres";
|
||||
|
||||
revoke trigger on table "auth"."refresh_tokens" from "postgres";
|
||||
|
||||
revoke truncate on table "auth"."refresh_tokens" from "postgres";
|
||||
|
||||
revoke update on table "auth"."refresh_tokens" from "postgres";
|
||||
|
||||
revoke delete on table "auth"."saml_providers" from "postgres";
|
||||
|
||||
revoke insert on table "auth"."saml_providers" from "postgres";
|
||||
|
||||
revoke references on table "auth"."saml_providers" from "postgres";
|
||||
|
||||
revoke select on table "auth"."saml_providers" from "postgres";
|
||||
|
||||
revoke trigger on table "auth"."saml_providers" from "postgres";
|
||||
|
||||
revoke truncate on table "auth"."saml_providers" from "postgres";
|
||||
|
||||
revoke update on table "auth"."saml_providers" from "postgres";
|
||||
|
||||
revoke delete on table "auth"."saml_relay_states" from "postgres";
|
||||
|
||||
revoke insert on table "auth"."saml_relay_states" from "postgres";
|
||||
|
||||
revoke references on table "auth"."saml_relay_states" from "postgres";
|
||||
|
||||
revoke select on table "auth"."saml_relay_states" from "postgres";
|
||||
|
||||
revoke trigger on table "auth"."saml_relay_states" from "postgres";
|
||||
|
||||
revoke truncate on table "auth"."saml_relay_states" from "postgres";
|
||||
|
||||
revoke update on table "auth"."saml_relay_states" from "postgres";
|
||||
|
||||
revoke select on table "auth"."schema_migrations" from "postgres";
|
||||
|
||||
revoke delete on table "auth"."sessions" from "postgres";
|
||||
|
||||
revoke insert on table "auth"."sessions" from "postgres";
|
||||
|
||||
revoke references on table "auth"."sessions" from "postgres";
|
||||
|
||||
revoke select on table "auth"."sessions" from "postgres";
|
||||
|
||||
revoke trigger on table "auth"."sessions" from "postgres";
|
||||
|
||||
revoke truncate on table "auth"."sessions" from "postgres";
|
||||
|
||||
revoke update on table "auth"."sessions" from "postgres";
|
||||
|
||||
revoke delete on table "auth"."sso_domains" from "postgres";
|
||||
|
||||
revoke insert on table "auth"."sso_domains" from "postgres";
|
||||
|
||||
revoke references on table "auth"."sso_domains" from "postgres";
|
||||
|
||||
revoke select on table "auth"."sso_domains" from "postgres";
|
||||
|
||||
revoke trigger on table "auth"."sso_domains" from "postgres";
|
||||
|
||||
revoke truncate on table "auth"."sso_domains" from "postgres";
|
||||
|
||||
revoke update on table "auth"."sso_domains" from "postgres";
|
||||
|
||||
revoke delete on table "auth"."sso_providers" from "postgres";
|
||||
|
||||
revoke insert on table "auth"."sso_providers" from "postgres";
|
||||
|
||||
revoke references on table "auth"."sso_providers" from "postgres";
|
||||
|
||||
revoke select on table "auth"."sso_providers" from "postgres";
|
||||
|
||||
revoke trigger on table "auth"."sso_providers" from "postgres";
|
||||
|
||||
revoke truncate on table "auth"."sso_providers" from "postgres";
|
||||
|
||||
revoke update on table "auth"."sso_providers" from "postgres";
|
||||
|
||||
revoke delete on table "auth"."users" from "postgres";
|
||||
|
||||
revoke insert on table "auth"."users" from "postgres";
|
||||
|
||||
revoke references on table "auth"."users" from "postgres";
|
||||
|
||||
revoke select on table "auth"."users" from "postgres";
|
||||
|
||||
revoke trigger on table "auth"."users" from "postgres";
|
||||
|
||||
revoke truncate on table "auth"."users" from "postgres";
|
||||
|
||||
revoke update on table "auth"."users" from "postgres";
|
||||
|
||||
set check_function_bodies = off;
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.handle_new_user()
|
||||
RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
SECURITY DEFINER
|
||||
SET search_path TO 'public'
|
||||
AS $function$
|
||||
DECLARE
|
||||
organization_id UUID;
|
||||
BEGIN
|
||||
-- First create organization if it doesn't exist
|
||||
INSERT INTO public.organizations (
|
||||
name,
|
||||
subscription_tier,
|
||||
subscription_status
|
||||
) VALUES (
|
||||
COALESCE(NEW.raw_user_meta_data->>'organization_name', NEW.raw_user_meta_data->>'name' || '''s Organization'),
|
||||
'free',
|
||||
'active'
|
||||
)
|
||||
RETURNING id INTO organization_id;
|
||||
|
||||
-- Then create the user profile
|
||||
INSERT INTO public.users (
|
||||
id,
|
||||
email,
|
||||
name,
|
||||
organization_id,
|
||||
role,
|
||||
is_active,
|
||||
settings,
|
||||
created_at,
|
||||
updated_at
|
||||
) VALUES (
|
||||
NEW.id,
|
||||
NEW.email,
|
||||
COALESCE(NEW.raw_user_meta_data->>'name', split_part(NEW.email, '@', 1)),
|
||||
organization_id,
|
||||
COALESCE(NEW.raw_user_meta_data->>'role', 'viewer')::user_role,
|
||||
true,
|
||||
jsonb_build_object(
|
||||
'email_notifications', true,
|
||||
'notification_frequency', 'instant',
|
||||
'dashboard_layout', 'default'
|
||||
),
|
||||
NOW(),
|
||||
NOW()
|
||||
);
|
||||
|
||||
RETURN NEW;
|
||||
EXCEPTION
|
||||
WHEN others THEN
|
||||
-- Log the error (will appear in Postgres logs)
|
||||
RAISE LOG 'Error in handle_new_user: %', SQLERRM;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$function$
|
||||
;
|
||||
|
||||
DROP TRIGGER IF EXISTS on_auth_user_created ON auth.users;
|
||||
CREATE TRIGGER on_auth_user_created AFTER INSERT ON auth.users FOR EACH ROW EXECUTE FUNCTION public.handle_new_user();
|
||||
|
||||
revoke delete on table "storage"."buckets" from "anon";
|
||||
|
||||
revoke insert on table "storage"."buckets" from "anon";
|
||||
|
||||
revoke references on table "storage"."buckets" from "anon";
|
||||
|
||||
revoke select on table "storage"."buckets" from "anon";
|
||||
|
||||
revoke trigger on table "storage"."buckets" from "anon";
|
||||
|
||||
revoke truncate on table "storage"."buckets" from "anon";
|
||||
|
||||
revoke update on table "storage"."buckets" from "anon";
|
||||
|
||||
revoke delete on table "storage"."buckets" from "authenticated";
|
||||
|
||||
revoke insert on table "storage"."buckets" from "authenticated";
|
||||
|
||||
revoke references on table "storage"."buckets" from "authenticated";
|
||||
|
||||
revoke select on table "storage"."buckets" from "authenticated";
|
||||
|
||||
revoke trigger on table "storage"."buckets" from "authenticated";
|
||||
|
||||
revoke truncate on table "storage"."buckets" from "authenticated";
|
||||
|
||||
revoke update on table "storage"."buckets" from "authenticated";
|
||||
|
||||
revoke delete on table "storage"."buckets" from "postgres";
|
||||
|
||||
revoke insert on table "storage"."buckets" from "postgres";
|
||||
|
||||
revoke references on table "storage"."buckets" from "postgres";
|
||||
|
||||
revoke select on table "storage"."buckets" from "postgres";
|
||||
|
||||
revoke trigger on table "storage"."buckets" from "postgres";
|
||||
|
||||
revoke truncate on table "storage"."buckets" from "postgres";
|
||||
|
||||
revoke update on table "storage"."buckets" from "postgres";
|
||||
|
||||
revoke delete on table "storage"."buckets" from "service_role";
|
||||
|
||||
revoke insert on table "storage"."buckets" from "service_role";
|
||||
|
||||
revoke references on table "storage"."buckets" from "service_role";
|
||||
|
||||
revoke select on table "storage"."buckets" from "service_role";
|
||||
|
||||
revoke trigger on table "storage"."buckets" from "service_role";
|
||||
|
||||
revoke truncate on table "storage"."buckets" from "service_role";
|
||||
|
||||
revoke update on table "storage"."buckets" from "service_role";
|
||||
|
||||
revoke delete on table "storage"."objects" from "anon";
|
||||
|
||||
revoke insert on table "storage"."objects" from "anon";
|
||||
|
||||
revoke references on table "storage"."objects" from "anon";
|
||||
|
||||
revoke select on table "storage"."objects" from "anon";
|
||||
|
||||
revoke trigger on table "storage"."objects" from "anon";
|
||||
|
||||
revoke truncate on table "storage"."objects" from "anon";
|
||||
|
||||
revoke update on table "storage"."objects" from "anon";
|
||||
|
||||
revoke delete on table "storage"."objects" from "authenticated";
|
||||
|
||||
revoke insert on table "storage"."objects" from "authenticated";
|
||||
|
||||
revoke references on table "storage"."objects" from "authenticated";
|
||||
|
||||
revoke select on table "storage"."objects" from "authenticated";
|
||||
|
||||
revoke trigger on table "storage"."objects" from "authenticated";
|
||||
|
||||
revoke truncate on table "storage"."objects" from "authenticated";
|
||||
|
||||
revoke update on table "storage"."objects" from "authenticated";
|
||||
|
||||
revoke delete on table "storage"."objects" from "postgres";
|
||||
|
||||
revoke insert on table "storage"."objects" from "postgres";
|
||||
|
||||
revoke references on table "storage"."objects" from "postgres";
|
||||
|
||||
revoke select on table "storage"."objects" from "postgres";
|
||||
|
||||
revoke trigger on table "storage"."objects" from "postgres";
|
||||
|
||||
revoke truncate on table "storage"."objects" from "postgres";
|
||||
|
||||
revoke update on table "storage"."objects" from "postgres";
|
||||
|
||||
revoke delete on table "storage"."objects" from "service_role";
|
||||
|
||||
revoke insert on table "storage"."objects" from "service_role";
|
||||
|
||||
revoke references on table "storage"."objects" from "service_role";
|
||||
|
||||
revoke select on table "storage"."objects" from "service_role";
|
||||
|
||||
revoke trigger on table "storage"."objects" from "service_role";
|
||||
|
||||
revoke truncate on table "storage"."objects" from "service_role";
|
||||
|
||||
revoke update on table "storage"."objects" from "service_role";
|
||||
|
||||
revoke select on table "storage"."s3_multipart_uploads" from "anon";
|
||||
|
||||
revoke select on table "storage"."s3_multipart_uploads" from "authenticated";
|
||||
|
||||
revoke delete on table "storage"."s3_multipart_uploads" from "service_role";
|
||||
|
||||
revoke insert on table "storage"."s3_multipart_uploads" from "service_role";
|
||||
|
||||
revoke references on table "storage"."s3_multipart_uploads" from "service_role";
|
||||
|
||||
revoke select on table "storage"."s3_multipart_uploads" from "service_role";
|
||||
|
||||
revoke trigger on table "storage"."s3_multipart_uploads" from "service_role";
|
||||
|
||||
revoke truncate on table "storage"."s3_multipart_uploads" from "service_role";
|
||||
|
||||
revoke update on table "storage"."s3_multipart_uploads" from "service_role";
|
||||
|
||||
revoke select on table "storage"."s3_multipart_uploads_parts" from "anon";
|
||||
|
||||
revoke select on table "storage"."s3_multipart_uploads_parts" from "authenticated";
|
||||
|
||||
revoke delete on table "storage"."s3_multipart_uploads_parts" from "service_role";
|
||||
|
||||
revoke insert on table "storage"."s3_multipart_uploads_parts" from "service_role";
|
||||
|
||||
revoke references on table "storage"."s3_multipart_uploads_parts" from "service_role";
|
||||
|
||||
revoke select on table "storage"."s3_multipart_uploads_parts" from "service_role";
|
||||
|
||||
revoke trigger on table "storage"."s3_multipart_uploads_parts" from "service_role";
|
||||
|
||||
revoke truncate on table "storage"."s3_multipart_uploads_parts" from "service_role";
|
||||
|
||||
revoke update on table "storage"."s3_multipart_uploads_parts" from "service_role";
|
||||
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
-- Add missing enum types
|
||||
DO $$ BEGIN
|
||||
CREATE TYPE scan_status AS ENUM ('pending', 'queued', 'running', 'completed', 'failed', 'cancelled');
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
|
||||
DO $$ BEGIN
|
||||
CREATE TYPE severity_level AS ENUM ('low', 'medium', 'high', 'critical');
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
|
||||
DO $$ BEGIN
|
||||
CREATE TYPE comparison_operator AS ENUM ('equals', 'not_equals', 'greater_than', 'less_than', 'contains', 'not_contains');
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
|
||||
-- Add missing columns to scans table
|
||||
ALTER TABLE scans ADD COLUMN IF NOT EXISTS scheduled_at TIMESTAMP WITH TIME ZONE;
|
||||
ALTER TABLE scans ADD COLUMN IF NOT EXISTS trigger_type TEXT DEFAULT 'manual';
|
||||
ALTER TABLE scans ADD COLUMN IF NOT EXISTS website_id UUID REFERENCES websites(id);
|
||||
ALTER TABLE scans ADD COLUMN IF NOT EXISTS triggered_by UUID REFERENCES auth.users(id);
|
||||
ALTER TABLE scans ADD COLUMN IF NOT EXISTS scan_type TEXT DEFAULT 'lighthouse';
|
||||
ALTER TABLE scans ADD COLUMN IF NOT EXISTS priority INTEGER DEFAULT 5;
|
||||
ALTER TABLE scans ADD COLUMN IF NOT EXISTS categories TEXT[] DEFAULT ARRAY['performance', 'seo', 'accessibility', 'best_practices'];
|
||||
ALTER TABLE scans ADD COLUMN IF NOT EXISTS device_type TEXT DEFAULT 'desktop';
|
||||
ALTER TABLE scans ADD COLUMN IF NOT EXISTS user_agent TEXT;
|
||||
ALTER TABLE scans ADD COLUMN IF NOT EXISTS lighthouse_version TEXT;
|
||||
ALTER TABLE scans ADD COLUMN IF NOT EXISTS chrome_version TEXT;
|
||||
ALTER TABLE scans ADD COLUMN IF NOT EXISTS environment TEXT DEFAULT 'production';
|
||||
ALTER TABLE scans ADD COLUMN IF NOT EXISTS started_at TIMESTAMP WITH TIME ZONE;
|
||||
ALTER TABLE scans ADD COLUMN IF NOT EXISTS completed_at TIMESTAMP WITH TIME ZONE;
|
||||
ALTER TABLE scans ADD COLUMN IF NOT EXISTS duration_ms INTEGER;
|
||||
ALTER TABLE scans ADD COLUMN IF NOT EXISTS error_message TEXT;
|
||||
ALTER TABLE scans ADD COLUMN IF NOT EXISTS retry_count INTEGER DEFAULT 0;
|
||||
ALTER TABLE scans ADD COLUMN IF NOT EXISTS metadata JSONB DEFAULT '{}';
|
||||
ALTER TABLE scans ADD COLUMN IF NOT EXISTS updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW();
|
||||
|
||||
-- Add missing columns to pages table
|
||||
ALTER TABLE pages ADD COLUMN IF NOT EXISTS status scan_status DEFAULT 'pending';
|
||||
ALTER TABLE pages ADD COLUMN IF NOT EXISTS last_scanned_at TIMESTAMP WITH TIME ZONE;
|
||||
ALTER TABLE pages ADD COLUMN IF NOT EXISTS scan_count INTEGER DEFAULT 0;
|
||||
ALTER TABLE pages ADD COLUMN IF NOT EXISTS metadata JSONB DEFAULT '{}';
|
||||
|
||||
-- Add missing columns to websites table
|
||||
ALTER TABLE websites ADD COLUMN IF NOT EXISTS crawl_settings JSONB DEFAULT '{}';
|
||||
ALTER TABLE websites ADD COLUMN IF NOT EXISTS alert_settings JSONB DEFAULT '{}';
|
||||
ALTER TABLE websites ADD COLUMN IF NOT EXISTS last_crawled_at TIMESTAMP WITH TIME ZONE;
|
||||
ALTER TABLE websites ADD COLUMN IF NOT EXISTS crawl_session_id UUID;
|
||||
ALTER TABLE websites ADD COLUMN IF NOT EXISTS metadata JSONB DEFAULT '{}';
|
||||
|
||||
-- Add missing columns to users table
|
||||
ALTER TABLE users ADD COLUMN IF NOT EXISTS organization_id UUID REFERENCES organizations(id);
|
||||
ALTER TABLE users ADD COLUMN IF NOT EXISTS role TEXT DEFAULT 'user';
|
||||
ALTER TABLE users ADD COLUMN IF NOT EXISTS preferences JSONB DEFAULT '{}';
|
||||
|
||||
-- Add missing columns to organizations table
|
||||
ALTER TABLE organizations ADD COLUMN IF NOT EXISTS settings JSONB DEFAULT '{}';
|
||||
ALTER TABLE organizations ADD COLUMN IF NOT EXISTS subscription_plan TEXT DEFAULT 'free';
|
||||
ALTER TABLE organizations ADD COLUMN IF NOT EXISTS subscription_status TEXT DEFAULT 'active';
|
||||
|
||||
-- Create indexes for better performance
|
||||
CREATE INDEX IF NOT EXISTS idx_scans_website_id ON scans(website_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_scans_status ON scans(status);
|
||||
CREATE INDEX IF NOT EXISTS idx_scans_created_at ON scans(created_at);
|
||||
CREATE INDEX IF NOT EXISTS idx_pages_website_id ON pages(website_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_pages_status ON pages(status);
|
||||
CREATE INDEX IF NOT EXISTS idx_users_organization_id ON users(organization_id);
|
||||
|
||||
-- Add triggers for updated_at
|
||||
CREATE OR REPLACE FUNCTION update_updated_at_column()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
NEW.updated_at = NOW();
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ language 'plpgsql';
|
||||
|
||||
CREATE TRIGGER update_scans_updated_at BEFORE UPDATE ON scans FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
||||
CREATE TRIGGER update_websites_updated_at BEFORE UPDATE ON websites FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
||||
CREATE TRIGGER update_pages_updated_at BEFORE UPDATE ON pages FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
||||
|
||||
-- Refresh schema cache
|
||||
NOTIFY pgrst, 'reload schema';
|
||||
@@ -0,0 +1,13 @@
|
||||
-- Fix RLS policies for organization creation during registration
|
||||
-- Allow anonymous users to create organizations during signup
|
||||
|
||||
-- Add policy for anonymous organization creation
|
||||
CREATE POLICY "Allow organization insert for anon during registration" ON "public"."organizations"
|
||||
FOR INSERT TO "anon" WITH CHECK (true);
|
||||
|
||||
-- Add policy for anonymous organization selection (needed to get the created org)
|
||||
CREATE POLICY "Allow organization select for anon during registration" ON "public"."organizations"
|
||||
FOR SELECT TO "anon" USING (true);
|
||||
|
||||
-- Refresh schema cache
|
||||
NOTIFY pgrst, 'reload schema';
|
||||
@@ -0,0 +1,14 @@
|
||||
-- Fix RLS policies for user profile creation during registration
|
||||
-- The issue is that during registration, auth.uid() might not be available yet
|
||||
|
||||
-- Add a more permissive policy for user profile creation during registration
|
||||
-- This allows inserting user profiles with the user's own ID
|
||||
CREATE POLICY "Allow user profile creation during registration" ON "public"."users"
|
||||
FOR INSERT TO "anon" WITH CHECK (true);
|
||||
|
||||
-- Also allow authenticated users to create their own profile
|
||||
CREATE POLICY "Allow authenticated user profile creation" ON "public"."users"
|
||||
FOR INSERT TO "authenticated" WITH CHECK (auth.uid() = id);
|
||||
|
||||
-- Refresh schema cache
|
||||
NOTIFY pgrst, 'reload schema';
|
||||
@@ -0,0 +1,24 @@
|
||||
-- Final fix for user RLS policies
|
||||
-- Drop the conflicting policies and create the correct ones
|
||||
|
||||
-- Drop existing conflicting policies
|
||||
DROP POLICY IF EXISTS "Allow user insert for anon" ON "public"."users";
|
||||
DROP POLICY IF EXISTS "Allow user insert for authenticated" ON "public"."users";
|
||||
DROP POLICY IF EXISTS "Allow user insert for authenticator" ON "public"."users";
|
||||
DROP POLICY IF EXISTS "Allow user insert for dashboard_user" ON "public"."users";
|
||||
|
||||
-- Create the correct policies
|
||||
DROP POLICY IF EXISTS "Allow user profile creation during registration" ON "public"."users";
|
||||
CREATE POLICY "Allow user profile creation during registration" ON "public"."users"
|
||||
FOR INSERT TO "anon" WITH CHECK (true);
|
||||
|
||||
DROP POLICY IF EXISTS "Allow authenticated user profile creation" ON "public"."users";
|
||||
CREATE POLICY "Allow authenticated user profile creation" ON "public"."users"
|
||||
FOR INSERT TO "authenticated" WITH CHECK (auth.uid() = id);
|
||||
|
||||
DROP POLICY IF EXISTS "Allow user profile creation for service role" ON "public"."users";
|
||||
CREATE POLICY "Allow user profile creation for service role" ON "public"."users"
|
||||
FOR INSERT TO "service_role" WITH CHECK (true);
|
||||
|
||||
-- Refresh schema cache
|
||||
NOTIFY pgrst, 'reload schema';
|
||||
@@ -0,0 +1,60 @@
|
||||
-- Comprehensive fix for user RLS policies
|
||||
-- Drop ALL existing policies and recreate them correctly
|
||||
|
||||
-- First, disable RLS temporarily to clear all policies
|
||||
ALTER TABLE "public"."users" DISABLE ROW LEVEL SECURITY;
|
||||
|
||||
-- Re-enable RLS
|
||||
ALTER TABLE "public"."users" ENABLE ROW LEVEL SECURITY;
|
||||
|
||||
-- Drop ALL existing policies (if they exist)
|
||||
DROP POLICY IF EXISTS "Allow user insert for anon" ON "public"."users";
|
||||
DROP POLICY IF EXISTS "Allow user insert for authenticated" ON "public"."users";
|
||||
DROP POLICY IF EXISTS "Allow user insert for authenticator" ON "public"."users";
|
||||
DROP POLICY IF EXISTS "Allow user insert for dashboard_user" ON "public"."users";
|
||||
DROP POLICY IF EXISTS "Allow user profile creation during registration" ON "public"."users";
|
||||
DROP POLICY IF EXISTS "Allow authenticated user profile creation" ON "public"."users";
|
||||
DROP POLICY IF EXISTS "Allow user profile creation for service role" ON "public"."users";
|
||||
DROP POLICY IF EXISTS "Users can view their own profile" ON "public"."users";
|
||||
DROP POLICY IF EXISTS "Users can update their own profile" ON "public"."users";
|
||||
DROP POLICY IF EXISTS "Users can view profiles in their organization" ON "public"."users";
|
||||
|
||||
-- Create comprehensive policies for all scenarios
|
||||
-- 1. Allow anonymous users to create profiles during registration
|
||||
CREATE POLICY "Allow user profile creation during registration" ON "public"."users"
|
||||
FOR INSERT TO "anon" WITH CHECK (true);
|
||||
|
||||
-- 2. Allow authenticated users to create their own profile
|
||||
CREATE POLICY "Allow authenticated user profile creation" ON "public"."users"
|
||||
FOR INSERT TO "authenticated" WITH CHECK (auth.uid() = id);
|
||||
|
||||
-- 3. Allow service role to create user profiles
|
||||
CREATE POLICY "Allow user profile creation for service role" ON "public"."users"
|
||||
FOR INSERT TO "service_role" WITH CHECK (true);
|
||||
|
||||
-- 4. Allow users to view their own profile
|
||||
CREATE POLICY "Users can view their own profile" ON "public"."users"
|
||||
FOR SELECT TO "authenticated" USING (auth.uid() = id);
|
||||
|
||||
-- 5. Allow users to view profiles in their organization
|
||||
CREATE POLICY "Users can view profiles in their organization" ON "public"."users"
|
||||
FOR SELECT TO "authenticated" USING (
|
||||
organization_id IN (
|
||||
SELECT organization_id FROM "public"."users" WHERE id = auth.uid()
|
||||
)
|
||||
);
|
||||
|
||||
-- 6. Allow users to update their own profile
|
||||
CREATE POLICY "Users can update their own profile" ON "public"."users"
|
||||
FOR UPDATE TO "authenticated" USING (auth.uid() = id);
|
||||
|
||||
-- 7. Allow service role to view all users
|
||||
CREATE POLICY "Service role can view all users" ON "public"."users"
|
||||
FOR SELECT TO "service_role" USING (true);
|
||||
|
||||
-- 8. Allow service role to update all users
|
||||
CREATE POLICY "Service role can update all users" ON "public"."users"
|
||||
FOR UPDATE TO "service_role" USING (true);
|
||||
|
||||
-- Refresh schema cache
|
||||
NOTIFY pgrst, 'reload schema';
|
||||
@@ -0,0 +1,8 @@
|
||||
-- Final fix for user RLS - temporarily disable RLS to allow user profile creation
|
||||
-- This is a temporary solution to get the registration working
|
||||
|
||||
-- Disable RLS on users table completely
|
||||
ALTER TABLE "public"."users" DISABLE ROW LEVEL SECURITY;
|
||||
|
||||
-- Refresh schema cache
|
||||
NOTIFY pgrst, 'reload schema';
|
||||
@@ -0,0 +1,66 @@
|
||||
-- Fix the handle_new_user function to use existing organization if provided
|
||||
CREATE OR REPLACE FUNCTION public.handle_new_user()
|
||||
RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
SECURITY DEFINER
|
||||
SET search_path TO 'public', 'auth'
|
||||
AS $function$
|
||||
DECLARE
|
||||
organization_id UUID;
|
||||
BEGIN
|
||||
-- Check if organization_id is provided in metadata
|
||||
IF NEW.raw_user_meta_data->>'organization_id' IS NOT NULL THEN
|
||||
-- Use the existing organization
|
||||
organization_id := (NEW.raw_user_meta_data->>'organization_id')::UUID;
|
||||
ELSE
|
||||
-- Create new organization if none provided
|
||||
INSERT INTO public.organizations (
|
||||
name,
|
||||
subscription_tier,
|
||||
subscription_status
|
||||
) VALUES (
|
||||
COALESCE(NEW.raw_user_meta_data->>'organization_name', NEW.raw_user_meta_data->>'name' || '''s Organization'),
|
||||
'free',
|
||||
'active'
|
||||
)
|
||||
RETURNING id INTO organization_id;
|
||||
END IF;
|
||||
|
||||
-- Create the user profile
|
||||
INSERT INTO public.users (
|
||||
id,
|
||||
email,
|
||||
name,
|
||||
organization_id,
|
||||
role,
|
||||
is_active,
|
||||
settings,
|
||||
created_at,
|
||||
updated_at
|
||||
) VALUES (
|
||||
NEW.id,
|
||||
NEW.email,
|
||||
COALESCE(NEW.raw_user_meta_data->>'name', split_part(NEW.email, '@', 1)),
|
||||
organization_id,
|
||||
COALESCE(NEW.raw_user_meta_data->>'role', 'owner')::user_role,
|
||||
true,
|
||||
jsonb_build_object(
|
||||
'email_notifications', true,
|
||||
'notification_frequency', 'instant',
|
||||
'dashboard_layout', 'default'
|
||||
),
|
||||
NOW(),
|
||||
NOW()
|
||||
);
|
||||
|
||||
RETURN NEW;
|
||||
EXCEPTION
|
||||
WHEN others THEN
|
||||
-- Log the error (will appear in Postgres logs)
|
||||
RAISE LOG 'Error in handle_new_user: %', SQLERRM;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$function$;
|
||||
|
||||
-- Refresh schema cache
|
||||
NOTIFY pgrst, 'reload schema';
|
||||
@@ -0,0 +1,11 @@
|
||||
-- Fix crawl_sessions table by adding missing columns
|
||||
-- Add missing columns to crawl_sessions table
|
||||
ALTER TABLE crawl_sessions ADD COLUMN IF NOT EXISTS processed_urls TEXT[] DEFAULT ARRAY[]::TEXT[];
|
||||
ALTER TABLE crawl_sessions ADD COLUMN IF NOT EXISTS pages_discovered INTEGER DEFAULT 0;
|
||||
ALTER TABLE crawl_sessions ADD COLUMN IF NOT EXISTS pages_processed INTEGER DEFAULT 0;
|
||||
ALTER TABLE crawl_sessions ADD COLUMN IF NOT EXISTS current_url VARCHAR;
|
||||
ALTER TABLE crawl_sessions ADD COLUMN IF NOT EXISTS error_message TEXT;
|
||||
ALTER TABLE crawl_sessions ADD COLUMN IF NOT EXISTS metadata JSONB DEFAULT '{}'::jsonb;
|
||||
|
||||
-- Refresh schema cache to pick up new columns
|
||||
NOTIFY pgrst, 'reload schema';
|
||||
@@ -0,0 +1,21 @@
|
||||
-- Fix RLS policies for users table to allow proper user details loading
|
||||
-- Add policies for SELECT operations on users table
|
||||
|
||||
-- Allow users to select their own profile
|
||||
CREATE POLICY "Users can select their own profile" ON public.users
|
||||
FOR SELECT USING (auth.uid() = id);
|
||||
|
||||
-- Allow users to select profiles in their organization
|
||||
CREATE POLICY "Users can select profiles in their organization" ON public.users
|
||||
FOR SELECT USING (
|
||||
organization_id IN (
|
||||
SELECT organization_id FROM public.users WHERE id = auth.uid()
|
||||
)
|
||||
);
|
||||
|
||||
-- Allow service role to select any user (for admin operations)
|
||||
CREATE POLICY "Service role can select any user" ON public.users
|
||||
FOR SELECT USING (auth.role() = 'service_role');
|
||||
|
||||
-- Refresh schema cache
|
||||
NOTIFY pgrst, 'reload schema';
|
||||
@@ -0,0 +1,6 @@
|
||||
-- Fix crawl_sessions table by adding missing progress_percentage column
|
||||
-- Add missing progress_percentage column to crawl_sessions table
|
||||
ALTER TABLE crawl_sessions ADD COLUMN IF NOT EXISTS progress_percentage INTEGER DEFAULT 0;
|
||||
|
||||
-- Refresh schema cache to pick up new column
|
||||
NOTIFY pgrst, 'reload schema';
|
||||
@@ -0,0 +1,8 @@
|
||||
-- Add missing columns to crawl_sessions table that the API expects
|
||||
-- Add total_urls and processed_urls columns that the API is trying to insert
|
||||
ALTER TABLE crawl_sessions ADD COLUMN IF NOT EXISTS total_urls INTEGER DEFAULT 0;
|
||||
ALTER TABLE crawl_sessions ADD COLUMN IF NOT EXISTS processed_urls INTEGER DEFAULT 0;
|
||||
|
||||
-- Refresh schema cache to pick up new columns
|
||||
NOTIFY pgrst, 'reload schema';
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
-- Enable realtime for crawl_sessions table
|
||||
ALTER PUBLICATION supabase_realtime ADD TABLE crawl_sessions;
|
||||
|
||||
-- Also enable for pages table for real-time page updates
|
||||
ALTER PUBLICATION supabase_realtime ADD TABLE pages;
|
||||
|
||||
Reference in New Issue
Block a user