The CortexOS database uses PostgreSQL with Row Level Security (RLS) for fine-grained access control. The schema supports multi-user environments with master users and sub-agents.
Stores all users including the master user and sub-agents.
Columns:
id(SERIAL PRIMARY KEY) - Unique identifieruuid(UUID) - Universal unique identifierusername(VARCHAR) - Unique usernamerole(VARCHAR) - User role: 'master', 'agent', 'sub_agent'api_key(VARCHAR) - API authentication keypermissions(JSONB) - Permission configurationcreated_at(TIMESTAMP) - Creation timestampupdated_at(TIMESTAMP) - Last update timestamp
RLS Policies:
- Master can see all users
- Users can see themselves
- Self-update allowed
Stores all tasks with hierarchical support (parent-child relationships).
Columns:
id(SERIAL PRIMARY KEY) - Unique identifieruuid(UUID) - Universal unique identifiergoal(TEXT) - Task description/goalstatus(VARCHAR) - Task status: 'pending', 'planning', 'executing', 'completed', 'failed', 'paused'priority(INTEGER) - Task priority (higher = more important)parent_task_id(INTEGER) - Reference to parent taskcreated_by(INTEGER) - User who created the taskassigned_to(INTEGER) - User assigned to the taskmetadata(JSONB) - Additional task metadatacreated_at(TIMESTAMP) - Creation timestampupdated_at(TIMESTAMP) - Last update timestamp
RLS Policies:
- Master can see all tasks
- Users can see tasks they created
- Users can see tasks assigned to them
- Users can create tasks
- Users can update their own or assigned tasks
Stores individual steps for each task.
Columns:
id(SERIAL PRIMARY KEY) - Unique identifieruuid(UUID) - Universal unique identifiertask_id(INTEGER) - Reference to parent taskaction(TEXT) - Step action descriptionstatus(VARCHAR) - Step status: 'pending', 'executing', 'completed', 'failed'result(TEXT) - Step execution resulterror(TEXT) - Error message if failedretry_count(INTEGER) - Number of retry attemptsmetadata(JSONB) - Additional step metadatacreated_at(TIMESTAMP) - Creation timestampupdated_at(TIMESTAMP) - Last update timestamp
RLS Policies:
- Master can see all steps
- Users can see steps for tasks they have access to
- Users can create/update steps for their tasks
Stores agent memories with vector embeddings for semantic search.
Columns:
id(SERIAL PRIMARY KEY) - Unique identifieruuid(UUID) - Universal unique identifiercontent(TEXT) - Memory contenttype(VARCHAR) - Memory type: 'short_term', 'long_term', 'skill', 'context'embedding(VECTOR(1536)) - Vector embedding for semantic searchscore(FLOAT) - Relevance/importance scoretask_id(INTEGER) - Associated taskuser_id(INTEGER) - Associated usermetadata(JSONB) - Additional memory metadatacreated_at(TIMESTAMP) - Creation timestamp
RLS Policies:
- Master can see all memories
- Users can see their own memories
- Users can see memories for tasks they have access to
- Users can create memories
Audit trail for all system actions.
Columns:
id(SERIAL PRIMARY KEY) - Unique identifieruuid(UUID) - Universal unique identifiertask_id(INTEGER) - Associated taskuser_id(INTEGER) - User who performed the actionaction(TEXT) - Action descriptionresult(TEXT) - Action resultlevel(VARCHAR) - Log level: 'info', 'warning', 'error', 'critical'metadata(JSONB) - Additional log metadatatimestamp(TIMESTAMP) - Log timestamp
RLS Policies:
- Master can see all logs
- Users can see logs for tasks they have access to
- Users can see their own logs
- Logs are append-only (no updates/deletes)
Performance indexes are created on:
- Task status, parent_task_id, created_by, assigned_to, created_at
- Step task_id, status, created_at
- Log task_id, user_id, timestamp, level
- Memory type, task_id, user_id, created_at
- User role, uuid
update_updated_at_column() - Automatically updates the updated_at timestamp on:
- users table
- tasks table
- steps table
- vector - For storing and querying embeddings
- uuid-ossp - For generating UUIDs
A default master user is created:
- Username:
master - Role:
master - Permissions:
{"all": true}
RLS policies use app.current_user_id session variable to determine the current user. This must be set before executing queries:
SELECT set_config('app.current_user_id', '1', true);Run the migration script to set up the database:
npm run db:migrateThis will:
- Create all tables
- Set up RLS policies
- Create indexes
- Set up triggers
- Insert default master user