refactor(automigrate): Limit ordered.Map usage to migrator internals #1164
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.
This PR addresses one of the issues raised here:
Indeed,
Database
,Table
, andBunModelSchema
(with Tables field) are all exported members ofsqlschema
package. Having them returninternal/ordered.Map
has several implications:As noted in the comment, external packages aren't able to use return of Tables(), while other methods, e.g. ForeignKeys() return usable objects. Same is true for
Columns()
.Since
sqlschema
requires dialects to use/returnordered.Map
, no otherwise compatible 3rd-party dialect will be able to implementsqlschema.Inspector
We've originally decided to use an ordered map to achieve stable query generation, which really is a great use case for it.
This PR limits the usage of the ordered map to where it's most useful -- the
migrate.detector
, which calculates schema diff. Meanwhile, schema inspectors will return Tables and Columns as slices, reducing the complexity and making the package more extendable and interoperable.Some of the tests got a tiny bit more verbose as a result, but overall the code looks simpler.