Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

add xspace-agent/packages/core/src/db/migrations/0002_rbac.sql

overstepping9cc57eed1153
diff --git a/xspace-agent/packages/core/src/db/migrations/0002_rbac.sql b/xspace-agent/packages/core/src/db/migrations/0002_rbac.sql
new file mode 100644
index 000000000..0b9360d9c
--- /dev/null
+++ b/xspace-agent/packages/core/src/db/migrations/0002_rbac.sql
@@ -0,0 +1,58 @@
+-- Migration: 0002_rbac
+-- Description: Add RBAC tables — org_members, custom_roles, invitations, teams
+-- Created: 2026-03-23
+
+-- Custom Roles (Enterprise)
+CREATE TABLE IF NOT EXISTS custom_roles (
+ id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
+ org_id UUID NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
+ name TEXT NOT NULL,
+ description TEXT,
+ permissions TEXT[] NOT NULL DEFAULT '{}',
+ created_at TIMESTAMPTZ DEFAULT NOW()
+);
+
+-- Organization Members (maps users to orgs with roles)
+CREATE TABLE IF NOT EXISTS org_members (
+ org_id UUID NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
+ user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
+ role TEXT NOT NULL DEFAULT 'viewer',
+ custom_role_id UUID REFERENCES custom_roles(id),
+ invited_by UUID REFERENCES users(id),
+ joined_at TIMESTAMPTZ DEFAULT NOW(),
+ PRIMARY KEY (org_id, user_id)
+);
+
+-- Invitations
+CREATE TABLE IF NOT EXISTS invitations (
+ id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
+ org_id UUID NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
+ email TEXT NOT NULL,
+ role TEXT NOT NULL,
+ invited_by UUID REFERENCES users(id),
+ token_hash TEXT NOT NULL,
+ status TEXT NOT NULL DEFAULT 'pending',
+ expires_at TIMESTAMPTZ NOT NULL,
+ created_at TIMESTAMPTZ DEFAULT NOW()
+);
+
+-- Teams
+CREATE TABLE IF NOT EXISTS teams (
+ id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
+ org_id UUID NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
+ name TEXT NOT NULL,
+ description TEXT,
+ member_ids UUID[] DEFAULT '{}',
+ created_at TIMESTAMPTZ DEFAULT NOW()
+);
+
+-- Indexes
+CREATE INDEX IF NOT EXISTS idx_custom_roles_org ON custom_roles(org_id);
+CREATE INDEX IF NOT EXISTS idx_org_members_org ON org_members(org_id);
+CREATE INDEX IF NOT EXISTS idx_org_members_user ON org_members(user_id);
+CREATE INDEX IF NOT EXISTS idx_invitations_org ON invitations(org_id);
+CREATE INDEX IF NOT EXISTS idx_invitations_email ON invitations(email);
+CREATE INDEX IF NOT EXISTS idx_invitations_token ON invitations(token_hash);
+CREATE INDEX IF NOT EXISTS idx_teams_org ON teams(org_id);
+
+