Commit 1f2a02b
fix(cli): generated SQL migrations give timestamp columns their time zone (#16070)
* fix(cli): generated SQL migrations give timestamp columns their time zone (#15521)
`os generate migration --format sql` spelled its two audit-stamp columns, and
every declared `datetime` field, as bare `TIMESTAMP`. On PostgreSQL that is
`timestamp WITHOUT time zone`, while both other producers of the same columns
yield `timestamptz`: driver-sql's `createAuditTimestampColumn` and this CLI's
own TypeScript migration format both build them with knex's `table.timestamp`,
and `createColumn`'s `datetime` arm states the zone-aware column as a decision —
"Postgres deliberately keeps `table.timestamp` -> `timestamptz`".
Driven rather than compiled: all three producers were run against a live
PostgreSQL 16.13 and their columns read back out of
`information_schema.columns`. Only the SQL format came back zone-naive. The
consequence is a data defect, not a cosmetic type difference: a zone-naive
column stores the wall clock of whatever session wrote the row, and
`DEFAULT now()` is folded into that session's TimeZone on the way in. Two
defaulted rows inserted six milliseconds apart, one under `TimeZone='UTC'` and
one under `Asia/Tokyo`, were recorded nine hours apart in the generated table
and 3 ms apart in the driver's own.
The whole temporal class was enumerated in the same run and `datetime` is its
only divergent member; `date` and `time` already agreed on all three producers,
so neither moves.
The nullability half of #15521 is deliberately untouched — the driver leaves
both audit columns nullable, both generators say NOT NULL, nothing fails either
way, and the driver's audit DDL is dialect-branched in a way a Postgres-
flavoured generated migration does not reproduce. It stays recorded, with the
`now()` / `CURRENT_TIMESTAMP` default spelling beside it, in
generate-builtin-id-column.pin.test.ts.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D47qPfEWVPmhguWgBZCi5N
* docs(changeset): cite ADR-0053 D-B4 as the governing decision (#15521)
Contract review corrected the AUTHORITY behind this change, not its answer.
The changeset cited driver-sql's own comment; the decision it implements is
ADR-0053 D-B4 (accepted), whose resolution states both sites in one sentence:
`Field.datetime` maps to DATETIME(3) on MySQL while "Postgres deliberately
keeps timestamptz", and "the builtin created_at/updated_at take the same type
-- the registry declares them Field.datetime".
So the declared-field row and the audit-stamp rows belong in one diff by
decision rather than by this seat's judgement, and a reader of the release
notes does not have to reconstruct that from a driver source comment.
Changeset prose only. No code, no pin, no test and no FIELD_TYPE_SQL_MAP entry
moves; the nullability and now()/CURRENT_TIMESTAMP rows stay untouched and open
with the maintainer.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D47qPfEWVPmhguWgBZCi5N
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent a4816a7 commit 1f2a02b
4 files changed
Lines changed: 198 additions & 30 deletions
File tree
- .changeset
- packages/cli/src/commands
Lines changed: 22 additions & 0 deletions
| 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 | + | |
| 22 | + | |
Lines changed: 78 additions & 26 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | | - | |
50 | | - | |
51 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
52 | 65 | | |
53 | 66 | | |
54 | 67 | | |
| |||
173 | 186 | | |
174 | 187 | | |
175 | 188 | | |
176 | | - | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
177 | 196 | | |
178 | | - | |
179 | | - | |
180 | | - | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
181 | 200 | | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
187 | 230 | | |
188 | | - | |
| 231 | + | |
189 | 232 | | |
190 | | - | |
191 | | - | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
192 | 239 | | |
193 | | - | |
194 | | - | |
195 | | - | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
196 | 243 | | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
201 | 253 | | |
202 | | - | |
203 | | - | |
| 254 | + | |
| 255 | + | |
204 | 256 | | |
205 | 257 | | |
206 | 258 | | |
207 | 259 | | |
208 | 260 | | |
209 | | - | |
| 261 | + | |
210 | 262 | | |
211 | 263 | | |
212 | 264 | | |
| |||
Lines changed: 47 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
543 | 543 | | |
544 | 544 | | |
545 | 545 | | |
546 | | - | |
| 546 | + | |
547 | 547 | | |
548 | 548 | | |
549 | 549 | | |
| |||
571 | 571 | | |
572 | 572 | | |
573 | 573 | | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
574 | 620 | | |
575 | 621 | | |
576 | 622 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1014 | 1014 | | |
1015 | 1015 | | |
1016 | 1016 | | |
1017 | | - | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
1018 | 1034 | | |
1019 | 1035 | | |
1020 | 1036 | | |
| |||
1200 | 1216 | | |
1201 | 1217 | | |
1202 | 1218 | | |
1203 | | - | |
1204 | | - | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
1205 | 1253 | | |
1206 | 1254 | | |
1207 | 1255 | | |
| |||
0 commit comments