From 49a7d778db0fde732ad919aba1e45e9bbbe9a72e Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Tue, 22 Feb 2022 14:37:46 +0530 Subject: [PATCH 1/2] fix: batch insert issue on data migration --- frappe/backends/sqlite.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/frappe/backends/sqlite.js b/frappe/backends/sqlite.js index d198e83ac..e9ab69eed 100644 --- a/frappe/backends/sqlite.js +++ b/frappe/backends/sqlite.js @@ -105,12 +105,27 @@ class SqliteDatabase extends Database { } async prestigeTheTable(tableName, tableRows) { + const max = 200; + // 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); - await this.knex.batchInsert(tempName, tableRows); + + if (tableRows.length > 200) { + const fi = Math.floor(tableRows.length / max); + for (let i = 0; i <= fi; i++) { + const rowSlice = tableRows.slice(i * max, i + 1 * max); + if (rowSlice.length === 0) { + break; + } + await this.knex.batchInsert(tempName, rowSlice); + } + } else { + await this.knex.batchInsert(tempName, tableRows); + } + await this.knex.schema.dropTable(tableName); await this.knex.schema.renameTable(tempName, tableName); await this.knex.raw('PRAGMA foreign_keys=ON'); From 9b9abc01c7a5094e738d5928e860dc9931eda69c Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Tue, 22 Feb 2022 14:47:54 +0530 Subject: [PATCH 2/2] v0.2.1-beta.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cf4807b3e..d88b9e9a1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "frappe-books", - "version": "0.2.0-beta.0", + "version": "0.2.1-beta.0", "description": "Simple book-keeping app for everyone", "author": { "name": "Frappe Technologies Pvt. Ltd.",