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

Allow non-superuser to create sqitch. #307

Closed
wants to merge 4 commits into from
Closed

Conversation

djk447
Copy link
Contributor

@djk447 djk447 commented Jul 5, 2016

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.

@djk447
Copy link
Contributor Author

djk447 commented Jul 5, 2016

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.

@djk447 djk447 closed this Jul 5, 2016
@theory
Copy link
Collaborator

theory commented Jul 5, 2016

Well, we could change it to check to see if the changes table exists in that schema. See initialized().

@djk447 djk447 reopened this Jul 5, 2016
@djk447
Copy link
Contributor Author

djk447 commented Jul 5, 2016

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
Copy link
Collaborator

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];

@djk447
Copy link
Contributor Author

djk447 commented Jul 5, 2016

Thanks. Done.

@theory theory closed this in 07ac244 May 2, 2017
@theory
Copy link
Collaborator

theory commented May 2, 2017

Finally worked this in. See also 5bd23c5. Thank you!

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.

None yet

2 participants