@mikro-orm/knex 6.4.6-dev.5 → 6.4.6-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.
|
@@ -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.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
|
"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.7",
|
|
70
70
|
"better-sqlite3": "*",
|
|
71
71
|
"libsql": "*",
|
|
72
72
|
"mariadb": "*"
|