41 lines
1.3 KiB
MySQL
41 lines
1.3 KiB
MySQL
|
|
-- Create user_introductions table
|
||
|
|
CREATE TABLE user_introductions (
|
||
|
|
user_id UUID PRIMARY KEY REFERENCES auth.users(id) ON DELETE CASCADE,
|
||
|
|
intro_email TEXT NOT NULL,
|
||
|
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
||
|
|
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
||
|
|
);
|
||
|
|
|
||
|
|
-- Enable RLS
|
||
|
|
ALTER TABLE user_introductions ENABLE ROW LEVEL SECURITY;
|
||
|
|
|
||
|
|
-- Policy: Users can view their own introduction
|
||
|
|
CREATE POLICY "Users can view their own introduction"
|
||
|
|
ON user_introductions
|
||
|
|
FOR SELECT
|
||
|
|
USING (auth.uid() = user_id);
|
||
|
|
|
||
|
|
-- Policy: Users can insert their own introduction
|
||
|
|
CREATE POLICY "Users can insert their own introduction"
|
||
|
|
ON user_introductions
|
||
|
|
FOR INSERT
|
||
|
|
WITH CHECK (auth.uid() = user_id);
|
||
|
|
|
||
|
|
-- Policy: Users can update their own introduction
|
||
|
|
CREATE POLICY "Users can update their own introduction"
|
||
|
|
ON user_introductions
|
||
|
|
FOR UPDATE
|
||
|
|
USING (auth.uid() = user_id);
|
||
|
|
|
||
|
|
-- Policy: Users can delete their own introduction
|
||
|
|
CREATE POLICY "Users can delete their own introduction"
|
||
|
|
ON user_introductions
|
||
|
|
FOR DELETE
|
||
|
|
USING (auth.uid() = user_id);
|
||
|
|
|
||
|
|
-- Add comment to describe the table
|
||
|
|
COMMENT ON TABLE user_introductions IS 'Stores user introduction email templates';
|
||
|
|
COMMENT ON COLUMN user_introductions.user_id IS 'Reference to the user';
|
||
|
|
COMMENT ON COLUMN user_introductions.intro_email IS 'User introduction email text';
|
||
|
|
|