diff --git a/src/apply-migrations.ts b/src/apply-migrations.ts index 94f86320e..d43f67bf4 100644 --- a/src/apply-migrations.ts +++ b/src/apply-migrations.ts @@ -10,8 +10,22 @@ process.env.DB_LOGGING = "true"; import { closeDatabase, initDatabase } from "@spacebar/util"; -initDatabase().then(() => { - closeDatabase().then((r) => { - console.log("Successfully applied migrations!"); - }); -}); +async function main() { + let success = false; + while (!success) { + try { + await initDatabase().then(async () => { + await closeDatabase().then(async () => { + console.log("Successfully applied migrations!"); + success = true; + }); + }); + } catch (e) { + console.error("Failed to apply migrations, retrying in 2s...", e); + await new Promise((res) => setTimeout(res, 2000)); + await main(); + } + } +} + +main().then((r) => console.log("meow"));