Backups: use new locatorInfo & mediaName (#10627)

This commit is contained in:
trevor-signal
2025-06-18 13:16:29 -04:00
committed by GitHub
parent 099f94a809
commit fb0c414702
78 changed files with 2271 additions and 2842 deletions

View File

@@ -6,9 +6,11 @@ import { assert } from 'chai';
import type { ReadableDB, WritableDB } from '../../sql/Interface';
import { jsonToObject, objectToJSON, sql, sqlJoin } from '../../sql/util';
import { createDB, updateToVersion, explain } from './helpers';
import type { LegacyAttachmentDownloadJobType } from '../../sql/migrations/1040-undownloaded-backed-up-media';
import type {
_AttachmentDownloadJobTypeV1030,
_AttachmentDownloadJobTypeV1040,
} from '../../sql/migrations/1040-undownloaded-backed-up-media';
import type { AttachmentType } from '../../types/Attachment';
import type { AttachmentDownloadJobType } from '../../types/AttachmentDownload';
import { IMAGE_JPEG } from '../../types/MIME';
function getAttachmentDownloadJobs(
@@ -28,7 +30,7 @@ function getAttachmentDownloadJobs(
}
type UnflattenedAttachmentDownloadJobType = Omit<
AttachmentDownloadJobType,
_AttachmentDownloadJobTypeV1040,
'digest' | 'contentType' | 'size' | 'source' | 'ciphertextSize'
>;
function insertNewJob(
@@ -301,25 +303,27 @@ describe('SQL/updateToSchemaVersion1040', () => {
});
it('respects foreign key constraint on messageId', () => {
const job: Omit<AttachmentDownloadJobType, 'source' | 'ciphertextSize'> =
{
messageId: 'message1',
attachmentType: 'attachment',
attachment: {
digest: 'digest1',
contentType: IMAGE_JPEG,
size: 128,
},
receivedAt: 1970,
const job: Omit<
_AttachmentDownloadJobTypeV1040,
'source' | 'ciphertextSize'
> = {
messageId: 'message1',
attachmentType: 'attachment',
attachment: {
digest: 'digest1',
contentType: IMAGE_JPEG,
size: 128,
sentAt: 2070,
active: false,
retryAfter: null,
attempts: 0,
lastAttemptTimestamp: null,
};
},
receivedAt: 1970,
digest: 'digest1',
contentType: IMAGE_JPEG,
size: 128,
sentAt: 2070,
active: false,
retryAfter: null,
attempts: 0,
lastAttemptTimestamp: null,
};
// throws if we don't add the message first
assert.throws(() => insertNewJob(db, job, false));
insertNewJob(db, job, true);
@@ -460,7 +464,7 @@ describe('SQL/updateToSchemaVersion1040', () => {
function insertLegacyJob(
db: WritableDB,
job: Partial<LegacyAttachmentDownloadJobType>
job: Partial<_AttachmentDownloadJobTypeV1030>
): void {
db.prepare('INSERT OR REPLACE INTO messages (id) VALUES ($id)').run({
id: job.messageId ?? null,

View File

@@ -5,13 +5,13 @@ import { assert } from 'chai';
import { omit } from 'lodash';
import type { WritableDB } from '../../sql/Interface';
import { createDB, updateToVersion, explain } from './helpers';
import type { AttachmentDownloadJobType } from '../../types/AttachmentDownload';
import { jsonToObject, objectToJSON, sql } from '../../sql/util';
import { IMAGE_BMP } from '../../types/MIME';
import type { _AttachmentDownloadJobTypeV1040 } from '../../sql/migrations/1040-undownloaded-backed-up-media';
function insertOldJob(
db: WritableDB,
job: Omit<AttachmentDownloadJobType, 'source' | 'ciphertextSize'>,
job: Omit<_AttachmentDownloadJobTypeV1040, 'source' | 'ciphertextSize'>,
addMessageFirst: boolean = true
): void {
if (addMessageFirst) {
@@ -86,7 +86,10 @@ describe('SQL/updateToSchemaVersion1180', () => {
});
it('adds source column with default standard to any existing jobs', async () => {
const job: Omit<AttachmentDownloadJobType, 'source' | 'ciphertextSize'> = {
const job: Omit<
_AttachmentDownloadJobTypeV1040,
'source' | 'ciphertextSize'
> = {
messageId: '123',
digest: 'digest',
attachmentType: 'attachment',

View File

@@ -6,11 +6,11 @@ import { assert } from 'chai';
import { AttachmentDownloadSource, type WritableDB } from '../../sql/Interface';
import { objectToJSON, sql } from '../../sql/util';
import { createDB, updateToVersion, explain } from './helpers';
import type { AttachmentDownloadJobType } from '../../types/AttachmentDownload';
import { IMAGE_JPEG } from '../../types/MIME';
import type { _AttachmentDownloadJobTypeV1040 } from '../../sql/migrations/1040-undownloaded-backed-up-media';
type UnflattenedAttachmentDownloadJobType = Omit<
AttachmentDownloadJobType,
_AttachmentDownloadJobTypeV1040,
'digest' | 'contentType' | 'size' | 'ciphertextSize'
>;