From 8906d8f7f79c239128c0010f11d81c807a3c57d1 Mon Sep 17 00:00:00 2001 From: Danny Morabito Date: Wed, 26 Mar 2025 19:27:33 +0100 Subject: [PATCH] make sure migrations always run from 0 to n --- index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/index.ts b/index.ts index c3f110f..f9cbd6b 100644 --- a/index.ts +++ b/index.ts @@ -63,7 +63,12 @@ const relays = [ ]; export function runMigrations(db: Database, latestVersion: number) { - const migrations = Deno.readDirSync(`${import.meta.dirname}/migrations`); + const migrations = [...Deno.readDirSync(`${import.meta.dirname}/migrations`)]; + migrations.sort((a, b) => { + const aVersion = Number.parseInt(a.name.split('-')[0], 10); + const bVersion = Number.parseInt(b.name.split('-')[0], 10); + return aVersion - bVersion; + }); for (const migrationFile of migrations) { const migrationVersion = Number.parseInt( migrationFile.name.split('-')[0],