Dashboard-Automatizase/supabase/migrations/20250105_create_portal_integrations.sql
Luis Erlacher 0152a2fda0 feat: add n8n API testing script for Google OAuth2 schema and existing credentials
- Implemented a bash script to test n8n API and retrieve credential schemas.
- Added types for API responses, Google Calendar, and WhatsApp instances.
- Configured Vitest for testing with React and added setup for testing-library.
2025-10-10 14:29:02 -03:00

49 lines
1.6 KiB
SQL

-- Create portal schema if it doesn't exist
CREATE SCHEMA IF NOT EXISTS portal;
-- Create integrations table in portal schema
CREATE TABLE IF NOT EXISTS portal.integrations (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id UUID NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE,
provider VARCHAR(50) NOT NULL,
status VARCHAR(20) NOT NULL DEFAULT 'disconnected',
connected_at TIMESTAMPTZ,
updated_at TIMESTAMPTZ DEFAULT NOW(),
created_at TIMESTAMPTZ DEFAULT NOW(),
UNIQUE(user_id, provider)
);
-- Create index for faster lookups
CREATE INDEX IF NOT EXISTS idx_integrations_user_id ON portal.integrations(user_id);
CREATE INDEX IF NOT EXISTS idx_integrations_provider ON portal.integrations(provider);
-- Enable Row Level Security
ALTER TABLE portal.integrations ENABLE ROW LEVEL SECURITY;
-- Policy: Users can only read their own integrations
CREATE POLICY "Users can view own integrations"
ON portal.integrations
FOR SELECT
USING (auth.uid() = user_id);
-- Policy: Users can insert their own integrations
CREATE POLICY "Users can insert own integrations"
ON portal.integrations
FOR INSERT
WITH CHECK (auth.uid() = user_id);
-- Policy: Users can update their own integrations
CREATE POLICY "Users can update own integrations"
ON portal.integrations
FOR UPDATE
USING (auth.uid() = user_id);
-- Policy: Users can delete their own integrations
CREATE POLICY "Users can delete own integrations"
ON portal.integrations
FOR DELETE
USING (auth.uid() = user_id);
-- Add comment to table
COMMENT ON TABLE portal.integrations IS 'Stores OAuth integration status for users (Google Calendar, etc)';