Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pgroll migrate subcommand #465

Merged
merged 9 commits into from
Nov 18, 2024
Merged

Add pgroll migrate subcommand #465

merged 9 commits into from
Nov 18, 2024

Conversation

andrew-farries
Copy link
Collaborator

Add a pgroll migrate subcommand.

Documentation

pgroll migrate applies all outstanding migrations from a source directory to the target database.

Assuming that migrations up to and including migration 40_create_enum_type from the example migrations directory have been applied, running:

$ pgroll migrate examples/

will apply migrations from 41_add_enum_column onwards to the target database.

If the --complete flag is passed to pgroll migrate the final migration to be applied will be completed. Otherwise the final migration will be left active (started but not completed).

Notes:

  • If no migrations have yet been applied to the target database, migrate applies all of the migrations in the source directory.
  • This PR removes the pgroll bootstrap command (New command: bootstrap #414) as it is equivalent to running pgroll migrate <directory> --complete against a fresh database.

Part of #446

@andrew-farries andrew-farries marked this pull request as ready for review November 14, 2024 13:11
cmd/migrate.go Outdated Show resolved Hide resolved
@andrew-farries andrew-farries force-pushed the pgroll-migrate-command branch 2 times, most recently from 1ba785f to 31a2714 Compare November 18, 2024 09:49
cmd/start.go Show resolved Hide resolved
pkg/roll/roll.go Outdated Show resolved Hide resolved
UnappliedMigrations returns a slice of unapplied migrations from `dir`,
lexicographically ordered by filename. Applying each of the returned
migrations in order will bring the database up to date with `dir`.
Its functionality is now equivalent to running:

```
pgroll migrate <dir> --complete
```

against a database with no migrations applied.
Make the `Roll.UnappliedMigrations` method fail with an error when the
local migrations on the filesystem do not match the migrations in the
target schema.

Add a test for this new behavior.
And rename the test file accordingly.
@andrew-farries andrew-farries merged commit 85e917c into main Nov 18, 2024
27 checks passed
@andrew-farries andrew-farries deleted the pgroll-migrate-command branch November 18, 2024 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants