CREATE TYPE user_role AS ENUM ('platform_admin', 'shop_owner', 'shop_staff', 'customer'); CREATE TYPE shop_status AS ENUM ('active', 'suspended'); CREATE TABLE shops ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), name JSONB NOT NULL, slug TEXT NOT NULL UNIQUE, status shop_status NOT NULL DEFAULT 'active', created_at TIMESTAMPTZ NOT NULL DEFAULT now() ); CREATE TABLE users ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), email TEXT NOT NULL UNIQUE, password_hash TEXT NOT NULL, display_name TEXT NOT NULL, role user_role NOT NULL DEFAULT 'customer', shop_id UUID REFERENCES shops (id), locale TEXT NOT NULL DEFAULT 'en', created_at TIMESTAMPTZ NOT NULL DEFAULT now(), CONSTRAINT shop_role_requires_shop CHECK ( role IN ('customer', 'platform_admin') OR shop_id IS NOT NULL ) ); CREATE INDEX idx_users_shop ON users (shop_id);