📋 Resolve Pegasus Conflicts

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.

QUICK INSTALL
npx playbooks add skill saaspegasus/pegasus-skills --skill resolve-pegasus-conflicts

Resolve Pegasus Conflicts instructions

Resolve Pegasus Conflicts

Instructions

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.

When invoked

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.

If the merge hasn't been run yet

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.

If there's an active merge with conflicts

The user has already run git merge <main branch> and has conflicts to resolve. Help them resolve the conflicts using these strategies:

Dependency files

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.

Database Migrations

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).

  • On a conflict: For conflicted migration files, accept the user's version from main with git checkout --theirs <migration-file>, then run ./manage.py makemigrations after all conflicts are resolved.
  • Header-only conflicts: Pegasus regenerates some migrations on every release, which rewrites the # 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.
Other files
  • Static assets: built bundles in static/ (js/css/assets), if the project commits them: take either side; they're rebuilt by npm run build in the post-merge steps.
  • Configuration files (.env.example, settings files): merge carefully, keeping the user's customizations.
  • Everything else: read both versions, understand the changes, and merge.

Check for silent migration changes

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:

  • Pegasus regenerates its own auto-generated migrations and sometimes renames them (e.g. 0002_customuser_language... → 0002_customuser_customer...). A rename is a delete on one side and an add on the other, so it merges cleanly.
  • Pegasus adds a new migration to an app you've also added migrations to (e.g. Pegasus adds 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.

Post-merge steps

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.

  1. Frontend install + build: npm install && npm run build
  2. Python dependency sync: uv sync
  3. Migrations: ./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.
  4. Tests: ./manage.py test

Commit 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.

Recovering from a partial migration

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.

  1. See what actually applied — check, don't theorize. Surprising schema (tables/columns you didn't expect) is far more likely to be something you just applied than pre-existing cruft. Confirm with timestamps:
   ./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.

  1. Reverse them back to the last good state, in reverse-dependency order (unapply the app that depends on another before the one it depends on):
   ./manage.py migrate <app> <last_good_migration>   # or `zero` to unapply an app entirely
  1. If the reverse errors loudly (e.g. 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.)
  2. Once back at a clean baseline, fix the offending migration (see "Database Migrations" above — usually a Pegasus rename/duplicate), then re-run ./manage.py migrate and confirm the full chain applies cleanly from the baseline.

Pushing

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:

  • A verification step failed or had warnings worth a human look
  • The user said earlier they wanted to review before pushing, or asked to "stop before push"
  • The merge required non-trivial judgment calls you're not confident about
  • There are local commits unrelated to the upgrade that the user may not want pushed

Important reminders

  • Enable rerere: Suggest running git config rerere.enabled true to remember conflict resolutions for future upgrades
  • Never squash: When merging Pegasus PRs in GitHub, always use "Create a merge commit" (not squash or rebase)

Edge cases

  • No pegasus upgrade branch: If the user doesn't have a pegasus-<version>-<timestamp> branch, direct them to the Pegasus upgrade documentation
  • Too many conflicts: If there are dozens of conflicts across many files, suggest reviewing them in priority order (migrations first, then lock files, then configuration)
  • Custom modifications: Be conservative with user customizations - when in doubt, keep their changes and note what was different in Pegasus
  • Renamed files: Pegasus sometimes renames files (e.g. test_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.
  • Unfamiliar file types: If you encounter conflicts in files you're not sure how to handle, explain both sides of the conflict and ask the user which approach makes sense

Related Skills

Get the best new skills
in your inbox

Weekly roundup of top Claude Code skills, MCP servers, and AI coding tips.