When restoring archived files, migration happens automatically
This commit is contained in:
@@ -18,8 +18,8 @@ export function getArchiveObj(creatureId){
|
|||||||
const logs = CreatureLogs.find({creatureId}).fetch();
|
const logs = CreatureLogs.find({creatureId}).fetch();
|
||||||
let archiveCreature = {
|
let archiveCreature = {
|
||||||
meta: {
|
meta: {
|
||||||
archiveDate: new Date(),
|
|
||||||
schemaVersion: SCHEMA_VERSION,
|
schemaVersion: SCHEMA_VERSION,
|
||||||
|
archiveDate: new Date(),
|
||||||
},
|
},
|
||||||
creature,
|
creature,
|
||||||
properties,
|
properties,
|
||||||
|
|||||||
@@ -9,15 +9,16 @@ import Experiences from '/imports/api/creature/experience/Experiences.js';
|
|||||||
import { removeCreatureWork } from '/imports/api/creature/creatures/methods/removeCreature.js';
|
import { removeCreatureWork } from '/imports/api/creature/creatures/methods/removeCreature.js';
|
||||||
import ArchiveCreatureFiles from '/imports/api/creature/archive/ArchiveCreatureFiles.js';
|
import ArchiveCreatureFiles from '/imports/api/creature/archive/ArchiveCreatureFiles.js';
|
||||||
import readFile from '/imports/api/creature/archive/methods/readFile.js';
|
import readFile from '/imports/api/creature/archive/methods/readFile.js';
|
||||||
|
import migrateArchive from '/imports/migrations/server/migrateArchive.js';
|
||||||
|
|
||||||
function restoreCreature(file, archive){
|
function restoreCreature(file, archive){
|
||||||
if (SCHEMA_VERSION < file.meta.schemaVersion){
|
if (SCHEMA_VERSION < archive.meta.schemaVersion){
|
||||||
throw new Meteor.Error('Incompatible',
|
throw new Meteor.Error('Incompatible',
|
||||||
'The archive file is from a newer version. Update required to read.')
|
'The archive file is from a newer version. Update required to read.')
|
||||||
}
|
}
|
||||||
|
|
||||||
// Migrate and verify the archive meets the current schema
|
// Migrate and verify the archive meets the current schema
|
||||||
// migrateArchive(archive, file.meta.schemaVersion);
|
migrateArchive(archive);
|
||||||
|
|
||||||
// Insert the creature sub documents
|
// Insert the creature sub documents
|
||||||
// They still have their original _id's
|
// They still have their original _id's
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ function migrateCollection({collection, reversed}){
|
|||||||
bulk.execute();
|
bulk.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function migrateProperty({collection, reversed, prop}){
|
export function migrateProperty({collection, reversed, prop}){
|
||||||
const transforms = [
|
const transforms = [
|
||||||
...(transformsByPropType[prop.type] || []),
|
...(transformsByPropType[prop.type] || []),
|
||||||
{from: 'dependencies'}
|
{from: 'dependencies'}
|
||||||
|
|||||||
28
app/imports/migrations/server/migrateArchive.js
Normal file
28
app/imports/migrations/server/migrateArchive.js
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
||||||
|
|
||||||
|
/* eslint no-fallthrough: "off" -- Using switch fallthrough to run all
|
||||||
|
migration steps after the current version of the file. */
|
||||||
|
export default function migrateArchive(archive){
|
||||||
|
switch (archive.meta.schemaVersion){
|
||||||
|
// V1 of DiceCloud
|
||||||
|
case 'version1':
|
||||||
|
migrateLegacyArchive(archive);
|
||||||
|
// V2 of DiceCloud, Schema version 1
|
||||||
|
case 1:
|
||||||
|
cleanAt1(archive);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function migrateLegacyArchive(archive){
|
||||||
|
// TODO:
|
||||||
|
throw 'Not implemented';
|
||||||
|
}
|
||||||
|
|
||||||
|
function cleanAt1(archive){
|
||||||
|
archive.properties.map(prop => {
|
||||||
|
const schema = CreatureProperties.simpleSchema(prop);
|
||||||
|
const cleanProp = schema.clean(prop);
|
||||||
|
schema.validate(cleanProp);
|
||||||
|
return cleanProp;
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user