Thread: [patch] psql tab completion for ALTER DEFAULT PRIVILEGES
Hi, When tab-completing after ALTER DEFAULT PRIVILEGES ... GRANT|REVOKE, currently psql injects completion from the GRANT|REVOKE order, rather than the one expected. A patch is attached. It adds the right completion to GRANT|REVOKE after ALTER DEFAULT PRIVILEGES and after FOR ROLE|USER + IN SCHEMA. If there's no objection I will add it to next commit fest. Best regards, -- Gilles Darold Consultant PostgreSQL http://dalibo.com - http://dalibo.org
Attachment
Le 20/11/2016 à 15:46, Gilles Darold a écrit : > Hi, > > When tab-completing after ALTER DEFAULT PRIVILEGES ... GRANT|REVOKE, > currently psql injects completion from the GRANT|REVOKE order, rather > than the one expected. > > A patch is attached. It adds the right completion to GRANT|REVOKE after > ALTER DEFAULT PRIVILEGES and after FOR ROLE|USER + IN SCHEMA. > > If there's no objection I will add it to next commit fest. > > Best regards, Added to next commitfest. To explain more this patch, the completion of SQL command: ALTER DEFAULT PRIVILEGES FOR ROLE xxx [tab] propose: GRANT REVOKE and it should also propose IN SCHEMA. Same with ALTER DEFAULT PRIVILEGES IN SCHEMA it should propose FOR ROLE. For example: gilles=# ALTER DEFAULT PRIVILEGES IN SCHEMA public FOR ROLE user1 GRANT ALL ON TABLES TO user2; ALTER DEFAULT PRIVILEGES is valid but current completion doesn't help. The second issue addressed is the completion after GRANT|REVOKE, which show completion for the GRANT|REVOKE command but the element are not the same in the ALTER DEFAULT PRIVILEGES command. I mean completion on command ALTER DEFAULT PRIVILEGES IN SCHEMA public FOR ROLE user1 GRANT ALL [tab] propose the following keywords: ALL FUNCTIONS IN SCHEMA ALL SEQUENCES IN SCHEMA DOMAIN LANGUAGE LARGE OBJECT TABLE TABLESPACE ALL TABLES IN SCHEMA FOREIGN DATA WRAPPER FOREIGN SERVER SCHEMA FUNCTION SEQUENCE TYPE DATABASE which is wrong. Keywords should only be ON TABLES ON SEQUENCES ON FUNCTIONS ON TYPES This is what the patch is trying to fix. -- Gilles Darold Consultant PostgreSQL http://dalibo.com - http://dalibo.org
Gilles, * Gilles Darold (gilles.darold@dalibo.com) wrote: > Le 20/11/2016 à 15:46, Gilles Darold a écrit : > > When tab-completing after ALTER DEFAULT PRIVILEGES ... GRANT|REVOKE, > > currently psql injects completion from the GRANT|REVOKE order, rather > > than the one expected. > > > > A patch is attached. It adds the right completion to GRANT|REVOKE after > > ALTER DEFAULT PRIVILEGES and after FOR ROLE|USER + IN SCHEMA. > > Added to next commitfest. To explain more this patch, the completion of > SQL command: I've started looking at this. First off, it looks pretty good and seems like it's actually a bug fix which should be back-patched since the current behavior in released branches is also wrong. There's been some changes in this area, so it might not be practical to go all the way back, will have to see once I start getting into it. One minor nit is that multi-line comments should be of the form: /** ...*/ The tab-completion code does do some like this: /* ... */ /* ... */ Which is probably alright, but you've add some like: /* ... .... */ Which we really don't do. I'll clean that up and might do a bit of word-smithing on the comments also, so no need for a new patch, but thought I'd mention it for future patches. Thanks! Stephen
Gilles, * Gilles Darold (gilles.darold@dalibo.com) wrote: > Added to next commitfest. To explain more this patch, the completion of > SQL command: > > ALTER DEFAULT PRIVILEGES FOR ROLE xxx [tab] Here is a cleaned up patch for master and 9.6. Tomorrow I'll look into what we can do for 9.5 and earlier, which are also wrong, but the code is quite a bit different. Note that beyond just changing the comments, I removed the alternative spelling of 'role' when doing tab completion- there's no different between 'role' and 'user', so there's no point in making the user have to pick one when they're tab-completing. Of course, we still accept both and if the user chooses to write out 'for user', we will handle that correctly and continue the tab completion beyond that. Thanks! Stephen
Attachment
Gilles, all, * Stephen Frost (sfrost@snowman.net) wrote: > * Gilles Darold (gilles.darold@dalibo.com) wrote: > > Added to next commitfest. To explain more this patch, the completion of > > SQL command: > > > > ALTER DEFAULT PRIVILEGES FOR ROLE xxx [tab] > > Here is a cleaned up patch for master and 9.6. Tomorrow I'll look into > what we can do for 9.5 and earlier, which are also wrong, but the code > is quite a bit different. Just a note that I've now fixed this and back-patched it, per discussion. I also closed it out on the commitfest app. Thanks again! Stephen