Closed mmulich closed 7 years ago
To resolve this in the mean time, we will give the database role back their superuser privileges.
Another approach is to write migrations that attempt to escalate to superuser using the guaranteed to exist postgres
user.
As to potential changes to dbmigrator
- I can think of a couple options.
One is up_super()
and down_super()
which are alternate methods to call, supplied with a cursor guaranteed to have superuser powers - then dbmigrator
would need to take an additional --super-user <username>
option, defaulting to postgres
probably. Good migration scripts would need to know the expected non-superuser username, to use when creating objects in a up_super()
script.
Would need to define behavior for which order to run the scripts in, if both are present.
Hmm, how about a @with_super
decorator instead, which then means the so decorated function will receive two cursors, one regular, one superuser? And if you need the username, extract it from the first one with cur.execute('SELECT CURRENT_USER')
In the meantime we've introduced the xxx_archive_db_user_role_attr_flags
variable. See also the specific line that handles this.
Super user context manager is in db-migrator v1.0.0: https://github.com/karenc/db-migrator/pull/43
We started using the super user context manager in db-migrator in our migrations and this worked in production when we deployed it.
Summary
We've recently changed the database user to a non-superuser after the initial provisioning has happened. As a result of this we have migrations that will not complete as coded. The following is example output of running the
tea
environment:Environment
tea specifically, but generally all
Notes
The discussion so far has leaned toward making this a coding issue because there are times when creation will by default assign ownership to the creating role, which may conflict with the role actually using the database via our applications.
The proposal is to make minor modifications to db-migrator to enable the use of a superuser when necessary. ( @reedstrm will fill in the implementation details )