generate:migration
Use the built-in CLI command for generating migrations to easily get up and running. Psychic will automatically timestamp the filename for your migrations, keeping them in sequential order, and will generate boilerplate to get you started with writing a migration.
pnpm psy g:migration --help
pnpm psy g:migration add-deleted-at-to-posts deleted_at:datetime
Usage
pnpm psy g:migration [options] <migrationName> [columnsWithTypes...]
Arguments
-
<migrationName>: End with-to-table-nameor-from-table-nameto prepopulate with an alterTable command. -
[columnsWithTypes...]: Space separated snake-case (except for belongs_to model name) properties like this:title:citext subtitle:string body_markdown:text style:enum:post_styles:formal,informal User:belongs_toAll properties default to not nullable; null can be allowed by appending
:optional:subtitle:string:optionalSupported types
citext,citext[]: case insensitive text (indexes and queries are automatically case insensitive)string,string[]: varchar; allowed length defaults to 255, but may be customized, e.g.:subtitle:string:128orsubtitle:string:128:optionaltext,text[]date,date[]datetime,datetime[]integer,integer[]decimal,decimal[]: scale,precision is required, e.g.:volume:decimal:3,2orvolume:decimal:3,2:optional- Leveraging arrays, add the "[]" suffix, e.g.:
volume:decimal[]:3,2
- Leveraging arrays, add the "[]" suffix, e.g.:
enum,enum[]: include the enum name to automatically create the enum:type:enum:room_types:bathroom,kitchen,bedroomortype:enum:room_types:bathroom,kitchen,bedroom:optional- Omit the enum values to leverage an existing enum (omits the enum type creation):
type:enum:room_typesortype:enum:room_types:optional - Leveraging arrays, add the "[]" suffix, e.g.:
type:enum[]:room_types:bathroom,kitchen,bedroom
- Omit the enum values to leverage an existing enum (omits the enum type creation):
belongs_to: adds a foreign key to migration- Include the fully qualified model name, e.g., if the Coach model is in
src/app/models/Health/Coach:Health/Coach:belongs_to
- Include the fully qualified model name, e.g., if the Coach model is in
Options
--connection-name <connectionName>: The connection name you wish to use for your migration.-h, --help: Display help for command.
Ending the migration name with -to-table-name will automatically include the underscored table name in the migration.
If you want to also generate a model for this migration, you can simply use the g:model or g:resource commands instead.