├── LICENSE ├── README.md ├── deploy ├── .gitkeep ├── session_type.sql ├── sessions.sql ├── speaker_order.sql ├── speakers.sql ├── sponsors.sql ├── ssl.sql └── v1schema.sql ├── revert ├── .gitkeep ├── session_type.sql ├── sessions.sql ├── speaker_order.sql ├── speakers.sql ├── sponsors.sql ├── ssl.sql └── v1schema.sql ├── sqitch.plan └── verify ├── .gitkeep ├── session_type.sql ├── sessions.sql ├── speaker_order.sql ├── speakers.sql ├── sponsors.sql ├── ssl.sql └── v1schema.sql /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Joe Nelson 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included 12 | in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Schema for an example 2 | [PostgREST](https://github.com/begriffs/postgrest) API. 3 | 4 | After cloning this, install [sqitch](http://sqitch.org/) and configure 5 | 6 | ```bash 7 | sqitch config --user user.name 'Your Name' 8 | sqitch config --user user.email 'your email' 9 | sqitch target add production db:pg://[user]:[pass]@[rds url]:5432/[dbname] 10 | sqitch config core.engine pg 11 | sqitch config core.pg.target production 12 | sqitch config --bool deploy.verify true 13 | sqitch config --bool rebase.verify true 14 | ``` 15 | 16 | Thereafter you can deploy. 17 | 18 | ```bash 19 | sqitch deploy 20 | ``` 21 | 22 | For more sqitch info, see the 23 | [guide](https://github.com/theory/sqitch/blob/master/lib/sqitchtutorial.pod). 24 | -------------------------------------------------------------------------------- /deploy/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/begriffs/postgrest-example/0fcccaaf5436204d0298b0ec9769c2baa77012d9/deploy/.gitkeep -------------------------------------------------------------------------------- /deploy/session_type.sql: -------------------------------------------------------------------------------- 1 | -- Deploy session_type 2 | -- requires: sessions 3 | 4 | BEGIN; 5 | 6 | CREATE TYPE session_type_enum AS ENUM ('talk', 'workshop'); 7 | 8 | ALTER TABLE "1".sessions 9 | ADD COLUMN session_type session_type_enum NOT NULL; 10 | 11 | COMMIT; 12 | -------------------------------------------------------------------------------- /deploy/sessions.sql: -------------------------------------------------------------------------------- 1 | -- Deploy sessions 2 | -- requires: speakers 3 | 4 | BEGIN; 5 | 6 | CREATE TABLE "1".sessions 7 | ( 8 | id serial, 9 | speaker_id integer, 10 | start_time time with time zone not NULL, 11 | end_time time with time zone not NULL, 12 | location character varying, 13 | 14 | CONSTRAINT speaker_id FOREIGN KEY (speaker_id) 15 | REFERENCES "1".speakers (id) MATCH SIMPLE 16 | ON UPDATE CASCADE ON DELETE RESTRICT 17 | ) 18 | WITH ( 19 | OIDS = FALSE 20 | ); 21 | 22 | ALTER TABLE "1".sessions 23 | ADD CONSTRAINT sessions_pkey PRIMARY KEY(id); 24 | 25 | ALTER TABLE "1".sessions 26 | ADD CONSTRAINT start_end_in_order 27 | CHECK (start_time < end_time); 28 | 29 | ALTER TABLE "1".sessions 30 | ADD CONSTRAINT during_normal_hours 31 | CHECK ('6:00am' < start_time and end_time < '10:00pm'); 32 | 33 | COMMIT; 34 | -------------------------------------------------------------------------------- /deploy/speaker_order.sql: -------------------------------------------------------------------------------- 1 | -- Deploy speaker_order 2 | -- requires: speakers 3 | 4 | BEGIN; 5 | 6 | ALTER TABLE "1".speakers ADD COLUMN lineup_order integer; 7 | 8 | COMMIT; 9 | -------------------------------------------------------------------------------- /deploy/speakers.sql: -------------------------------------------------------------------------------- 1 | -- Deploy speakers 2 | -- requires: v1schema 3 | 4 | BEGIN; 5 | 6 | CREATE TABLE "1".speakers 7 | ( 8 | id serial, 9 | name character varying NOT NULL, 10 | twitter character varying, 11 | avatar_url character varying NOT NULL, 12 | bio text, 13 | featured boolean NOT NULL DEFAULT FALSE 14 | ) 15 | WITH ( 16 | OIDS = FALSE 17 | ); 18 | 19 | ALTER TABLE "1".speakers 20 | ADD CONSTRAINT speakers_pkey PRIMARY KEY(id); 21 | 22 | COMMIT; 23 | -------------------------------------------------------------------------------- /deploy/sponsors.sql: -------------------------------------------------------------------------------- 1 | -- Deploy sponsors 2 | -- requires: v1schema 3 | 4 | BEGIN; 5 | 6 | CREATE TABLE "1".sponsors 7 | ( 8 | id serial, 9 | name character varying NOT NULL, 10 | site_url character varying NOT NULL, 11 | logo_url character varying NOT NULL 12 | ) 13 | WITH ( 14 | OIDS = FALSE 15 | ); 16 | 17 | ALTER TABLE "1".sponsors 18 | ADD CONSTRAINT sponsors_pkey PRIMARY KEY(id); 19 | 20 | COMMIT; 21 | -------------------------------------------------------------------------------- /deploy/ssl.sql: -------------------------------------------------------------------------------- 1 | -- Deploy ssl 2 | 3 | BEGIN; 4 | 5 | create extension if not exists sslinfo; 6 | 7 | COMMIT; 8 | -------------------------------------------------------------------------------- /deploy/v1schema.sql: -------------------------------------------------------------------------------- 1 | -- Deploy v1schema 2 | 3 | BEGIN; 4 | 5 | create schema "1"; 6 | 7 | COMMIT; 8 | -------------------------------------------------------------------------------- /revert/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/begriffs/postgrest-example/0fcccaaf5436204d0298b0ec9769c2baa77012d9/revert/.gitkeep -------------------------------------------------------------------------------- /revert/session_type.sql: -------------------------------------------------------------------------------- 1 | -- Revert session_type 2 | 3 | BEGIN; 4 | 5 | ALTER TABLE "1".sessions 6 | DROP COLUMN session_type; 7 | 8 | DROP TYPE session_type_enum; 9 | 10 | COMMIT; 11 | -------------------------------------------------------------------------------- /revert/sessions.sql: -------------------------------------------------------------------------------- 1 | -- Revert sessions 2 | 3 | BEGIN; 4 | 5 | DROP TABLE "1".sessions; 6 | 7 | COMMIT; 8 | -------------------------------------------------------------------------------- /revert/speaker_order.sql: -------------------------------------------------------------------------------- 1 | -- Revert speaker_order 2 | 3 | BEGIN; 4 | 5 | ALTER TABLE "1".speakers DROP COLUMN lineup_order; 6 | 7 | COMMIT; 8 | -------------------------------------------------------------------------------- /revert/speakers.sql: -------------------------------------------------------------------------------- 1 | -- Revert speakers 2 | 3 | BEGIN; 4 | 5 | DROP TABLE "1".speakers; 6 | 7 | COMMIT; 8 | -------------------------------------------------------------------------------- /revert/sponsors.sql: -------------------------------------------------------------------------------- 1 | -- Revert sponsors 2 | 3 | BEGIN; 4 | 5 | DROP TABLE "1".sponsors; 6 | 7 | COMMIT; 8 | -------------------------------------------------------------------------------- /revert/ssl.sql: -------------------------------------------------------------------------------- 1 | -- Revert ssl 2 | 3 | BEGIN; 4 | 5 | --drop extension sslinfo; 6 | 7 | COMMIT; 8 | -------------------------------------------------------------------------------- /revert/v1schema.sql: -------------------------------------------------------------------------------- 1 | -- Revert v1schema 2 | 3 | BEGIN; 4 | 5 | drop schema "1"; 6 | 7 | COMMIT; 8 | -------------------------------------------------------------------------------- /sqitch.plan: -------------------------------------------------------------------------------- 1 | %syntax-version=1.0.0-b2 2 | %project=forward-api 3 | %uri=https://github.com/loop-recur/forward-api 4 | 5 | v1schema 2014-10-06T04:00:12Z Joe Nelson # Schema for v1 routes 6 | speakers [v1schema] 2014-10-06T04:10:51Z Joe Nelson # Speakers table 7 | sessions [speakers] 2014-10-06T21:49:41Z Joe Nelson # Conference sessions 8 | session_type [sessions] 2014-10-07T03:03:01Z Joe Nelson # Are they talks or workshops? 9 | sponsors [v1schema] 2014-10-07T03:20:07Z Joe Nelson # Our good sponsors 10 | speaker_order [speakers] 2014-10-13T03:35:24Z Joe Nelson # Front-page order for speaker list 11 | ssl [v1schema] 2014-10-13T04:10:51Z Joe Nelson # Enable SSL 12 | -------------------------------------------------------------------------------- /verify/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/begriffs/postgrest-example/0fcccaaf5436204d0298b0ec9769c2baa77012d9/verify/.gitkeep -------------------------------------------------------------------------------- /verify/session_type.sql: -------------------------------------------------------------------------------- 1 | -- Verify session_type 2 | 3 | BEGIN; 4 | 5 | SELECT session_type from "1".sessions where FALSE; 6 | 7 | ROLLBACK; 8 | -------------------------------------------------------------------------------- /verify/sessions.sql: -------------------------------------------------------------------------------- 1 | -- Verify sessions 2 | 3 | BEGIN; 4 | 5 | SELECT id, speaker_id, start_time, end_time, location 6 | FROM "1".sessions 7 | WHERE FALSE; 8 | 9 | SELECT nextval('1.sessions_id_seq'); 10 | 11 | ROLLBACK; 12 | -------------------------------------------------------------------------------- /verify/speaker_order.sql: -------------------------------------------------------------------------------- 1 | -- Verify speaker_order 2 | 3 | BEGIN; 4 | 5 | select lineup_order from "1".speakers where false; 6 | 7 | ROLLBACK; 8 | -------------------------------------------------------------------------------- /verify/speakers.sql: -------------------------------------------------------------------------------- 1 | -- Verify speakers 2 | 3 | BEGIN; 4 | 5 | SELECT id, name, twitter, avatar_url, bio, featured 6 | FROM "1".speakers 7 | WHERE FALSE; 8 | 9 | SELECT nextval('1.speakers_id_seq'); 10 | 11 | ROLLBACK; 12 | -------------------------------------------------------------------------------- /verify/sponsors.sql: -------------------------------------------------------------------------------- 1 | -- Verify sponsors 2 | 3 | BEGIN; 4 | 5 | SELECT id, name, site_url, logo_url FROM "1".sponsors WHERE FALSE; 6 | 7 | ROLLBACK; 8 | -------------------------------------------------------------------------------- /verify/ssl.sql: -------------------------------------------------------------------------------- 1 | -- Verify ssl 2 | 3 | BEGIN; 4 | 5 | SELECT ssl_is_used(); 6 | 7 | ROLLBACK; 8 | -------------------------------------------------------------------------------- /verify/v1schema.sql: -------------------------------------------------------------------------------- 1 | -- Verify v1schema 2 | 3 | BEGIN; 4 | 5 | SELECT pg_catalog.has_schema_privilege('1', 'usage'); 6 | 7 | ROLLBACK; 8 | --------------------------------------------------------------------------------