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: Execute upgrade scripts twice to ensure they are idempotent #57

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

thomasdax98
Copy link
Member

@thomasdax98 thomasdax98 commented Jan 30, 2025

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

@@ -11,6 +12,8 @@ function microserviceExists(microservice: "api" | "admin" | "site") {
return fs.existsSync(`${microservice}/package.json`);
}

const isLocalDevelopment = !process.argv[1].includes("/_npx");
Copy link
Member Author

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.

Copy link
Collaborator

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? 🤔

Comment on lines +207 to +210
if (diffBefore !== diffAfter) {
console.error(`❌ ${script.name}: Changes detected when executing script twice`);
process.exit(-1);
}
Copy link
Member Author

@thomasdax98 thomasdax98 Jan 30, 2025

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

Copy link
Collaborator

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.

Copy link
Collaborator

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

@thomasdax98 thomasdax98 changed the title Execute upgrade scripts twice to ensure they are idempotent RFC: Execute upgrade scripts twice to ensure they are idempotent Jan 30, 2025
@thomasdax98 thomasdax98 marked this pull request as ready for review January 30, 2025 10:08
@auto-assign auto-assign bot requested a review from johnnyomair January 30, 2025 10:08
@johnnyomair johnnyomair removed their request for review January 30, 2025 11:35
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

Successfully merging this pull request may close these issues.

2 participants