diff --git a/app/imports/constants/MAINTENANCE_MODE.js b/app/imports/constants/MAINTENANCE_MODE.js index 42045410..aece8399 100644 --- a/app/imports/constants/MAINTENANCE_MODE.js +++ b/app/imports/constants/MAINTENANCE_MODE.js @@ -1,15 +1,23 @@ import { Migrations } from 'meteor/percolate:migrations'; import SCHEMA_VERSION from '/imports/constants/SCHEMA_VERSION.js'; -if (Meteor.isServer){ - Meteor.startup(()=>{ +if (Meteor.isServer) { + Meteor.startup(() => { const dbVersion = Migrations.getVersion(); + // If there are no users, this is a new DB, set the version to latest + const aUser = Meteor.users.findOne({}); + const latestVersion = Migrations._list[Migrations._list.length - 1].version + if (!aUser && dbVersion !== latestVersion) { + Migrations._collection.update({ _id: 'control' }, { version: latestVersion }); + return; + } + // Otherwise put the app in maintenance mode if it's not the right version if ( !Meteor.settings.public.maintenanceMode && dbVersion !== undefined && SCHEMA_VERSION !== dbVersion - ){ - Meteor.settings.public.maintenanceMode = { + ) { + Meteor.settings.public.maintenanceMode = { reason: 'App data needs to be migrated to the latest version' }; }