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
Allow non-superuser to create sqitch. #307
Conversation
Well, this doesn't work as the only thing that it checks to see if it needs an upgrade is if the schema exists, so basically there's no way to initialize sqitch if the sqitch schema already exists. It'd be nice if there was, but I'm not quite sure how to add that. |
Well, we could change it to check to see if the changes table exists in that schema. See |
Okay. I changed that and I think that should work now. Thanks! |
@@ -157,7 +157,7 @@ sub initialized { | |||
my $self = shift; | |||
return $self->dbh->selectcol_arrayref(q{ | |||
SELECT EXISTS( | |||
SELECT TRUE FROM pg_catalog.pg_namespace WHERE nspname = ? | |||
SELECT TRUE FROM pg_catalog.pg_tables WHERE schemaname = ? AND tablename = changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changes
needs single quotes around it, 'change'
. Or better make it a ?
and pass the string "changes":
return $self->dbh->selectcol_arrayref(q{
SELECT EXISTS(
SELECT TRUE FROM pg_catalog.pg_namespace WHERE nspname = ? AND tablename = ?
)
}, undef, $self->registry, 'changes')->[0];
Thanks. Done. |
Finally worked this in. See also 5bd23c5. Thank you! |
I'm rather careful to not use superusers when I don't have to. I have been able to avoid needing superuser status for deployments by giving users ownership over their own schemas etc. I ran into trouble deploying sqitch because it would error if the schema was already created.
The basic use case is, as a superuser, I would like to be able to run:
CREATE SCHEMA sqitch AUTHORIZATION sqitch_user;
then when connected as sqitch_user, I want sqitch to deploy as normal, the problem is it errored completely if the schema already exists. If it exists, I would prefer it continue. If I had failed to give it ownership of the schema, further bits would fail (commenting, creating tables etc.) but this allows for this use case to work and for the sqitch_user not to need superuser privileges. (I can grant it privileges on other schemas that it needs to work in otherwise).
Let me know if there are any troubles with this.