Derive Message.CURRENT_SCHEMA_VERSION
This commit is contained in:
parent
63bd9dcc61
commit
101041f106
1 changed files with 12 additions and 21 deletions
|
@ -35,13 +35,6 @@ const PRIVATE = 'private';
|
||||||
|
|
||||||
const INITIAL_SCHEMA_VERSION = 0;
|
const INITIAL_SCHEMA_VERSION = 0;
|
||||||
|
|
||||||
// Increment this version number every time we add a message schema upgrade
|
|
||||||
// step. This will allow us to retroactively upgrade existing messages. As we
|
|
||||||
// add more upgrade steps, we could design a pipeline that does this
|
|
||||||
// incrementally, e.g. from version 0 / unknown -> 1, 1 --> 2, etc., similar to
|
|
||||||
// how we do database migrations:
|
|
||||||
exports.CURRENT_SCHEMA_VERSION = 6;
|
|
||||||
|
|
||||||
// Public API
|
// Public API
|
||||||
exports.GROUP = GROUP;
|
exports.GROUP = GROUP;
|
||||||
exports.PRIVATE = PRIVATE;
|
exports.PRIVATE = PRIVATE;
|
||||||
|
@ -212,7 +205,6 @@ exports._mapQuotedAttachments = upgradeAttachment => async (
|
||||||
};
|
};
|
||||||
|
|
||||||
const toVersion0 = async message => exports.initializeSchemaVersion(message);
|
const toVersion0 = async message => exports.initializeSchemaVersion(message);
|
||||||
|
|
||||||
const toVersion1 = exports._withSchemaVersion(
|
const toVersion1 = exports._withSchemaVersion(
|
||||||
1,
|
1,
|
||||||
exports._mapAttachments(Attachment.autoOrientJPEG)
|
exports._mapAttachments(Attachment.autoOrientJPEG)
|
||||||
|
@ -230,7 +222,6 @@ const toVersion4 = exports._withSchemaVersion(
|
||||||
exports._mapQuotedAttachments(Attachment.migrateDataToFileSystem)
|
exports._mapQuotedAttachments(Attachment.migrateDataToFileSystem)
|
||||||
);
|
);
|
||||||
const toVersion5 = exports._withSchemaVersion(5, initializeAttachmentMetadata);
|
const toVersion5 = exports._withSchemaVersion(5, initializeAttachmentMetadata);
|
||||||
|
|
||||||
const toVersion6 = exports._withSchemaVersion(
|
const toVersion6 = exports._withSchemaVersion(
|
||||||
6,
|
6,
|
||||||
exports._mapContact(
|
exports._mapContact(
|
||||||
|
@ -238,6 +229,16 @@ const toVersion6 = exports._withSchemaVersion(
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const VERSIONS = [
|
||||||
|
toVersion0,
|
||||||
|
toVersion1,
|
||||||
|
toVersion2,
|
||||||
|
toVersion3,
|
||||||
|
toVersion4,
|
||||||
|
toVersion5,
|
||||||
|
];
|
||||||
|
exports.CURRENT_SCHEMA_VERSION = VERSIONS.length - 1;
|
||||||
|
|
||||||
// UpgradeStep
|
// UpgradeStep
|
||||||
exports.upgradeSchema = async (rawMessage, { writeNewAttachmentData } = {}) => {
|
exports.upgradeSchema = async (rawMessage, { writeNewAttachmentData } = {}) => {
|
||||||
if (!isFunction(writeNewAttachmentData)) {
|
if (!isFunction(writeNewAttachmentData)) {
|
||||||
|
@ -245,18 +246,8 @@ exports.upgradeSchema = async (rawMessage, { writeNewAttachmentData } = {}) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
let message = rawMessage;
|
let message = rawMessage;
|
||||||
const versions = [
|
// eslint-disable-next-line no-restricted-syntax
|
||||||
toVersion0,
|
for (const currentVersion of VERSIONS) {
|
||||||
toVersion1,
|
|
||||||
toVersion2,
|
|
||||||
toVersion3,
|
|
||||||
toVersion4,
|
|
||||||
toVersion5,
|
|
||||||
toVersion6,
|
|
||||||
];
|
|
||||||
|
|
||||||
for (let i = 0, max = versions.length; i < max; i += 1) {
|
|
||||||
const currentVersion = versions[i];
|
|
||||||
// We really do want this intra-loop await because this is a chained async action,
|
// We really do want this intra-loop await because this is a chained async action,
|
||||||
// each step dependent on the previous
|
// each step dependent on the previous
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue