Files
ICON-CRM/legacy/supabase_icon_users.sql
2026-09-14 16:55:32 +02:00

48 lines
1.7 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- ============================================================
-- ICON CRM – Benutzerverwaltung (icon_users)
-- Dieses Skript einmalig in der Supabase SQL-Konsole ausführen.
-- ============================================================
-- 1. Tabelle erstellen (vorherige Tabelle löschen, falls vorhanden, um Schema-Konflikte zu vermeiden)
DROP TABLE IF EXISTS public.icon_users CASCADE;
CREATE TABLE public.icon_users (
id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
username text NOT NULL UNIQUE,
email text UNIQUE,
name text NOT NULL,
role text NOT NULL DEFAULT 'user' CHECK (role IN ('admin', 'user')),
password_hash text NOT NULL,
created_at timestamptz DEFAULT now()
);
-- 2. Row-Level-Security aktivieren
ALTER TABLE public.icon_users ENABLE ROW LEVEL SECURITY;
-- 3. Anon-Key Zugriff erlauben (die App nutzt den Anon-Key)
DROP POLICY IF EXISTS "Allow anon full access to icon_users" ON public.icon_users;
CREATE POLICY "Allow anon full access to icon_users"
ON public.icon_users
FOR ALL
TO anon
USING (true)
WITH CHECK (true);
-- 4. Admin-Passwort-Hash berechnen und einfügen.
-- SHA-256 von "Elonsucks69!" wird direkt von Postgres berechnet.
INSERT INTO public.icon_users (username, email, name, role, password_hash)
VALUES (
'Admin',
'admin@icon-experts.de',
'Admin User',
'admin',
encode(sha256('Elonsucks69!'::bytea), 'hex')
)
ON CONFLICT (username)
DO UPDATE SET password_hash = EXCLUDED.password_hash;
-- ============================================================
-- FERTIG! Tabelle bereit. Erster Login: Admin / Elonsucks69!
-- ============================================================