cardano-db-sync icon indicating copy to clipboard operation
cardano-db-sync copied to clipboard

How to customize database schema name?

Open zxpectre opened this issue 1 year ago • 3 comments

Is there a way to make db-sync use another schema instead of 'public'?

Say like passing a POSTGRES_SCHEMA env var with a different name?

This is really needed to properly take control over the setup and to manage better security permissions and versions.

zxpectre avatar Feb 23 '24 19:02 zxpectre

The schema looks to be hardcoded. I would support making this configurable

sgillespie avatar Feb 23 '24 20:02 sgillespie

Thanks @sgillespie, we really need this. Also I'm about to suggest CF's Ledger Sync to take same approach earlier.

Yes it is harcoded all across the repo, on code, migration files and tests.

Example: https://github.com/IntersectMBO/cardano-db-sync/blob/045330da2352504f67f68a0b870cc5e08951810b/cardano-db/src/Cardano/Db/Migration.hs#L289

zxpectre avatar Feb 23 '24 20:02 zxpectre

db-sync currently uses the default schema of the db. One solution is to change it before starting db-sync

alter database <db> set search_path to <schema>;

then db-sync will use the correct one.

Btw the "public" reference in the link that you sent is only used for testing and shouldn't be a problem.

kderme avatar Feb 24 '24 22:02 kderme