forked from jmug/cactoide
feat: add lists page
This commit is contained in:
34
database/20250819001_add-user-id-to-rsvps.sql
Normal file
34
database/20250819001_add-user-id-to-rsvps.sql
Normal file
@@ -0,0 +1,34 @@
|
||||
-- Migration: Add user_id column to RSVPs table
|
||||
-- Run this against your existing Supabase database
|
||||
|
||||
-- Add user_id column to existing rsvps table
|
||||
ALTER TABLE rsvps
|
||||
ADD COLUMN user_id VARCHAR(100);
|
||||
|
||||
-- Set a default value for existing records (you can modify this if needed)
|
||||
-- This assigns a unique user ID to each existing RSVP
|
||||
UPDATE rsvps
|
||||
SET user_id = 'legacy_user_' || id::text
|
||||
WHERE user_id IS NULL;
|
||||
|
||||
-- Make the column NOT NULL after setting default values
|
||||
ALTER TABLE rsvps
|
||||
ALTER COLUMN user_id SET NOT NULL;
|
||||
|
||||
-- Add index for better performance
|
||||
CREATE INDEX IF NOT EXISTS idx_rsvps_user_id ON rsvps(user_id);
|
||||
|
||||
-- Verify the migration
|
||||
SELECT
|
||||
column_name,
|
||||
data_type,
|
||||
is_nullable,
|
||||
column_default
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'rsvps'
|
||||
AND column_name = 'user_id';
|
||||
|
||||
-- Show sample of updated data
|
||||
SELECT id, name, user_id, created_at
|
||||
FROM rsvps
|
||||
LIMIT 5;
|
||||
34
database/20250819002_add-user-id-to-events.sql
Normal file
34
database/20250819002_add-user-id-to-events.sql
Normal file
@@ -0,0 +1,34 @@
|
||||
-- Migration: Add user_id column to Events table
|
||||
-- Run this against your existing Supabase database
|
||||
|
||||
-- Add user_id column to existing events table
|
||||
ALTER TABLE events
|
||||
ADD COLUMN user_id VARCHAR(100);
|
||||
|
||||
-- Set a default value for existing records (you can modify this if needed)
|
||||
-- This assigns a unique user ID to each existing event
|
||||
UPDATE events
|
||||
SET user_id = 'legacy_user_' || id::text
|
||||
WHERE user_id IS NULL;
|
||||
|
||||
-- Make the column NOT NULL after setting default values
|
||||
ALTER TABLE events
|
||||
ALTER COLUMN user_id SET NOT NULL;
|
||||
|
||||
-- Add index for better performance
|
||||
CREATE INDEX IF NOT EXISTS idx_events_user_id ON events(user_id);
|
||||
|
||||
-- Verify the migration
|
||||
SELECT
|
||||
column_name,
|
||||
data_type,
|
||||
is_nullable,
|
||||
column_default
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'events'
|
||||
AND column_name = 'user_id';
|
||||
|
||||
-- Show sample of updated data
|
||||
SELECT id, name, user_id, created_at
|
||||
FROM events
|
||||
LIMIT 5;
|
||||
63
database/init_supabase-setup.sql
Normal file
63
database/init_supabase-setup.sql
Normal file
@@ -0,0 +1,63 @@
|
||||
-- Create events table
|
||||
CREATE TABLE IF NOT EXISTS events (
|
||||
id VARCHAR(8) PRIMARY KEY,
|
||||
name VARCHAR(100) NOT NULL,
|
||||
date DATE NOT NULL,
|
||||
time TIME NOT NULL,
|
||||
location VARCHAR(200) NOT NULL,
|
||||
type VARCHAR(20) NOT NULL CHECK (type IN ('limited', 'unlimited')),
|
||||
attendee_limit INTEGER CHECK (attendee_limit > 0),
|
||||
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
||||
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
||||
);
|
||||
|
||||
-- Create RSVPs table
|
||||
CREATE TABLE IF NOT EXISTS rsvps (
|
||||
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
|
||||
event_id VARCHAR(8) NOT NULL REFERENCES events(id) ON DELETE CASCADE,
|
||||
name VARCHAR(50) NOT NULL,
|
||||
user_id VARCHAR(100) NOT NULL,
|
||||
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
||||
UNIQUE(event_id, name)
|
||||
);
|
||||
|
||||
-- Create indexes for better performance
|
||||
CREATE INDEX IF NOT EXISTS idx_events_id ON events(id);
|
||||
CREATE INDEX IF NOT EXISTS idx_rsvps_event_id ON rsvps(event_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_rsvps_user_id ON rsvps(user_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_rsvps_created_at ON rsvps(created_at);
|
||||
|
||||
-- Enable Row Level Security (RLS)
|
||||
ALTER TABLE events ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE rsvps ENABLE ROW LEVEL SECURITY;
|
||||
|
||||
-- Create policies for public access (since this is a public RSVP app)
|
||||
CREATE POLICY "Allow public read access to events" ON events
|
||||
FOR SELECT USING (true);
|
||||
|
||||
CREATE POLICY "Allow public insert access to events" ON events
|
||||
FOR INSERT WITH CHECK (true);
|
||||
|
||||
CREATE POLICY "Allow public read access to RSVPs" ON rsvps
|
||||
FOR SELECT USING (true);
|
||||
|
||||
CREATE POLICY "Allow public insert access to RSVPs" ON rsvps
|
||||
FOR INSERT WITH CHECK (true);
|
||||
|
||||
CREATE POLICY "Allow public delete access to RSVPs" ON rsvps
|
||||
FOR DELETE USING (true);
|
||||
|
||||
-- Create function to update updated_at timestamp
|
||||
CREATE OR REPLACE FUNCTION update_updated_at_column()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
NEW.updated_at = NOW();
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ language 'plpgsql';
|
||||
|
||||
-- Create trigger to automatically update updated_at
|
||||
CREATE TRIGGER update_events_updated_at
|
||||
BEFORE UPDATE ON events
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION update_updated_at_column();
|
||||
Reference in New Issue
Block a user