Skip to content

fix(store): MySQL workspaces migration fails on populated tables under strict mode#58

Draft
TYRMars wants to merge 1 commit into
mainfrom
claude/vibrant-dijkstra-5dhmt
Draft

fix(store): MySQL workspaces migration fails on populated tables under strict mode#58
TYRMars wants to merge 1 commit into
mainfrom
claude/vibrant-dijkstra-5dhmt

Conversation

@TYRMars
Copy link
Copy Markdown
Owner

@TYRMars TYRMars commented May 30, 2026

Fixes #53

Problem

The MySQL projects migration added workspaces as TEXT NOT NULL with no DEFAULT, then backfilled in a separate UPDATE. Under strict SQL mode (MySQL 8 default STRICT_TRANS_TABLES), the ALTER TABLE … ADD COLUMN … TEXT NOT NULL itself aborts on a populated table because TEXT has no implicit default — so the migration fails before the backfill ever runs. This broke idempotent re-migration / upgrade on MySQL deployments that pre-date the workspaces column.

Fix

crates/harness-store/src/mysql.rs: add the column nullable first, backfill the legacy rows, then MODIFY to NOT NULL. This satisfies strict mode on populated tables, works across MySQL 5.7/8.x regardless of sql_mode, and preserves the NOT NULL invariant. It mirrors the safe nullable-then-backfill pattern already used for the automation column just below.

ALTER TABLE projects ADD COLUMN workspaces TEXT;
UPDATE projects SET workspaces = '[]' WHERE workspaces IS NULL OR workspaces = '';
ALTER TABLE projects MODIFY COLUMN workspaces TEXT NOT NULL;

Incidental fix

While verifying, I found the crate did not compile with either SQL feature: ephemeral_tenants(...) was called from the Postgres and MySQL arms of connect_all but defined nowhere. Added the missing in-memory TenantStore fallback the call sites intended (there's no SQL TenantStore impl yet), mirroring the channel-store fallback in the same arms. Without this I couldn't compile-verify the MySQL migration path.

Verification

  • cargo check -p harness-store --features mysql
  • cargo check -p harness-store --features postgres
  • cargo clippy -p harness-store --features mysql --all-targets -- -D warnings

https://claude.ai/code/session_01TGN22RyFNGoC1KCPCrWKXn


Generated by Claude Code

…r strict mode

The MySQL `projects` migration added `workspaces TEXT NOT NULL` with no
DEFAULT, then backfilled in a separate UPDATE. Under strict SQL mode
(MySQL 8 default STRICT_TRANS_TABLES) the ADD COLUMN itself aborts on a
populated table because TEXT has no implicit default, so the migration
fails before the backfill ever runs.

Add the column nullable first, backfill, then MODIFY to NOT NULL — works
across MySQL 5.7/8.x regardless of sql_mode while preserving the NOT NULL
invariant. Mirrors the safe nullable-then-backfill pattern already used
for the `automation` column.

Also add the missing `ephemeral_tenants` helper: it was referenced from
the Postgres and MySQL arms of `connect_all` but defined nowhere, so the
crate failed to compile with either SQL feature. Adds the in-memory
TenantStore fallback the call sites intended, mirroring the channel-store
fallback in the same arms.

Fixes #53

https://claude.ai/code/session_01TGN22RyFNGoC1KCPCrWKXn
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.

MySQL migration: ADD COLUMN workspaces TEXT NOT NULL has no DEFAULT — fails on populated tables under strict mode

2 participants