Conversation
| const defaultValue = columnMetadata.default; | ||
|
|
||
| if (defaultValue === null) { | ||
| return undefined |
There was a problem hiding this comment.
Should we maybe be differentiating here between null and undefined? When the user sets the column default explicitly to null perhaps they would want the column generated to also explicitly specify DEFAULT NULL, even if that is probably unnecessary.
It is also already dealt with in places like this anyway:
typeorm/src/driver/mysql/MysqlQueryRunner.ts
Lines 1877 to 1878 in 2fa6231
There was a problem hiding this comment.
@nebkat thank you for review!
I've checked MySQL and Postgres databases and they are storing both null and undefined defaults like (NULL) value, therefore there is no difference on database level between null and undefined.
So, we can't differentiate these values during synchronization process that leads to unnecessary update queries.
There was a problem hiding this comment.
This problem was also brought up somewhat in #7229 (comment) but now we have TypeScript 4.2 with support for the ?? operator. Maybe we could start using ?? null when comparing all the fields to avoid these situations?
Now that I think about it more it might actually make sense to have such a mapping in normalizeDefault but I think it should be if (defaultValue === undefined) return null rather than vice-versa. It's a small change but I think it might save some headaches in a few months when someone else is looking at it: it makes more sense that we are saying "if the column default wasn't defined, we default to null" rather than "if the column was explicitly set to null we change it back to not being defined (and then assume that elsewhere the code will treat undefined as null)".
updated `postgres-enum` test;
updated `postgres-enum` test;
| // replace double escaped backslash to single escaped e.g. \\\\ -> \\ | ||
| val = val.replace(/(\\\\)/g, "\\") | ||
| // replace escaped double quotes to non-escaped e.g. \"asd\" -> "asd" | ||
| return val.replace(/(\\")/g, '"') |
There was a problem hiding this comment.
I am not so good in regex and here can be more elegant solution
| // replace double quotes from the beginning and from the end | ||
| val = val.replace(/(^")|("$)/g, "") | ||
| // replace double escaped backslash to single escaped e.g. \\\\ -> \\ | ||
| val = val.replace(/(\\\\)/g, "\\") | ||
| // replace escaped double quotes to non-escaped e.g. \"asd\" -> "asd" | ||
| return val.replace(/(\\")/g, '"') |
There was a problem hiding this comment.
Could be faster? Probably slightly easier to read. Safer for the start/end quotes because it won't fix a broken "string with missing start/end quote.
| // replace double quotes from the beginning and from the end | |
| val = val.replace(/(^")|("$)/g, "") | |
| // replace double escaped backslash to single escaped e.g. \\\\ -> \\ | |
| val = val.replace(/(\\\\)/g, "\\") | |
| // replace escaped double quotes to non-escaped e.g. \"asd\" -> "asd" | |
| return val.replace(/(\\")/g, '"') | |
| // replace double quotes from the beginning and from the end | |
| if (val.startsWith(`"`) && val.endsWith(`"`)) val = val.slice(1, -1); | |
| // replace double escaped backslash to single escaped e.g. \\ -> \ | |
| val = val.replaceAll("\\\\", "\\"); | |
| // replace escaped double quotes to non-escaped e.g. \"asd\" -> "asd" | |
| return val.replaceAll(`\\"`, `"`); |
|
@AlexMesser When this changes will be available? Thanks a lot, I was waiting this fixes for quite some time. 🤯🥳🥳🥳 |
* docs: fix small typo on package.json script example (typeorm#7408) Add missing colon in JSON property at `package.json` `"script"` example * feat: output Javascript Migrations instead of TypeScript (typeorm#7294) * docs / test: Added tests and documentation for Feature 7253 - Migrations Javascript output * Change in the test * test: Re-arranged the tests to move them to the core tests directory * tests: Adjusted Tests a bit * tests - renamed tests to follow the other functional tests naming * tests - renamed tests to follow the other functional tests naming * tests - Fixed issues with the test connections setup * tests - Removed unnecesary restore * fix: improve EntityManager.save() return type (typeorm#7391) This brings it in line with the equivalent method in Repository. * fix: resolve issue building tree entities with embeded primary column (typeorm#7416) Closes: typeorm#7415 * Adjust mongodb driver options & connect driver to support replica set (typeorm#7402) - Dupplicate buildDriverOptions for mongodb especially - Add hostReplicaSet to MongoConnectionOptions properties for collect host replica list - Adjust buildConnectionUrl to build replica set connection url * fix: performance issues of `RelationId`. (typeorm#7318) * test: relationId is too slow * perf: RelationId is too slow When we join a lot of relations we can get 1k+ records from db even it is only 10 entities. Then when relationId are loaded the query contains too many duplciates for the same ids. The solution is to check that the relationId query fetches only unique values. Closes: typeorm#5691 * fix: Array type default value should not generate SQL commands without change (typeorm#7409) * fix(1532) Array type default value should not generate SQL commands without change * Update PostgresDriver.ts * removed `arrayCast` from `normalizeDefault` since casting for default value is already removed in `PostgresQueryRunner.loadTables()` method; * removed support for function definition in `default` because function syntax suppose to support raw sql, we don't have to confuse things by applying custom modifications. * Update User.ts removed incorrect `default` definition with functions Co-authored-by: AlexMesser <[email protected]> * feat: add check and dryrun to migration generate (typeorm#7275) Adds support for “check” and “drynrun” modes to the migration generate command. Fixes typeorm#3037 Refs typeorm#6978 * chore: typescript version upgrade (typeorm#7422) * chore: dependencies update (typeorm#7424) * typescript version upgrade * fixing linting * fixing mongo query runner issues * fixing linting * updated all dependencies * fixes typeorm#7418 * fixes typeorm#7418 * adding missing ILike operator docs (took from next branch) * fix: mongodb connectionurl parse options (#1) * fix: mongodb connectionurl parse options - Loop every options in mongodb connection url and turn it as object to merge with connection url object before return of method "parseMongoDBConnectionUrl" - unit test of mongodb replicaset parse connectionurl of typeorm#7401 - unit test of mongodb options parse connectionurl of typeorm#7437 * fix: add semicolon by lint suggestion /home/circleci/typeorm/src/driver/DriverUtils.ts 192:39 error Missing semicolon @typescript-eslint/semi * chore: @beamdev package scope (#2) * chore: update master (typeorm#3) * fix: fixed all known enum issues (typeorm#7419) * fix typeorm#5371 * fix typeorm#6471; fix: `enumName` changes not handled; fix: `enumName` does not handle table schema; * fixed falling test; * added test for typeorm#7217 * fix typeorm#6047, typeorm#7283; * fix typeorm#5871 * added support for `enumName` in `joinColumns` (typeorm#5729) * fix typeorm#5478 * fixed falling test; updated `postgres-enum` test; * added column `array` property change detection (typeorm#5882); updated `postgres-enum` test; * fix typeorm#5275 * added validation for `enum` property (typeorm#2233) * fix typeorm#5648 * improved missing "enum" or "enumName" properties validation; * fix typeorm#4897, typeorm#6376 * lint fix; * fixed falling tests; * fixed falling tests; * removed .only * fix typeorm#6115 * refactor: improve README.md and DEVLOPER.md code examples formatting (typeorm#7436) * fix: correctly get referenceColumn value in `getEntityValueMap` (typeorm#7005) * test: add test case (typeorm#7002) * fix: correctly get referenceColumn value in `getEntityValueMap` * test: reproduction for issue typeorm#3246 (typeorm#3247) * Add reproduction for issue 3246 * Update test/github-issues/3246/issue-3246.ts Co-authored-by: Json Choi <[email protected]> Co-authored-by: Dan Imbrogno <[email protected]> Co-authored-by: AlexMesser <[email protected]> Co-authored-by: Json Choi <[email protected]> * code refactoring in test; * added test for typeorm#2758 * feat: allow to pass the given table name as string in RelationDecorators (typeorm#7448) * feat(RelationDecorators): allow to pass the given table name as string * Update EntityMetadataBuilder.ts added parentheses; Co-authored-by: Emily Marigold Klassen <[email protected]> * feat: add option for installing package using CLI (typeorm#6889) * init cli: add options for installing package * yarg choice, add await, revert formatter changes * init flag - set default to npm Co-authored-by: AlexMesser <[email protected]> Co-authored-by: Henry Boisdequin <[email protected]> Co-authored-by: Json Choi <[email protected]> Co-authored-by: Dan Imbrogno <[email protected]> Co-authored-by: Dan Imbrogno <[email protected]> Co-authored-by: Emily Marigold Klassen <[email protected]> Co-authored-by: Emily Marigold Klassen <[email protected]> Co-authored-by: Gaurav Sharma <[email protected]> * chore: update master typeorm/typeorm (typeorm#5) * fix: fixed all known enum issues (typeorm#7419) * fix typeorm#5371 * fix typeorm#6471; fix: `enumName` changes not handled; fix: `enumName` does not handle table schema; * fixed falling test; * added test for typeorm#7217 * fix typeorm#6047, typeorm#7283; * fix typeorm#5871 * added support for `enumName` in `joinColumns` (typeorm#5729) * fix typeorm#5478 * fixed falling test; updated `postgres-enum` test; * added column `array` property change detection (typeorm#5882); updated `postgres-enum` test; * fix typeorm#5275 * added validation for `enum` property (typeorm#2233) * fix typeorm#5648 * improved missing "enum" or "enumName" properties validation; * fix typeorm#4897, typeorm#6376 * lint fix; * fixed falling tests; * fixed falling tests; * removed .only * fix typeorm#6115 * refactor: improve README.md and DEVLOPER.md code examples formatting (typeorm#7436) * fix: correctly get referenceColumn value in `getEntityValueMap` (typeorm#7005) * test: add test case (typeorm#7002) * fix: correctly get referenceColumn value in `getEntityValueMap` * test: reproduction for issue typeorm#3246 (typeorm#3247) * Add reproduction for issue 3246 * Update test/github-issues/3246/issue-3246.ts Co-authored-by: Json Choi <[email protected]> Co-authored-by: Dan Imbrogno <[email protected]> Co-authored-by: AlexMesser <[email protected]> Co-authored-by: Json Choi <[email protected]> * code refactoring in test; * added test for typeorm#2758 * feat: allow to pass the given table name as string in RelationDecorators (typeorm#7448) * feat(RelationDecorators): allow to pass the given table name as string * Update EntityMetadataBuilder.ts added parentheses; Co-authored-by: Emily Marigold Klassen <[email protected]> * feat: add option for installing package using CLI (typeorm#6889) * init cli: add options for installing package * yarg choice, add await, revert formatter changes * init flag - set default to npm Co-authored-by: AlexMesser <[email protected]> Co-authored-by: Henry Boisdequin <[email protected]> Co-authored-by: Json Choi <[email protected]> Co-authored-by: Dan Imbrogno <[email protected]> Co-authored-by: Dan Imbrogno <[email protected]> Co-authored-by: Emily Marigold Klassen <[email protected]> Co-authored-by: Emily Marigold Klassen <[email protected]> Co-authored-by: Gaurav Sharma <[email protected]> Co-authored-by: rccursach <[email protected]> Co-authored-by: Jorge Luis Vargas <[email protected]> Co-authored-by: Anthony Rosequist <[email protected]> Co-authored-by: Tomas Zaluckij <[email protected]> Co-authored-by: MG <[email protected]> Co-authored-by: Ed Mitchell <[email protected]> Co-authored-by: AlexMesser <[email protected]> Co-authored-by: Christian Holm <[email protected]> Co-authored-by: Umed Khudoiberdiev <[email protected]> Co-authored-by: Henry Boisdequin <[email protected]> Co-authored-by: Json Choi <[email protected]> Co-authored-by: Dan Imbrogno <[email protected]> Co-authored-by: Dan Imbrogno <[email protected]> Co-authored-by: Emily Marigold Klassen <[email protected]> Co-authored-by: Emily Marigold Klassen <[email protected]> Co-authored-by: Gaurav Sharma <[email protected]>
|
@carlocorradini these changes are now available in version |
|
@AlexMesser I still see the issue when using |
|
@duvanmonsa #7661 hurrying to the rescue |
|
Hello folks! |
|
Can confirm still an issue in 0.3.28 |
Description of change
enum issues:
Fixes #2233
Fixes #4833
Fixes #4350
Fixes #4897
Fixes #5000
Fixes #5275
Fixes #5371
Fixes #5478
Fixes #5648
Fixes #5729
Fixes #5871
Fixes #6047
Fixes #6115
Fixes #6376
Fixes #6471
Fixes #6772
Fixes #7217
Fixes #7283
related issues:
Fixes #5882
covered pull-requests:
Closes #4005
Closes #5276
Closes #5479
Closes #6126
Closes #7221
Pull-Request Checklist
masterbranchnpm run lintpasses with this changenpm run testpasses with this changeFixes #0000