-- GoChat Dashboard Apps Table -- Reference: Chatwoot app/models/dashboard_app.rb — P2B M12 spec -- Stores custom dashboard widget configurations (iframe embeds) per account/user CREATE TABLE IF NOT EXISTS dashboard_apps ( id SERIAL PRIMARY KEY, account_id INTEGER NOT NULL, user_id INTEGER, -- optional: per-user dashboard title VARCHAR(255) NOT NULL, -- dashboard display name description TEXT DEFAULT '', -- dashboard description icon VARCHAR(255) DEFAULT '', -- icon URL or icon name url VARCHAR(512) DEFAULT '', -- primary iframe URL kind VARCHAR(100) DEFAULT 'frame', -- app kind: frame, link content JSONB DEFAULT '[]', -- iframe config array: [{"type":"frame","url":"..."}] active BOOLEAN DEFAULT TRUE NOT NULL, -- whether the app is active created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(), updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(), deleted_at TIMESTAMP WITH TIME ZONE -- soft-delete support ); CREATE INDEX idx_dashboard_apps_account_id ON dashboard_apps(account_id) WHERE deleted_at IS NULL; CREATE INDEX idx_dashboard_apps_user_id ON dashboard_apps(user_id) WHERE deleted_at IS NULL AND user_id IS NOT NULL; CREATE INDEX idx_dashboard_apps_deleted_at ON dashboard_apps(deleted_at);