From 0bfdb73b474ef2f182f4bf7240d285728ecd7399 Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Fri, 4 Nov 2022 12:34:37 +0200 Subject: [PATCH] Added a quick exit for migrations if the database is new --- app/imports/constants/MAINTENANCE_MODE.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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' }; }