From e0bd4d9798c17ea8886b761e8207cc549c48caee Mon Sep 17 00:00:00 2001 From: David May <85513542+davidleomay@users.noreply.github.com> Date: Wed, 27 May 2026 00:34:05 +0200 Subject: [PATCH] fix(db): add compat view for renamed asset table + fix rootstockBalance casing (#193) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An external sync client polls POST /v1/support/db with hardcoded table/column names that are out of date, causing ~6 PG errors/min: 1. `SELECT * FROM "asset"` — table was renamed to asset_account in migration 1715583133193. Create a view alias so old queries work. 2. `monitoring_balance.rootstockBalance` sent unquoted — Postgres case-folds to lowercase, doesn't match the mixed-case column. Column is unused by the app (Rootstock removed in PR #124). Rename to lowercase for compat. Fixes #192 --- .../1779834163000-fixStaleSchemaCompat.js | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 migration/1779834163000-fixStaleSchemaCompat.js diff --git a/migration/1779834163000-fixStaleSchemaCompat.js b/migration/1779834163000-fixStaleSchemaCompat.js new file mode 100644 index 000000000..9083bf13b --- /dev/null +++ b/migration/1779834163000-fixStaleSchemaCompat.js @@ -0,0 +1,44 @@ +/** + * @typedef {import('typeorm').MigrationInterface} MigrationInterface + * @typedef {import('typeorm').QueryRunner} QueryRunner + */ + +/** + * Fixes two stale-schema issues surfaced by an external sync client + * (POST /v1/support/db) that polls with hardcoded table/column names: + * + * 1. `asset` table was renamed to `asset_account` in migration + * 1715583133193-setupFrankencoinPay. The caller still queries + * `SELECT * FROM "asset"`. Fix: create a view alias. + * + * 2. `monitoring_balance.rootstockBalance` column exists but the caller + * sends it unquoted. Postgres case-folds unquoted identifiers to + * lowercase, so it looks for `rootstockbalance` which doesn't match + * the mixed-case `"rootstockBalance"`. The column is no longer used + * by the app (Rootstock integration removed in PR #124). + * Fix: rename to lowercase so both quoted and unquoted access work. + * + * See: https://github.com/LightningDotSpace/api/issues/192 + * + * @class + * @implements {MigrationInterface} + */ +module.exports = class FixStaleSchemaCompat1779834163000 { + name = 'FixStaleSchemaCompat1779834163000' + + /** + * @param {QueryRunner} queryRunner + */ + async up(queryRunner) { + await queryRunner.query(`CREATE VIEW "asset" AS SELECT * FROM "asset_account"`); + await queryRunner.query(`ALTER TABLE "monitoring_balance" RENAME COLUMN "rootstockBalance" TO "rootstockbalance"`); + } + + /** + * @param {QueryRunner} queryRunner + */ + async down(queryRunner) { + await queryRunner.query(`ALTER TABLE "monitoring_balance" RENAME COLUMN "rootstockbalance" TO "rootstockBalance"`); + await queryRunner.query(`DROP VIEW "asset"`); + } +}