Migration

Generate a migration that alters a collection that already exists. Use this to add, remove or rename fields after the collection has been generated.

Syntax

$ vela generate migration <collection> <op> [args...]
$ vela generate migration pets add birthday:date

The collection has to exist already — Vela reads its current fields to work out the change. The change is applied to the local database as the migration is written, so there is no need to run vela migrate up here. Commit the file in migrations/: it is what applies the change to every other environment, on the next deploy or a teammate’s vela migrate up.

The Zod schema is kept in step. When src/lib/schemas/<model>.ts exists, add, remove, rename and references edit the keys they name in its z.object and leave the rest of the file alone. A file with no schema the command recognises is reported, with the edit to make by hand; vela generate schema rebuilds it from the collection.

Operations

  • add - Add one or more fields
  • remove - Remove one or more fields
  • rename - Rename a field
  • references - Add a relation to another collection

Examples

$ vela generate migration pets add birthday:date weight:number
$ vela generate migration pets remove weight
$ vela generate migration pets rename birthday born_on
$ vela generate migration pets references owner:user
$ vela generate migration pets add tag_code:text!:unique

Field definitions use the same field syntax as the other generators, and --help prints it. A field added with :unique gets its unique index in the same migration. For a blank migration to write by hand, use vela migrate create.