Last active
October 9, 2016 13:41
-
-
Save deinspanjer/c2bd3e7cc8a32e2d9b94b4cf53ef1f4f to your computer and use it in GitHub Desktop.
Sqitch create function templates for pg engine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Deploy [% project %]:[% change %] to [% engine %] | |
| [% FOREACH item IN requires -%] | |
| -- requires: [% item %] | |
| [% END -%] | |
| [% FOREACH item IN conflicts -%] | |
| -- conflicts: [% item %] | |
| [% END -%] | |
| BEGIN; | |
| SET SEARCH_PATH TO [% IF schema %][% schema %],[% END %]public; | |
| CREATE OR REPLACE FUNCTION [% IF name %][% name %][% ELSE %][% change %][% END %] ( | |
| [% FOREACH arg IN argument -%] | |
| [% arg %] [% type.item( loop.index ) or 'TEXT' %][% loop.last ? '' : ', ' %] | |
| [% END -%] | |
| ) | |
| RETURNS [% IF returns; returns; ELSE %]VOID[% END %] | |
| LANGUAGE plpgsql | |
| SET SEARCH_PATH TO [% IF schema %][% schema %],[% END %]public | |
| [% IF owner %]SECURITY DEFINER[% END %] | |
| AS $$ | |
| BEGIN | |
| PERFORM TRUE; | |
| IF NOT FOUND THEN RAISE EXCEPTION '% did not work', 'something'; END IF; | |
| RETURN; | |
| END | |
| $$; | |
| [% IF owner -%] | |
| ALTER FUNCTION [% IF name %][% name %][% ELSE %][% change %][% END %] ( | |
| [%- FOREACH typ IN type -%] | |
| [%- typ %][% loop.last ? '' : ', ' -%] | |
| [%- END -%] | |
| ) OWNER TO [% owner %] | |
| [% END %] | |
| [% IF execute -%] | |
| GRANT EXECUTE ON FUNCTION [% IF name %][% name %][% ELSE %][% change %][% END %] ( | |
| [%- FOREACH typ IN type -%] | |
| [%- typ %][% loop.last ? '' : ', ' -%] | |
| [%- END -%] | |
| ) TO [% execute %]; | |
| [% END %] | |
| COMMIT; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Revert [% project %]:[% change %] from [% engine %] | |
| BEGIN; | |
| SET SEARCH_PATH TO [% IF schema %][% schema %],[% END %]public; | |
| [% IF owner -%] | |
| ALTER FUNCTION [% IF name %][% name %][% ELSE %][% change %][% END %] ( | |
| [%- FOREACH typ IN type -%] | |
| [%- typ %][% loop.last ? '' : ', ' -%] | |
| [%- END -%] | |
| ) OWNER TO CURRENT_USER | |
| [% END %] | |
| DROP FUNCTION [% IF name %][% name %][% ELSE %][% change %][% END %]( | |
| [%- FOREACH typ IN type -%] | |
| [%- typ %][% loop.last ? '' : ',' -%] | |
| [%- END -%]); | |
| COMMIT; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Verify [% project %]:[% change %] on [% engine %] | |
| BEGIN; | |
| SET SEARCH_PATH TO [% IF schema %][% schema %],[% END %]public; | |
| SELECT pg_catalog.has_function_privilege('[% IF name %][% name %][% ELSE %][% change %][% END %]( | |
| [%- FOREACH typ IN type -%] | |
| [%- typ %][% loop.last ? '' : ',' -%] | |
| [% END -%])','execute'); | |
| ROLLBACK; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment