Commit 3fe0ff1
fix(driver-sql): the plan must not promise columns the apply can never create (#3978)
The mirror image of #3954. That issue closed "the plan understates what
apply does"; this closes the other direction — the plan promising work
apply CANNOT do.
`previewDeferredSchemaWork()` listed every declared field name when
computing pending create_table / add_columns work, but `createColumn`
returns early for a virtual `formula` field: no column is ever created.
So a formula field appeared as pending `add_columns`, `apply` reported it
as performed without doing anything, and the very next `plan` reported it
again. A freshly-applied database looked permanently un-migrated with no
invocation able to clear the finding. On examples/app-crm that was four
columns reported forever: crm_contact.full_name, crm_lead.is_closed,
crm_opportunity.expected_revenue and crm_opportunity.days_to_close.
The preview now filters through `fieldHasColumn` — the same helper
`createColumn` and the column differ already answer "does this field
materialize a column?" with, and the one place that had not adopted it —
so the plan and the flush cannot disagree. `multiple` fields are
unaffected: they materialize as a JSON column and are still reported.
`PendingSchemaWork.columns` now states the constraint in the type.
Regression coverage in sql-driver-deferred-ddl.test.ts: the formula field
is omitted from a create_table preview while the JSON column is kept; the
same for add_columns; a flush is followed by an empty preview (the
convergence property the issue asks for); and what flush REPORTS having
done matches the columns physically created. All four fail without the
filter.
Closes #3978
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FcphmGzBuWwF8SaYPSCtCw1 parent 5c8afed commit 3fe0ff1
4 files changed
Lines changed: 114 additions & 1 deletion
File tree
- .changeset
- packages/plugins/driver-sql/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
113 | 118 | | |
114 | 119 | | |
115 | 120 | | |
| |||
Lines changed: 75 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
139 | 214 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
2864 | 2865 | | |
2865 | 2866 | | |
2866 | 2867 | | |
| 2868 | + | |
| 2869 | + | |
| 2870 | + | |
| 2871 | + | |
| 2872 | + | |
| 2873 | + | |
| 2874 | + | |
| 2875 | + | |
| 2876 | + | |
2867 | 2877 | | |
2868 | 2878 | | |
2869 | 2879 | | |
2870 | 2880 | | |
2871 | | - | |
| 2881 | + | |
| 2882 | + | |
| 2883 | + | |
2872 | 2884 | | |
2873 | 2885 | | |
2874 | 2886 | | |
| |||
0 commit comments