neuron icon indicating copy to clipboard operation
neuron copied to clipboard

chore: Update typeorm to v3

Open yanguoyu opened this issue 2 years ago • 17 comments

When I want to use the find operator with the column that has the transform property. It can not work well. It has been fixed by https://github.com/typeorm/typeorm/pull/9777. So I want to update typeorm to v3. But it brings in another issue https://github.com/typeorm/typeorm/issues/9316.

Assume there exists a table table_a.

field_a field_b
'a1' 'b1'
'a2' null
  1. If we work with v2.
    const repo = connection.getRepository(TableA)
    // console []
    console.log(await repo.find({ field_b: undefined }))
   // console [ TableA { field_b: null, field_a: 'a2' } ]
    console.log(await repo.find({ field_b: null }))
    // console []
    console.log(await repo.createQueryBuilder('table_a').where({ field_b: undefined }).getMany())
    // console [ TableA { field_b: null, field_a: 'a2' } ]
    console.log(await repo.createQueryBuilder('table_a').where({ field_b: null }).getMany())
  1. If we work with v3.
    const repo = connection.getRepository(TableA)
    // console [TableA { field_b: 'b1', field_a: 'a1' }, TableA { field_b: null, field_a: 'a2' }]
    console.log(await repo.findBy({ field_b: undefined }))
    // console [TableA { field_b: 'b1', field_a: 'a1' }, TableA { field_b: null, field_a: 'a2' }]
    console.log(await repo.findBy({ field_b: null }))
    // console [TableA { field_b: null, field_a: 'a2' }], this is the recommended usage for v3, use IsNull to filter null field.
    console.log(await repo.findBy({ field_b: IsNull() }))
    // console []
    console.log(await repo.createQueryBuilder('table_a').where({ field_b: undefined }).getMany())
    // console []
    console.log(await repo.createQueryBuilder('table_a').where({ field_b: null }).getMany())

Currently, it's hard to check how many query has been affected, we can have a full test after the new UI release. Or waiting for the https://github.com/typeorm/typeorm/issues/9316 conclusion then update typeorm. What do you think? @Keith-CY @WhiteMinds @homura

yanguoyu avatar Sep 12 '23 03:09 yanguoyu

Currently, it's hard to check how many query has been affected, we can have a full test after the new UI release. Or waiting for the https://github.com/typeorm/typeorm/issues/9316 conclusion then update typeorm. What do you think?

There will likely be quite a bit of debate on this issue. I believe it is unlikely that TypeORM will revert to the old behavior unless some critical role of that old behavior is highlighted in the discussion.

BTW, I personally also prefer using approaches like isNULL, DATATYPE.NULL / DATATYPE.INTEGER etc to distinguish database types from JS native types, avoiding conflating their intent.

So I suggest we migrate to the new behavior, but do try to handle places that may be impacted, like hash: string | null | undefined, as much as possible at static code authoring time.

We could consider some actions to reduce the psychological burden of migrating from old to new behavior, such as temporarily (or permanently) removing null | undefined from the accepted value types in findOpts, using TS to provide cues, and enforcing no implicit any and checking explicit any to ensure proper type checking.

We could also consider patching TypeORM to report (just code locations) to something like Sentry when it receives null | undefined in findOpts, to quickly respond to unexpected errors.

WhiteMinds avatar Sep 18 '23 09:09 WhiteMinds

It's ready for review now. Please have a review. @Keith-CY @homura @devchenyan @WhiteMinds

yanguoyu avatar Jan 24 '24 01:01 yanguoyu

Conflicted

Keith-CY avatar Mar 21 '24 03:03 Keith-CY

@silySuper now focuses on other issues, I'd suggest merging this one first and verify it in a regression test.

Keith-CY avatar Mar 28 '24 03:03 Keith-CY

/package Packaging for test is done in 8462022029. @silySuper

silySuper avatar Mar 28 '24 03:03 silySuper

https://github.com/yanguoyu/neuron/blob/d9a1d9b8e2ed22e6bcd173a1ab0a2c3aa40fdce0/packages/neuron-wallet/src/services/cell-local-info.ts#L31

image

@yanguoyu Regression testing found problems, not fully replaced.

devchenyan avatar Mar 29 '24 03:03 devchenyan

1.When the remaining amount is 0,amend page shows 0 total amount,in expect it should be equal to amount in left.

截屏2024-03-29 10 24 06

2.In customized assets page ,when claim a histoty asset,it shows error(The same error shows when create asset account) 截屏2024-03-29 10 49 12

silySuper avatar Mar 29 '24 03:03 silySuper

https://github.com/yanguoyu/neuron/blob/d9a1d9b8e2ed22e6bcd173a1ab0a2c3aa40fdce0/packages/neuron-wallet/src/services/cell-local-info.ts#L31

image

@yanguoyu Regression testing found problems, not fully replaced.

I guess findOne also works well.

yanguoyu avatar Mar 29 '24 03:03 yanguoyu

1.When the remaining amount is 0,amend page shows 0 total amount,in expect it should be equal to amount in left.

截屏2024-03-29 10 24 06 2.In customized assets page ,when claim a histoty asset,it shows error(The same error shows when create asset account) 截屏2024-03-29 10 49 12

There may be some problems with your SQLite file. Could you rebuild the SQLite file with the release version and then test with this PR? Could you upload your SQLite file then I will check whether typeorm cannot connect your SQLite file.

yanguoyu avatar Mar 29 '24 03:03 yanguoyu

1.When the remaining amount is 0,amend page shows 0 total amount,in expect it should be equal to amount in left. 截屏2024-03-29 10 24 06 2.In customized assets page ,when claim a histoty asset,it shows error(The same error shows when create asset account) 截屏2024-03-29 10 49 12

There may be some problems with your SQLite file. Could you rebuild the SQLite file with the release version and then test with this PR? Could you upload your SQLite file then I will check whether typeorm cannot connect your SQLite file.

Another package I download yesterday can claim successfully.I do not change any file relate to sqlite manually.

截屏2024-03-29 14 51 21

https://github.com/nervosnetwork/neuron/assets/25971273/725146dc-4ad9-4ed1-9b77-f1a7adbe8830

This is my sqlite : cells.zip

silySuper avatar Mar 29 '24 06:03 silySuper

Another package I download yesterday can claim successfully.I do not change any file relate to sqlite manually.

I'm not sure whether your local SQLite file is migrated by Neuron, Could you upload the main.log?

yanguoyu avatar Mar 29 '24 07:03 yanguoyu

main.log

silySuper avatar Mar 29 '24 07:03 silySuper

main.log

Besides, you can back up the SQLite files and then delete these files to test run by creating a new local file.

yanguoyu avatar Mar 29 '24 07:03 yanguoyu

main.log

Besides, you can back up the SQLite files and then delete these files to test run by creating a new local file.

Ok,this operation will sync from 0%,I am waiting it to sync 100%

silySuper avatar Mar 29 '24 09:03 silySuper

This PR https://github.com/typeorm/typeorm/pull/9751/files#diff-4cfd478e52f9edd89cf748e00253bfb16a436f300c5c93404739a51433edca1aR39-R47 change the query slow log to warn, so I copy the Logger from typeorm and change console.warn to console.info

yanguoyu avatar Mar 29 '24 09:03 yanguoyu

After open the neuron and turn off the computer at the same time for a long time,the log shows [error] Sync:ChildProcess: query is slow: SELECT "tx"."hash" AS "tx_hash", "tx"."version" AS "tx_version", "tx"."cellDeps" AS "tx_cellDeps", "tx"."headerDeps" AS "tx_headerDeps", "tx"."witnesses" AS "tx_witnesses", "tx"."timestamp" AS "tx_timestamp", "tx"."blockNumber" AS "tx_blockNumber", "tx"."blockHash" AS "tx_blockHash", "tx"."description" AS "tx_description", "tx"."status" AS "tx_status", "tx"."createdAt" AS "tx_createdAt", "tx"."updatedAt" AS "tx_updatedAt", "tx"."confirmed" AS "tx_confirmed" FROM "transaction" "tx" WHERE "tx"."status" = ? -- PARAMETERS: ["pending"] execution time: 48

silySuper avatar Apr 01 '24 02:04 silySuper

Any update on this PR

Keith-CY avatar Apr 29 '24 06:04 Keith-CY

/package Packaging for test is done in 9030541323. @Keith-CY

Keith-CY avatar May 10 '24 09:05 Keith-CY

/package Packaging for test is done in 9030541323. @Keith-CY

Verified, could be merged first and tested again by @silySuper in regression tests.

Keith-CY avatar May 14 '24 08:05 Keith-CY