feat: add after_tables to custom_statements so raw SQL can depend on another table#799
Merged
zachdaniel merged 2 commits intoJul 23, 2026
Conversation
jechol
force-pushed
the
migration-ordering-and-after-tables
branch
from
July 18, 2026 16:54
bbd0d0a to
5a883ea
Compare
jechol
marked this pull request as draft
July 18, 2026 17:20
jechol
force-pushed
the
migration-ordering-and-after-tables
branch
6 times, most recently
from
July 19, 2026 10:05
28ccc51 to
bd9b300
Compare
jechol
marked this pull request as ready for review
July 19, 2026 10:35
jechol
marked this pull request as draft
July 20, 2026 08:26
Contributor
|
Ready for this to be backmerged |
jechol
force-pushed
the
migration-ordering-and-after-tables
branch
from
July 22, 2026 22:46
bd9b300 to
2d27e29
Compare
jechol
force-pushed
the
migration-ordering-and-after-tables
branch
from
July 22, 2026 22:58
2d27e29 to
251aaec
Compare
Contributor
Author
|
Done — rebased onto |
jechol
marked this pull request as ready for review
July 22, 2026 23:29
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.
Motivation
custom_statementshad no way to declare "this depends on another table's structure being finalized first." The only rule was "adds always run last, removes always run first." That breaks for a raw-SQL statement that needs to run after some other table is fully set up — e.g. a composite foreign key referencing a unique index that isn't guaranteed to exist yet.What changed
AshPostgres.Statementgets a newafter_tablesoption (a list of table name strings) so a statement can declare that dependency explicitly:Internally, #798 has a single per-table "doneness" fact,
:table_structure_ready— provided by every structural operation (columns, indexes, constraints, etc.) on the table. This PR adds a second, broader fact on top of it::table_structure_ready(existing) — this table's structural operations are done.:table_finalized(new) — the table is truly done, including anycustom_statementsdeclared on it. Provided by everything that provides:table_structure_ready, plus eachAddCustomStatementon the table — so a table with no custom statements is finalized as soon as its structure is ready.A statement's own implicit "wait for my own table" requirement uses the narrower
:table_structure_ready, so two statements on the same table never end up requiring each other's completion (a guaranteed cycle if both used the broader fact). A declaredafter_tablesentry uses the broader:table_finalized, so it also waits for the referenced table's own custom statements — not just its structure.Statements with no
after_tableskeep the previous default behavior exactly (no declared dependency → best-effort last), so this is fully backwards compatible.Testing
Builds on the dependency-graph rewrite in #798. New tests in
test/migration_generator/operation_deps_test.exscover: a statement's own-table requirement being satisfied by structural ops, anafter_tablesrequirement being satisfied by another table's custom statement (the actual new capability), and two same-table statements not creating a cycle. Fullmix test: 858 passed.Contributor checklist
Leave anything that you believe does not apply unchecked.