How to get environment from client on migration

Is there an easy way to get the environment on client received on migration scripts?
Reason behind that is to be able to filter out roles not in current environment in legacy scripts

Currently not as far as I know, I’m looking for something like this myself too!

my workaround is

const extractArgValue = (argName) => {
  const foundArg = process.argv.filter((arg) => arg.startsWith(`--${argName}`))
  if (foundArg.length > 0) {
    return foundArg[0].split(`--${argName}=`)[1]
  }
}

console.log("env", extractArgValue("--source"))

However, it’s far from ideal, since we are already passing the environment to the client

@mateus.carvalho @wrsmit00_datocms you can get the environment in this way:

client.config.environment

sorry for the delay in getting back to you!

1 Like