Skip to content

Remove IF NOT EXISTS from migrations and drop mysql CLI fallback#19

Merged
wesbillman merged 1 commit intomainfrom
baxen/remove-if-not-exists-and-mysql-fallback
Mar 10, 2026
Merged

Remove IF NOT EXISTS from migrations and drop mysql CLI fallback#19
wesbillman merged 1 commit intomainfrom
baxen/remove-if-not-exists-and-mysql-fallback

Conversation

@baxen
Copy link
Collaborator

@baxen baxen commented Mar 10, 2026

What

  • Drop IF NOT EXISTS from all CREATE TABLE statements in the initial migration.
  • Remove the mysql CLI fallback path in dev-setup.sh.

Why

IF NOT EXISTS in managed migrations is an anti-pattern. sqlx tracks applied migrations in _sqlx_migrations and guarantees each runs exactly once. The guard was masking partial failures and giving a false sense of idempotency — the CREATE TABLE might silently succeed while subsequent CREATE INDEX statements fail.

The mysql CLI fallback bypasses migration tracking. Running raw .sql files via docker exec mysql doesn't record anything in _sqlx_migrations, so a subsequent sqlx migrate run would attempt to re-apply the same migration and hard-fail (especially now that IF NOT EXISTS is removed). Two code paths for the same operation is a recipe for inconsistent environments.

The script now fails fast with a clear cargo install sqlx-cli message instead.

Changes

File Change
migrations/20260306000001_initial_schema.sql CREATE TABLE IF NOT EXISTSCREATE TABLE (9 tables)
scripts/dev-setup.sh Remove mysql CLI fallback, fail with install instructions

@baxen baxen requested a review from wesbillman as a code owner March 10, 2026 20:42
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3e506dffb1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

-- ─── Channels ────────────────────────────────────────────────────────────────

CREATE TABLE IF NOT EXISTS channels (
CREATE TABLE channels (

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep initial migration idempotent for fallback runners

Removing IF NOT EXISTS here makes the initial schema file non-idempotent, but the repo still has raw-SQL fallback paths that re-run migration files directly (scripts/run-tests.sh:118-127 and justfile:128-142) and suppress mysql errors with || true. In environments without sqlx (common in CI/dev shells), those paths will now hit "table exists" on the first CREATE TABLE, stop executing the rest of that file, and still report success, which can leave schema drift undetected.

Useful? React with 👍 / 👎.

- Drop IF NOT EXISTS from all CREATE TABLE statements in the initial
  migration. sqlx tracks applied migrations in _sqlx_migrations and
  guarantees each runs exactly once; the guard was masking partial
  failures and giving a false sense of idempotency.

- Remove the mysql CLI fallback in dev-setup.sh. Running raw .sql
  files via docker exec bypasses sqlx migration tracking, which
  causes re-apply errors on subsequent runs. Fail fast with a clear
  install message instead.
@baxen baxen force-pushed the baxen/remove-if-not-exists-and-mysql-fallback branch from 3e506df to 3b65b90 Compare March 10, 2026 21:33
@wesbillman wesbillman merged commit 3fb4699 into main Mar 10, 2026
8 checks passed
@wesbillman wesbillman deleted the baxen/remove-if-not-exists-and-mysql-fallback branch March 10, 2026 21:46
tlongwell-block added a commit that referenced this pull request Mar 11, 2026
* origin/main:
  Migrate channel scoping to h tags (#22)
  Remove IF NOT EXISTS from migrations and drop mysql CLI fallback (#19)
  fix: resolve 10 E2E bugs + add desktop Playwright tests (#21)
  Add desktop search and result anchors (#15)
  fix: mcp and desktop communication (#18)
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.

2 participants