Commit 438b165
fix(driver-sql): translate defaultValue 'NOW()' + literal value to CURRENT_TIMESTAMP
The driver previously only mapped the implicit created_at / updated_at
columns to CURRENT_TIMESTAMP and ignored field.defaultValue entirely.
Every other datetime field that declared the framework convention
defaultValue: 'NOW()' (sys_activity.timestamp, sys_comment threads,
sys_presence.last_seen, …) ended up with no DB-level default, and any
upstream caller that helpfully passed the literal string 'NOW()' would
write that string into the column verbatim — producing 'Invalid Date'
in the UI and a class of subtle correctness bugs.
Fix has two parts:
1. Schema (createColumn): for datetime/date/time fields, when
field.defaultValue === 'NOW()' (case-insensitive), apply
.defaultTo(this.knex.fn.now()). For other scalar defaultValues,
pass them through verbatim instead of dropping them on the floor.
2. Insert/update (formatInput): scan every value before it hits the
DB and replace any string of the form 'NOW()' with a real ISO
timestamp. Cross-driver (not just SQLite).
Verified via DDL inspection (sys_activity.timestamp now has
'default CURRENT_TIMESTAMP') and a live REST insert that submitted
created_at='NOW()' — the persisted row has a proper ISO datetime.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 1cc117e commit 438b165
1 file changed
Lines changed: 40 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1002 | 1002 | | |
1003 | 1003 | | |
1004 | 1004 | | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
1005 | 1024 | | |
1006 | 1025 | | |
1007 | 1026 | | |
| |||
1096 | 1115 | | |
1097 | 1116 | | |
1098 | 1117 | | |
1099 | | - | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
1100 | 1137 | | |
1101 | 1138 | | |
1102 | | - | |
| 1139 | + | |
1103 | 1140 | | |
1104 | | - | |
| 1141 | + | |
1105 | 1142 | | |
1106 | 1143 | | |
1107 | 1144 | | |
| |||
0 commit comments