Database

Overview

Lillo uses a serverless-first database architecture powered by Vercel Postgres, designed for scalable AI agent interactions and content management.

Schema Structure

Core Tables

1. chat_messages

CREATE TABLE chat_messages (
  id SERIAL PRIMARY KEY,
  message_id BIGINT NOT NULL,
  chat_id BIGINT NOT NULL,
  user_id BIGINT NOT NULL,
  user_first_name VARCHAR(255) NOT NULL,
  username VARCHAR(255),
  role VARCHAR(50) NOT NULL,
  content TEXT NOT NULL,
  timestamp BIGINT NOT NULL,
  reply_to_message_id BIGINT,
  agent_id VARCHAR(255) NOT NULL,
  created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
  UNIQUE(chat_id, message_id, agent_id)
);

-- Indexes
CREATE INDEX idx_chat_messages_chat_id_timestamp 
ON chat_messages(chat_id, timestamp DESC);

CREATE INDEX idx_chat_messages_agent_id
ON chat_messages(agent_id);

2. posts

3. user_data

4. command_metrics

5. gerta_poses

6. illustrations

7. agents

8. model_preferences

Type Definitions

Core Types

Database Operations

Message Operations

Agent Operations

Metrics Operations

Performance Considerations

1. Indexing Strategy

  • Compound indexes for frequently accessed fields

  • Timestamp-based sorting optimization

  • Unique constraints for data integrity

  • Agent-specific lookups

2. Query Optimization

  • Prepared statements

  • Efficient joins

  • Limit-based pagination

  • Type-safe queries

3. Connection Management

  • Connection pooling

  • Automatic retries

  • Error handling

  • Transaction support

Security Features

1. Data Protection

  • Encrypted agent configurations

  • Secure credential storage

  • Type validation

  • SQL injection prevention

2. Access Control

  • Role-based permissions

  • Agent-specific access

  • Command restrictions

  • Data isolation

Best Practices

1. Data Access

  • Use type-safe operations

  • Implement proper error handling

  • Follow the principle of least privilege

  • Use parameterized queries

2. Schema Management

  • Version control migrations

  • Backward compatibility

  • Clear naming conventions

  • Proper constraints

3. Performance

  • Regular index maintenance

  • Query optimization

  • Connection pooling

  • Error handling

Last updated