Commit 602d8f4
fix(cli/migrate): pre-drop dependent views before table recreates
SQLite's ALTER TABLE ... RENAME re-parses dependent view definitions
and errors with "no such table" if the referenced source table is
mid-recreate (the recreate-and-copy pattern temporarily drops the
source table and creates a __new_<table>, then RENAMEs). Even though
the rename restores the source table name, SQLite's parser sees the
intermediate state and aborts the rename.
Surfaced when applying a real mikes-website migration: every dropped
table that backed a projection view (purchases→v_customer_summary,
v_purchase_summary; weeks/workouts/exercises→v_program_summary)
failed at the RENAME step, leaving the DB in a half-migrated state.
Fix: emit `DROP VIEW IF EXISTS <view>;` for every projection view at
the very top of the combined migration, before any table SQL. The
viewUpSql block (already at the tail of the migration) recreates them
fresh. Only emitted when hasTableChanges is true — pure view-only
migrations are unaffected.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 88aaa0a commit 602d8f4
1 file changed
Lines changed: 20 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
256 | 256 | | |
257 | 257 | | |
258 | 258 | | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
263 | 268 | | |
264 | 269 | | |
265 | | - | |
| 270 | + | |
266 | 271 | | |
267 | | - | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
268 | 282 | | |
269 | 283 | | |
270 | 284 | | |
| |||
0 commit comments