Simplify database migrations

This commit is contained in:
Fedor Indutny 2025-08-06 10:32:08 -07:00 committed by GitHub
commit e6809c95db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
106 changed files with 4661 additions and 6814 deletions

View file

@ -4,37 +4,24 @@ import type { LoggerType } from '../../types/Logging';
import { sql } from '../util';
import type { WritableDB } from '../Interface';
export const version = 1310;
// Value from ts/util/timestamp.ts at the time of creation of this migration
const MAX_SAFE_DATE = 8640000000000000;
export function updateToSchemaVersion1310(
currentVersion: number,
export default function updateToSchemaVersion1310(
db: WritableDB,
logger: LoggerType
): void {
if (currentVersion >= 1310) {
return;
const [query, params] = sql`
UPDATE conversations
SET json = json_replace(
json,
'$.muteExpiresAt',
9007199254740991 -- max safe integer
)
WHERE json ->> '$.muteExpiresAt' IS ${MAX_SAFE_DATE};
`;
const { changes } = db.prepare(query).run(params);
if (changes !== 0) {
logger.warn(`fixed ${changes} conversations`);
}
db.transaction(() => {
const [query, params] = sql`
UPDATE conversations
SET json = json_replace(
json,
'$.muteExpiresAt',
9007199254740991 -- max safe integer
)
WHERE json ->> '$.muteExpiresAt' IS ${MAX_SAFE_DATE};
`;
const { changes } = db.prepare(query).run(params);
if (changes !== 0) {
logger.warn(`updateToSchemaVersion1310: fixed ${changes} conversations`);
}
db.pragma('user_version = 1310');
})();
logger.info('updateToSchemaVersion1310: success!');
}