fix(support): rewrite legacy 'asset' table alias to 'asset_account'#195
Draft
TaprootFreak wants to merge 1 commit into
Draft
fix(support): rewrite legacy 'asset' table alias to 'asset_account'#195TaprootFreak wants to merge 1 commit into
TaprootFreak wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #193, which added a PG view aliasing the renamed
assettable but did not resolve the symptom for the QueryBuilder path. After #193 deployed,POST /v1/support/dbrequests withtable: "asset"now return HTTP 400:{"statusCode":400,"message":"Cannot get entity metadata for the given alias \"asset\"","error":"Bad Request"}SupportService.getRawDatabuilds the query viadataSource.createQueryBuilder().from(query.table, query.table).select(...). TypeORM resolves the alias against its entity registry to map columns.assetis no longer a registered entity (renamed toasset_accountin migration1715583133193-setupFrankencoinPay, and the correspondingAssetEntitywas replaced byAssetAccountEntitymapped 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 inselect/where/joininputs) toasset_accountinsidegetRawData.AssetAccountEntity's metadata is then picked up via the matchingtableName, and the response keys come back throughtransformResultArray→renameDbKeys('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— passnpm run lint— passnpm run test— 22/22 pass (includingquery-builder-alias.spec.ts, which scans for unquoted column refs)POST /v1/support/dbwith{"table":"asset"}returns 200 with rows fromasset_accountlds-lds-api-1logs after PRD merge:POST /v1/support/dbshould drop from400to201forasset-table calls. Verify via:Refs #192, follow-up to #193.