@mikro-orm/sql 7.2.13-dev.12 → 7.2.13-dev.13
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/sql",
|
|
3
|
-
"version": "7.2.13-dev.
|
|
3
|
+
"version": "7.2.13-dev.13",
|
|
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",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@mikro-orm/core": "^7.2.12"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.2.13-dev.
|
|
56
|
+
"@mikro-orm/core": "7.2.13-dev.13"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|
package/schema/DatabaseTable.js
CHANGED
|
@@ -33,8 +33,11 @@ export class DatabaseTable {
|
|
|
33
33
|
this.#platform = platform;
|
|
34
34
|
}
|
|
35
35
|
getQuotedName() {
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
// a dot in the name can be a `database.schema.table` qualifier, it is kept inside the identifier in the default schema only
|
|
37
|
+
if (this.schema && this.schema !== this.#platform.getDefaultSchemaName()) {
|
|
38
|
+
return this.#platform.quoteIdentifier(this.getShortestName()).replaceAll('\\?', '?');
|
|
39
|
+
}
|
|
40
|
+
return this.#platform.quoteQualifiedName(this.name);
|
|
38
41
|
}
|
|
39
42
|
getColumns() {
|
|
40
43
|
return Object.values(this.#columns);
|
package/schema/SchemaHelper.d.ts
CHANGED
|
@@ -189,6 +189,8 @@ export declare abstract class SchemaHelper {
|
|
|
189
189
|
/** Returns SQL to create a foreign key constraint on a table. */
|
|
190
190
|
createForeignKey(table: DatabaseTable, foreignKey: ForeignKey, alterTable?: boolean, inline?: boolean): string;
|
|
191
191
|
splitTableName(name: string, skipDefaultSchema?: boolean): [string | undefined, string];
|
|
192
|
+
/** Splits a developer-supplied name on the last dot, the qualifier can have more parts (`database.schema`). */
|
|
193
|
+
splitQualifiedName(name: string): [string | undefined, string];
|
|
192
194
|
getReferencedTableName(referencedTableName: string, schema?: string): string;
|
|
193
195
|
createIndex(index: IndexDef, table: DatabaseTable, createPrimary?: boolean): string;
|
|
194
196
|
createCheck(table: DatabaseTable, check: CheckDef): string;
|
|
@@ -224,7 +226,7 @@ export declare abstract class SchemaHelper {
|
|
|
224
226
|
get options(): NonNullable<Options['schemaGenerator']>;
|
|
225
227
|
protected processComment(comment: string): string;
|
|
226
228
|
protected quote(...keys: (string | undefined)[]): string;
|
|
227
|
-
/**
|
|
229
|
+
/** A dot in the name stays inside the identifier in the default schema only, elsewhere it can be a `database.schema.table` qualifier. */
|
|
228
230
|
protected quoteTableName(name: string, schema?: string): string;
|
|
229
231
|
dropForeignKey(tableName: string, constraintName: string): string;
|
|
230
232
|
dropIndex(table: string, index: IndexDef, oldIndexName?: string): string;
|
package/schema/SchemaHelper.js
CHANGED
|
@@ -885,6 +885,11 @@ export class SchemaHelper {
|
|
|
885
885
|
}
|
|
886
886
|
return [schemaName, tableName];
|
|
887
887
|
}
|
|
888
|
+
/** Splits a developer-supplied name on the last dot, the qualifier can have more parts (`database.schema`). */
|
|
889
|
+
splitQualifiedName(name) {
|
|
890
|
+
const index = name.lastIndexOf('.');
|
|
891
|
+
return index === -1 ? [undefined, name] : [name.substring(0, index), name.substring(index + 1)];
|
|
892
|
+
}
|
|
888
893
|
getReferencedTableName(referencedTableName, schema) {
|
|
889
894
|
const [schemaName, tableName] = this.splitTableName(referencedTableName);
|
|
890
895
|
schema = schemaName ?? schema ?? this.platform.getConfig().get('schema');
|
|
@@ -1025,9 +1030,12 @@ export class SchemaHelper {
|
|
|
1025
1030
|
// DDL is not a query template, so question marks need no escaping there
|
|
1026
1031
|
return this.platform.quoteIdentifier(keys.filter(Boolean).join('.')).replaceAll('\\?', '?');
|
|
1027
1032
|
}
|
|
1028
|
-
/**
|
|
1033
|
+
/** A dot in the name stays inside the identifier in the default schema only, elsewhere it can be a `database.schema.table` qualifier. */
|
|
1029
1034
|
quoteTableName(name, schema) {
|
|
1030
|
-
|
|
1035
|
+
if (schema && schema !== this.platform.getDefaultSchemaName()) {
|
|
1036
|
+
return this.quote(schema, name);
|
|
1037
|
+
}
|
|
1038
|
+
return this.platform.quoteQualifiedName(name);
|
|
1031
1039
|
}
|
|
1032
1040
|
dropForeignKey(tableName, constraintName) {
|
|
1033
1041
|
return `alter table ${this.quote(tableName)} drop foreign key ${this.quote(constraintName)}`;
|
|
@@ -201,7 +201,7 @@ export class SqlSchemaGenerator extends AbstractSchemaGenerator {
|
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
203
|
if (options.dropMigrationsTable) {
|
|
204
|
-
const [schema, name] = this.helper.
|
|
204
|
+
const [schema, name] = this.helper.splitQualifiedName(this.config.get('migrations').tableName);
|
|
205
205
|
this.append(ret, this.helper.dropTableIfExists(name, schema ?? this.config.get('schema')));
|
|
206
206
|
}
|
|
207
207
|
return this.wrapSchema(ret, options);
|
|
@@ -521,7 +521,7 @@ export class SqlSchemaGenerator extends AbstractSchemaGenerator {
|
|
|
521
521
|
return false;
|
|
522
522
|
}
|
|
523
523
|
async dropTableIfExists(name, schema) {
|
|
524
|
-
const [schemaName, tableName] = schema ?
|
|
524
|
+
const [schemaName, tableName] = this.helper.splitQualifiedName(schema ? `${schema}.${name}` : name);
|
|
525
525
|
const sql = this.helper.dropTableIfExists(tableName, schemaName);
|
|
526
526
|
return this.execute(sql);
|
|
527
527
|
}
|