PostGIS in a separate schema

I have seen it advised to install postgis in a separate schema, not the public schema. However, I am running into errors such as "error: function st_dwithin(extensions.geometry, unknown, numeric) does not exist" when trying to query using PostGIS functions. Does Drizzle support extensions installed in schemas other than public? If so, how do you set the search_path with Drizzle (I understand it's on a session basis)?
3 Replies
Mario564
Mario5643w ago
Drizzle doesn't support having extensions in another schema. However, in the generated migration file you can add the schema prefix manually (like col1 extensions_schema.geometry). For functions, you'd have to use the sql operator to also prefix them with the schema. If you want to change the search_path, you could run db.execute(sql/* query to set the search path */) right after you'd initialized the connection
EagleEyes
EagleEyes3w ago
Thanks @Mario564. I've ended up doing the latter (search_path with the extensions installed in a dedicated schema). I set the search_path in a migration via:
SET search_path TO "$user", public, extensions;
ALTER database my_db SET search_path TO "$user", public, extensions;
SET search_path TO "$user", public, extensions;
ALTER database my_db SET search_path TO "$user", public, extensions;
The first is to set the search_path for the session (aka running the migrations without having to declare extensions.extension_field and the second is to set the search path permanently. You can't just use the latter as it requires a connection reset to take effect. Seems to be working!
Mario564
Mario5643w ago
Sounds good 👍
Want results from more Discord servers?
Add your server