Last active
October 9, 2016 13:50
-
-
Save deinspanjer/7f722226d4bf7cdf9944a5b958a6dd98 to your computer and use it in GitHub Desktop.
Sqitch create type 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 TYPE [% IF name %][% name %][% ELSE %][% change %][% END %] AS ( | |
| [%- FOREACH attr IN attribute -%] | |
| [% attr %] [% type.item( loop.index ) or 'TEXT' %] NOT NULL[% 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
| -- Revert [% project %]:[% change %] from [% engine %] | |
| BEGIN; | |
| SET SEARCH_PATH TO [% IF schema %][% schema %],[% END %]public; | |
| DROP TYPE [% IF name %][% name %][% ELSE %][% change %][% END %] CASCADE; | |
| 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; | |
| SELECT true | |
| FROM pg_type t | |
| JOIN pg_namespace n ON t.typnamespace = n.oid | |
| WHERE typname = '[% IF name %][% name %][% ELSE %][% change %][% END %]' | |
| [% IF schema %]AND n.nspname = '[% schema %]'[% END %]; | |
| ROLLBACK; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment