mirror of
https://github.com/frappe/books.git
synced 2024-12-23 11:29:03 +00:00
fix: circumvent possible sqlite bug
- sqlite throws not null on direct insert - this doesn't seem to be happening on bulk or individual inserts
This commit is contained in:
parent
b4bed9521f
commit
b9a65b75d5
@ -30,8 +30,18 @@ class SqliteDatabase extends Database {
|
|||||||
// create temp table
|
// create temp table
|
||||||
await this.createTable(doctype, tempName);
|
await this.createTable(doctype, tempName);
|
||||||
|
|
||||||
|
try {
|
||||||
// copy from old to new table
|
// copy from old to new table
|
||||||
await this.knex(tempName).insert(this.knex.select().from(doctype));
|
await this.knex(tempName).insert(this.knex.select().from(doctype));
|
||||||
|
} catch (err) {
|
||||||
|
|
||||||
|
await this.sql('ROLLBACK');
|
||||||
|
await this.sql('PRAGMA foreign_keys=ON');
|
||||||
|
|
||||||
|
const rows = await this.knex.select().from(doctype);
|
||||||
|
await this.prestigeTheTable(doctype, rows);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// drop old table
|
// drop old table
|
||||||
await this.knex.schema.dropTable(doctype);
|
await this.knex.schema.dropTable(doctype);
|
||||||
@ -110,6 +120,7 @@ class SqliteDatabase extends Database {
|
|||||||
// Alter table hacx for sqlite in case of schema change.
|
// Alter table hacx for sqlite in case of schema change.
|
||||||
const tempName = `__${tableName}`;
|
const tempName = `__${tableName}`;
|
||||||
await this.knex.schema.dropTableIfExists(tempName);
|
await this.knex.schema.dropTableIfExists(tempName);
|
||||||
|
|
||||||
await this.knex.raw('PRAGMA foreign_keys=OFF');
|
await this.knex.raw('PRAGMA foreign_keys=OFF');
|
||||||
await this.createTable(tableName, tempName);
|
await this.createTable(tableName, tempName);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user