-
-
Notifications
You must be signed in to change notification settings - Fork 34
Open
Labels
Description
- 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.
- This is a bit tricky, but doable for
node-postgres
it has to be passed as paramoptions=-c search_path=pongo'
, e.g.postgresql://postgres:postgres@localhost:5432/postgres?options=-c search_path=pongo
. - After that, all SQL queries will be handled in the order of the search path.
- 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 $$;
- 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).