@mikro-orm/knex 6.4.6-dev.1 → 6.4.6-dev.11
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.
|
@@ -169,21 +169,32 @@ class BaseSqliteSchemaHelper extends SchemaHelper_1.SchemaHelper {
|
|
|
169
169
|
return name.startsWith('sqlite_');
|
|
170
170
|
}
|
|
171
171
|
async getAlterTable(changedTable, wrap) {
|
|
172
|
-
wrap ??= this.options.disableForeignKeys;
|
|
173
172
|
const tempName = `${(changedTable.toTable.name)}__temp_alter`;
|
|
174
173
|
const quotedName = this.platform.quoteIdentifier(changedTable.toTable.name);
|
|
175
174
|
const quotedTempName = this.platform.quoteIdentifier(tempName);
|
|
176
175
|
const createSql = await this.dump(this.createTable(changedTable.toTable), '');
|
|
177
176
|
const [first, ...rest] = createSql.split('\n');
|
|
178
|
-
|
|
177
|
+
const sql = [
|
|
179
178
|
'pragma foreign_keys = off;',
|
|
180
179
|
first.replace(`create table ${quotedName}`, `create table ${quotedTempName}`),
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
180
|
+
];
|
|
181
|
+
const columns = [];
|
|
182
|
+
for (const column of changedTable.toTable.getColumns()) {
|
|
183
|
+
const fromColumn = changedTable.fromTable.getColumn(column.name);
|
|
184
|
+
/* istanbul ignore else */
|
|
185
|
+
if (fromColumn) {
|
|
186
|
+
columns.push(this.platform.quoteIdentifier(column.name));
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
columns.push(`null as ${this.platform.quoteIdentifier(column.name)}`);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
sql.push(`insert into ${quotedTempName} select ${columns.join(', ')} from ${quotedName};`);
|
|
193
|
+
sql.push(`drop table ${quotedName};`);
|
|
194
|
+
sql.push(`alter table ${quotedTempName} rename to ${quotedName};`);
|
|
195
|
+
sql.push(...rest);
|
|
196
|
+
sql.push('pragma foreign_keys = on;');
|
|
197
|
+
return sql.join('\n');
|
|
187
198
|
}
|
|
188
199
|
}
|
|
189
200
|
exports.BaseSqliteSchemaHelper = BaseSqliteSchemaHelper;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/knex",
|
|
3
|
-
"version": "6.4.6-dev.
|
|
3
|
+
"version": "6.4.6-dev.11",
|
|
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.4.5"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@mikro-orm/core": "6.4.6-dev.
|
|
69
|
+
"@mikro-orm/core": "6.4.6-dev.11",
|
|
70
70
|
"better-sqlite3": "*",
|
|
71
71
|
"libsql": "*",
|
|
72
72
|
"mariadb": "*"
|
package/query/QueryBuilder.js
CHANGED
|
@@ -832,7 +832,7 @@ class QueryBuilder {
|
|
|
832
832
|
ref.as(aliasName);
|
|
833
833
|
}
|
|
834
834
|
const schema = this.getSchema(this.mainAlias);
|
|
835
|
-
if (schema) {
|
|
835
|
+
if (schema && schema !== this.platform.getDefaultSchemaName()) {
|
|
836
836
|
ref.withSchema(schema);
|
|
837
837
|
}
|
|
838
838
|
if (metadata?.virtual && processVirtualEntity) {
|
|
@@ -1053,7 +1053,7 @@ class QueryBuilder {
|
|
|
1053
1053
|
const schema = this.getSchema(this.mainAlias);
|
|
1054
1054
|
// Joined tables doesn't need to belong to the same schema as the main table
|
|
1055
1055
|
const joinSchema = this._schema ?? this.em?.schema ?? schema;
|
|
1056
|
-
if (schema) {
|
|
1056
|
+
if (schema && schema !== this.platform.getDefaultSchemaName()) {
|
|
1057
1057
|
qb.withSchema(schema);
|
|
1058
1058
|
}
|
|
1059
1059
|
if (this._indexHint) {
|
|
@@ -1372,7 +1372,7 @@ class QueryBuilder {
|
|
|
1372
1372
|
getSchema(alias) {
|
|
1373
1373
|
const { metadata } = alias;
|
|
1374
1374
|
const metaSchema = metadata?.schema && metadata.schema !== '*' ? metadata.schema : undefined;
|
|
1375
|
-
return this._schema ?? metaSchema ?? this.em?.schema ?? this.em?.config.
|
|
1375
|
+
return this._schema ?? metaSchema ?? this.em?.schema ?? this.em?.config.getSchema(true);
|
|
1376
1376
|
}
|
|
1377
1377
|
createAlias(entityName, aliasName, subQuery) {
|
|
1378
1378
|
const metadata = this.metadata.find(entityName);
|
|
@@ -206,7 +206,7 @@ class QueryBuilderHelper {
|
|
|
206
206
|
const conditions = [];
|
|
207
207
|
const params = [];
|
|
208
208
|
schema = join.schema && join.schema !== '*' ? join.schema : schema;
|
|
209
|
-
if (schema) {
|
|
209
|
+
if (schema && schema !== this.platform.getDefaultSchemaName()) {
|
|
210
210
|
table = `${schema}.${table}`;
|
|
211
211
|
}
|
|
212
212
|
if (join.prop.name !== '__subquery__') {
|