Resource generator: many-to-many, views, no-PK tables, and prompt UX#748
Merged
zachdaniel merged 8 commits intoMay 14, 2026
Merged
Conversation
resource generator and fix yes option
instead of composite primary keys join_table?/1 previously required the table's primary key to equal the two FK columns. Hibernate / legacy schemas commonly enforce join-table uniqueness with a UNIQUE INDEX over (a, b) instead of a PRIMARY KEY constraint, so those tables silently fell through and no many_to_many was generated. Accept either signal: composite PK matching the FK columns, OR a unique index (with no WHERE clause) covering exactly the FK columns.
Contributor
|
🚀 Thank you for your contribution! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Contributor checklist
Leave anything that you believe does not apply unchecked.
This PR improves
mix ash_postgres.gen.resourcesadding many_to_many detection, views and better conflict resolution. See: https://discordapp.com/channels/711271361523351632/1495458363960721629I also set up an example project with a legacy DB schema, to test the generator on a real-world schema. https://github.com/weljoda/gen_resources_example
New capabilities
--include-views. View-backed resources are emitted withmigrate? falseand a :read-only default action. The underlying introspection queries were ported from information_schema to pg_catalog so views are discoverable at all.require_primary_key? falseand a:read, create: :*default action, each carrying a # WARNING: comment pointing the user at the fix.--skip-many-to-manyflag for users who prefer just has_many on join tables.Conflict-resolution UX overhaul
When multiple FKs produce duplicate default relationship names, the generator now:
In my usecase this reduced the prompts by using auto-resolve to 4 from 58 previously.
Bug fixes folded in
Generated-code ordering