Resolve merge conflicts when upgrading SaaS Pegasus. Use when the user has merge conflicts after running git merge during a Pegasus upgrade, or when they need help with the merge process.
npx playbooks add skill saaspegasus/pegasus-skills --skill resolve-pegasus-conflicts
This skill helps users resolve merge conflicts when upgrading their SaaS Pegasus codebase. Most users will invoke this skill when they have merge conflicts after merging their main branch into a Pegasus upgrade branch, but you can also help run the merge process for them.
This guidance assumes the standard upgrade flow: you're on the Pegasus upgrade branch, merging the user's branch (usually main) into it. So HEAD/--ours is Pegasus and --theirs is the user's code. Verify the branch state matches before resolving anything, and adjust accordingly if it doesn't. For non-trivial conflicts, compare the clean versions from each side rather than reading conflict markers.
Before resolving conflicts, read the release notes for every version between the user's previous Pegasus version and the new one (_pegasus_version in pegasus-config.yaml on each side). They're at https://docs.saaspegasus.com/release-notes/, or https://docs.saaspegasus.com/release-notes-dev/ for dev builds. The page is long, so look specifically for those versions' sections. Follow any upgrade-specific guidance there. It takes precedence over the general guidance in this skill.
Check git status to see where things stand. If no merge is in progress, start with the next section; otherwise go straight to resolving conflicts. Briefly tell the user your plan, then proceed.
Pegasus creates the upgrade branch on the remote (named pegasus-<version>-<timestamp>), and the user's local branches are often behind. Fetch first, make sure both the upgrade branch and the user's branch are up to date with the remote, then check out the upgrade branch and merge the user's branch into it.
The user has already run git merge <main branch> and has conflicts to resolve. Help them resolve the conflicts using these strategies:
Merge source files (pyproject.toml, requirements/.in, package.json) by hand, keeping the user's customizations. For lock files (uv.lock, requirements/.txt, package-lock.json), take the Pegasus side, then re-lock and install from the merged source files right away. Later steps like makemigrations need a working environment.
Before committing the merge, check for lost upgrades: taking Pegasus's lock drops any versions the user bumped since their last upgrade. For each package the user changed between the merge base and their branch (packages only Pegasus changed don't need checking), confirm the merged lock still has their version. If not, pick the sensible one (usually the newer, unless the user's change looks deliberate, like a pin or downgrade) and restore it. Ask if unclear.
Principle: When main/local and Pegasus disagree about a migration, main/local wins. Main's migration files typically reflect what the local DB (and prod) have already applied, so that history is the baseline you protect. When a Pegasus migration conflicts with or duplicates something main has already applied, you should drop Pegasus's version in favour of main's, then run ./manage.py makemigrations to re-express any genuine change as a clean forward diff (the change lives in the merged models, so makemigrations re-derives it).
git checkout --theirs <migration-file>, then run ./manage.py makemigrations after all conflicts are resolved.# Generated by Django ... on <date> header even when nothing else changed. If git diff main HEAD -- <migration-file> shows only the header line, take main's version and move on — there's no schema change to re-derive.static/ (js/css/assets), if the project commits them: take either side; they're rebuilt by npm run build in the post-merge steps..env.example, settings files): merge carefully, keeping the user's customizations.Do this whether or not the merge had conflicts — this is easy to miss. Git can merge migration changes with no conflict markers, leaving duplicate or competing migrations that the conflict step never flagged. Two common causes:
0002_customuser_language... → 0002_customuser_customer...). A rename is a delete on one side and an add on the other, so it merges cleanly.chat/0005_chat_message_history while main already has chat/0005 through chat/0009). Both sides merge cleanly, leaving the app with competing migrations.Diff the migration dirs against main. Before the merge is committed, compare the staged result — not HEAD, which is still the bare Pegasus commit and would list every one of your own migrations as deleted:
git diff --cached --name-status main -- '*/migrations/*.py'
(If the merge is already committed, use git diff --name-status main HEAD -- '/migrations/.py' instead.) Empty output means there's nothing to fix. Otherwise, handle each line:
R (rename): restore main's file (git checkout main -- <old-file>) and delete Pegasus's regenerated copy (git rm <new-file>).A in an app that doesn't exist on main (e.g. a freshly added ecommerce app): fine, keep it as-is.A in an app that exists on main: open it and check its dependencies. If it depends on main's latest migration for that app, keep it. If it depends on an earlier one (or its number collides with one of main's), it competes with main's history — git rm it. If it contains RunPython or RunSQL operations, port those into a new migration by hand, since makemigrations only re-derives schema changes.Then run ./manage.py makemigrations to re-express any genuine schema change as a clean forward diff. If makemigrations reports "Conflicting migrations detected; multiple leaf nodes", a competing migration slipped through — find it with the diff above rather than running makemigrations --merge.
After all conflicts are resolved and the merge is complete, run the verification steps below. By default, work straight through them without pausing for confirmation between steps — the user kicked off an upgrade and expects forward motion. Stop only if a step fails, or if the user has said they want to review before pushing.
npm install && npm run builduv sync./manage.py makemigrations then ./manage.py migrate. If makemigrations alters or removes a field the user added or customized, the merge probably changed something unintentionally — check the merged model before migrating. If migrate fails partway, see "Recovering from a partial migration" below../manage.py testCommit any pending changes produced by the steps above (e.g. new migrations, formatting fixes) with a clear message. Docker users can substitute make upgrade for the build/migrate steps.
migrate commits each migration separately, so a failure partway through can leave earlier migrations applied while a later one fails — the DB is now in a half-migrated state that no longer matches its starting baseline. The local dev DB is typically kept at the same migration state as production, so it matters that you put it back. For Pegasus's schema-only, reversible migrations this is straightforward to undo.
./manage.py dbshell -- -c "SELECT app, name, applied FROM django_migrations ORDER BY applied DESC LIMIT 20;"
The recent timestamps are what this run applied.
./manage.py migrate <app> <last_good_migration> # or `zero` to unapply an app entirely
IrreversibleError — a data migration with no reverse defined), stop and raise to a human rather than forcing it. Don't pre-gate on atomic = False or side effects; just attempt the reverse and let it fail loudly if it can't. (If a forward op already dropped data, that loss happened on apply — reversing won't recover it, and that's also a human escalation.)./manage.py migrate and confirm the full chain applies cleanly from the baseline.If everything above passed, the default is to push so the user can open a PR:
git push -u origin <branch-name>
Then report the branch name and a summary of what was upgraded. The push output includes a "Create a pull request" URL — surface that link to the user and tell them that's where they can review the diff and open the PR.
Hold off on pushing (and ask first) if any of these are true:
git config rerere.enabled true to remember conflict resolutions for future upgradespegasus-<version>-<timestamp> branch, direct them to the Pegasus upgrade documentationtest_agents.py → test_events.py). Git follows the rename, so a conflict with your edits to the old file shows up under the new name.Weekly roundup of top Claude Code skills, MCP servers, and AI coding tips.