From b9a65b75d5fb8a3d5b6233505d42f6daaad84e52 Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Tue, 8 Mar 2022 15:20:07 +0530 Subject: [PATCH] fix: circumvent possible sqlite bug - sqlite throws not null on direct insert - this doesn't seem to be happening on bulk or individual inserts --- frappe/backends/sqlite.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/frappe/backends/sqlite.js b/frappe/backends/sqlite.js index e9ab69ee..321699ca 100644 --- a/frappe/backends/sqlite.js +++ b/frappe/backends/sqlite.js @@ -30,8 +30,18 @@ class SqliteDatabase extends Database { // create temp table await this.createTable(doctype, tempName); - // copy from old to new table - await this.knex(tempName).insert(this.knex.select().from(doctype)); + try { + // copy from old to new table + 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 await this.knex.schema.dropTable(doctype); @@ -110,6 +120,7 @@ class SqliteDatabase extends Database { // Alter table hacx for sqlite in case of schema change. const tempName = `__${tableName}`; await this.knex.schema.dropTableIfExists(tempName); + await this.knex.raw('PRAGMA foreign_keys=OFF'); await this.createTable(tableName, tempName);