Database migrations

How to create and run database migrations in the Saas UI starterkit

Database migrations are a fundamental part of managing your database schema. They allow you to make changes to your database schema in a controlled and repeatable way. In the Saas UI starterkit, we use the Drizzle Kit CLI to manage database migrations.

Migration files

Migration files are generated by Drizzle Kit and live in the packages/db/drizzle directory.

Creating migrations

When you make changes to your database schema, you can generate a new migration file using the following command.

yarn db:generate

This will run the Drizzle Kit CLI and create a new migration file in the packages/db/drizzle directory.

Running migrations

To apply migrations run the following command:

yarn db:migrate

Prototyping database changes

If you want to iterate quickly during local development without having to create migrations you can directly push your schema changes to the database.

Don't use this command on your production database, unless your provider manages migrations for you, like Neon.

yarn db:push

Other commands

Drizzle Kit supports a range of other useful commands that can be run by calling the CLI directly.

See all commands in the Drizzle Kit docs.

# Drop migration
yarn workspace @acme/db drizzle-kit drop
# Check if migrations are consistent
yarn workspace @acme/db drizzle-kit check

Learn more

Was this helpful?