Better Activity

CLI

Generate and apply the activity-table schema for your configured adapter.

better-activity ships a small CLI with three commands: schema, generate, and migrate. All three load your activity instance from a config file and dispatch to the adapter that instance was built with.

pnpm better-activity <command> [options]

The config file

Each CLI command needs to find your BetterActivity instance. The default lookup path is one of:

  • better-activity.config.ts
  • better-activity.config.mts
  • better-activity.config.mjs
  • better-activity.config.js

…in the current working directory. Pass --config <path> to override.

The config file must export the instance as default (or as activity / betterActivity):

better-activity.config.ts
import { betterActivity } from "better-activity";
import { postgresAdapter } from "better-activity/adapters/postgres";
import { Pool } from "pg";

export default betterActivity({
  database: postgresAdapter({ pool: new Pool() }),
  entities: { /* ... */ },
});

schema

Print the schema SQL to stdout. Doesn't write or execute anything. Useful for piping into your migration tool of choice.

pnpm better-activity schema --config ./better-activity.config.ts

Options:

FlagNotes
--configPath to the config file.
--dialectpostgres / mysql / sqlite (when ambiguous).

generate

Write the migration to disk.

pnpm better-activity generate \
  --config ./better-activity.config.ts \
  --out ./migrations/0001_activity.sql

Options:

FlagNotes
--configPath to the config file.
--outOutput file. Defaults to the adapter's suggested path.
--yesOverwrite an existing file without prompting.

If the target file already exists, generate exits with a warning unless --yes is passed.

migrate

Apply the schema directly to the configured database. Supported for the SQL adapters that ship with their own pool (postgres, mysql, sqlite). For Drizzle / Prisma / MongoDB / Kysely, use generate and hand the output to your normal migration tooling.

pnpm better-activity migrate --config ./better-activity.config.ts

The command splits the SQL on ; boundaries and runs each statement through the adapter's pool. The DDL the CLI emits has no embedded semicolons, so the naive split is safe.

help

Prints the usage block:

pnpm better-activity help

Running the CLI without pnpm

The package exposes the binary as better-activity, so any of the following work after installation:

pnpm better-activity ...
npx better-activity ...
node ./node_modules/.bin/better-activity ...

In a monorepo, add a script to your package:

package.json
{
  "scripts": {
    "activity:generate": "better-activity generate"
  }
}

On this page