pgroll icon indicating copy to clipboard operation
pgroll copied to clipboard

Add support for running SQL migration files using `pgroll`

Open kvch opened this issue 7 months ago • 0 comments

This PR adds support for running SQL migration files using pgroll. SQL migrations files must have up.sql suffix. You can define your up migration in {migration_name}.up.sql files. Down migrations are optional. If you want a down migration, name your file {migration_name}.down.sql.

For example pgroll can run the following migration in an SQL transaction:

CREATE TABLE my_table(name text);

As these migrations run in a single transaction, rollbacks are not necessary, as PostgreSQL cleans up all the leftover objects for you if the transaction fails. However, if you decide to add a down migration, it will be executed if the up migration fails.

For SQL migrations complete phase is a no-op.

Limitations

When you pull migrations from the target database the migration file is stored in JSON format on disk (as well as in pgroll.migrations table).

In a follow-up PR/issue

  • [ ] add documentation for SQL migrations

Issues

Closes https://github.com/xataio/pgroll/issues/785

kvch avatar Apr 17 '25 17:04 kvch