-
Notifications
You must be signed in to change notification settings - Fork 331
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
chore: fix migration conflicts #9097
Conversation
Signed-off-by: Matt Krick <matt.krick@gmail.com>
Signed-off-by: Matt Krick <matt.krick@gmail.com>
Signed-off-by: Matt Krick <matt.krick@gmail.com>
Signed-off-by: Matt Krick <matt.krick@gmail.com>
Signed-off-by: Matt Krick <matt.krick@gmail.com>
Signed-off-by: Matt Krick <matt.krick@gmail.com>
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 will only catch some of the cases. If I have 2 PRs with conflicting migrations, both will pass the build pre-merge, but might cause an issue post merge as they're not re-verified after each master change.
I think we could only reliably check this on master post-merge.
elif [[ 'OLD_MIGRATIONS_COUNT + 1' -lt 'NEW_MIGRATIONS_COUNT' ]]; then | ||
# Necessary since we only check the newest migration, not each one | ||
echo Please only PR 1 Migration at a time | ||
exit 1 | ||
fi |
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.
+1 I'm not a fan of this restriction. If you know the number of migrations, you can do
FIRST_NEW_MIGRATION=$(ls packages/server/postgres/migrations | tail -n $NEW_MIGRATION_COUNT | head -n1)
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.
After thinking about it, I think I would prefer if we could just check master that it's in the correct order. I think something along the lines of this
#!/bin/bash
PREV_COMMIT=$(git rev-list HEAD | tail -n 1)
PREV_FILE=''
for F in packages/server/postgres/migrations/*.ts; do
CURR_COMMIT=$( git log --diff-filter=A --pretty=format:"%H" -- "$F")
git merge-base --is-ancestor $PREV_COMMIT $CURR_COMMIT > /dev/null
if [ $? -ne 0 ]; then
echo "$PREV_FILE was added after $F but has a smaller timestamp"
fi
PREV_COMMIT=$CURR_COMMIT
PREV_FILE=$F
done
This needs some cleanup though, or we make sure to only consider all files after the last failure
We should probably break this out into its own action. That way it could run when the PR gets opened & re-run whenever a commit to master gets pushed. I'll toy around a bit more! |
i found a solution. |
Description
The most frequent reason for a failed release is a failed predeploy due to conflicting migration names. For example, an older PR gets merged after a newer PR was already merged & pushed to prod, invalidating the migration run order.
This PR stops that by making sure the PR doesn't include any migrations that predate the latest migration on master.
DEMO
If you have no migrations in your PR, you get this
If you have 1 valid migration in your PR, you get this
If you have 1 migration and it predates the latest migration on master, you get this
If you have 2 migrations in your PR you should consolidate or break apart your PR, so you get this