Skip to content

test: validate typeorm entities#375

Open
SgtPooki wants to merge 3 commits intomainfrom
ci/typeorm-entity-validation
Open

test: validate typeorm entities#375
SgtPooki wants to merge 3 commits intomainfrom
ci/typeorm-entity-validation

Conversation

@SgtPooki
Copy link
Collaborator

@SgtPooki SgtPooki commented Mar 18, 2026

Summary

  • Adds a postbuild script that validates compiled TypeORM entity metadata against the Postgres driver, catching unsupported column types before deployment
  • Runs automatically after every pnpm build — locally, in CI (test.yml), and in Docker image builds (Dockerfile)

Problem

PR #186 introduced a bigint TS type on StorageProvider.providerId without an explicit type in @Column(). TypeORM can't infer a Postgres column type for JS BigInt, so the app throws DataTypeNotSupportedError at startup and crash-loops.

Why unit tests didn't catch it

Vitest uses SWC to transpile, which does not emit emitDecoratorMetadata the same way tsc does. TypeORM never sees the BigInt design type in tests — only in the production tsc build output.

Approaches tried

  1. DataSource.initialize() in vitest — SWC doesn't emit decorator metadata, so TypeORM validation passes in tests but fails in prod.
  2. Static analysis of entity source files — regex-based scan for bigint types missing explicit @Column({ type }). Works but brittle and doesn't cover other validation TypeORM performs.
  3. Postbuild validation of compiled dist/ output (chosen) — imports tsc-compiled entities, uses TypeORM's DataSource.buildMetadatas() to run the same driver-level validation as production startup, without needing a database connection.

Test plan

  • pnpm -C apps/backend build fails on PR Upgrade to synapse 0.39.0. Closes #170 #186 with: ✗ entity-metadata: Data type "BigInt" in "StorageProvider.providerId" is not supported by "postgres" database.
  • After fixing the entity (e.g. @Column({ type: "bigint" })), build passes with: ✓ entity-metadata
  • pnpm test unaffected (275 tests pass)

Related

Copilot AI review requested due to automatic review settings March 18, 2026 16:42
@FilOzzy FilOzzy added this to FOC Mar 18, 2026
@github-project-automation github-project-automation bot moved this to 📌 Triage in FOC Mar 18, 2026
@SgtPooki SgtPooki self-assigned this Mar 18, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a backend post-build validation step that loads the tsc-compiled TypeORM entities from dist/ and runs TypeORM’s driver-level metadata validation to catch unsupported column types (e.g. BigInt inference) before deployment.

Changes:

  • Add apps/backend/scripts/postbuild-checks.mjs to import compiled entities and run DataSource.buildMetadatas() with the Postgres driver.
  • Hook the script into the backend build via a new postbuild npm lifecycle script.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
apps/backend/scripts/postbuild-checks.mjs Implements post-build checks that load dist/database/entities/*.entity.js and validate TypeORM metadata against the Postgres driver.
apps/backend/package.json Adds postbuild script to run the validation automatically after nest build.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@SgtPooki SgtPooki requested a review from silent-cipher March 18, 2026 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 📌 Triage

Development

Successfully merging this pull request may close these issues.

3 participants