-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PostGIS support #1601
PostGIS support #1601
Conversation
9da316e
to
a1a7b6c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution, @crossworth. Can you check the CI? Let me know if I can help with anything
@crossworth @a8m I took a look of the CI failures, and they are all caused by the extra schemas added by I'm not familiar with the code base enough to have the best way to fix this, but this change fixes the tests: --- a/sql/postgres/inspect.go
+++ b/sql/postgres/inspect.go
@@ -1073,7 +1073,7 @@ const (
// Query to list database schemas.
- schemasQuery = "SELECT schema_name FROM information_schema.schemata WHERE schema_name NOT IN ('information_schema', 'pg_catalog', 'pg_toast', 'crdb_internal', 'pg_extension') AND schema_name NOT LIKE 'pg_%temp_%' ORDER BY schema_name"
+ schemasQuery = "SELECT schema_name FROM information_schema.schemata WHERE schema_name NOT IN ('information_schema', 'pg_catalog', 'pg_toast', 'crdb_internal', 'pg_extension', 'tiger', 'tiger_data', 'topology') AND schema_name NOT LIKE 'pg_%temp_%' ORDER BY schema_name" These schemas are created because the |
Hello @plutino, thanks for giving a look on the issue. While this change fix this problem, it's not the best solution, this would limit the names To make the CI pass, we only need to provide a way to exclude this schemas as needed (vs hardcoded on the query), Atlas already has support for it in a few places (the In my opinion the best solution is to add support for the I plan to take a look at it this week and see if I can make progress, but if you would like to give a try, please let me know. |
Sounds good. Thanks @crossworth . This will help us a lot! |
88e9682
to
b8374cc
Compare
Alright, I tried my ideia of adding support for the exclude flag, but seems like I had only two ways of doing (in a backward compatible way):
The first option seems to me the best way, since it creates a better API, but it requires changes to a lot of packages until we get to the packages used by the After thinking a bit, I remembered that my goal with this PR was quite simple, making the CI pass with PostGIS, with as little code change as possible, so I took a step back and implemented a different solution, a little bit hacky as well, but at least only in the tests part. We drop the unused schemas, would be better to have a lean docker image, but maintaining a custom docker image could not be worth for this case. This means that the problem related to the Now, with this change both the declarative and versioned migration strategies works, without the need of the NOTE: Each test was done with a empty database running on docker: docker run --rm -e POSTGRES_PASSWORD=pass -e POSTGRES_DB=test -p 25432:5432 postgis/postgis:latest Declarative
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work, @crossworth!
Thanks @crossworth. This would really resolve our problem. @a8m do you have an estimate on when this can be released? We currently uses a custom build and I'd really love to switch to an official release. |
The binary is released two times a day. You can install the latest version with:
|
Hello,
while Atlas supports using PostGIS in some capacity, we could improve it. This PR is an attempt to adds support to PostGIS extension to Atlas test suite.
PostGIS is the most used extension for Postgres.
The goals of this PR are small:
I think that been able to pass all the tests with PosGIS would solve the problems related to the schemas created by the extension (#1568 and #1577) and would pave the way to solve the problem related to geometry detection (#1577).
The problem
PostGIS (can) create a few schema/tables, that Atlas recognize as user defined, this schema/tables are used to provide extra functionality and most of the time should not be changed by the user (or Atlas), there is ways to exclude them, but I think that Atlas should be able to identify schema/tables created by extensions and make the flow as easy as possible.
schemas:
postgis_topology
)postgis_tiger_geocoder
)tables:
Declarative:
When running inspect on an empty database, Atlas tries to define the table
spatial_ref_sys
schema.hcl
It's possible to mitigate the problem using
exclude
:When applying the schema, we have to exclude it as well, otherwise we face an error:
Versioned:
The
atlas migrate diff
don't support the exclude flag, so when generating from a database with the PostGIS extension already enabled, we get thespatial_ref_sys
table definition, one way to solve it would be to edit the file and hash the migration directory again.The
atlas migrate apply
works as expected as well, but theatlas migrate lint
causes problems.When running with the docker image, we get a
pq: extension "postgis" is not available
error as expected.When using an externa database with PostGIS installed, we get different errors:
and
Since the
atlas migrate
commands dont support theexclude
flag, we don't really have a work around in this case.The solution (‽)
This PR tries to solve the problem by changing the query used to inspect tables to ignore tables created/used by extensions. This fixes the problem of the
spatial_ref_sys
table and mostly (if not all) the problems of the declarative way and the versioned way as well.But...
The tests are still failing due to the schemas created by PostGIS docker image and
Driver.CheckClean
checks.See, on my machine I don't have that schemas (because I only use the base
postgis
extension), so the tests against my local Postgres instance works.Tests error:
I tried to change the query used to inspect the schemas as well, got one almost working, but the
tiger_data
still cause problems.Tests error:
The way I see, there is no perfect way to ensure a schema/table is used (only) by the extension in some cases (like this one), so while this PR make some progress, it's not the complete solution and tests are failing.
Maybe the best solution would be embrace that sometimes we can not exclude the schema/tables created by extensions automatically and let the user exclude it as required.
So that means adding a
exclude
to theatlas migrate lint
andatlas migrate diff
commands and to make the tests pass, we would need to allow providingInspectOptions
toDriver.CheckClean
/Driver.Snapshot
and skip the PostGIS schemas.Alternatively we could create a custom PostGIS image without the
postgis_topology
andpostgis_tiger_geocoder
extensions and handle them at a later stage.Comments or ideas are appreciated.