48 lines
1.7 KiB
SQL
48 lines
1.7 KiB
SQL
-- ============================================================
|
||
-- 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!
|
||
-- ============================================================
|