Skip to content

Commit

Permalink
fix: migrate db schema before current round init (#148)
Browse files Browse the repository at this point in the history
Deployment of #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š <[email protected]>
  • Loading branch information
bajtos authored Nov 22, 2023
1 parent e163962 commit 16500a1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 2 additions & 0 deletions bin/spark.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 0 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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} ...`)
Expand Down

0 comments on commit 16500a1

Please sign in to comment.