Skip to content

refactor(automigrate): Limit ordered.Map usage to migrator internals #1164

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

Merged
merged 2 commits into from
Apr 7, 2025

Conversation

bevzzz
Copy link
Collaborator

@bevzzz bevzzz commented Apr 3, 2025

This PR addresses one of the issues raised here:

One piece of feedback regarding ordered.Map as a dependency [...] The choice to use an internal type in exported fields of exported structs made this code unusable as is, and made extending and building upon it really really messy.

Indeed, Database, Table, and BunModelSchema (with Tables field) are all exported members of sqlschema package. Having them return internal/ordered.Map has several implications:

  1. 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().

  2. Since sqlschema requires dialects to use/return ordered.Map, no otherwise compatible 3rd-party dialect will be able to implement sqlschema.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.

bevzzz added 2 commits April 3, 2025 00:58
ordered.Map is an internal type, which makes a public method
of a public interface Database unusable outside of bun.
ordered.Map is an internal type, which makes a public method
of a public interface Table unusable outside of bun.
@bevzzz bevzzz requested review from vmihailenco and j2gg0s April 3, 2025 00:40
@bevzzz bevzzz changed the title refactor(automigrate): LImit ordered.Map usage to migrator internals refactor(automigrate): Limit ordered.Map usage to migrator internals Apr 3, 2025
@bevzzz bevzzz self-assigned this Apr 3, 2025
@j2gg0s j2gg0s merged commit c0e7a42 into master Apr 7, 2025
5 checks passed
@j2gg0s j2gg0s deleted the refactor/automigrate-orderedmap branch April 7, 2025 05:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants