Files
evig/scripts/db/migrations/048_subscription_pools.sql
g-butandClaude Opus 4.6 f893115ad7 feat: complete all remaining audit items (12 items across 9 batches)
Accessibility:
- Add skip-to-content link in root layout
- Fix 125 gray-400 contrast violations across 92 files (→ gray-500)
- Fix 13 undersized admin touch targets (p-1 → p-2, w-8 → w-10)

Performance:
- Fix workshops N+1 waterfall: single ?include=instances API call
  replaces O(W×I) client-side fetch loops

Architecture:
- Remove legacy admin-auth.ts dual auth system
- Migrate 4 routes from CMS JWT to Auth.js/withAdmin

Responsive:
- Add mobile-first breakpoints to 5 components (sell page,
  bookings, decisions, product tables, filter bars)

Mission features:
- Public financial transparency page at /about/finances
- Per-listing CO2 impact badge on marketplace (Fraunhofer IZM 2023)
- Subscription exchange design spec + draft migration

0 TypeScript errors, 0 ESLint errors, 362/362 tests passing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 16:30:01 +01:00

65 lines
2.5 KiB
SQL

-- Migration: 048_subscription_pools
-- Status: DRAFT — Do not run until feature implementation begins
-- Feature: Subscription Exchange (Abo-Tauschbörse)
-- See: docs/features/SUBSCRIPTION_EXCHANGE.md
-- Subscription pools (one per shared service)
CREATE TABLE IF NOT EXISTS subscription_pools (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
service_name TEXT NOT NULL,
service_category TEXT NOT NULL DEFAULT 'other',
max_members INT NOT NULL CHECK (max_members > 0),
monthly_cost_chf DECIMAL(10,2) NOT NULL CHECK (monthly_cost_chf >= 0),
cost_per_member_chf DECIMAL(10,2) GENERATED ALWAYS AS (monthly_cost_chf / max_members) STORED,
owner_id UUID NOT NULL REFERENCES users(id),
status TEXT NOT NULL DEFAULT 'active',
description TEXT,
rules TEXT,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW()
);
-- Pool memberships
CREATE TABLE IF NOT EXISTS pool_memberships (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
pool_id UUID NOT NULL REFERENCES subscription_pools(id) ON DELETE CASCADE,
user_id UUID NOT NULL REFERENCES users(id),
role TEXT NOT NULL DEFAULT 'member',
status TEXT NOT NULL DEFAULT 'active',
joined_at TIMESTAMPTZ DEFAULT NOW(),
left_at TIMESTAMPTZ,
UNIQUE(pool_id, user_id)
);
-- Payment contributions
CREATE TABLE IF NOT EXISTS pool_contributions (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
pool_id UUID NOT NULL REFERENCES subscription_pools(id) ON DELETE CASCADE,
user_id UUID NOT NULL REFERENCES users(id),
amount_chf DECIMAL(10,2) NOT NULL CHECK (amount_chf >= 0),
period_start DATE NOT NULL,
period_end DATE NOT NULL,
status TEXT NOT NULL DEFAULT 'pending',
payment_reference TEXT,
created_at TIMESTAMPTZ DEFAULT NOW()
);
-- Governance votes
CREATE TABLE IF NOT EXISTS pool_votes (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
pool_id UUID NOT NULL REFERENCES subscription_pools(id) ON DELETE CASCADE,
voter_id UUID NOT NULL REFERENCES users(id),
vote_type TEXT NOT NULL,
vote TEXT NOT NULL,
reason TEXT,
created_at TIMESTAMPTZ DEFAULT NOW(),
UNIQUE(pool_id, voter_id, vote_type)
);
-- Indexes
CREATE INDEX IF NOT EXISTS idx_pool_memberships_user ON pool_memberships(user_id);
CREATE INDEX IF NOT EXISTS idx_pool_memberships_pool ON pool_memberships(pool_id);
CREATE INDEX IF NOT EXISTS idx_pool_contributions_pool ON pool_contributions(pool_id);
CREATE INDEX IF NOT EXISTS idx_pool_contributions_status ON pool_contributions(status);
CREATE INDEX IF NOT EXISTS idx_subscription_pools_status ON subscription_pools(status);