You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In almost all of my regular usage script files, I have some code like this:
constreadline=require("readline")constsleep=(waitTimeInMs)=>newPromise((resolve)=>setTimeout(resolve,waitTimeInMs))exportdefaultasync()=>{if(process.env.DATABASE_URL.includes("prod_db_name")){console.log("This cmd runs against prod, to confirm type any input then press enter")constrl=readline.createInterface({input: process.stdin,output: process.stdout,terminal: false,})letresult=undefinedrl.on("line",function(line){result=line})while(!result)awaitsleep(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:
exportconstrequiresUserConfirmation=process.env.DATABASE_URL.includes("prod_db_name")exportdefaultasync()=>{// 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
The text was updated successfully, but these errors were encountered:
Heyo @orta - thanks as usual for a useful idea. I assume you're talking about rw exec here
Couple of thoughts:
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.
Wondering what other cases you might want to have a confirmation 🤔. Perhaps it should be a function instead? shouldRequireConfirmation: (parsedArgs, otherUsefulThings): Boolean
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!"
Summary
In almost all of my regular usage script files, I have some code like this:
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: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?
The text was updated successfully, but these errors were encountered: