feat: add db-seed to makefile and merge migrations

This commit is contained in:
Levente Orban
2025-11-10 09:59:44 +01:00
parent 5b7178bec1
commit 52d48e4839
4 changed files with 27 additions and 44 deletions

View File

@@ -19,7 +19,7 @@ CREATE TABLE IF NOT EXISTS events (
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')),
visibility VARCHAR(20) NOT NULL DEFAULT 'public' CHECK (visibility IN ('public','private', 'invite-only')),
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW()
);
@@ -34,6 +34,15 @@ CREATE TABLE IF NOT EXISTS rsvps (
updated_at TIMESTAMPTZ DEFAULT NOW()
);
-- Invite tokens
CREATE TABLE IF NOT EXISTS invite_tokens (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
event_id VARCHAR(8) NOT NULL REFERENCES events(id) ON DELETE CASCADE,
token VARCHAR(32) NOT NULL UNIQUE,
expires_at TIMESTAMPTZ NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW()
);
-- =======================================
-- Indexes
-- =======================================
@@ -42,5 +51,9 @@ CREATE INDEX IF NOT EXISTS idx_events_date ON events(date);
CREATE INDEX IF NOT EXISTS idx_events_location_type ON events(location_type);
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_invite_tokens_event_id ON invite_tokens(event_id);
CREATE INDEX IF NOT EXISTS idx_invite_tokens_token ON invite_tokens(token);
CREATE INDEX IF NOT EXISTS idx_invite_tokens_expires_at ON invite_tokens(expires_at);
COMMIT;

View File

@@ -1,25 +0,0 @@
-- Migration: Add invite-only events feature
-- Created: 2024-12-20
-- Description: Adds invite-only visibility option and invite tokens table
-- Add 'invite-only' to the visibility enum
ALTER TABLE events
DROP CONSTRAINT IF EXISTS events_visibility_check;
ALTER TABLE events
ADD CONSTRAINT events_visibility_check
CHECK (visibility IN ('public', 'private', 'invite-only'));
-- Create invite_tokens table
CREATE TABLE IF NOT EXISTS invite_tokens (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
event_id VARCHAR(8) NOT NULL REFERENCES events(id) ON DELETE CASCADE,
token VARCHAR(32) NOT NULL UNIQUE,
expires_at TIMESTAMPTZ NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW()
);
-- Create indexes for invite_tokens table
CREATE INDEX IF NOT EXISTS idx_invite_tokens_event_id ON invite_tokens(event_id);
CREATE INDEX IF NOT EXISTS idx_invite_tokens_token ON invite_tokens(token);
CREATE INDEX IF NOT EXISTS idx_invite_tokens_expires_at ON invite_tokens(expires_at);

View File

@@ -1,17 +0,0 @@
-- Rollback Migration: Remove invite-only events feature
-- Created: 2024-12-20
-- Description: Removes invite-only visibility option and invite tokens table
-- Drop invite_tokens table and its indexes
DROP INDEX IF EXISTS idx_invite_tokens_expires_at;
DROP INDEX IF EXISTS idx_invite_tokens_token;
DROP INDEX IF EXISTS idx_invite_tokens_event_id;
DROP TABLE IF EXISTS invite_tokens;
-- Revert visibility enum to original values
ALTER TABLE events
DROP CONSTRAINT IF EXISTS events_visibility_check;
ALTER TABLE events
ADD CONSTRAINT events_visibility_check
CHECK (visibility IN ('public', 'private'));