From 16500a17879a3e388738106cc7b6c0be0ac37eec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Wed, 22 Nov 2023 13:30:37 +0100 Subject: [PATCH] fix: migrate db schema before current round init (#148) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Deployment of https://github.com/filecoin-station/spark-api/pull/147 is failing because at startup, we are updating `spark_rounds` table with `meridian_contract` and `meridian_round` before running the database schema migration. This commit changes the initialisation order: db migrations first and everything else afterwards. Signed-off-by: Miroslav Bajtoš --- bin/spark.js | 2 ++ index.js | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/spark.js b/bin/spark.js index eb0b1a67..14f2b52a 100644 --- a/bin/spark.js +++ b/bin/spark.js @@ -7,6 +7,7 @@ import fs from 'node:fs/promises' import { join, dirname } from 'node:path' import { fileURLToPath } from 'node:url' import { createRoundGetter } from '../lib/round-tracker.js' +import { migrate } from '../lib/migrate.js' import assert from 'node:assert' const { @@ -52,6 +53,7 @@ client.on('error', err => { // https://github.com/brianc/node-postgres/issues/1324#issuecomment-308778405 console.error('An idle client has experienced an error', err.stack) }) +await migrate(client) const getCurrentRound = await createRoundGetter(client) diff --git a/index.js b/index.js index 7d68f9a9..abeab1c2 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,5 @@ import { json } from 'http-responders' import Sentry from '@sentry/node' -import { migrate } from './lib/migrate.js' import getRawBody from 'raw-body' import assert from 'http-assert' import { validate } from './lib/validate.js' @@ -271,7 +270,6 @@ export const createHandler = async ({ getCurrentRound, domain }) => { - await migrate(client) return (req, res) => { const start = new Date() logger.info(`${req.method} ${req.url} ...`)