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

[RFC]: Add an export for 'warn on prod' to scripts #9297

Open
1 task done
orta opened this issue Oct 12, 2023 · 4 comments
Open
1 task done

[RFC]: Add an export for 'warn on prod' to scripts #9297

orta opened this issue Oct 12, 2023 · 4 comments
Labels
help wanted p3 Low priority. The Core team will not prioritize this for now

Comments

@orta
Copy link
Contributor

orta commented Oct 12, 2023

Summary

In almost all of my regular usage script files, I have some code like this:

const readline = require("readline")
const sleep = (waitTimeInMs) => new Promise((resolve) => setTimeout(resolve, waitTimeInMs))

export default async () => {
  if (process.env.DATABASE_URL.includes("prod_db_name")) {
    console.log("This cmd runs against prod, to confirm type any input then press enter")
    const rl = readline.createInterface({
      input: process.stdin,
      output: process.stdout,
      terminal: false,
    })

    let result = undefined
    rl.on("line", function (line) {
      result = line
    })

    while (!result) await sleep(100)

    rl.close()
    console.log("Confirmed, running.")
  }

  // Do work
}

Which I use to ensure that if the script is going to run against production data it needs me to "say yes"

I wonder if instead, we could have a known export which when true checks to see if there is a stdin on the process and would wait until confirmation. So, I would write:

export const requiresUserConfirmation = process.env.DATABASE_URL.includes("prod_db_name")

export default async () => {
  // Do work
}

In my scripts.

Motivation

I treat prod with respect, but I trash my dev db all the time. I want to make sure I don't do this, and I think the solution is pretty useful for a lot of cases

Detailed proposal

It'd require a bit of work in the exec fn, and some docs but it shouldn't be too hard to add and maintain. Who know what other improvement could be usable via an export in the scripts.

Are you interested in working on this?

  • I'm interested in working on this
@orta
Copy link
Contributor Author

orta commented Nov 4, 2023

Poke

@dac09
Copy link
Collaborator

dac09 commented Nov 7, 2023

Heyo @orta - thanks as usual for a useful idea. I assume you're talking about rw exec here

Couple of thoughts:

  1. What do you think of just having a generic check like:
if (!process.env.DATABASE_URL.includes('localhost')) {
// prompt for confirmation
}

which we build into the execScript function.

  1. Wondering what other cases you might want to have a confirmation 🤔. Perhaps it should be a function instead? shouldRequireConfirmation: (parsedArgs, otherUsefulThings): Boolean

@Tobbe
Copy link
Member

Tobbe commented Dec 2, 2023

We'd happily accept a PR for some variation of this functionality, but can't prioritize it ourselves right now.

@Tobbe Tobbe added p3 Low priority. The Core team will not prioritize this for now help wanted labels Dec 2, 2023
@orta
Copy link
Contributor Author

orta commented Jan 24, 2024

Sorry for never responding, lol, life:

I don't think hardcoding a check like the url for db covers enough cases (because another chunk of my scripts check to see if they are against prod or staging stripe for example)

Having it as a function makes sense to me, we can pass the same args as the default export and it also gives folks a point to add a console.log basically giving context "you're on prod stripe!"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted p3 Low priority. The Core team will not prioritize this for now
Projects
None yet
Development

No branches or pull requests

3 participants