-
Notifications
You must be signed in to change notification settings - Fork 14
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
feat: custom role capabilities for pgtestdb user #6
Conversation
94f9a2f
to
1e2fe25
Compare
1e2fe25
to
b58cc21
Compare
Thanks so much for creating this pull request. Creating a super user TestRole worked fine for us (Kodergarten). We have for now kept the "CREATE EXTENSION postgis;" in Prepare so that we don't need to prepend this into our existing migrations list so I suppose we care about keeping prepare and maybe having a specific role for prepare. I note that this may be supporting an edge case though. |
@timberkeley Thanks for confirming that this worked for you. I'll merge this shortly so you can use it instead of your custom fork.
That's also very useful to know. I'll keep As an aside, I'm curious, what migration library / Thank you again for being so helpful, for providing great feedback, and for using my library 🙇 |
Hi Peter, |
@timberkeley very cool, I'm glad I asked because I hadn't heard of Bun before. I'd happily accept a PR, and if you just send me the basics of it I'm happy to help with all the packaging / go.mod stuff necessary to make it look like the other migrators. No rush or urgency on this from my side, and if you don't want to bother just let me know and I can write an implementation myself. |
kodergarten forked pgtestdb just to alter the role that is used to create the databases to be
SUPERUSER
so that they can install postgis in a migration, which requires superuser privileges.I checked with their team and they'd be interested in having support for this mainlined.
This PR
feature changes
Role
that would be created instead.test changes
postgis/postgis
docker image.docs changes
implementation changes
Role.Username
as the cache key.TB
interface that is a subset oftesting.TB
to make it easier to "check that a bad migration would cause the tests to fail".additional improvements
gopls
.depguard
has been removed.test-all
command now allows passing arguments, motivated by wanting to pass-count=1
to re-run all the tests and ignore cached results.What to do about
Prepare()
?This work raises the question: shouldn't the
Prepare()
method from theMigrator
interface have allowed for this? It was originally envisioned as the way to run admin-commands and install extensions as a superuser, separately from running migrations. But as kodergarten noticed, and I realized as a result:Prepare()
connects to the template database with the same role that is used to run the migrations and connect to each test database.NOSUPERUSER
in production (which it should), and your pgtestdb config connects to its tests with the same permissions (which it should), you can't install extensions.CREATE EXTENSION postgis;
.Prepare()
is still useful for installing extensions and running commands that you need to run that haven't been committed to migration files, but it can only ever run commands that could also be run in a migration.Prepare()
is only useful in very select circumstancesThe two ideas I have for improving this situation are:
Prepare()
method entirely from the interface. It's current docstrings are misleading, remove it.Prepare()
method.CREATE EXTENSION postgis
as a superuser in thePrepare()
methodNOSUPERUSER
, just like your production connections should be.For now, the goal is to solve kodergarten's problem, and is worth shipping as long as this works for them. I will continue to think about the role structure and the migrator interface, hopefully I can come up with something nice that solves all concerns.