@mikro-orm/knex 6.1.5-dev.2 → 6.1.5-dev.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/schema/DatabaseTable.js +13 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/knex",
|
|
3
|
-
"version": "6.1.5-dev.
|
|
3
|
+
"version": "6.1.5-dev.4",
|
|
4
4
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -66,6 +66,6 @@
|
|
|
66
66
|
"@mikro-orm/core": "^6.1.4"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@mikro-orm/core": "6.1.5-dev.
|
|
69
|
+
"@mikro-orm/core": "6.1.5-dev.4"
|
|
70
70
|
}
|
|
71
71
|
}
|
package/schema/DatabaseTable.js
CHANGED
|
@@ -477,8 +477,11 @@ class DatabaseTable {
|
|
|
477
477
|
const columnOptions = {};
|
|
478
478
|
if (fk.columnNames.length === 1) {
|
|
479
479
|
const column = this.getColumn(fk.columnNames[0]);
|
|
480
|
-
|
|
481
|
-
|
|
480
|
+
const defaultRaw = this.getPropertyDefaultValue(schemaHelper, column, column.type, true);
|
|
481
|
+
const defaultTs = this.getPropertyDefaultValue(schemaHelper, column, column.type);
|
|
482
|
+
columnOptions.default = defaultRaw !== defaultTs ? defaultTs : undefined;
|
|
483
|
+
columnOptions.defaultRaw = (column.nullable && defaultRaw === 'null') ? undefined : defaultRaw;
|
|
484
|
+
columnOptions.optional = typeof column.generated !== 'undefined' || defaultTs != null;
|
|
482
485
|
columnOptions.generated = column.generated;
|
|
483
486
|
columnOptions.nullable = column.nullable;
|
|
484
487
|
columnOptions.primary = column.primary;
|
|
@@ -507,6 +510,9 @@ class DatabaseTable {
|
|
|
507
510
|
const unique = compositeFkUniques[prop] || this.indexes.find(idx => idx.columnNames[0] === column.name && !idx.composite && idx.unique && !idx.primary);
|
|
508
511
|
const kind = this.getReferenceKind(fk, unique);
|
|
509
512
|
const type = this.getPropertyTypeForColumn(namingStrategy, column, fk);
|
|
513
|
+
const defaultRaw = this.getPropertyDefaultValue(schemaHelper, column, type, true);
|
|
514
|
+
const defaultParsed = this.getPropertyDefaultValue(schemaHelper, column, type);
|
|
515
|
+
const defaultTs = defaultRaw !== defaultParsed ? defaultParsed : undefined;
|
|
510
516
|
const fkOptions = {};
|
|
511
517
|
if (fk) {
|
|
512
518
|
fkOptions.fieldNames = fk.columnNames;
|
|
@@ -520,13 +526,15 @@ class DatabaseTable {
|
|
|
520
526
|
type,
|
|
521
527
|
kind,
|
|
522
528
|
generated: column.generated,
|
|
529
|
+
optional: defaultRaw !== 'null' || defaultTs != null || typeof column.generated !== 'undefined',
|
|
523
530
|
columnType: column.type,
|
|
524
|
-
default:
|
|
525
|
-
defaultRaw:
|
|
531
|
+
default: defaultTs,
|
|
532
|
+
defaultRaw: (column.nullable && defaultRaw === 'null') ? undefined : defaultRaw,
|
|
526
533
|
nullable: column.nullable,
|
|
527
534
|
primary: column.primary && persist,
|
|
528
535
|
autoincrement: column.autoincrement,
|
|
529
536
|
fieldName: column.name,
|
|
537
|
+
unsigned: column.unsigned,
|
|
530
538
|
length: column.length,
|
|
531
539
|
precision: column.precision,
|
|
532
540
|
scale: column.scale,
|
|
@@ -590,7 +598,7 @@ class DatabaseTable {
|
|
|
590
598
|
if (propType === 'boolean' && !raw) {
|
|
591
599
|
return !['0', 'false', 'f', 'n', 'no', 'off'].includes('' + column.default);
|
|
592
600
|
}
|
|
593
|
-
if (propType === 'number') {
|
|
601
|
+
if (propType === 'number' && !raw) {
|
|
594
602
|
return +column.default;
|
|
595
603
|
}
|
|
596
604
|
// unquote string defaults if `raw = false`
|