Change sessions.id to a TEXT field to prevent type coercion
This commit is contained in:
parent
a780fa3bab
commit
11fdf22881
2 changed files with 40 additions and 3 deletions
39
app/sql.js
39
app/sql.js
|
@ -422,13 +422,50 @@ async function updateToSchemaVersion6(currentVersion, instance) {
|
||||||
console.log('updateToSchemaVersion6: success!');
|
console.log('updateToSchemaVersion6: success!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function updateToSchemaVersion7(currentVersion, instance) {
|
||||||
|
if (currentVersion >= 7) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log('updateToSchemaVersion7: starting...');
|
||||||
|
await instance.run('BEGIN TRANSACTION;');
|
||||||
|
|
||||||
|
// SQLite has been coercing our STRINGs into numbers, so we force it with TEXT
|
||||||
|
// We create a new table then copy the data into it, since we can't modify columns
|
||||||
|
|
||||||
|
await instance.run('DROP INDEX sessions_number;');
|
||||||
|
await instance.run('ALTER TABLE sessions RENAME TO sessions_old;');
|
||||||
|
|
||||||
|
await instance.run(
|
||||||
|
`CREATE TABLE sessions(
|
||||||
|
id TEXT PRIMARY KEY,
|
||||||
|
number TEXT,
|
||||||
|
json TEXT
|
||||||
|
);`
|
||||||
|
);
|
||||||
|
|
||||||
|
await instance.run(`CREATE INDEX sessions_number ON sessions (
|
||||||
|
number
|
||||||
|
) WHERE number IS NOT NULL;`);
|
||||||
|
|
||||||
|
await instance.run(`INSERT INTO sessions(id, number, json)
|
||||||
|
SELECT "+" || id, number, json FROM sessions_old;
|
||||||
|
`);
|
||||||
|
|
||||||
|
await instance.run('DROP TABLE sessions_old;');
|
||||||
|
|
||||||
|
await instance.run('PRAGMA schema_version = 7;');
|
||||||
|
await instance.run('COMMIT TRANSACTION;');
|
||||||
|
console.log('updateToSchemaVersion7: success!');
|
||||||
|
}
|
||||||
|
|
||||||
const SCHEMA_VERSIONS = [
|
const SCHEMA_VERSIONS = [
|
||||||
updateToSchemaVersion1,
|
updateToSchemaVersion1,
|
||||||
updateToSchemaVersion2,
|
updateToSchemaVersion2,
|
||||||
updateToSchemaVersion3,
|
updateToSchemaVersion3,
|
||||||
updateToSchemaVersion4,
|
updateToSchemaVersion4,
|
||||||
// version 5 was dropped
|
() => null, // version 5 was dropped
|
||||||
updateToSchemaVersion6,
|
updateToSchemaVersion6,
|
||||||
|
updateToSchemaVersion7,
|
||||||
];
|
];
|
||||||
|
|
||||||
async function updateSchema(instance) {
|
async function updateSchema(instance) {
|
||||||
|
|
|
@ -940,7 +940,7 @@ describe('SignalProtocolStore', () => {
|
||||||
describe('getDeviceIds', () => {
|
describe('getDeviceIds', () => {
|
||||||
it('returns deviceIds for a number', async () => {
|
it('returns deviceIds for a number', async () => {
|
||||||
const testRecord = 'an opaque string';
|
const testRecord = 'an opaque string';
|
||||||
const devices = [1, 2, 3].map(deviceId => {
|
const devices = [1, 2, 3, 10].map(deviceId => {
|
||||||
return [number, deviceId].join('.');
|
return [number, deviceId].join('.');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -951,7 +951,7 @@ describe('SignalProtocolStore', () => {
|
||||||
);
|
);
|
||||||
|
|
||||||
const deviceIds = await store.getDeviceIds(number);
|
const deviceIds = await store.getDeviceIds(number);
|
||||||
assert.sameMembers(deviceIds, [1, 2, 3]);
|
assert.sameMembers(deviceIds, [1, 2, 3, 10]);
|
||||||
});
|
});
|
||||||
it('returns empty array for a number with no device ids', async () => {
|
it('returns empty array for a number with no device ids', async () => {
|
||||||
const deviceIds = await store.getDeviceIds('foo');
|
const deviceIds = await store.getDeviceIds('foo');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue