From 4c387a10f126fb828fcf3423cb09c56a67e7bc9c Mon Sep 17 00:00:00 2001 From: Levente Orban Date: Wed, 27 Aug 2025 08:47:05 +0200 Subject: [PATCH] feat: add public/private event types --- .../20250825001_add-visibility-to-events.sql | 42 +++++ src/lib/components/Navbar.svelte | 11 +- src/lib/stores/events-supabase.ts | 31 ++++ src/lib/types.ts | 4 + src/routes/+page.svelte | 26 +++- src/routes/create/+page.svelte | 37 ++++- src/routes/discover/+page.svelte | 145 ++++++++++++++++++ src/routes/event/+page.svelte | 19 ++- src/routes/event/[id]/+page.svelte | 10 +- 9 files changed, 313 insertions(+), 12 deletions(-) create mode 100644 database/20250825001_add-visibility-to-events.sql create mode 100644 src/routes/discover/+page.svelte diff --git a/database/20250825001_add-visibility-to-events.sql b/database/20250825001_add-visibility-to-events.sql new file mode 100644 index 0000000..cffcea1 --- /dev/null +++ b/database/20250825001_add-visibility-to-events.sql @@ -0,0 +1,42 @@ +-- 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; diff --git a/src/lib/components/Navbar.svelte b/src/lib/components/Navbar.svelte index 83053aa..bb32267 100644 --- a/src/lib/components/Navbar.svelte +++ b/src/lib/components/Navbar.svelte @@ -14,7 +14,7 @@