diff --git a/framework/dist/lisk-service-framework-1.6.1.tgz b/framework/dist/lisk-service-framework-1.6.1.tgz new file mode 100644 index 0000000000..4fbff85bc9 Binary files /dev/null and b/framework/dist/lisk-service-framework-1.6.1.tgz differ diff --git a/framework/package.json b/framework/package.json index a2b1dd4dde..f74b65d0dc 100644 --- a/framework/package.json +++ b/framework/package.json @@ -1,6 +1,6 @@ { "name": "lisk-service-framework", - "version": "1.6.0", + "version": "1.6.1", "description": "Lisk Service Framework", "keywords": [ "lisk", diff --git a/framework/src/database/sqlite3.js b/framework/src/database/sqlite3.js index 502a414f3f..8abbf6945a 100644 --- a/framework/src/database/sqlite3.js +++ b/framework/src/database/sqlite3.js @@ -61,24 +61,24 @@ const createDBConnection = async (dbDataDir, tableName) => { return knex; }; -const getDBConnection = async (tableName, dbDataDir) => { - if (!connectionPool[tableName]) { +const getDBConnection = async (tableName, dbDataDir = DB_DATA_DIR) => { + if (!connectionPool[dbDataDir]) { if (!(await exists(dbDataDir))) { await mkdir(dbDataDir, { recursive: true }); } - connectionPool[tableName] = await createDBConnection(dbDataDir, tableName); + connectionPool[dbDataDir] = await createDBConnection(dbDataDir, tableName); } - const knex = connectionPool[tableName]; + const knex = connectionPool[dbDataDir]; return knex; }; -const createTableIfNotExists = async tableConfig => { +const createTableIfNotExists = async (tableConfig, dbDataDir = DB_DATA_DIR) => { const { tableName } = tableConfig; if (!tablePool[tableName]) { logger.info(`Creating schema for ${tableName}`); - const knex = await getDBConnection(tableName); + const knex = await getDBConnection(tableName, dbDataDir); await util.loadSchema(knex, tableName, tableConfig); tablePool[tableName] = true; } @@ -91,7 +91,7 @@ const getTableInstance = async (tableConfig, dbDataDir = DB_DATA_DIR) => { const createDefaultTransaction = async connection => util.startDBTransaction(connection); - await createTableIfNotExists(tableConfig); + await createTableIfNotExists(tableConfig, dbDataDir); const dbOperations = util.getTableInstance(tableConfig, knex); diff --git a/framework/tests/unit/database/sqlite3.spec.js b/framework/tests/unit/database/sqlite3.spec.js index 04a53fe03d..bfd61674c3 100644 --- a/framework/tests/unit/database/sqlite3.spec.js +++ b/framework/tests/unit/database/sqlite3.spec.js @@ -269,7 +269,7 @@ describe('Test sqlite3 implementation', () => { it('should insert row', async () => { const preUpsertResult = await testTable.find(); expect(preUpsertResult.length).toBe(0); - const connection = await getDBConnection(tableName); + const connection = await getDBConnection(tableName, testDir); const trx = await startDBTransaction(connection); await testTable.upsert([blockWithoutTransaction.header], trx); await commitDBTransaction(trx); @@ -287,7 +287,7 @@ describe('Test sqlite3 implementation', () => { }); it('should update row', async () => { - const connection = await getDBConnection(tableName); + const connection = await getDBConnection(tableName, testDir); const trx = await startDBTransaction(connection); const { id } = blockWithTransaction.header; await testTable.upsert([{ ...blockWithTransaction.header, height: 20 }], trx); @@ -310,7 +310,7 @@ describe('Test sqlite3 implementation', () => { }); it('should increment column value', async () => { - const connection = await getDBConnection(tableName); + const connection = await getDBConnection(tableName, testDir); const trx = await startDBTransaction(connection); const { id } = blockWithoutTransaction.header; await testTable.increment({ @@ -324,7 +324,7 @@ describe('Test sqlite3 implementation', () => { }); it('should delete row by primary key', async () => { - const connection = await getDBConnection(tableName); + const connection = await getDBConnection(tableName, testDir); const trx = await startDBTransaction(connection); const [existingBlock] = await testTable.find(); const existingBlockId = existingBlock[`${schema.primaryKey}`]; @@ -339,7 +339,7 @@ describe('Test sqlite3 implementation', () => { }); it('should delete rows', async () => { - const connection = await getDBConnection(tableName); + const connection = await getDBConnection(tableName, testDir); const trx = await startDBTransaction(connection); await testTable.upsert([blockWithoutTransaction.header, blockWithTransaction.header]); @@ -357,7 +357,7 @@ describe('Test sqlite3 implementation', () => { }); it('should delete row', async () => { - const connection = await getDBConnection(tableName); + const connection = await getDBConnection(tableName, testDir); const trx = await startDBTransaction(connection); await testTable.upsert([blockWithoutTransaction.header]); @@ -375,7 +375,7 @@ describe('Test sqlite3 implementation', () => { }); it('should insert rows in a batch', async () => { - const connection = await getDBConnection(tableName); + const connection = await getDBConnection(tableName, testDir); const trx = await startDBTransaction(connection); const preUpsertResult = await testTable.find(); expect(preUpsertResult.length).toBe(0);