-- Hauptnutzer und Mitarbeiter. Alle bestehenden Konten sind Hauptnutzer. -- Ein Mitarbeiter-Konto entsteht durch eine Einladung und hat den einladenden Eigentümer als Förderer. ALTER TABLE auth_accounts ADD COLUMN account_kind text NOT NULL DEFAULT 'main', ADD COLUMN sponsor_id uuid REFERENCES auth_accounts (id), ADD CONSTRAINT auth_accounts_kind CHECK (account_kind IN ('main', 'employee')), ADD CONSTRAINT auth_accounts_sponsor CHECK ( (account_kind = 'employee' AND sponsor_id IS NOT NULL) OR (account_kind = 'main' AND sponsor_id IS NULL) ); CREATE INDEX auth_accounts_sponsor ON auth_accounts (sponsor_id) WHERE sponsor_id IS NOT NULL;