Migrate sourceDevice from TEXT to INTEGER

This commit is contained in:
Fedor Indutny 2021-08-02 14:55:31 -07:00 committed by GitHub
parent eccd682920
commit 6637fc2b95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 6 deletions

2
ts/model-types.d.ts vendored
View File

@ -119,7 +119,7 @@ export type MessageAttributesType = {
}>;
requiredProtocolVersion?: number;
retryOptions?: RetryOptions;
sourceDevice?: string | number;
sourceDevice?: number;
supportedVersionAtReceive?: unknown;
synced?: boolean;
unidentifiedDeliveryReceived?: boolean;

View File

@ -1149,7 +1149,7 @@ async function getMessageBySender(
}: {
source: string;
sourceUuid: string;
sourceDevice: string;
sourceDevice: number;
sent_at: number;
},
{ Message }: { Message: typeof MessageModel }

View File

@ -195,7 +195,7 @@ export type UnprocessedType = {
export type UnprocessedUpdateType = {
source?: string;
sourceUuid?: string;
sourceDevice?: string;
sourceDevice?: number;
serverGuid?: string;
serverTimestamp?: number;
decrypted?: string;
@ -459,7 +459,7 @@ export type ServerInterface = DataInterface & {
getMessageBySender: (options: {
source: string;
sourceUuid: string;
sourceDevice: string;
sourceDevice: number;
sent_at: number;
}) => Promise<Array<MessageType>>;
getMessagesBySentAt: (sentAt: number) => Promise<Array<MessageType>>;
@ -548,7 +548,7 @@ export type ClientInterface = DataInterface & {
data: {
source: string;
sourceUuid: string;
sourceDevice: string;
sourceDevice: number;
sent_at: number;
},
options: { Message: typeof MessageModel }

View File

@ -2040,6 +2040,42 @@ function updateToSchemaVersion37(currentVersion: number, db: Database) {
console.log('updateToSchemaVersion37: success!');
}
function updateToSchemaVersion38(currentVersion: number, db: Database) {
if (currentVersion >= 38) {
return;
}
db.transaction(() => {
// TODO: Remove deprecated columns once sqlcipher is updated to support it
db.exec(`
DROP INDEX IF EXISTS messages_duplicate_check;
ALTER TABLE messages
RENAME COLUMN sourceDevice TO deprecatedSourceDevice;
ALTER TABLE messages
ADD COLUMN sourceDevice INTEGER;
UPDATE messages
SET
sourceDevice = CAST(deprecatedSourceDevice AS INTEGER),
deprecatedSourceDevice = NULL;
ALTER TABLE unprocessed
RENAME COLUMN sourceDevice TO deprecatedSourceDevice;
ALTER TABLE unprocessed
ADD COLUMN sourceDevice INTEGER;
UPDATE unprocessed
SET
sourceDevice = CAST(deprecatedSourceDevice AS INTEGER),
deprecatedSourceDevice = NULL;
`);
db.pragma('user_version = 38');
})();
console.log('updateToSchemaVersion38: success!');
}
const SCHEMA_VERSIONS = [
updateToSchemaVersion1,
updateToSchemaVersion2,
@ -2078,6 +2114,7 @@ const SCHEMA_VERSIONS = [
updateToSchemaVersion35,
updateToSchemaVersion36,
updateToSchemaVersion37,
updateToSchemaVersion38,
];
function updateSchema(db: Database): void {
@ -3744,7 +3781,7 @@ async function getMessageBySender({
}: {
source: string;
sourceUuid: string;
sourceDevice: string;
sourceDevice: number;
sent_at: number;
}): Promise<Array<MessageType>> {
const db = getInstance();