- The DB lacks version control, and a team cannot collaborate. There is no consistent way to evolve the schema.
- Keep all db code in version control as test-driven migrations
- Don't change the db except through migrations
- Use a tool like Sqitch to apply the migrations and keep track of migration history using an auxiliary set of tables in the db
- Write tests for views and functions with plpgunit
- Deployment is easier because changing a backend means changing the database. Just point sqitch at the staging/production db and apply the migration(s) same as you would locally.
- Central computation in a database can't scale
- Start with RDS which allows you to scale pretty far
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
| import Control.Monad | |
| import Data.Int | |
| import Data.Monoid | |
| import Data.Functor.Contravariant | |
| import Hasql.Connection | |
| import Hasql.Session | |
| import Hasql.Query | |
| import qualified Hasql.Decoders as HD | |
| import qualified Hasql.Encoders as HE |
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
| createReadStatement | |
| asCsvF | |
| asJsonF | |
| asJsonSingleF | |
| limitF | |
| locationF | |
| createWriteStatement | |
| asCsvF | |
| asJsonF |
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
| -- JSON FESTIVAL | |
| WITH pg_source AS | |
| (SELECT "public"."festival".* FROM "public"."festival") | |
| SELECT | |
| (SELECT pg_catalog.Count(1) FROM "public"."festival") AS total_result_set, | |
| pg_catalog.Count(t) AS page_total, | |
| NULL AS header, | |
| Array_to_json(Array_agg(Row_to_json(t)))::character VARYING AS body | |
| FROM |
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
| #lang racket | |
| (require quickcheck) | |
| (define my_gt | |
| (lambda (n m) | |
| (cond | |
| ((zero? n) #f) | |
| ((zero? m) #t) | |
| (else (my_gt (sub1 n) (sub1 m)))))) |
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
| 2015-12-28T03:32:53.153150+00:00 heroku[router]: at=info method=OPTIONS path="/speakers?id=eq.140" host=postgrest.herokuapp.com request_id=dcdd0fb5-98f3-45ae-a769-4d6be6a4b6c8 fwd="73.233.161.119" dyno=web.1 connect=1ms service=1ms status=200 bytes=427 | |
| 2015-12-28T03:32:53.144669+00:00 heroku[router]: at=info method=OPTIONS path="/speakers?id=eq.140" host=postgrest.herokuapp.com request_id=bfd29fc2-942e-456a-aba1-74346dbb1a23 fwd="73.233.161.119" dyno=web.1 connect=1ms service=16ms status=200 bytes=427 | |
| 2015-12-28T03:32:53.132313+00:00 heroku[router]: at=info method=OPTIONS path="/speakers?id=eq.140" host=postgrest.herokuapp.com request_id=2121268b-397c-4fe9-90e9-b842c1e2c668 fwd="73.233.161.119" dyno=web.1 connect=1ms service=1ms status=200 bytes=427 | |
| 2015-12-28T03:32:53.133157+00:00 app[web.1]: 10.180.57.199 - - [28/Dec/2015:03:32:53 +0000] "OPTIONS /speakers HTTP/1.1" 200 - "http://timwis.com/handsontable-postgrest/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrom |
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
| primesTo :: Int -> [Int] | |
| primesTo n = removeHeadMultiples [2..n] | |
| where | |
| removeHeadMultiples same@(p:xs) | |
| | p*p > n = same -- short circuit factors greater than sqrt(n) | |
| | otherwise = p : removeHeadMultiples [x | x <- xs, x `rem` p > 0] |
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
| #%RAML 1.0 | |
| title: PostgREST Demo | |
| version: v1 | |
| baseUri: https://postgrest.herokuapp.com/ | |
| types: | |
| Sessions: | |
| type: object | |
| properties: | |
| id: integer | |
| speaker_id: integer |
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
| Sun Nov 22 15:25 2015 Time and Allocation Profiling Report (Final) | |
| postgrest +RTS -p -L500 -RTS -- postgresql://postgrest_test:@localhost:5432/postgrest_test -a postgrest_test -s test | |
| total time = 8.31 secs (8311 ticks @ 1000 us, 1 processor) | |
| total alloc = 40,138,127,800 bytes (excludes profiling overheads) | |
| COST CENTRE MODULE %time %alloc | |
| MAIN MAIN 95.9 98.4 |