This commit is contained in:
seb
2026-10-29 16:17:38 +01:00
parent a5cef78d30
commit 3cb5ec5a7a
2 changed files with 26 additions and 2 deletions

View File

@@ -138,8 +138,11 @@ export function makeVersionContext(file, getVersion, setVersion) {
* @returns {Promise<number>} Number of steps applied.
*/
export async function migrateSchema({ direction, dirUrl, current, target, runStep, log = console.log }) {
if (direction === 'upgrade' && target < current) {
throw new Error(`Database schema version ${current} is newer than this application supports (${target})`);
if (direction === 'upgrade' && current > target) {
throw new Error(
`Refusing to start: database schema version (${current}) is higher than the highest version in the upgrade folder (${target}). ` +
`The database was updated by a newer version of the application. Please update the application code or downgrade the database schema.`
);
}
if (direction === 'downgrade' && target > current) {
throw new Error(`Cannot downgrade schema from version ${current} to higher version ${target}`);