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

New command: bootstrap #414

Merged
merged 3 commits into from
Oct 18, 2024
Merged

New command: bootstrap #414

merged 3 commits into from
Oct 18, 2024

Conversation

kvch
Copy link
Contributor

@kvch kvch commented Oct 17, 2024

This PR adds a new command called bootstrap. It runs all the migrations in the specified folder. Migration files are JSON files, ordered alphabetically.

Help:

> go run . bootstrap -h
Bootstrap a new database from a directory of migration files. All files in the directory will be executed
in alphabetical order. All migrations are completed.

Usage:
  pgroll bootstrap <folder> [flags]

Flags:
  -h, --help   help for bootstrap

Closes #269

@kvch kvch requested a review from andrew-farries October 17, 2024 16:20
@kvch kvch enabled auto-merge (squash) October 17, 2024 16:20
cmd/bootstrap.go Outdated Show resolved Hide resolved
cmd/bootstrap.go Outdated Show resolved Hide resolved
cmd/bootstrap.go Show resolved Hide resolved
@kvch kvch requested a review from andrew-farries October 18, 2024 08:33
Copy link
Collaborator

@andrew-farries andrew-farries left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍 Just a couple of small things.


for _, fileName := range migrationFiles {
if err := runMigrationFromFile(cmd.Context(), m, fileName, true); err != nil {
return fmt.Errorf("running migration file '%s': %w", fileName, err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return fmt.Errorf("running migration file '%s': %w", fileName, err)
return fmt.Errorf("running migration file %q: %w", fileName, err)

file, err := os.Open(fileName)
if err != nil {
return fmt.Errorf("opening migration file: %w", err)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that this is a function I think that file.Close() can be deferred here rather than called later.

@kvch kvch merged commit 7130506 into xataio:main Oct 18, 2024
26 checks passed
andrew-farries added a commit that referenced this pull request Nov 18, 2024
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](https://github.com/xataio/pgroll/tree/main/examples) 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
(#414) as it is equivalent to
running `pgroll migrate <directory> --complete` against a fresh
database.

Part of #446
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.

Improve database bootstrap story
2 participants