typebase-io-cli init
Scaffold a new Typebase project structure.
Last updated on
Scaffold a new Typebase project structure.
npx typebase-io-cli initCreates a typebase/ directory with:
tsconfig.json: TypeScript configdb/schema.ts: example database schemadb/relations.ts: example relationsactions/queries/todos.ts: example query actionsactions/mutations/todos.ts: example mutation actionsenv.ts: an empty env schema with a commented-out example key_generated/: auto-generated type files
It also creates a typebase.json at the project root if there isn't one, holding a $schema reference so your editor
autocompletes the config as you fill it in. On the first command in a project, the file also gets a telemetry
entry recording that the telemetry notice was shown. Every option stays on its default until you set it. Running init over an existing typebase.json keeps
the values already in it.
Options
| Flag | Description |
|---|---|
-f, --force | Overwrite tsconfig.json and regenerate the scaffolded example files. |
--with-auth | Include an example auth.ts with email/password authentication. |
--with-db-publisher | Include a publisher.ts, the events table it needs, and actions that use it. |
--with-storage | Include a storage.ts with a public and a private bucket, and actions that use them. |
--skip-example | Skip generating the example schema, actions, and env.ts. |
--with-migrations | Record schema changes as migrations instead of pushing them. |
--with-auth
Sets up authentication with better-auth, using email and password. On top of the usual scaffold it writes:
auth.ts: adefineAuthconfig withemailAndPasswordenabled andhttp://localhost:3000trusteddb/schema.ts: theusers,sessions,accounts, andverificationstables better-auth needsdb/relations.ts: those tables registered, plus the relations between them andtodosactions/custom-actions.ts: anauthedActionthat rejects requests without a valid sessionactions/queries/todos.tsandactions/mutations/todos.ts: built onauthedAction, and scoped to the signed-in user
--skip-example, which skips the example this flag adds to.--with-migrations
Starts the project in migrations mode, so it has schema history from its first commit rather than needing conversion later. On top of the usual scaffold it writes:
db/migrations/<timestamp>_initial/: one migration holding the creation SQL for the scaffolded schema, plus the snapshot the next migration is diffed against
The migration is generated from your actual schema files, so combining this with --with-auth or --with-db-publisher puts those tables in the same
first migration. It is one migration, not one per flag: with auth the example table references the auth users table, so a migration holding the
example table alone would reference a table nothing had created.
From then on, db <target> push refuses to run and you use db migrations generate and db <target> migrate instead.
Already have a project? You don't need to start over. db migrations init adopts migrations on an existing
project without recreating your databases.
--with-db-publisher
Sets up a publisher, so actions can publish events and stream them to clients. On top of the usual scaffold it writes:
publisher.ts: adbpublisher declaring one example event,todo.createddb/schema.ts: theeventstable the publisher keeps events indb/relations.ts: anevents: {}entry registering that tableactions/mutations/todos.ts:createpublishestodo.createdafter insertingactions/queries/todos.ts:getManybecomes a streaming action that re-sends the list on every new todo
--skip-example, which skips the example this flag adds to.--with-storage
Sets up storage, so actions can keep files in buckets and hand out URLs to them. On top of the usual scaffold it writes:
storage.ts: avercelstorage provider with a publicavatarsbucket and a privatedocumentsbucketactions/queries/storage.ts:getAvatarUploadUrl, which returns a signed upload URL for an avatar, andgetDocumentUrl, which returns a signed URL to read a document
Nothing is created on Vercel yet. A local run uses local storage and works straight away; run
storage sync dev or deploy when you want the real buckets. To keep files somewhere else, change provider in storage.ts before
your first sync.
--skip-example, which skips the example this flag adds to.