Skip to content

Conditionally run migrations per-player #503

Answered by mmkal
cckelly asked this question in Q&A
Discussion options

You must be logged in to vote

Interesting use case! Yes, I'd think you'll need a custom storage. They're not difficult to write. I don't know what your stack is, but here's a working example I threw together with pg-mem as a pseudo-db. You can swap it out with whatever you want though:

const umzug = require("umzug@3.0.0-beta.15")
const pgMem = require('pg-mem')

const db = pgMem.newDb()

db.public.query('create table migrations(player_id text, name text)')

class PlayerStorage {
  constructor(playerId) {
    this.playerId = playerId
  }
  
  async executed() {
    const result = db.public.query(`
      select name from migrations where player_id = '${this.playerId}'`
    )
    return result.rows.map(r => r.name)
  }

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@cckelly
Comment options

@cckelly
Comment options

@cckelly
Comment options

Answer selected by cckelly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #502 on September 20, 2021 22:26.