fix: restore earthdistance function search paths#5205
Conversation
✅ Deploy Preview for teslamate ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
this isn't needed anymore, is it ? |
|
@swiffer I back my teslamate instance with a Google Cloud SQL PG instance. I've been looking to upgrade form 17 to 18 and it fails some pre-upgrade checks (I have two schemas on the same database):
My guess is that you're right, PG itself doesn't require this but at least Google's managed instances do. |
|
Ok, seems to be problematic if using inplace upgrade / pg_restore without previously creating the extensions agian like we do in the docs. You have been able to upgrade correctly after setting the search_path? |
|
Yes, I was able to run those two commands manually and upgrade the database. Restarting Teslamate against the modified and upgraded database does not appear to have any problems. |
|
Good to hear - if we set this via migration - are we able to drop creating the schema and extensions in our own restore? |
|
My hypothesis is yes, but I've never upgraded this way, so I defer to others on an authoritative answer. |
|
I will give it a try over the weekend ;) |
|
Disclaimer: I don't really understand these functions, or why they are required. Or why setting the search path is important. So I might have got details wrong. I can say that the migration will only run if it has not run before. So if you restore an old backup that hasn't had this migration, it will run the migration. But if you restore a recent backup that already has had this migration applied, it will not run this migration again. Because it is already recorded in the schema_migrations table. Normally this wouldn't matter, because the backup would also have all the values from all the applied migrations. If I look at my backup, after manually applying the changes in this migration, the backup does not contain the new search_path values, all I see in my backup is this line: Which I think might be insufficient. ? |
|
This pull request has been automatically marked as stale because it has not had recent activity. It could be closed if no further activity occurs. Thank you for your contributions. |
|
I'd like to keep this alive and eventually get it merged if possible. The change does appear to be necessary for some installations and the change has been validated. |
|
As above, it makes me nervous that this value does not appear to be saved in backups. Do we need to update the restore documentation to include a step to manually fix this? |
Copy that. I'll update the PR. |
2647ff3 to
7b6c2af
Compare
✅ Deploy Preview for teslamate ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Documentation updated and ready for re-review. |
Reapply the public search_path for ll_to_earth and earth_box after the earthdistance extension upgrade. TeslaMate previously set these functions to use the public schema to avoid lookup errors around the earth type. The later earthdistance update migration upgrades the extension but does not restore that custom function metadata, which can leave the functions without the expected search path. This adds a follow-up migration that sets the search path for both functions back to public and updates restore documentation to include these changes. Signed-off-by: Ben Hale <nebhale@nebhale.com>
7b6c2af to
2de5913
Compare
No, the issue is only present when someone does not follow the restore docu:
So imo this PR is not needed
And as you observed does not provide any meaningful value. |
|
I do think we need more data to justify the need for this. i.e. what steps are required to reproduce the search_path being unset. For the record, AI is telling me the solution is not to rely on the search path at all, and prefix everything with "public.", e.g. |

Summary
Reapply the public search path for the ll_to_earth and earth_box functions after the earthdistance extension upgrade.
Why
TeslaMate previously added search_path = public for these functions in the PostgreSQL 17 compatibility work because earthdistance functions without an explicit search path can fail to resolve the earth type correctly.
Later, the earthdistance v1.2 upgrade migration updated the extension but did not restore that custom function metadata. That appears to drop the expected search path from the extension-managed functions.
This follow-up migration restores the public search path for both functions.
Context
Validation