sql/postgres: fixed inspection/migration for enums and indexes #711
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'm evaluating Atlas for a project I'm working on. We're using Postgres and I stumbled across a couple of issues related to enums and indexes.
Enums:
schema.EnumType
lacks schema information which is important for Pg as user types belong to a schema (namespace). This is fatal when performingNormalizeRealm
: the schema name is changed to a temp one (atlas_dev_%s_%d
) and then applied to the dev db. Since enums don't have a reference to theschema.Schema
they belong to, the generated schema change statements (sql) are incorrect as enums are referenced by name only which usually means that they are created in thepublic
schema and not the atlas_dev_xxx schema. Also enum types may be referenced in expressions like column default value:which when inspected become like this:
The reason is the query the index metadata is retrieved from Postgres.
Last but not least (as it is the first problem I hit): there is a problem if the DSN contains an username with
_
: the initial url is split in provider (postgres/...) and dns (the rest after the ://) and the later is parsed as an url (url.Parse
). As this url already have the scheme stripped it becomes somewhat malformed as per the standard lib source code and results in an error: first path segment in URL cannot contain colon.In any case Atlas is amazing and I'm looking forward to start using it as the main schema management tool for the project I'm currently working on.