Skip to content

Migrate the backend to TypeORM 1.x - #70

Merged
raphvallee merged 1 commit into
mainfrom
migrate/typeorm-1x
Oct 2, 2026
Merged

raphvallee merged 1 commit into
mainfrom
migrate/typeorm-1x

Conversation

@raphvallee

Copy link
Copy Markdown
Owner

Bumps typeorm from ^0.3.28 to ^1.1.1 in the backend. That single line is the entire change; no source edits were needed.

1.1.1 is the current latest tag on npm. 0.3.31 is now published as legacy.

Why no code changed

TypeORM 1.0 removes a large set of APIs that were deprecated across the 0.3 cycle. I audited every removal and change in the official upgrading guide against all nine modules that touch TypeORM. The codebase already uses the forms 1.x keeps, so the codemod had nothing to do:

  • DataSource, not the removed Connection alias
  • dataSource.manager / getRepository, not the removed global functions
  • object syntax for relations, not the removed string arrays
  • no findOneById, findByIds, exist, printSql, useContainer or RelationCount

Two driver notes already hold too. 1.x drops the sqlite3 package and requires better-sqlite3 (done back in af9c93b), and the DataSource type here is already "better-sqlite3". scripts/sync-db.ts goes through the DataSource API rather than the typeorm CLI, so the CLI changes never reach it.

Behavioural changes, and why none of them bite

Three changes had real potential to break this app at runtime. All three are inert here:

Change Why it does not apply
invalidWhereValuesBehavior now throws on a null/undefined value in a where clause, where 0.3 silently skipped the property and returned every row Every where clause in fetch-provider.service.ts filters on a numeric id, so there is nothing to skip
SHA1 hashing no longer pre-encodes with encodeURIComponent, which renames hashed FK/REL constraints Confirmed inert by the schema diff below; every hashed input is plain ASCII
orphanedRowAction: "nullify" now deletes children of non-nullable FKs instead of raising a constraint violation, and nullable: false relations switched to INNER JOIN No relation in entities.ts declares nullable, so they all stay LEFT JOIN

The first one is the one to keep an eye on if this app ever grows user-supplied filters, since the old behaviour was a silent full-table read rather than an error.

The schema is provably unchanged

synchronize: true rebuilds the schema from entity metadata on every dev boot, so there is no migration to write and no data to back up. To prove that rather than assume it, I dumped sqlite_master from a database built by 0.3.28 and by 1.1.1 and diffed them.

They are identical, down to the hashed constraint names (FK_4eae649d1312f6fdfae101172d3, REL_33d6020087f027d8dfa14d869f), which is what rules out the hashing change.

Verification

Baseline taken on 0.3.28 before the bump, then the same gates re-run on 1.1.1:

Gate 0.3.28 1.1.1
bun run typecheck pass pass
bun run build pass pass
bun run test 106 pass, 1 skip, 0 fail 106 pass, 1 skip, 0 fail
bun run test:vitest 106 pass, 1 skip 106 pass, 1 skip
coverage (bun + vitest) 100% funcs/lines 100% funcs/lines
bun run smoke:sqlite 8/8 ok 8/8 ok
bun run sync:db 5 tables 5 tables

dist was also run directly, because tsc alone never loads the native better-sqlite3 addon, so a passing build says nothing about the data layer.

Deliberately out of scope

tsconfig.build.json still targets es2016, below the ES2023 floor that 1.x documents. Nothing needs it today: the build compiles, dist runs against 1.1.1, and it produces the identical schema. I did test raising it to es2022, which is also clean, so it can land as its own change rather than riding along with a dependency bump.

TypeORM 1.0 removes a large set of APIs that were deprecated across the 0.3
cycle. 1.1.1 is the current `latest` tag; 0.3.31 is now published as `legacy`.

The version bump is the whole change. The nine modules that touch TypeORM
already use the forms 1.x keeps, so nothing needed rewriting:

- DataSource, not the removed Connection alias
- dataSource.manager / getRepository, not the removed global functions
- object syntax for relations, not the removed string arrays
- no findOneById, findByIds, exist, printSql, useContainer or RelationCount

Two driver notes already hold too: 1.x drops the sqlite3 package and requires
better-sqlite3 (done in af9c93b), and the DataSource type here is already
"better-sqlite3". sync-db.ts goes through the DataSource API rather than the
typeorm CLI, so the CLI changes do not reach it either.

Three behavioural changes could have bitten, and none of them do here:

- invalidWhereValuesBehavior now throws on a null or undefined value in a
  where clause, where 0.3 silently skipped the property and returned every row.
  Every where clause in fetch-provider.service.ts filters on a numeric id, so
  there is nothing to skip.
- SHA1 hashing no longer pre-encodes with encodeURIComponent, which renames
  hashed FK and REL constraints. Confirmed inert below.
- orphanedRowAction "nullify" now deletes children of non-nullable FKs instead
  of raising a constraint violation, and nullable: false relations switched to
  INNER JOIN. No relation in entities.ts declares nullable, so they all stay
  LEFT JOIN.

The schema is worth proving, because synchronize: true rebuilds from entity
metadata on every boot. I dumped sqlite_master from a database built by 0.3.28
and by 1.1.1 and diffed them: identical, down to the hashed constraint names
(FK_4eae649d1312f6fdfae101172d3, REL_33d6020087f027d8dfa14d869f). Every
hashed input is plain ASCII, which is why the hashing change lands on the same
names.

Verified on 1.1.1 against the same gates, taken on 0.3.28 before the bump:
typecheck, build, bun test (106 pass, 1 skip), vitest (106 pass, 1 skip), both
coverage gates still at 100%, smoke:sqlite 8/8, and sync:db rebuilding all 5
tables. dist was also run directly, because tsc alone never loads the native
addon.

One thing deliberately left alone: tsconfig.build.json still targets es2016,
below the ES2023 floor that 1.x documents. Nothing needs it today, the build
compiles and dist runs against 1.1.1 producing the identical schema. Raising it
to es2022 was tested and is equally clean, so it can land as its own change
instead of riding along with the dependency bump.
@raphvallee
raphvallee merged commit d73c3c1 into main Oct 2, 2026
2 checks passed
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