diff --git a/migrations.py b/migrations.py index 41b82eb..d485aa7 100644 --- a/migrations.py +++ b/migrations.py @@ -302,3 +302,33 @@ async def m001_satmachine_v2_initial(db): ); """ ) + + +async def m002_rename_commission_split_wallet_id_to_target(db): + """One-off correction for installs whose `dca_commission_splits` table + pre-exists from an earlier partial v2 migration run (where the column + was named `wallet_id`). The collapsed m001 uses `CREATE TABLE IF NOT + EXISTS`, which is a no-op when the table already exists — so the + schema drift survives the documented uninstall + reinstall workflow + because LNbits' uninstall wipes the dbversions tracker but NOT the + satoshimachine.sqlite3 file on disk. + + Idempotent: probes for the `wallet_id` column via a SELECT. If the + probe succeeds the column still exists and we RENAME it; otherwise + the rename is already done (or the table was fresh) and we no-op. + + Fresh installs from m001 onward already have `target` directly — for + them this migration is a no-op. + """ + try: + await db.fetchone( + "SELECT wallet_id FROM satoshimachine.dca_commission_splits LIMIT 1" + ) + except Exception: + # wallet_id column doesn't exist; either m001 produced the correct + # schema on a fresh install or the rename already landed. + return + await db.execute( + "ALTER TABLE satoshimachine.dca_commission_splits " + "RENAME COLUMN wallet_id TO target" + )