Skip to main content

Overview

ActumX uses PostgreSQL as its database, managed with Drizzle ORM for schema definitions and migrations.

PostgreSQL Setup with Docker

Start PostgreSQL

The quickest way to get started is using Docker:
This creates a database named x402 accessible at:

Verify Database is Running

You should see the actumx-postgres container running.

Stop/Start Database

Stop the database:
Start it again:

Remove Database

To completely remove the database container:
This will delete all data in the database.

Running Migrations

ActumX uses Drizzle Kit for database migrations.

Initial Migration

After setting up PostgreSQL, run the initial migrations:
This applies all pending migrations from the api/drizzle/ directory.

Generate New Migrations

When you modify the database schema in src/db/schema.ts or src/db/auth-schema.ts, generate a migration:
This creates a new migration file in api/drizzle/ based on your schema changes.

Reset Database

To completely reset the database and re-run all migrations:
This will delete all data and recreate the database schema from scratch.

Database Schema Overview

The ActumX database schema is organized into two main files:

Authentication Schema

Located at api/src/db/auth-schema.ts, this includes Better Auth tables:
  • user - User accounts with email and profile information
  • account - OAuth provider accounts linked to users
  • session - Active user sessions with tokens and metadata
  • verification - Email verification tokens

Application Schema

Located at api/src/db/schema.ts, this includes:

API Keys Table

Payment Intents Table

Credit Ledger Table

X402 Transactions Table

Usage Events Table

Agents Table

Database Configuration

Drizzle configuration is located at api/drizzle.config.ts:

Connecting to the Database

The database URL is configured via the DATABASE_URL environment variable:
See Environment Variables for more details.

Troubleshooting

Connection Refused

If you get a connection error:
  1. Verify PostgreSQL is running: docker ps
  2. Check the port isn’t in use: lsof -i :5432
  3. Verify DATABASE_URL in your .env file

Migration Failures

If migrations fail:
  1. Check PostgreSQL logs: docker logs actumx-postgres
  2. Verify your schema syntax
  3. Try resetting: bun run db:reset

Schema Out of Sync

If your database schema doesn’t match your code: