Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔨 switch almost all remaining typeorm util function holdouts to knex #3359

Merged
merged 1 commit into from
Mar 26, 2024

Conversation

danyx23
Copy link
Contributor

@danyx23 danyx23 commented Mar 16, 2024

This PR cleans up almost all remaining uses of TypeORM utility funcitons. The only remaining holdouts now are the ones in the chart revision tool related functions which will be done in a later PR.

@danyx23 danyx23 marked this pull request as ready for review March 16, 2024 13:39
@danyx23 danyx23 force-pushed the eslint-no-floating-promises branch from af5f9ca to b4aa5dc Compare March 16, 2024 13:46
@danyx23 danyx23 force-pushed the db-cleanup-after-big-db-refactor branch from ed42cc5 to ffac6a7 Compare March 16, 2024 13:47
@danyx23 danyx23 force-pushed the eslint-no-floating-promises branch from b4aa5dc to 5a640e2 Compare March 16, 2024 14:00
@danyx23 danyx23 force-pushed the db-cleanup-after-big-db-refactor branch from ffac6a7 to aa50f14 Compare March 16, 2024 14:00
@danyx23 danyx23 force-pushed the eslint-no-floating-promises branch from 5a640e2 to 0366771 Compare March 16, 2024 17:18
@danyx23 danyx23 force-pushed the db-cleanup-after-big-db-refactor branch from aa50f14 to 4de4a18 Compare March 16, 2024 17:18
@danyx23 danyx23 force-pushed the eslint-no-floating-promises branch from 0366771 to 34fca5b Compare March 16, 2024 17:31
@danyx23 danyx23 force-pushed the db-cleanup-after-big-db-refactor branch from 4de4a18 to ea68c64 Compare March 16, 2024 17:31
@danyx23 danyx23 force-pushed the db-cleanup-after-big-db-refactor branch from fe40423 to e559c80 Compare March 18, 2024 15:54
@danyx23 danyx23 force-pushed the eslint-no-floating-promises branch from f078be0 to 78bb8aa Compare March 18, 2024 18:59
@danyx23 danyx23 force-pushed the db-cleanup-after-big-db-refactor branch from 94180e6 to 445e098 Compare March 18, 2024 18:59
@danyx23 danyx23 requested a review from ikesau March 18, 2024 19:00
@danyx23 danyx23 force-pushed the eslint-no-floating-promises branch from 78bb8aa to 29b9ac2 Compare March 19, 2024 16:02
@danyx23 danyx23 force-pushed the db-cleanup-after-big-db-refactor branch from 445e098 to c968925 Compare March 19, 2024 16:02
@danyx23 danyx23 force-pushed the eslint-no-floating-promises branch from 29b9ac2 to b8f843c Compare March 20, 2024 10:05
@danyx23 danyx23 force-pushed the db-cleanup-after-big-db-refactor branch from c968925 to 79b18e1 Compare March 20, 2024 10:05
@danyx23 danyx23 force-pushed the eslint-no-floating-promises branch from b8f843c to 849b260 Compare March 20, 2024 20:31
Copy link
Member

@ikesau ikesau left a comment

Choose a reason for hiding this comment

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

Nice! Really amazing effort on all of this - just a little bit more to go! 🏳️ 🏎️

@@ -0,0 +1,105 @@
import { NextFunction, Request, Response, Router } from "express"
import * as db from "../db/db.js"
export function getPlainRouteWithROTransaction<T>(
Copy link
Member

Choose a reason for hiding this comment

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

I wasn't even aware of the plain/functional router distinction!

Not for the PR of course, but do you think it's worth keeping both around?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I think we could clean that up but it doesn't seem particularly urgent

testPageRouter.get("/embeds", async (req, res) => {
const props = await db.knexReadonlyTransaction((trx) =>
propsFromQueryParams(trx, {
getPlainRouteWithROTransaction(
Copy link
Member

Choose a reason for hiding this comment

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

At http://localhost:3030/admin/test , only the explorer test embeds appear to work

Everything else gets:

TypeError: The operator "undefined" is not permitted

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah nice, thanks for catching that. Fixed on the new top stack PR #3391

@@ -431,8 +431,6 @@ export class SiteBaker {
private async removeDeletedPosts(knex: db.KnexReadonlyTransaction) {
if (!this.bakeSteps.has("removeDeletedPosts")) return

await db.getConnection()
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this change has come from here, but I also checked in the head of this PR chain and it's happening there too so I'll just write it here that:

node itsJustJavascript/baker/buildLocalBake.js --steps specialPages

with

TypeError: Cannot read properties of null (reading 'toLocaleDateString')
    at formatDate (grapher/packages/@ourworldindata/utils/dist/Util.js:960:17)
    at grapher/itsJustJavascript/db/model/Gdoc/GdocBase.js:674:49
    at Array.map (<anonymous>)
    at getMinimalGdocPostsByIds (grapher/itsJustJavascript/db/model/Gdoc/GdocBase.js:668:17)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async GdocHomepage.loadLinkedDocuments (grapher/itsJustJavascript/db/model/Gdoc/GdocBase.js:507:33)
    at async GdocHomepage.loadState (grapher/itsJustJavascript/db/model/Gdoc/GdocBase.js:626:9)
    at async loadGdocFromGdocBase (grapher/itsJustJavascript/db/model/Gdoc/GdocFactory.js:199:5)
    at async renderFrontPage (grapher/itsJustJavascript/baker/siteRenderers.js:172:30)
    at async SiteBaker.bakeSpecialPages (grapher/itsJustJavascript/baker/SiteBaker.js:353:66)

Comment on lines 21 to 28
// export const batchTagWithGpt = async ({
// debug,
// limit,
// }: BatchTagWithGptArgs = {}) => {
// await db.knexReadonlyTransaction((trx) =>
// batchTagChartsWithGpt(trx, { debug, limit })
// )
// }
Copy link
Member

Choose a reason for hiding this comment

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

Commented out?

@@ -1,18 +1,15 @@
#! /usr/bin/env jest
import sqlFixtures from "sql-fixtures"
import { dbTestConfig } from "./dbTestConfig.js"
import { dataSource } from "./dataSource.dbtests.js"
Copy link
Member

Choose a reason for hiding this comment

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

Nice! Hadn't remembered we had these - tested and confirmed working 👍

if (!variableMetadata) throw new JsonError("No such variable", 404)
getPlainRouteWithROTransaction(
adminRouter,
"/datapage-preview/:id",
Copy link
Member

Choose a reason for hiding this comment

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

I'm getting an error when trying to visit this route: http://localhost:3030/admin/datapage-preview/7216 which requires the server to be restarted

error: Error: Transaction query already complete, run with DEBUG=knex:tx for more info

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching that, fixed also in the top PR

Copy link
Contributor Author

danyx23 commented Mar 26, 2024

Merge activity

  • Mar 26, 10:04 AM EDT: @danyx23 started a stack merge that includes this pull request via Graphite.
  • Mar 26, 10:23 AM EDT: Graphite rebased this pull request as part of a merge.
  • Mar 26, 10:24 AM EDT: @danyx23 merged this pull request with Graphite.

@danyx23 danyx23 force-pushed the eslint-no-floating-promises branch from 95652fc to acbfb58 Compare March 26, 2024 14:19
Base automatically changed from eslint-no-floating-promises to master March 26, 2024 14:22
The only remaining uses of the typeorm functions are related to the chart revision tool
@danyx23 danyx23 force-pushed the db-cleanup-after-big-db-refactor branch from 299207d to 63d6d63 Compare March 26, 2024 14:23
@danyx23 danyx23 merged commit 53f4424 into master Mar 26, 2024
17 of 20 checks passed
@danyx23 danyx23 deleted the db-cleanup-after-big-db-refactor branch March 26, 2024 14:24
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.

2 participants