Simplify database migrations
This commit is contained in:
parent
46d5b06bfc
commit
e6809c95db
106 changed files with 4661 additions and 6814 deletions
|
|
@ -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!');
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue