Added sql migration.

pull/27/head
Mikunj 7 years ago
parent 77602e3dbb
commit 98185fa6fd

@ -47,6 +47,7 @@ module.exports = {
getContactPreKeyById, getContactPreKeyById,
getContactPreKeyByIdentityKey, getContactPreKeyByIdentityKey,
getContactPreKeys, getContactPreKeys,
getAllContactPreKeys,
bulkAddContactPreKeys, bulkAddContactPreKeys,
removeContactPreKeyById, removeContactPreKeyById,
removeAllContactPreKeys, removeAllContactPreKeys,
@ -424,7 +425,6 @@ async function updateToSchemaVersion6(currentVersion, instance) {
await instance.run( await instance.run(
`CREATE TABLE preKeys( `CREATE TABLE preKeys(
id INTEGER PRIMARY KEY ASC, id INTEGER PRIMARY KEY ASC,
recipient STRING,
json TEXT json TEXT
);` );`
); );
@ -435,27 +435,42 @@ async function updateToSchemaVersion6(currentVersion, instance) {
);` );`
); );
await instance.run('PRAGMA schema_version = 6;');
await instance.run('COMMIT TRANSACTION;');
console.log('updateToSchemaVersion6: success!');
}
async function updateToSchemaVersion7(currentVersion, instance) {
if (currentVersion >= 7) {
return;
}
console.log('updateToSchemaVersion7: starting...');
await instance.run('BEGIN TRANSACTION;');
// Add recipient row
await instance.run('ALTER TABLE preKeys ADD recipient STRING;');
await instance.run( await instance.run(
`CREATE TABLE contactPreKeys( `CREATE TABLE contactPreKeys(
id INTEGER PRIMARY KEY ASC AUTO_INCREMENT, id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
identityKeyString VARCHAR(255),
keyId INTEGER, keyId INTEGER,
identityKeyString STRING,
json TEXT json TEXT
);` );`
); );
await instance.run( await instance.run(
`CREATE TABLE contactSignedPreKeys( `CREATE TABLE contactSignedPreKeys(
id INTEGER PRIMARY KEY ASC AUTO_INCREMENT, id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
identityKeyString STRING, identityKeyString VARCHAR(255),
keyId INTEGER, keyId INTEGER,
json TEXT json TEXT
);` );`
); );
await instance.run('PRAGMA schema_version = 6;'); await instance.run('PRAGMA schema_version = 7;');
await instance.run('COMMIT TRANSACTION;'); await instance.run('COMMIT TRANSACTION;');
console.log('updateToSchemaVersion6: success!'); console.log('updateToSchemaVersion7: success!');
} }
const SCHEMA_VERSIONS = [ const SCHEMA_VERSIONS = [
@ -465,6 +480,7 @@ const SCHEMA_VERSIONS = [
updateToSchemaVersion4, updateToSchemaVersion4,
// version 5 was dropped // version 5 was dropped
updateToSchemaVersion6, updateToSchemaVersion6,
updateToSchemaVersion7, // Loki schema
]; ];
async function updateSchema(instance) { async function updateSchema(instance) {
@ -759,6 +775,10 @@ async function getAllSignedPreKeys() {
const rows = await db.all('SELECT json FROM signedPreKeys ORDER BY id ASC;'); const rows = await db.all('SELECT json FROM signedPreKeys ORDER BY id ASC;');
return map(rows, row => jsonToObject(row.json)); return map(rows, row => jsonToObject(row.json));
} }
async function getAllContactPreKeys() {
const rows = await db.all('SELECT json FROM contactPreKeys ORDER BY id ASC;');
return map(rows, row => jsonToObject(row.json));
}
async function bulkAddSignedPreKeys(array) { async function bulkAddSignedPreKeys(array) {
return bulkAdd(SIGNED_PRE_KEYS_TABLE, array); return bulkAdd(SIGNED_PRE_KEYS_TABLE, array);
} }

@ -238,7 +238,7 @@
keyId: preKey.keyId, keyId: preKey.keyId,
}; };
await window.Signal.Data.createorUpdateContactPreKey(key); await window.Signal.Data.createOrUpdateContactPreKey(key);
}, },
async storePreKey(keyId, keyPair, contactIdentityKeyString) { async storePreKey(keyId, keyPair, contactIdentityKeyString) {
const data = { const data = {
@ -357,7 +357,7 @@
created_at: Date.now(), created_at: Date.now(),
confirmed: false, confirmed: false,
}; };
await window.Signal.Date.createorUpdateContactSignedPreKey(key); await window.Signal.Data.createOrUpdateContactSignedPreKey(key);
}, },
async removeSignedPreKey(keyId) { async removeSignedPreKey(keyId) {
await window.Signal.Data.removeSignedPreKeyById(keyId); await window.Signal.Data.removeSignedPreKeyById(keyId);

Loading…
Cancel
Save