|
| 1 | +module.exports = class Data1781633867200 { |
| 2 | + name = 'Data1781633867200' |
| 3 | + |
| 4 | + async up(db) { |
| 5 | + // In-place upgrade of the live v155 database (continues the existing DB, no re-sync): |
| 6 | + // add the per-asset `outstanding_assets` array (in-flight protocol redemptions, aligned |
| 7 | + // to Arm.assets) and backfill it from existing data. Adding a NOT NULL column to a |
| 8 | + // populated table requires a temporary default; we backfill, then drop the default so the |
| 9 | + // schema matches main's squashed migration (where the column is created NOT NULL, no default). |
| 10 | + await db.query(`ALTER TABLE "arm_state" ADD COLUMN "outstanding_assets" text array NOT NULL DEFAULT '{}'`) |
| 11 | + await db.query(`ALTER TABLE "arm_daily_stat" ADD COLUMN "outstanding_assets" text array NOT NULL DEFAULT '{}'`) |
| 12 | + // Every ARM is still pre-upgrade (single base asset, upgradeBlock=null), so |
| 13 | + // outstanding_assets = [0, outstandingAssets1]: [0] = liquidity asset (never redeems into |
| 14 | + // itself), [1] = the existing outstanding_assets1 scalar. outstanding_assets1 is a numeric |
| 15 | + // BigInt; cast to plain-integer text to match the entity's decimal-string array format. |
| 16 | + await db.query(`UPDATE "arm_state" SET "outstanding_assets" = ARRAY['0', "outstanding_assets1"::text]`) |
| 17 | + await db.query(`UPDATE "arm_daily_stat" SET "outstanding_assets" = ARRAY['0', "outstanding_assets1"::text]`) |
| 18 | + await db.query(`ALTER TABLE "arm_state" ALTER COLUMN "outstanding_assets" DROP DEFAULT`) |
| 19 | + await db.query(`ALTER TABLE "arm_daily_stat" ALTER COLUMN "outstanding_assets" DROP DEFAULT`) |
| 20 | + } |
| 21 | + |
| 22 | + async down(db) { |
| 23 | + await db.query(`ALTER TABLE "arm_state" DROP COLUMN "outstanding_assets"`) |
| 24 | + await db.query(`ALTER TABLE "arm_daily_stat" DROP COLUMN "outstanding_assets"`) |
| 25 | + } |
| 26 | +} |
0 commit comments