Reusing an already deployed postresql database with new units

Is there anyone that has implemented code for a charm making use of an already instantiated postgresql database. I’m using this lib https://github.com/canonical/ops-lib-pgsql

I’m trying to figure out how to deal with a situation where my application (nextcloud) removes the “last unit” and then adds back a new one. The new unit should be made detecting that there is already a database which should be re-used.

I’m not sure how other have dealt with this in operator for machine charms so I’m looking for advice and perhaps someone got some code for this scenario.