@mikro-orm/knex 6.3.14-dev.0 → 6.3.14-dev.2
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 +8 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/knex",
|
|
3
|
-
"version": "6.3.14-dev.
|
|
3
|
+
"version": "6.3.14-dev.2",
|
|
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,7 +66,7 @@
|
|
|
66
66
|
"@mikro-orm/core": "^6.3.13"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@mikro-orm/core": "6.3.14-dev.
|
|
69
|
+
"@mikro-orm/core": "6.3.14-dev.2",
|
|
70
70
|
"better-sqlite3": "*",
|
|
71
71
|
"libsql": "*",
|
|
72
72
|
"mariadb": "*"
|
package/schema/DatabaseTable.js
CHANGED
|
@@ -557,9 +557,9 @@ class DatabaseTable {
|
|
|
557
557
|
const column = this.getColumn(fk.columnNames[0]);
|
|
558
558
|
const defaultRaw = this.getPropertyDefaultValue(schemaHelper, column, column.type, true);
|
|
559
559
|
const defaultTs = this.getPropertyDefaultValue(schemaHelper, column, column.type);
|
|
560
|
-
columnOptions.default = defaultRaw !== defaultTs ? defaultTs : undefined;
|
|
560
|
+
columnOptions.default = (defaultRaw !== defaultTs || defaultRaw === '') ? defaultTs : undefined;
|
|
561
561
|
columnOptions.defaultRaw = (column.nullable && defaultRaw === 'null') ? undefined : defaultRaw;
|
|
562
|
-
columnOptions.optional = typeof column.generated !== 'undefined' ||
|
|
562
|
+
columnOptions.optional = typeof column.generated !== 'undefined' || defaultRaw !== 'null';
|
|
563
563
|
columnOptions.generated = column.generated;
|
|
564
564
|
columnOptions.nullable = column.nullable;
|
|
565
565
|
columnOptions.primary = column.primary;
|
|
@@ -598,7 +598,7 @@ class DatabaseTable {
|
|
|
598
598
|
const ignoreSchemaChanges = (type === 'unknown' && column.length) ? (column.extra ? ['type', 'extra'] : ['type']) : undefined;
|
|
599
599
|
const defaultRaw = this.getPropertyDefaultValue(schemaHelper, column, runtimeType, true);
|
|
600
600
|
const defaultParsed = this.getPropertyDefaultValue(schemaHelper, column, runtimeType);
|
|
601
|
-
const defaultTs = defaultRaw !== defaultParsed ? defaultParsed : undefined;
|
|
601
|
+
const defaultTs = (defaultRaw !== defaultParsed || defaultParsed === '') ? defaultParsed : undefined;
|
|
602
602
|
const fkOptions = {};
|
|
603
603
|
if (fk) {
|
|
604
604
|
fkOptions.fieldNames = fk.columnNames;
|
|
@@ -677,19 +677,16 @@ class DatabaseTable {
|
|
|
677
677
|
return column.mappedType?.runtimeType ?? 'unknown';
|
|
678
678
|
}
|
|
679
679
|
getPropertyDefaultValue(schemaHelper, column, propType, raw = false) {
|
|
680
|
-
const
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
const val = schemaHelper.normalizeDefaultValue(column.default, column.length);
|
|
685
|
-
if (column.nullable && val === 'null') {
|
|
686
|
-
return empty;
|
|
680
|
+
const defaultValue = column.default ?? 'null';
|
|
681
|
+
const val = schemaHelper.normalizeDefaultValue(defaultValue, column.length);
|
|
682
|
+
if (val === 'null') {
|
|
683
|
+
return raw ? 'null' : (column.nullable ? null : undefined);
|
|
687
684
|
}
|
|
688
685
|
if (propType === 'boolean' && !raw) {
|
|
689
686
|
return !['0', 'false', 'f', 'n', 'no', 'off'].includes('' + column.default);
|
|
690
687
|
}
|
|
691
688
|
if (propType === 'number' && !raw) {
|
|
692
|
-
return +
|
|
689
|
+
return +defaultValue;
|
|
693
690
|
}
|
|
694
691
|
// unquote string defaults if `raw = false`
|
|
695
692
|
const match = ('' + val).match(/^'(.*)'$/);
|