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; requiredProtocolVersion?: number;
retryOptions?: RetryOptions; retryOptions?: RetryOptions;
sourceDevice?: string | number; sourceDevice?: number;
supportedVersionAtReceive?: unknown; supportedVersionAtReceive?: unknown;
synced?: boolean; synced?: boolean;
unidentifiedDeliveryReceived?: boolean; unidentifiedDeliveryReceived?: boolean;

View file

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

View file

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

View file

@ -2040,6 +2040,42 @@ function updateToSchemaVersion37(currentVersion: number, db: Database) {
console.log('updateToSchemaVersion37: success!'); 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 = [ const SCHEMA_VERSIONS = [
updateToSchemaVersion1, updateToSchemaVersion1,
updateToSchemaVersion2, updateToSchemaVersion2,
@ -2078,6 +2114,7 @@ const SCHEMA_VERSIONS = [
updateToSchemaVersion35, updateToSchemaVersion35,
updateToSchemaVersion36, updateToSchemaVersion36,
updateToSchemaVersion37, updateToSchemaVersion37,
updateToSchemaVersion38,
]; ];
function updateSchema(db: Database): void { function updateSchema(db: Database): void {
@ -3744,7 +3781,7 @@ async function getMessageBySender({
}: { }: {
source: string; source: string;
sourceUuid: string; sourceUuid: string;
sourceDevice: string; sourceDevice: number;
sent_at: number; sent_at: number;
}): Promise<Array<MessageType>> { }): Promise<Array<MessageType>> {
const db = getInstance(); const db = getInstance();