@mikro-orm/knex 6.3.8-dev.8 → 6.3.8
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.
|
@@ -12,7 +12,7 @@ export declare class MySqlSchemaHelper extends SchemaHelper {
|
|
|
12
12
|
'current_timestamp(?)': string[];
|
|
13
13
|
'0': string[];
|
|
14
14
|
};
|
|
15
|
-
getSchemaBeginning(charset: string): string;
|
|
15
|
+
getSchemaBeginning(charset: string, disableForeignKeys?: boolean): string;
|
|
16
16
|
disableForeignKeysSQL(): string;
|
|
17
17
|
enableForeignKeysSQL(): string;
|
|
18
18
|
finalizeTable(table: Knex.CreateTableBuilder, charset: string, collate?: string): void;
|
|
@@ -10,8 +10,11 @@ class MySqlSchemaHelper extends SchemaHelper_1.SchemaHelper {
|
|
|
10
10
|
'current_timestamp(?)': ['current_timestamp(?)'],
|
|
11
11
|
'0': ['0', 'false'],
|
|
12
12
|
};
|
|
13
|
-
getSchemaBeginning(charset) {
|
|
14
|
-
|
|
13
|
+
getSchemaBeginning(charset, disableForeignKeys) {
|
|
14
|
+
if (disableForeignKeys) {
|
|
15
|
+
return `set names ${charset};\n${this.disableForeignKeysSQL()}\n\n`;
|
|
16
|
+
}
|
|
17
|
+
return `set names ${charset};\n\n`;
|
|
15
18
|
}
|
|
16
19
|
disableForeignKeysSQL() {
|
|
17
20
|
return 'set foreign_key_checks = 0;';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/knex",
|
|
3
|
-
"version": "6.3.8
|
|
3
|
+
"version": "6.3.8",
|
|
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",
|
|
@@ -63,10 +63,10 @@
|
|
|
63
63
|
"sqlstring": "2.3.3"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@mikro-orm/core": "^6.3.
|
|
66
|
+
"@mikro-orm/core": "^6.3.8"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@mikro-orm/core": "6.
|
|
69
|
+
"@mikro-orm/core": "^6.0.0",
|
|
70
70
|
"better-sqlite3": "*",
|
|
71
71
|
"libsql": "*",
|
|
72
72
|
"mariadb": "*"
|
package/schema/SchemaHelper.d.ts
CHANGED
|
@@ -8,10 +8,10 @@ import type { DatabaseTable } from './DatabaseTable';
|
|
|
8
8
|
export declare abstract class SchemaHelper {
|
|
9
9
|
protected readonly platform: AbstractSqlPlatform;
|
|
10
10
|
constructor(platform: AbstractSqlPlatform);
|
|
11
|
-
getSchemaBeginning(charset: string): string;
|
|
11
|
+
getSchemaBeginning(charset: string, disableForeignKeys?: boolean): string;
|
|
12
12
|
disableForeignKeysSQL(): string;
|
|
13
13
|
enableForeignKeysSQL(): string;
|
|
14
|
-
getSchemaEnd(): string;
|
|
14
|
+
getSchemaEnd(disableForeignKeys?: boolean): string;
|
|
15
15
|
finalizeTable(table: Knex.TableBuilder, charset: string, collate?: string): void;
|
|
16
16
|
supportsSchemaConstraints(): boolean;
|
|
17
17
|
getPrimaryKeys(connection: AbstractSqlConnection, indexes: IndexDef[] | undefined, tableName: string, schemaName?: string): Promise<string[]>;
|
package/schema/SchemaHelper.js
CHANGED
|
@@ -7,8 +7,11 @@ class SchemaHelper {
|
|
|
7
7
|
constructor(platform) {
|
|
8
8
|
this.platform = platform;
|
|
9
9
|
}
|
|
10
|
-
getSchemaBeginning(charset) {
|
|
11
|
-
|
|
10
|
+
getSchemaBeginning(charset, disableForeignKeys) {
|
|
11
|
+
if (disableForeignKeys) {
|
|
12
|
+
return `${this.disableForeignKeysSQL()}\n`;
|
|
13
|
+
}
|
|
14
|
+
return '';
|
|
12
15
|
}
|
|
13
16
|
disableForeignKeysSQL() {
|
|
14
17
|
return '';
|
|
@@ -16,8 +19,11 @@ class SchemaHelper {
|
|
|
16
19
|
enableForeignKeysSQL() {
|
|
17
20
|
return '';
|
|
18
21
|
}
|
|
19
|
-
getSchemaEnd() {
|
|
20
|
-
|
|
22
|
+
getSchemaEnd(disableForeignKeys) {
|
|
23
|
+
if (disableForeignKeys) {
|
|
24
|
+
return `${this.enableForeignKeysSQL()}\n`;
|
|
25
|
+
}
|
|
26
|
+
return '';
|
|
21
27
|
}
|
|
22
28
|
finalizeTable(table, charset, collate) {
|
|
23
29
|
//
|
|
@@ -51,7 +51,6 @@ class SqlSchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
51
51
|
return DatabaseSchema_1.DatabaseSchema.fromMetadata(metadata, this.platform, this.config, schemaName);
|
|
52
52
|
}
|
|
53
53
|
async getCreateSchemaSQL(options = {}) {
|
|
54
|
-
const wrap = options.wrap ?? this.options.disableForeignKeys;
|
|
55
54
|
const toSchema = this.getTargetSchema(options.schema);
|
|
56
55
|
let ret = '';
|
|
57
56
|
for (const namespace of toSchema.getNamespaces()) {
|
|
@@ -79,7 +78,7 @@ class SqlSchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
79
78
|
for (const tableDef of toSchema.getTables()) {
|
|
80
79
|
ret += await this.dump(this.helper.createSchemaBuilder(tableDef.schema).alterTable(tableDef.name, table => this.createForeignKeys(table, tableDef, options.schema)));
|
|
81
80
|
}
|
|
82
|
-
return this.wrapSchema(ret,
|
|
81
|
+
return this.wrapSchema(ret, options);
|
|
83
82
|
}
|
|
84
83
|
async dropSchema(options = {}) {
|
|
85
84
|
if (options.dropDb) {
|
|
@@ -114,7 +113,6 @@ class SqlSchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
114
113
|
}
|
|
115
114
|
async getDropSchemaSQL(options = {}) {
|
|
116
115
|
await this.ensureDatabase();
|
|
117
|
-
const wrap = options.wrap ?? this.options.disableForeignKeys;
|
|
118
116
|
const metadata = this.getOrderedMetadata(options.schema).reverse();
|
|
119
117
|
const schemas = this.getTargetSchema(options.schema).getNamespaces();
|
|
120
118
|
const schema = await DatabaseSchema_1.DatabaseSchema.create(this.connection, this.platform, this.config, options.schema, schemas);
|
|
@@ -122,7 +120,7 @@ class SqlSchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
122
120
|
// remove FKs explicitly if we can't use cascading statement and we don't disable FK checks (we need this for circular relations)
|
|
123
121
|
for (const meta of metadata) {
|
|
124
122
|
const table = schema.getTable(meta.tableName);
|
|
125
|
-
if (!this.platform.usesCascadeStatement() && table && (!
|
|
123
|
+
if (!this.platform.usesCascadeStatement() && table && (!this.options.disableForeignKeys || options.dropForeignKeys)) {
|
|
126
124
|
for (const fk of Object.values(table.getForeignKeys())) {
|
|
127
125
|
const builder = this.helper.createSchemaBuilder(table.schema).alterTable(table.name, tbl => {
|
|
128
126
|
tbl.dropForeign(fk.columnNames, fk.constraintName);
|
|
@@ -143,7 +141,7 @@ class SqlSchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
143
141
|
if (options.dropMigrationsTable) {
|
|
144
142
|
ret += await this.dump(this.dropTable(this.config.get('migrations').tableName, this.config.get('schema')), '\n');
|
|
145
143
|
}
|
|
146
|
-
return this.wrapSchema(ret + '\n',
|
|
144
|
+
return this.wrapSchema(ret + '\n', options);
|
|
147
145
|
}
|
|
148
146
|
getSchemaName(meta, options) {
|
|
149
147
|
const schemaName = options.schema ?? this.config.get('schema');
|
|
@@ -175,7 +173,6 @@ class SqlSchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
175
173
|
};
|
|
176
174
|
}
|
|
177
175
|
async prepareSchemaForComparison(options) {
|
|
178
|
-
options.wrap ??= this.options.disableForeignKeys;
|
|
179
176
|
options.safe ??= false;
|
|
180
177
|
options.dropTables ??= true;
|
|
181
178
|
const toSchema = this.getTargetSchema(options.schema);
|
|
@@ -439,13 +436,12 @@ class SqlSchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
439
436
|
await core_1.Utils.runSerial(groups.flat(), line => this.driver.execute(line));
|
|
440
437
|
}
|
|
441
438
|
wrapSchema(sql, options) {
|
|
442
|
-
options.wrap
|
|
443
|
-
if (!options.wrap || sql.trim() === '') {
|
|
439
|
+
if (options.wrap === false || sql.trim() === '') {
|
|
444
440
|
return sql;
|
|
445
441
|
}
|
|
446
|
-
let ret = this.helper.getSchemaBeginning(this.config.get('charset'));
|
|
442
|
+
let ret = this.helper.getSchemaBeginning(this.config.get('charset'), this.options.disableForeignKeys);
|
|
447
443
|
ret += sql;
|
|
448
|
-
ret += this.helper.getSchemaEnd();
|
|
444
|
+
ret += this.helper.getSchemaEnd(this.options.disableForeignKeys);
|
|
449
445
|
return ret;
|
|
450
446
|
}
|
|
451
447
|
dropIndex(table, index, oldIndexName = index.keyName) {
|