Files
evig/scripts/db/migrations/062_membership_system.sql
g-butandClaude Sonnet 4.6 fce743b182 feat: real membership application system (replaces email-only flow)
Architecture:
- User ≠ Member: users are accounts, members are users with is_member=true
- Migration 062: adds is_member/member_since/member_type/member_paid_until
  to users + creates membership_applications table
- Fixed misleading "Mitglieder" stat label (now "Nutzer:innen")

New membership flow:
- /mitglied-werden now has a real form (not mailto: link)
- Works both for logged-in and anonymous users
- Logged-in: pre-fills name/email, links application to user_id
- Anonymous: accepts application, admin manually links later
- Shows 3 states: form, pending application, already a member
- Member type selection: Regular CHF 50 / Reduced CHF 20

API:
- POST /api/membership/apply — validated, rate-limited
- Prevents duplicate pending applications from same user
- Stores in membership_applications with pending status

FAQ updated to clarify:
- Difference between user account and Verein membership
- How application process works
- How to pay annual dues

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-10 17:12:35 +02:00

32 lines
1.5 KiB
SQL

-- Membership system for Swiss Verein governance
-- Add membership fields to users table
ALTER TABLE users ADD COLUMN IF NOT EXISTS is_member BOOLEAN DEFAULT false;
ALTER TABLE users ADD COLUMN IF NOT EXISTS member_since TIMESTAMP WITH TIME ZONE;
ALTER TABLE users ADD COLUMN IF NOT EXISTS member_type TEXT DEFAULT 'regular' CHECK (member_type IN ('regular', 'reduced', 'honorary'));
ALTER TABLE users ADD COLUMN IF NOT EXISTS member_paid_until TIMESTAMP WITH TIME ZONE;
-- Membership applications table
CREATE TABLE IF NOT EXISTS membership_applications (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id UUID REFERENCES users(id) ON DELETE CASCADE,
applicant_name TEXT NOT NULL,
applicant_email TEXT NOT NULL,
address_street TEXT,
address_postal_code TEXT,
address_city TEXT,
birth_date DATE,
member_type TEXT DEFAULT 'regular' CHECK (member_type IN ('regular', 'reduced')),
motivation TEXT,
status TEXT DEFAULT 'pending' CHECK (status IN ('pending', 'approved', 'rejected')),
admin_notes TEXT,
reviewed_by UUID REFERENCES users(id),
reviewed_at TIMESTAMP WITH TIME ZONE,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS idx_membership_applications_user_id ON membership_applications(user_id);
CREATE INDEX IF NOT EXISTS idx_membership_applications_status ON membership_applications(status);
CREATE INDEX IF NOT EXISTS idx_users_is_member ON users(is_member) WHERE is_member = true;