Skip to content

th pearls: heal scheduled_at/tool_calls columns on pre-existing stores#178

Merged
brentrager merged 2 commits into
mainfrom
th-eba7b4-migrate-fix
Jul 6, 2026
Merged

th pearls: heal scheduled_at/tool_calls columns on pre-existing stores#178
brentrager merged 2 commits into
mainfrom
th-eba7b4-migrate-fix

Conversation

@brentrager

Copy link
Copy Markdown
Contributor

Problem

th pearls due (shipped in #176) errors on any pre-existing pearl store:

Error: table "p" does not have column "scheduled_at"

Root cause: the embedded Dolt engine has no ALTER TABLE ... ADD COLUMN IF NOT EXISTS (Error 1105, syntax error near IF). Two migrations shipped with exactly that form and were swallowed by let _ = …, so the columns were never added to existing databases:

Fresh stores were fine (columns come from CREATE TABLE), which is why tests and the throwaway-repo smoke passed — the ALTER path only runs on old stores.

Fix

Move both into migrate_schema's new COLUMN_HEALS loop, gated on column_exists() — the same proven pattern already used for pearl_comments.seq and jira_key: probe information_schema first, run a bare ADD COLUMN only when genuinely absent, commit best-effort. The two broken ADD COLUMN IF NOT EXISTS lines in ensure_schema are removed (with a pointer comment to where the heal now lives).

Verification

  • New regression test test_migrate_heals_column_if_not_exists_columns: drops both columns, asserts a reopen re-adds them, due_scheduled() works, and a second migrate_schema is idempotent (no "duplicate column").
  • cargo test -p smooai-smooth-pearls → 148 passed. cargo fmt --check + cargo clippy clean.
  • Healed the real repo store: before, th pearls due threw the column error; after, it returns "No pearls due" and SHOW COLUMNS FROM pearls confirms scheduled_at is present.

🤖 Generated with Claude Code

… stores

The embedded Dolt engine has no `ALTER TABLE ... ADD COLUMN IF NOT EXISTS`
(Error 1105, syntax error near `IF`). Two migrations shipped with exactly that
form — pearls.scheduled_at (th-01aa6a) and session_messages.tool_calls
(th-880f2c) — so the ALTER failed on every open and was swallowed by `let _ =`,
meaning the columns were never added to any pre-existing store. Symptom:
`th pearls due` errors `table "p" does not have column "scheduled_at"`.

Move both into migrate_schema's COLUMN_HEALS loop, gated on column_exists()
(the same proven pattern as pearl_comments.seq / jira_key): probe
information_schema first, run a bare ADD COLUMN only when genuinely absent,
commit best-effort. Regression test drops both columns and asserts a reopen
re-adds them + due_scheduled() works + a second migrate is idempotent.

Verified: healed the real repo's .smooth/dolt store (due went from the column
error to "No pearls due"; SHOW COLUMNS confirms scheduled_at present).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Jul 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e5d6633

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@smooai/smooth Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@brentrager brentrager enabled auto-merge (squash) July 6, 2026 03:46
@brentrager brentrager merged commit 4fad6da into main Jul 6, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant