@ -41,7 +41,6 @@ module.exports = {
getAllOpenGroupV1Conversations ,
getAllOpenGroupV2Conversations ,
getPubkeysInPublicConversation ,
getAllConversationIds ,
getAllGroupsInvolvingId ,
removeAllConversations ,
@ -65,8 +64,6 @@ module.exports = {
getMessageBySenderAndServerTimestamp ,
getMessageIdsFromServerIds ,
getMessageById ,
getAllMessages ,
getAllMessageIds ,
getMessagesBySentAt ,
getSeenMessagesByHashList ,
getLastHashBySnode ,
@ -260,7 +257,7 @@ function openAndMigrateDatabase(filePath, key) {
switchToWAL ( db2 ) ;
// Because foreign key support is not enabled by default!
db2 . pragma ( 'foreign_keys = O N ') ;
db2 . pragma ( 'foreign_keys = O FF ') ;
return db2 ;
} catch ( error ) {
@ -834,6 +831,7 @@ const LOKI_SCHEMA_VERSIONS = [
updateToLokiSchemaVersion12 ,
updateToLokiSchemaVersion13 ,
updateToLokiSchemaVersion14 ,
updateToLokiSchemaVersion15 ,
] ;
function updateToLokiSchemaVersion1 ( currentVersion , db ) {
@ -1177,6 +1175,25 @@ function updateToLokiSchemaVersion14(currentVersion, db) {
console . log ( ` updateToLokiSchemaVersion ${ targetVersion } : success! ` ) ;
}
function updateToLokiSchemaVersion15 ( currentVersion , db ) {
const targetVersion = 15 ;
if ( currentVersion >= targetVersion ) {
return ;
}
console . log ( ` updateToLokiSchemaVersion ${ targetVersion } : starting... ` ) ;
db . transaction ( ( ) => {
db . exec ( `
DROP TABLE pairingAuthorisations ;
DROP TRIGGER messages _on _delete ;
DROP TRIGGER messages _on _update ;
` );
writeLokiSchemaVersion ( targetVersion , db ) ;
} ) ( ) ;
console . log ( ` updateToLokiSchemaVersion ${ targetVersion } : success! ` ) ;
}
function writeLokiSchemaVersion ( newVersion , db ) {
db . prepare (
` INSERT INTO loki_schema(
@ -1287,7 +1304,8 @@ function initialize({ configDir, key, messages, passwordAttempt }) {
// Clear any already deleted db entries on each app start.
vacuumDatabase ( db ) ;
getMessageCount ( ) ;
const msgCount = getMessageCount ( ) ;
console . warn ( 'total message count: ' , msgCount ) ;
} catch ( error ) {
if ( passwordAttempt ) {
throw error ;
@ -1612,13 +1630,6 @@ function getAllConversations() {
return map ( rows , row => jsonToObject ( row . json ) ) ;
}
function getAllConversationIds ( ) {
const rows = globalInstance
. prepare ( ` SELECT id FROM ${ CONVERSATIONS _TABLE } ORDER BY id ASC; ` )
. all ( ) ;
return map ( rows , row => row . id ) ;
}
function getAllOpenGroupV1Conversations ( ) {
const rows = globalInstance
. prepare (
@ -1992,16 +2003,6 @@ function getMessageById(id) {
return jsonToObject ( row . json ) ;
}
function getAllMessages ( ) {
const rows = globalInstance . prepare ( ` SELECT json FROM ${ MESSAGES _TABLE } ORDER BY id ASC; ` ) . all ( ) ;
return map ( rows , row => jsonToObject ( row . json ) ) ;
}
function getAllMessageIds ( ) {
const rows = globalInstance . prepare ( ` SELECT id FROM ${ MESSAGES _TABLE } ORDER BY id ASC; ` ) . all ( ) ;
return map ( rows , row => row . id ) ;
}
function getMessageBySender ( { source , sourceDevice , sentAt } ) {
const rows = globalInstance
. prepare (