Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

how to use db-schema? #160

Closed
ppKrauss opened this issue Jul 21, 2018 · 4 comments
Closed

how to use db-schema? #160

ppKrauss opened this issue Jul 21, 2018 · 4 comments

Comments

@ppKrauss
Copy link
Contributor

ppKrauss commented Jul 21, 2018

I am running docker run --rm --net=host -p 3000:3000 -e DB_SCHEMA=test -e PGRST_DB_URI="postgres://postgres:etc@localhost:5432/etcdb" -e PGRST_DB_ANON_ROLE="postgres" postgrest/postgrest &

And to test I also used at SQL a public create table t , but all other data is at SQL's CREATE schema test. Eg. there was create table test.t... So, http://localhost:3000/t is fine (!), BUT:

http://localhost:3000/test.t is an error, "relation "public.test.t" does not exist".

so, how to use DB_SCHEMA env, or how to say that I need a SQL-schema name that is not public?

@steve-chavez
Copy link
Member

The env var is PGRST_DB_SCHEMA, here is a list of the env vars for the docker image https://github.com/PostgREST/postgrest/blob/master/docker/Dockerfile#L27-L39.

@ppKrauss
Copy link
Contributor Author

Hi @steve-chavez, thanks, PGRST_DB_SCHEMA is working fine (!).

The term "schema" is confuse, the suggestion is to change documentation, can I edit there?


Now I have two new problmes:

  1. How to build mulple instances (varing the parameter PGRST_DB_SCHEMA) of PostgREST with docker run

  2. How to use RPC, I using copy/paste function of the documentation, but impossible to call it by GET as you the documensay. I use http//:localhost:3000/rpc/add_them?a=1&b=2 but it is an ERROR , "function test.add_them() does not exist".

The root also shows correct function definition,

{
"/rpc/add_them":{
  "post":{
     "tags":["(rpc) add_them"],
     "produces":["application/json","application/vnd.pgrst.object+json"],
     "parameters":[{
          "required":true,"schema":{"required":["a","b"],
          "type":"object",
          "properties":{"a":{"format":"integer","type":"integer"},"b":{"format":"integer","type":"integer"}}},
          "in":"body","name":"args"
        },{"$ref":"#/parameters/preferParams"}],"responses":{"200":{"description":"OK"}
   }}}
}

@steve-chavez
Copy link
Member

steve-chavez commented Jul 24, 2018

I think the term schema is pretty standard in a database context, but sure if you have suggestions for improving the docs you can open a PR and we'll discuss it there.

About your problems:

  1. You'll need to also change the port(PGRST_SERVER_PORT) for exposing multiple instances, an example docker-compose.yml:
version: '3'
services:
  pgrst1:
    image: postgrest/postgrest
    ports:
      - "3000:3000"
    environment:
      PGRST_DB_URI: postgres://postgrest_test_authenticator@localhost/postgrest_test
      PGRST_DB_SCHEMA: test
      PGRST_DB_ANON_ROLE: postgrest_test_anonymous
    network_mode: host
  pgrst2:
    image: postgrest/postgrest
    ports:
      - "3001:3001"
    environment:
      PGRST_DB_URI: postgres://postgrest_test_authenticator@localhost/sample
      PGRST_DB_SCHEMA: api
      PGRST_DB_ANON_ROLE: postgrest_test_anonymous
      PGRST_SERVER_PORT: 3001
    network_mode: host
  1. For GET on RPC to work correctly you must restart or send a SIGHUP to a postgrest process. I added a note about this, Whenever the function definition changes you must refresh PostgREST’s schema for this to work properly. See the section Schema Reloading, this is a bit below the section you pointed out. I think this note should definitely be reordered to be just after the CREATE FUNCTION to avoid confusion. Btw, for sending a SIGHUP to a docker container you could do
    docker kill --signal=HUP <container id or name>(this could be added to the Schema Reloading section).

@ppKrauss
Copy link
Contributor Author

Thanks @steve-chavez, 1 and 2 are solutions and are working fine with my server (!).

We can close this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants