Repository navigation
Migrate the backend to TypeORM 1.x - #70
Merged
Merged
Conversation
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.
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.
Bumps
typeormfrom^0.3.28to^1.1.1in the backend. That single line is the entire change; no source edits were needed.1.1.1 is the current
latesttag on npm. 0.3.31 is now published aslegacy.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 removedConnectionaliasdataSource.manager/getRepository, not the removed global functionsrelations, not the removed string arraysfindOneById,findByIds,exist,printSql,useContainerorRelationCountTwo driver notes already hold too. 1.x drops the
sqlite3package and requiresbetter-sqlite3(done back in af9c93b), and theDataSourcetype here is already"better-sqlite3".scripts/sync-db.tsgoes through the DataSource API rather than thetypeormCLI, 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:
invalidWhereValuesBehaviornow throws on a null/undefined value in awhereclause, where 0.3 silently skipped the property and returned every rowwhereclause infetch-provider.service.tsfilters on a numericid, so there is nothing to skipencodeURIComponent, which renames hashed FK/REL constraintsorphanedRowAction: "nullify"now deletes children of non-nullable FKs instead of raising a constraint violation, andnullable: falserelations switched toINNER JOINentities.tsdeclaresnullable, so they all stayLEFT JOINThe 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: truerebuilds 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 dumpedsqlite_masterfrom 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:
bun run typecheckbun run buildbun run testbun run test:vitestbun run smoke:sqlitebun run sync:dbdistwas also run directly, becausetscalone never loads the nativebetter-sqlite3addon, so a passing build says nothing about the data layer.Deliberately out of scope
tsconfig.build.jsonstill targetses2016, below the ES2023 floor that 1.x documents. Nothing needs it today: the build compiles,distruns against 1.1.1, and it produces the identical schema. I did test raising it toes2022, which is also clean, so it can land as its own change rather than riding along with a dependency bump.