@mikro-orm/core 7.0.16-dev.5 → 7.0.16-dev.7
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/metadata/MetadataDiscovery.js +2 -2
- package/package.json +1 -1
- package/platforms/Platform.d.ts +10 -2
- package/platforms/Platform.js +18 -2
- package/typings.js +3 -4
- package/utils/Utils.js +1 -1
|
@@ -1531,7 +1531,7 @@ export class MetadataDiscovery {
|
|
|
1531
1531
|
const table = this.createSchemaTable(meta);
|
|
1532
1532
|
for (const check of meta.checks) {
|
|
1533
1533
|
const fieldNames = check.property ? meta.properties[check.property].fieldNames : [];
|
|
1534
|
-
check.name ??= this.#
|
|
1534
|
+
check.name ??= this.#platform.getIndexName(meta.tableName, fieldNames, 'check');
|
|
1535
1535
|
if (check.expression instanceof Function) {
|
|
1536
1536
|
check.expression = check.expression(columns, table);
|
|
1537
1537
|
}
|
|
@@ -1556,7 +1556,7 @@ export class MetadataDiscovery {
|
|
|
1556
1556
|
}
|
|
1557
1557
|
if (expression) {
|
|
1558
1558
|
meta.checks.push({
|
|
1559
|
-
name: this.#
|
|
1559
|
+
name: this.#platform.getIndexName(meta.tableName, prop.fieldNames, 'check'),
|
|
1560
1560
|
property: prop.name,
|
|
1561
1561
|
expression,
|
|
1562
1562
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "7.0.16-dev.
|
|
3
|
+
"version": "7.0.16-dev.7",
|
|
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
|
"keywords": [
|
|
6
6
|
"data-mapper",
|
package/platforms/Platform.d.ts
CHANGED
|
@@ -271,9 +271,17 @@ export declare abstract class Platform {
|
|
|
271
271
|
/** Whether the platform supports unsigned integer columns. */
|
|
272
272
|
supportsUnsigned(): boolean;
|
|
273
273
|
/**
|
|
274
|
-
*
|
|
274
|
+
* Maximum length of identifiers (table, column, index, constraint, …) the platform supports.
|
|
275
|
+
* Names produced by {@link getIndexName} above this limit are hash-truncated. Defaults to
|
|
276
|
+
* `Infinity` (no truncation); SQL platforms override with their engine's limit
|
|
277
|
+
* (PG 63, MySQL/MariaDB 64, MSSQL/Oracle 128).
|
|
275
278
|
*/
|
|
276
|
-
|
|
279
|
+
getMaxIdentifierLength(): number;
|
|
280
|
+
/**
|
|
281
|
+
* Returns the default name of index for the given columns, hash-truncated if it would
|
|
282
|
+
* exceed {@link getMaxIdentifierLength}.
|
|
283
|
+
*/
|
|
284
|
+
getIndexName(tableName: string, columns: string[], type: 'index' | 'unique' | 'foreign' | 'primary' | 'sequence' | 'check'): string;
|
|
277
285
|
/** Returns the default primary key constraint name. */
|
|
278
286
|
getDefaultPrimaryName(tableName: string, columns: string[]): string;
|
|
279
287
|
/** Whether the platform supports custom names for primary key constraints. */
|
package/platforms/Platform.js
CHANGED
|
@@ -618,10 +618,26 @@ export class Platform {
|
|
|
618
618
|
return false;
|
|
619
619
|
}
|
|
620
620
|
/**
|
|
621
|
-
*
|
|
621
|
+
* Maximum length of identifiers (table, column, index, constraint, …) the platform supports.
|
|
622
|
+
* Names produced by {@link getIndexName} above this limit are hash-truncated. Defaults to
|
|
623
|
+
* `Infinity` (no truncation); SQL platforms override with their engine's limit
|
|
624
|
+
* (PG 63, MySQL/MariaDB 64, MSSQL/Oracle 128).
|
|
625
|
+
*/
|
|
626
|
+
getMaxIdentifierLength() {
|
|
627
|
+
return Infinity;
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Returns the default name of index for the given columns, hash-truncated if it would
|
|
631
|
+
* exceed {@link getMaxIdentifierLength}.
|
|
622
632
|
*/
|
|
623
633
|
getIndexName(tableName, columns, type) {
|
|
624
|
-
|
|
634
|
+
const indexName = this.namingStrategy.indexName(tableName, columns, type);
|
|
635
|
+
const max = this.getMaxIdentifierLength();
|
|
636
|
+
if (indexName.length > max) {
|
|
637
|
+
const suffix = type === 'primary' ? 'pkey' : type;
|
|
638
|
+
return `${indexName.substring(0, max - 8 - type.length)}_${Utils.hash(indexName, 5)}_${suffix}`;
|
|
639
|
+
}
|
|
640
|
+
return indexName;
|
|
625
641
|
}
|
|
626
642
|
/** Returns the default primary key constraint name. */
|
|
627
643
|
getDefaultPrimaryName(tableName, columns) {
|
package/typings.js
CHANGED
|
@@ -176,9 +176,10 @@ export class EntityMetadata {
|
|
|
176
176
|
// Virtual entities evaluate expressions at query time, view entities create actual database views.
|
|
177
177
|
this.virtual = !!this.expression && !this.view;
|
|
178
178
|
if (config) {
|
|
179
|
+
const platform = config.getPlatform();
|
|
179
180
|
for (const prop of this.props) {
|
|
180
181
|
if (prop.enum && !prop.nativeEnumName && prop.items?.every(item => typeof item === 'string')) {
|
|
181
|
-
const name =
|
|
182
|
+
const name = platform.getIndexName(this.tableName, prop.fieldNames, 'check');
|
|
182
183
|
const exists = this.checks.findIndex(check => check.name === name);
|
|
183
184
|
if (exists !== -1) {
|
|
184
185
|
this.checks.splice(exists, 1);
|
|
@@ -186,9 +187,7 @@ export class EntityMetadata {
|
|
|
186
187
|
this.checks.push({
|
|
187
188
|
name,
|
|
188
189
|
property: prop.name,
|
|
189
|
-
expression:
|
|
190
|
-
.getPlatform()
|
|
191
|
-
.getEnumCheckConstraintExpression(prop.fieldNames[0], prop.items),
|
|
190
|
+
expression: platform.getEnumCheckConstraintExpression(prop.fieldNames[0], prop.items),
|
|
192
191
|
});
|
|
193
192
|
}
|
|
194
193
|
}
|
package/utils/Utils.js
CHANGED
|
@@ -141,7 +141,7 @@ export function parseJsonSafe(value) {
|
|
|
141
141
|
/** Collection of general-purpose utility methods used throughout the ORM. */
|
|
142
142
|
export class Utils {
|
|
143
143
|
static PK_SEPARATOR = '~~~';
|
|
144
|
-
static #ORM_VERSION = '7.0.16-dev.
|
|
144
|
+
static #ORM_VERSION = '7.0.16-dev.7';
|
|
145
145
|
/**
|
|
146
146
|
* Checks if the argument is instance of `Object`. Returns false for arrays.
|
|
147
147
|
*/
|