Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration timeouts #618

Open
ofekatr opened this issue Aug 21, 2023 · 1 comment
Open

Migration timeouts #618

ofekatr opened this issue Aug 21, 2023 · 1 comment

Comments

@ofekatr
Copy link

ofekatr commented Aug 21, 2023

Does the tool support configuring timeouts on migrations?
What's the recommended way of setting these up?

@mmkal
Copy link
Contributor

mmkal commented Nov 6, 2023

Nothing out of the box, but I'm open to it if you can think of a clean API. Would need to make sure it's clear what happens when a migration times out, whether a timeout config is global or local, can it be overridden etc.

I don't want to go far as to say that this is the official recommended way to do this, but you could do something like

import { Umzug } from 'umzug'

const migrator = new Umzug({
  migrations: {
    glob: 'migrations/*.js',
    resolve(params) {
      const base = Umzug.defaultResolver(params);
      return {
        ...base,
        async up(upParams) {
          return Promise.race([
            base.up(upParams),
            new Promise((_resolve, reject) =>
              setTimeout(() => {
                reject(new Error('timeout'));
              }, 1000)
            ),
          ]);
        },
        async down(downParams) {
          return Promise.race([
            base.down(downParams),
            new Promise((_resolve, reject) =>
              setTimeout(() => {
                reject(new Error('timeout'));
              }, 1000)
            ),
          ]);
        },
      };
  },
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants