Added a quick exit for migrations if the database is new

This commit is contained in:
Stefan Zermatten
2022-11-04 12:34:37 +02:00
parent a462cc5ca2
commit 0bfdb73b47

View File

@@ -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'
};
}