CREATE TABLE IF NOT EXISTS portal_users (
    id SERIAL PRIMARY KEY,
    client_id INT NULL REFERENCES clients(id) ON DELETE SET NULL,
    email VARCHAR(255) NOT NULL UNIQUE,
    name VARCHAR(100) NOT NULL,
    phone VARCHAR(50),
    provider VARCHAR(30) NOT NULL DEFAULT 'local',
    provider_id VARCHAR(200),
    password_hash TEXT,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_portal_users_provider
    ON portal_users(provider, provider_id);
