-
Notifications
You must be signed in to change notification settings - Fork 67
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
Improve database bootstrap story #269
Comments
Hi @acaloiaro 👋 , thanks for opening the issue.
This is absolutely a missing feature of Using
I'm not entirely convinced of the need for a A nice feature of We'd gladly accept and review PRs that implement either of these, especially for point |
I agree. In the DB bootstrap scenario I'm generally standing up a new system with nothing to roll back to, so marking a boostrapped db as "complete" seems sensible by default.
Yeah I agree,
Instead of timestamping, perhaps auto-incrementing from the most-recent migration number would be sensible for
That sounds quite handy.
Sounds good. I'll get something in the works for I'll leave how |
After more hands-on time with pgroll, I think this issue has the potential to be a whole can of worms. The "bootstrap" problem scope is a subset of a more general one, which is running multiple, unapplied migrations in order. It's possible that bootstrapping is a problem worth solving on its own, and the more general problem of running unapplied migrations can be solved separately. But, I do think it's worth mentioning here that as a user, I pretty quickly ran into the issue of needing to run multiple unapplied migrations sequentially. I'll refer to this as the "MAM" problem below. The most obvious way that the MAM problem surfaces is when developers work on feature branches in which multiple migrations are required. While pgroll migrations do indeed support multiple At least two types of operations cannot be applied in the same migration with other operations: This results in the MAM problem surfacing more often than one would expect, e.g. when developers add new tables that necessitate one or more indices, or when postgres extensions need to be enabled, e.g. using This means that many features involving migrations result in multiple migrations, rather than a single migration. With multiple developers building multiple features that easily result in the MAM problem, managing migration releases becomes difficult. So is the MAM problem can of worms worth solving now, or should this issue focus solely on bootstrapping? Having fewer or no exclusive operations like @andrew-farries could you possibly share the xata team's experience managing this in production? |
I think this issue should focus solely on the issue of running The restrictions around multiple operations in a migration operating on the same resources is a separate issue IMO, already tracked in #239. Any solution for lifting the multiple operations restrictions is likely going to orthogonal to this 'bootstrap' issue. |
FWIW I'm working on relaxing the restrictions in the I wonder if having indices as part of the |
I think this would make sense. It's been raised before as #203 |
I just wanted to respond because I actually decided not to put any work into this for the time being, and I don't want anyone under the impression that it's a work in progress. This is not me pooh-poohing on pgroll. I still think pgroll's way of doing migrations is superior. However between the current shortcomings of no easy bootstrap, no way to define complex migrations (#203, #239), and the JSON migration file format that prevents me from using In my personal time I'm considering forking pgroll, removing the data migration I won't be shocked if I return to the mainline pgroll, however. But with the amount of migrations I'm currently authoring, the ergonomics just aren't working for me and the toil factor is too high. I think pgroll will feel a lot more comfortable for established applications with relatively stable data schemas. FYI: @andrew-farries This is where I ended up on this issue. |
Thanks for the feedback on what's pushing you away from using I hope you can adapt |
I'm confident I'll be back; pgroll has outstanding promise 😄 |
Hello! I had both the "bootsrap" and the echo "Generating DB schema for ${service}"
psql -U postgres -c "DROP DATABASE IF EXISTS ${service}_schemas;"
psql -U postgres -c "CREATE DATABASE ${service}_schemas;"
pgroll --postgres-url "postgres://postgres:postgres@0.0.0.0:5432/${service}_schemas?sslmode=disable" init
find . -path "./${service}/model/migrations/*.json" | xargs -I% pgroll --postgres-url "postgres://postgres:postgres@0.0.0.0:5432/${service}_schemas?sslmode=disable" start --complete %
pg_dump -s -x -n public -U postgres ${service}_schemas > ${service}/model/schema.sql
sqlc generate This is far from ideal, but it works as one would expect. Leaving it here so maybe I can save some time to the next one! :) |
Not bad at all really. Especially if you watch |
Coming from the traditional style of migration tools that you're probably familiar with, I've grown accustom to tooling that provides a clear path from an empty database, to one that fully reflects the current schema.
I believe this story starts with timestamped migration names, as schemas must be realized serially. I.e. fields can't be added to
users
untilusers
exists. This way, timestamped migrations in amigrations
directly declare the serialized path to the most current schema. Of course, some migrations can be parallelized since acreate table
cannot interfere with another create table, so long as its migrations doesn't involve foreign keys, but I don't think it's useful to get mired in implementation detail right now.As a user, what I'd like from pgroll is:
pgroll new <name> <dir>
to add new migration files with the correct timestamp format to<dir>
. It may be nice to open up$EDITOR
after file creation.pgroll start -c <dir>/*
, sorted. The command could perhaps bepgroll bootstrap <dir>
I don't believe either of these things present a significant amount of work, but can greatly improve adoption. I'll likely implement (1.) and (2.) in my own fork for personal use. I'd be happy to get feedback on this proposal and open a PR if it's deemed acceptable. I likely won't have time to write tests of acceptable quality, however.
The text was updated successfully, but these errors were encountered: