Skip to content

Support different database schema than the default one for Pongo #115

@oskardudycz

Description

@oskardudycz
  1. In Pongo and Dumbo, we'd like to promote passing the connection string with full setup, so it'd best if the schema is passed through it.
  2. This is a bit tricky, but doable for node-postgres it has to be passed as param options=-c search_path=pongo', e.g. postgresql://postgres:postgres@localhost:5432/postgres?options=-c search_path=pongo.
  3. After that, all SQL queries will be handled in the order of the search path.
  4. We still need to create schemas, this is doable based on the defined search path with e.g.:
DO $$
BEGIN
EXECUTE COALESCE((
   SELECT string_agg(format(‘CREATE SCHEMA %I;’, schema_name), E’\n’)
   FROM (
      SELECT trim(both ’ “’ from unnest(string_to_array(current_setting(‘search_path’), ‘,’))) as schema_name
   ) t
   WHERE schema_name != ‘’
   AND schema_name != ‘$user’
   AND NOT EXISTS (SELECT 1 FROM pg_namespace WHERE nspname = t.schema_name)
), ‘SELECT 1’);
END $$;
  1. This could be run upon the Pongo database setup, so as a first schema component in the database sqls (before collections), see:
    return schemaComponent('pongo:schema_component:db', {

Later on we'll need to think about advanced schema management whether we want to allow e.g. treating Pongo db as schema, or define it on the collection level, but as the first step it, what I outlined should be enough (of course verified with the proper test coverage, also for migrations).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions