Repository navigation
fix(driver-sql): removing a field default stores NULL on MySQL 8, and never leaves a NOT NULL column refusing writes - #36600
Conversation
…OT NULL columns pair it with the relax Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JQwxbY6wSVQZ9QBM4hLeYw
📓 Docs Drift CheckThis PR changes 1 package(s): 1 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
⛔ 1 release-owned page(s) also name something this change touched. These are read-only:
What this run could not see
Coarse fallback — 15 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 19710918a359f8b3a951a380226d0384992c1ae1 && git checkout 19710918a359f8b3a951a380226d0384992c1ae1
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 79d9c1435586d9b411b51a0ac395ea0c23dc3ddc f972c24ced205938213adc96316ec3b08d055b0f && git checkout -B drift-repro 79d9c1435586d9b411b51a0ac395ea0c23dc3ddc && git merge --no-ff f972c24ced205938213adc96316ec3b08d055b0f
node scripts/docs-audit/affected-docs.mjs --json 79d9c1435586d9b411b51a0ac395ea0c23dc3ddc
|
…lumn Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JQwxbY6wSVQZ9QBM4hLeYw
|
repo:objectstack#1 · os-warren · session_01JQwxbZeHNsF3RWcWpj7rGj 维护者速读修好主干变红:MySQL 上字段撤掉默认值后,不填该字段的写入不再被拒,改为存空值;三种数据库都在真实库上跑过。 席位核对 — ACCEPT (L1) · repo:objectstack#1 · head
|
Requested by Warren · project thread
Fixes #36596
Clause-②: no
Metadata-protocol: none
维护者速读
The cause (premise correction)
The card says the dropped DEFAULT "leaves the column NOT NULL". Measured on MySQL 8.0.46, it does not:
digestisIS_NULLABLE = YESthroughout. The cause is MySQL 8'sALTER COLUMN … DROP DEFAULT, which leaves even a nullable column with no default at all, so a strict-mode insert that omits it fails with ER 1364 "Field 'digest' doesn't have a default value".SET DEFAULT NULLstores NULL. Round 1 (#36564) was measured on MariaDB 10.11, which stores NULL afterDROP DEFAULT, and the live MySQL leg did not run on that PR.What changes
packages/drivers/driver-sql/**only, plus this changeset.drop_column_default(sql-driver-schema-sync.ts): on a nullable column it is nowALTER COLUMN … SET DEFAULT NULL; a NOT NULL column keepsDROP DEFAULT. This also covers the data: the SQL driver emits thecurrent_userframework token as a literal column DEFAULT, so the database itself writes a non-id into alookup('sys_user')#4560 token arm, which used the same statement.schema-drift.ts): the drop never travels alone, because an omitting insert would then be refused.relax_not_null:storage: { notNull: false }in words, or no storage declaration on a non-requiredfield), the drop is reported with that relax at the relax's category,needs_confirm.os migrate applyapplies both; the publish and the managed package install (Package objects: no hosted door relaxes a NOT NULL column after an upgrade declares storage.notNull:false, and the schema-drift remedy "publishing the object applies it" is refused (403 NOT_OVERRIDABLE) #33724) apply both when the field saysstorage: { notNull: false }. An unset insert then stores NULL. Dev auto-reconcile applies neither (ADR-0113 D5), so the column keeps storing the old default and is never left refusing writes.storage: { notNull: true }, arequiredfield, the ceremony-owned tenant column), the column is left alone. The entry isdestructive, so no automatic or non-destructive path applies it, and it is warned at boot and listed byos migrate plan.isPublishedColumnChange/isInstallRelaxationselect the paired drop alongside the declared relax (isDeclaredRelaxPair).Tests
sql-driver-36245-stale-literal-default.test.ts: §1 and §2 unchanged (not skipped, quarantined or narrowed); §2 now passes on live MySQL 8. New §3, per dialect cell (SQLite, live PG, live MySQL), on a NOT NULL column withDEFAULT 'none':drop_column_default+relax_not_null, bothneeds_confirm; dev boot leaves the column (unset insert stores'none');applyMigrationEntriesapplies both; unset insert stores NULL; no drift after.storage: { notNull: false }:applyPublishedColumnChangesapplies both; unset insert stores NULL.storage: { notNull: true }: onedestructiveentry; boot, publish and non-destructive apply leave the column NOT NULL with its default.required: true, no storage: same as 3.Live PG + MySQL evidence (in-container, CI's own setup)
Servers: MySQL 8.0.46 (
STRICT_TRANS_TABLES,innodb_strict_mode=1,SET GLOBAL time_zone='+08:00') and PostgreSQL 16 (ALTER SYSTEM SET timezone='Asia/Shanghai'). Run exactly as the "Temporal Conformance (live PG + MySQL)" step runs it:TZ=America/New_York OS_EXPECT_LIVE_DIALECT_MATRIX=1 OS_TEST_POSTGRES_URL=… OS_TEST_MYSQL_URL=… pnpm --filter @objectstack/driver-sql test.Before (origin/main 79d9c14), the red reproduced on live MySQL 8:
After (head f972c24), the file, verbose: 51 passed (51). Every §2 and §3 case passes on
sqlite,live postgresandlive mysql(18 two-boot cases, 6 per dialect);driver-sql live-dialect coverage: all 3 dialects were exercised (sqlite, live postgres, live mysql).After, the whole driver-sql suite under the CI step's setup:
The one failure is not this PR's: it fails identically at origin/main 79d9c14 against the same local server (same command, main's
src/), and passes on main's CImysql:8.0image. The difference is this container's Ubuntu MySQL build, not the code: the case expects the server to refuse a new 40-column table, and this server accepts it. This PR touches no create path.Ablations (
scripts/ablation-replace.mjs, each restored to HEAD, run on all three cells):DROP DEFAULTon a nullable columnsafeand unpaired, as on mainstorage: { notNull: false }publish case on each dialectnotNull: trueandrequiredcases on each dialectFollow-ups (not in this PR)
content/docs/deployment/cli.mdx(the publish paragraph under the drift-category table) says the publish applies "everysafecolumn change, and arelax_not_nullwhose field declaresstorage: { notNull: false }". It now also applies the paireddrop_column_default. That page is outside this card's file surface, so it is not edited here.relax_not_nullrunsMODIFY … NULL, which also drops a column's declared literal DEFAULT (measured:NOT NULL DEFAULT 'x'becomesDEFAULT NULL); the schema sync: removing a literal defaultValue from a field leaves the physical column DEFAULT on every SQL database an earlier release created, so unset writes keep storing the old default #36245set_column_defaultarm restates it on the next sync. Pre-existing and unchanged here.driver-sqlPR is a.github/workflows/ci.ymlchange: governed (Tier H) and outside this card's file surface, so it is not made here. Evidence from in-container live servers is pasted instead.🤖 Generated with Claude Code
https://claude.ai/code/session_01JQwxbY6wSVQZ9QBM4hLeYw