Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
msalvadores committed Oct 24, 2018
2 parents 9e1b6b7 + ab23ed7 commit 85853a1
Show file tree
Hide file tree
Showing 35 changed files with 837 additions and 396 deletions.
52 changes: 46 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ build-distro-bin: &build-distro-bin
key: v1-{{ .Environment.CIRCLE_JOB }}-dependencies-{{ checksum "postgrest.cabal" }}-{{ checksum "stack.yaml" }}

jobs:
build-test:
build-test-9.4:
docker:
- image: circleci/buildpack-deps:trusty
environment:
Expand Down Expand Up @@ -138,6 +138,38 @@ jobs:
name: run tests
command: POSTGREST_TEST_CONNECTION=$(test/create_test_db "postgres://circleci@localhost" postgrest_test) stack test

build-test-10:
docker:
- image: circleci/buildpack-deps:trusty
environment:
- PGHOST=localhost
- image: circleci/postgres:10.5
environment:
- POSTGRES_USER=circleci
- POSTGRES_DB=circleci
steps:
- checkout
- restore_cache:
keys:
- v1-stack-dependencies-{{ checksum "postgrest.cabal" }}-{{ checksum "stack.yaml" }}
- run:
name: install stack & dependencies
command: |
curl -L https://github.com/commercialhaskell/stack/releases/download/v1.1.2/stack-1.1.2-linux-x86_64.tar.gz | tar zx -C /tmp
sudo mv /tmp/stack-1.1.2-linux-x86_64/stack /usr/bin
sudo apt-get update
sudo apt-get install -y libgmp-dev
sudo apt-get install -y postgresql-client
stack setup
- run:
name: build src and tests
command: |
stack build --fast -j1
stack build --fast --test --no-run-tests
- run:
name: run tests
command: POSTGREST_TEST_CONNECTION=$(test/create_test_db "postgres://circleci@localhost" postgrest_test) stack test

build-prof-test:
docker:
- image: circleci/buildpack-deps:trusty
Expand Down Expand Up @@ -224,22 +256,27 @@ workflows:
version: 2
build-test-release:
jobs:
- build-test:
- build-test-9.4:
filters:
tags:
only: /v[0-9]+(\.[0-9]+)*/
- build-test-9.6:
filters:
tags:
only: /v[0-9]+(\.[0-9]+)*/
- build-test-10:
filters:
tags:
only: /v[0-9]+(\.[0-9]+)*/
- build-prof-test:
filters:
tags:
only: /v[0-9]+(\.[0-9]+)*/
- centos6:
requires:
- build-test
- build-test-9.4
- build-test-9.6
- build-test-10
- build-prof-test
filters:
tags:
Expand All @@ -248,8 +285,9 @@ workflows:
ignore: /.*/
- centos7:
requires:
- build-test
- build-test-9.4
- build-test-9.6
- build-test-10
- build-prof-test
filters:
tags:
Expand All @@ -258,8 +296,9 @@ workflows:
ignore: /.*/
- ubuntu:
requires:
- build-test
- build-test-9.4
- build-test-9.6
- build-test-10
- build-prof-test
filters:
tags:
Expand All @@ -268,8 +307,9 @@ workflows:
ignore: /.*/
- ubuntui386:
requires:
- build-test
- build-test-9.4
- build-test-9.6
- build-test-10
- build-prof-test
filters:
tags:
Expand Down
2 changes: 1 addition & 1 deletion BACKERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ PostgREST ongoing development is only possible thanks to our Sponsors and Backer

- [Christiaan Westerbeek](https://devotis.nl)
- [Daniel Babiak](https://github.com/d-babiak)
- [Michel Pelletier](https://github.com/michelp/)

## Backers

- Tsingson Qin
- Michel Pelletier
- Jay Hannah
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,42 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Added

### Fixed

- #1182, Fix embedding on views with composite pks - @steve-chavez
- #1180, Fix embedding on views with subselects in pg10 - @steve-chavez
- #1197, Allow CORS for PUT - @bkylerussell

## [5.1.0] - 2018-08-31

### Added

- #1099, Add support for getting json/jsonb by array index - @steve-chavez
- #1145, Add materialized view columns to OpenAPI output - @steve-chavez
- #709, Allow embedding on views with subselects/CTE - @steve-chavez
- #1148, OpenAPI: add `required` section for the non-nullable columns - @laughedelic
- #1158, Add summary to OpenAPI doc for RPC functions - @mdr1384

### Fixed

- #1113, Fix UPSERT failing when having a camel case PK column - @steve-chavez
- #945, Fix slow start-up time on big schemas - @steve-chavez
- #1129, Fix view embedding when table is capitalized - @steve-chavez
- #1149, OpenAPI: Change `GET` response type to array - @laughedelic
- #1152, Fix RPC failing when having arguments with reserved or uppercase keywords - @mdr1384
- #905, Fix intermittent empty replies - @steve-chavez
- #1139, Fix JWTIssuedAtFuture failure for valid iat claim - @steve-chavez
- #1141, Fix app.settings resetting on pool timeout - @steve-chavez

### Changed

- #1099, Numbers in json path `?select=data->1->>key` now get treated as json array indexes instead of keys - @steve-chavez
- #1128, Allow finishing a json path with a single arrow `->`. Now a json can be obtained without resorting to casting, Previously: `/json_arr?select=data->>2::json`, now: `/json_arr?select=data->2` - @steve-chavez
- #724, Change server-host default of *4 to 127.0.0.1

### Deprecated

- #724, SIGHUP deprecated, SIGUSR1 should be used instead

## [0.5.0.0] - 2018-05-14

Expand Down
30 changes: 21 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
![Logo](static/logo.png "Logo")

[![Build Status](https://circleci.com/gh/PostgREST/postgrest/tree/master.svg?style=shield)](https://circleci.com/gh/PostgREST/postgrest/tree/master)
[![Donate](https://img.shields.io/badge/Donate-Patreon-orange.svg?colorB=F96854)](https://www.patreon.com/postgrest)
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.me/postgrest)
<a href="https://heroku.com/deploy?template=https://github.com/PostgREST/postgrest">
<img src="https://img.shields.io/badge/%E2%86%91_Deploy_to-Heroku-7056bf.svg" alt="Deploy">
</a>
[![Join the chat at https://gitter.im/begriffs/postgrest](https://img.shields.io/badge/gitter-join%20chat%20%E2%86%92-brightgreen.svg)](https://gitter.im/begriffs/postgrest)
[![Docs](https://img.shields.io/badge/docs-latest-brightgreen.svg?style=flat)](http://postgrest.org)
[![Docker Stars](https://img.shields.io/docker/pulls/postgrest/postgrest.svg)](https://hub.docker.com/r/postgrest/postgrest/)
[![Donate](https://img.shields.io/badge/patreon-donate-orange.svg?colorB=F96854)](https://www.patreon.com/postgrest)
[![Build Status](https://circleci.com/gh/PostgREST/postgrest/tree/master.svg?style=shield)](https://circleci.com/gh/PostgREST/postgrest/tree/master)
[![Hackage docs](https://img.shields.io/hackage/v/postgrest.svg?label=hackage)](http://hackage.haskell.org/package/postgrest)

PostgREST serves a fully RESTful API from any existing PostgreSQL
database. It provides a cleaner, more standards-compliant, faster
API than you are likely to write from scratch.

### Usage
## Usage

1. Download the binary ([latest release](https://github.com/PostgREST/postgrest/releases/latest))
for your platform.
Expand All @@ -23,7 +25,7 @@ API than you are likely to write from scratch.
postgrest --help
```

### Performance
## Performance

TLDR; subsecond response times for up to 2000 requests/sec on Heroku
free tier. If you're used to servers written in interpreted languages
Expand Down Expand Up @@ -51,7 +53,7 @@ by
* Using the PostgreSQL binary protocol
* Being stateless to allow horizontal scaling
### Security
## Security
PostgREST [handles
authentication](http://postgrest.org/en/stable/auth.html) (via JSON Web
Expand All @@ -72,15 +74,15 @@ are limited to certain templates using
functions, the trigger workaround does not compromise row-level
security.

### Versioning
## Versioning

A robust long-lived API needs the freedom to exist in multiple
versions. PostgREST does versioning through database schemas. This
allows you to expose tables and views without making the app brittle.
Underlying tables can be superseded and hidden behind public facing
views.

### Self-documentation
## Self-documentation

PostgREST uses the [OpenAPI](https://openapis.org/) standard to
generate up-to-date documentation for APIs. You can use a tool like
Expand All @@ -92,7 +94,7 @@ instance the number of rows returned by an endpoint is reported by -
and limited with - range headers. More about
[that](http://begriffs.com/posts/2014-03-06-beyond-http-header-links.html).

### Data Integrity
## Data Integrity

Rather than relying on an Object Relational Mapper and custom
imperative coding, this system requires you put declarative constraints
Expand All @@ -106,7 +108,17 @@ See examples of [PostgreSQL
constraints](http://www.tutorialspoint.com/postgresql/postgresql_constraints.htm)
and the [API guide](http://postgrest.org/en/stable/api.html).

### Thanks
## Supporting development

You can help PostgREST ongoing maintenance and development by:

- Making a regular donation through Patreon https://www.patreon.com/postgrest

- Alternatively, you can make a one-time donation via Paypal https://www.paypal.me/postgrest

Every donation will be spent on making PostgREST better for the whole community.

## Thanks

The PostgREST organization is grateful to:

Expand Down
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"POSTGREST_VER": {
"description": "Version of PostgREST to deploy",
"value": "0.5.0.0"
"value": "5.1.0"
},
"DB_URI": {
"description": "Database connection string, e.g. postgres://user:[email protected]/mydb",
Expand Down
36 changes: 14 additions & 22 deletions main/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ module Main where

import PostgREST.App (postgrest)
import PostgREST.Config (AppConfig (..),
minimumPgVersion,
prettyVersion, readOptions)
import PostgREST.DbStructure (getDbStructure, getPgVersion,
fillSessionWithSettings)
import PostgREST.DbStructure (getDbStructure, getPgVersion)
import PostgREST.Error (encodeError)
import PostgREST.OpenAPI (isMalformedProxyUri)
import PostgREST.Types (DbStructure, Schema, PgVersion(..))
import PostgREST.Types (DbStructure, Schema, PgVersion(..), minimumPgVersion)
import Protolude hiding (hPutStrLn, replace)


Expand All @@ -33,8 +31,7 @@ import qualified Hasql.Pool as P
import qualified Hasql.Session as H
import Network.Wai.Handler.Warp (defaultSettings,
runSettings, setHost,
setPort, setServerName,
setTimeout)
setPort, setServerName)
import System.IO (BufferMode (..),
hSetBuffering)

Expand Down Expand Up @@ -64,11 +61,10 @@ connectionWorker
:: ThreadId -- ^ This thread is killed if pg version is unsupported
-> P.Pool -- ^ The PostgreSQL connection pool
-> Schema -- ^ Schema PostgREST is serving up
-> [(Text, Text)] -- ^ Settings or Environment passed in through the config
-> IORef (Maybe DbStructure) -- ^ mutable reference to 'DbStructure'
-> IORef Bool -- ^ Used as a binary Semaphore
-> IO ()
connectionWorker mainTid pool schema settings refDbStructure refIsWorkerOn = do
connectionWorker mainTid pool schema refDbStructure refIsWorkerOn = do
isWorkerOn <- readIORef refIsWorkerOn
unless isWorkerOn $ do
atomicWriteIORef refIsWorkerOn True
Expand All @@ -86,7 +82,6 @@ connectionWorker mainTid pool schema settings refDbStructure refIsWorkerOn = do
("Cannot run in this PostgreSQL version, PostgREST needs at least "
<> pgvName minimumPgVersion)
killThread mainTid
fillSessionWithSettings settings
dbStructure <- getDbStructure schema actualPgVersion
liftIO $ atomicWriteIORef refDbStructure $ Just dbStructure
case result of
Expand Down Expand Up @@ -152,8 +147,7 @@ main = do
appSettings =
setHost ((fromString . toS) host) -- Warp settings
. setPort port
. setServerName (toS $ "postgrest/" <> prettyVersion)
. setTimeout 3600 $
. setServerName (toS $ "postgrest/" <> prettyVersion) $
defaultSettings

-- Checks that the provided proxy uri is formated correctly
Expand Down Expand Up @@ -186,7 +180,6 @@ main = do
mainTid
pool
(configSchema conf)
(configSettings conf)
refDbStructure
refIsWorkerOn
--
Expand All @@ -204,15 +197,15 @@ main = do
throwTo mainTid UserInterrupt
) Nothing

void $ installHandler sigHUP (
Catch $ connectionWorker
mainTid
pool
(configSchema conf)
(configSettings conf)
refDbStructure
refIsWorkerOn
) Nothing
forM_ [sigHUP, sigUSR1] $ \sig ->
void $ installHandler sig (
Catch $ connectionWorker
mainTid
pool
(configSchema conf)
refDbStructure
refIsWorkerOn
) Nothing
#endif


Expand All @@ -230,7 +223,6 @@ main = do
mainTid
pool
(configSchema conf)
(configSettings conf)
refDbStructure
refIsWorkerOn)

Expand Down
Loading

0 comments on commit 85853a1

Please sign in to comment.