Skip to content

fix(support): rewrite legacy 'asset' table alias to 'asset_account'#195

Draft
TaprootFreak wants to merge 1 commit into
developfrom
fix/support-db-asset-alias-rewrite
Draft

fix(support): rewrite legacy 'asset' table alias to 'asset_account'#195
TaprootFreak wants to merge 1 commit into
developfrom
fix/support-db-asset-alias-rewrite

Conversation

@TaprootFreak
Copy link
Copy Markdown
Contributor

Summary

Follow-up to #193, which added a PG view aliasing the renamed asset table but did not resolve the symptom for the QueryBuilder path. After #193 deployed, POST /v1/support/db requests with table: "asset" now return HTTP 400:

{"statusCode":400,"message":"Cannot get entity metadata for the given alias \"asset\"","error":"Bad Request"}

SupportService.getRawData builds the query via dataSource.createQueryBuilder().from(query.table, query.table).select(...). TypeORM resolves the alias against its entity registry to map columns. asset is no longer a registered entity (renamed to asset_account in migration 1715583133193-setupFrankencoinPay, and the corresponding AssetEntity was replaced by AssetAccountEntity mapped to @Entity('asset_account')). The view added in #193 lives at PG level, but the QueryBuilder never gets that far — it throws on entity-metadata lookup first.

This PR rewrites the table reference (and the asset. prefix in select / where / join inputs) to asset_account inside getRawData. AssetAccountEntity's metadata is then picked up via the matching tableName, and the response keys come back through transformResultArrayrenameDbKeys('asset_account', …) as bare column names — matching what the Apps Script callers expect in their sheet row 5.

The PG view from #193 becomes effectively unused for QueryBuilder traffic but remains valid for raw-SQL callers; not removing it here to keep the change minimal.

Test plan

  • npm run build — pass
  • npm run lint — pass
  • npm run test — 22/22 pass (including query-builder-alias.spec.ts, which scans for unquoted column refs)
  • Deploy to DEV (dfxdev), verify a manual POST /v1/support/db with {"table":"asset"} returns 200 with rows from asset_account
  • Watch dfxprd lds-lds-api-1 logs after PRD merge: POST /v1/support/db should drop from 400 to 201 for asset-table calls. Verify via:
ssh dfx01-remote 'curl -s "http://localhost:3101/loki/api/v1/query" \
  --data-urlencode "query=sum(count_over_time({container_name=\"lds-lds-api-1\", server=\"dfxprd\"} |~ \"support/db\" |~ \"400\" [30m]))"'

Refs #192, follow-up to #193.

PR #193 added a PG view aliasing the renamed asset table, but
SupportService.getRawData uses TypeORM's QueryBuilder, which requires
an entity-backed alias. 'asset' has no registered entity (renamed to
'asset_account' in migration 1715583133193), so the QueryBuilder
throws "Cannot get entity metadata for the given alias 'asset'" before
ever reaching the view. External callers (e.g. Google Apps Script
ledgers) get HTTP 400 instead of data.

Rewrite the table name and the 'asset.' prefix in select/where/join
inputs to 'asset_account' before passing to the QueryBuilder. The
existing entity metadata for AssetAccountEntity is picked up via the
matching tableName, and the request flows end-to-end.

Refs #192, follow-up to #193
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.

1 participant