feat: add docker and readme

This commit is contained in:
Levente Orban
2025-08-27 08:47:15 +02:00
parent 3d133a6539
commit 9feb3bf64d
19 changed files with 509 additions and 787 deletions

View File

@@ -1,34 +0,0 @@
-- 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;

View File

@@ -1,34 +0,0 @@
-- 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;

View File

@@ -1,42 +0,0 @@
-- Migration: Add visibility column to events table
-- Date: 2025-08-19
-- Description: Add visibility field to distinguish between public and private events
-- First ensure user_id column exists (in case this migration runs before the user_id migration)
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'events' AND column_name = 'user_id') THEN
ALTER TABLE events ADD COLUMN user_id VARCHAR(100);
UPDATE events SET user_id = 'legacy_user_' || id::text WHERE user_id IS NULL;
ALTER TABLE events ALTER COLUMN user_id SET NOT NULL;
CREATE INDEX IF NOT EXISTS idx_events_user_id ON events(user_id);
END IF;
END $$;
-- Add visibility column with default value 'public'
ALTER TABLE events
ADD COLUMN visibility TEXT NOT NULL DEFAULT 'public' CHECK (visibility IN ('public', 'private'));
-- Update existing events to have 'public' visibility (since they were created before this field existed)
UPDATE events SET visibility = 'public' WHERE visibility IS NULL;
-- Create index on visibility for better query performance
CREATE INDEX IF NOT EXISTS idx_events_visibility ON events(visibility);
-- Add comment to document the column
COMMENT ON COLUMN events.visibility IS 'Event visibility: public (visible to everyone) or private (only visible to creator and people with link)';
-- Verify the migration
SELECT
column_name,
data_type,
is_nullable,
column_default
FROM information_schema.columns
WHERE table_name = 'events'
AND column_name = 'visibility';
-- Show sample of updated data
SELECT id, name, visibility, user_id, created_at
FROM events
LIMIT 5;

60
database/init.sql Normal file
View File

@@ -0,0 +1,60 @@
BEGIN;
-- Extensions
CREATE EXTENSION IF NOT EXISTS pgcrypto; -- for gen_random_uuid()
-- =======================================
-- Tables
-- =======================================
-- Events
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),
user_id VARCHAR(100) NOT NULL,
visibility VARCHAR(20) NOT NULL DEFAULT 'public' CHECK (visibility IN ('public','private')),
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW()
);
-- RSVPs
CREATE TABLE IF NOT EXISTS rsvps (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
event_id VARCHAR(8) NOT NULL REFERENCES events(id) ON DELETE CASCADE,
name VARCHAR(100) NOT NULL,
user_id VARCHAR(100) NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW()
);
-- =======================================
-- Indexes
-- =======================================
CREATE INDEX IF NOT EXISTS idx_events_user_id ON events(user_id);
CREATE INDEX IF NOT EXISTS idx_events_date ON events(date);
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);
-- =======================================
-- Triggers (updated_at maintenance)
-- =======================================
CREATE OR REPLACE FUNCTION update_updated_at_column()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = NOW();
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
DROP TRIGGER IF EXISTS update_events_updated_at ON events;
CREATE TRIGGER update_events_updated_at
BEFORE UPDATE ON events
FOR EACH ROW
EXECUTE FUNCTION update_updated_at_column();
COMMIT;

View File

@@ -1,63 +0,0 @@
-- 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();