-
Notifications
You must be signed in to change notification settings - Fork 0
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: Execute upgrade scripts twice to ensure they are idempotent #57
base: main
Are you sure you want to change the base?
Conversation
@@ -11,6 +12,8 @@ function microserviceExists(microservice: "api" | "admin" | "site") { | |||
return fs.existsSync(`${microservice}/package.json`); | |||
} | |||
|
|||
const isLocalDevelopment = !process.argv[1].includes("/_npx"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the easiest way I found to check if the script is executed locally during development or via npx.
Maybe we can think of something smarter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why doesn't process.env.NODE_ENV === "development"
work? 🤔
if (diffBefore !== diffAfter) { | ||
console.error(`❌ ${script.name}: Changes detected when executing script twice`); | ||
process.exit(-1); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want / need this git diff
check?
The problem is that some scripts rely on EsLint for cleanup. These scripts fail now, making it more complicated to implement scripts. E.g., replace-gridcoldef-import.ts just adds an import declaration in the end (no matter if it's already present), since ESLint will clean it up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a nice idea, but I would still remove it, since upgrade scripts should be easy to write (otherwise devs won't do it). Also, it should be noticeable that a script doesn't by running it twice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want the git diff feature, we could move the second run to the single script run feature and diff after executing eslint
Alternative to #52
Description
Execute upgrade scripts twice in development to ensure they are idempotent (= the outcome is identical no matter how often they are executed).
I also added a
git diff
check that checks if anything changed between the first and second execution. If changes are found, the script fails.see comments for open questions