> ## Documentation Index
> Fetch the complete documentation index at: https://docs.devin.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Enforce a Migration Checklist on Every PR

export const UseCaseHero = ({title, description, prompt, category, features, devinUrl, agent, intent, playbookId, type}) => {
  const encodedPrompt = encodeURIComponent(prompt || '');
  const tag = 'docs-use-case-gallery';
  const utm = 'utm_source=docs&utm_medium=use-case-gallery&utm_campaign=hero-cta';
  const agentParams = (agent ? '&agent=' + agent : '') + (intent ? '&intent=' + intent : '') + (playbookId ? '&playbookId=' + playbookId : '');
  const devinHref = type === 'schedule' ? 'https://app.devin.ai/settings/schedules/create?' + utm + agentParams + (prompt ? '&prompt=' + encodedPrompt : '') : type === 'review' ? 'https://app.devin.ai/review?' + utm : agent === 'ada' ? 'https://app.devin.ai/search?' + utm + '&noSubmit=true' + (prompt ? '&prompt=' + encodedPrompt : '') : devinUrl ? devinUrl.includes('?') ? devinUrl + '&' + utm + agentParams : devinUrl + '?' + utm + agentParams : prompt ? 'https://app.devin.ai/?tags=' + tag + '&' + utm + agentParams + '&prompt=' + encodedPrompt : 'https://app.devin.ai/?' + utm + agentParams;
  const buttonLabel = type === 'schedule' ? 'Schedule in Devin ↗' : type === 'review' ? 'Set Up Devin Review ↗' : agent === 'advanced' ? 'Try in Devin ↗' : agent === 'dana' ? 'Try in Dana ↗' : agent === 'ada' ? 'Try in Ask Devin ↗' : 'Try in Devin ↗';
  const featureList = features ? features.split(',').map(f => f.trim()) : [];
  return <div className="uc-hero">
      <div className="uc-hero-inner">
        <div className="uc-hero-left">
          <h1 className="uc-hero-title">{title}</h1>
          <p className="uc-hero-desc">{description}</p>
          <div>
            <a href={devinHref} target="_blank" rel="noopener noreferrer" className="try-in-devin-btn">
              {buttonLabel}
            </a>
          </div>
        </div>
        <div className="uc-hero-meta">
          <div className="uc-meta-item">
            <span className="uc-meta-label">Author</span>
            <span className="uc-meta-value">Cognition</span>
          </div>
          <div className="uc-meta-item">
            <span className="uc-meta-label">Category</span>
            <span className="uc-meta-value">{category}</span>
          </div>
          {featureList.length > 0 && <div className="uc-meta-item">
              <span className="uc-meta-label">Features</span>
              <span className="uc-meta-value">{featureList.join(', ')}</span>
            </div>}
        </div>
      </div>
    </div>;
};

export const PromptBlock = ({children, type, agent, intent, playbookId}) => {
  var utm = 'utm_source=docs&utm_medium=use-case-gallery&utm_campaign=prompt-block';
  var tag = 'docs-use-case-gallery';
  var agentParams = (agent ? '&agent=' + agent : '') + (intent ? '&intent=' + intent : '') + (playbookId ? '&playbookId=' + playbookId : '');
  var label = type === 'schedule' ? 'Schedule in Devin' : type === 'playbook' ? 'Create Playbook' : type === 'knowledge' ? 'Add to Knowledge' : agent === 'advanced' ? 'Try in Devin' : agent === 'dana' ? 'Try in Dana' : agent === 'ada' ? 'Try in Ask Devin' : 'Try in Devin';
  var buildUrl = function (text) {
    var encoded = encodeURIComponent(text);
    if (type === 'schedule') return 'https://app.devin.ai/settings/schedules/create?' + utm + agentParams + '&prompt=' + encoded;
    if (type === 'playbook') return 'https://app.devin.ai/settings/playbooks/create?' + utm + '&body=' + encoded;
    if (type === 'knowledge') return 'https://app.devin.ai/knowledge?' + utm + '&body=' + encoded;
    if (agent === 'ada') return 'https://app.devin.ai/search?' + utm + '&noSubmit=true&prompt=' + encoded;
    return 'https://app.devin.ai/?tags=' + tag + '&' + utm + agentParams + '&prompt=' + encoded;
  };
  const ref = React.useRef(null);
  const [href, setHref] = React.useState('#');
  React.useEffect(() => {
    if (!ref.current) return;
    var codeEl = ref.current.querySelector('pre code');
    if (codeEl) {
      var text = codeEl.textContent.trim();
      if (text) setHref(buildUrl(text));
    }
    var header = ref.current.querySelector('[data-component-part="code-block-header"]');
    if (header && !header.querySelector('.prompt-block-devin-link')) {
      var link = document.createElement('a');
      link.href = href;
      link.target = '_blank';
      link.rel = 'noopener noreferrer';
      link.className = 'prompt-block-devin-link';
      link.style.cssText = 'display:inline-flex;align-items:center;gap:6px;text-decoration:none;color:#fff;font-size:11px;font-weight:500;padding:4px 10px;border-radius:6px;white-space:nowrap;background:#317CFF;transition:background 0.2s;margin-left:8px;';
      link.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg> ' + label;
      link.onmouseenter = function () {
        link.style.background = '#2968D9';
      };
      link.onmouseleave = function () {
        link.style.background = '#317CFF';
      };
      header.appendChild(link);
    }
    var existingLink = ref.current.querySelector('.prompt-block-devin-link');
    if (existingLink && href !== '#') existingLink.href = href;
  });
  return <div className="prompt-block" ref={ref}>{children}</div>;
};

<UseCaseHero title="Enforce a Migration Checklist on Every PR" description="Build a repo skill that makes Devin catch destructive operations, verify rollback safety, and validate schema changes whenever a PR touches database migrations." prompt="Create a skill file at .agents/skills/migration-checklist/migration-checklist.md that teaches Devin to review every database migration in a PR for destructive operations, missing indexes on foreign keys, rollback safety, and schema drift — then block the PR until every check passes." category="Core Devin" features="Skills" />

<div className="uc-detail-wrapper">
  <Tip>Don't want to set this up manually? Paste a link to this page into a Devin session and ask it to set everything up for you.</Tip>

  <Steps>
    <Step title="Create the migration checklist skill">
      A repository skill is a markdown file you commit to `.agents/skills/<your-skill>/` in any of your repos. Devin sees all skills across all connected repositories — you can trigger them manually or Devin can choose to trigger them automatically when it detects a relevant situation. This skill tells Devin exactly how to review database migrations before opening or updating a PR — catching the mistakes that code review usually misses.

      Commit `.agents/skills/migration-checklist/migration-checklist.md` to your repository:

      ```markdown theme={null}
      # Migration Safety Checklist

      ## Description
      Review every database migration in the current PR for safety issues
      before opening or updating the pull request.

      ## When to use
      Invoke this skill whenever the PR diff includes new or modified files
      in `db/migrate/` (Rails), `migrations/` (Django), or
      `prisma/migrations/` (Prisma).

      ## Checklist

      ### 1. Detect destructive operations
      Scan each migration file for:
      - `DROP TABLE` or `drop_table`
      - `DROP COLUMN`, `remove_column`, or column removal
      - `TRUNCATE`
      - Data-type changes that lose precision (e.g. `text` → `varchar(50)`)

      If any are found, add a PR comment flagging the operation and
      confirming whether a data backup step exists in the migration.

      ### 2. Verify foreign-key indexes
      For every `add_reference`, `add_foreign_key`, or new column ending
      in `_id`, confirm a matching index exists. If not, add one to the
      migration before committing.

      ### 3. Check rollback safety
      - Run `bin/rails db:migrate:rollback STEP=<n>` (where n = number of
        new migrations) against the test database.
      - If rollback fails, add a `down` method or reversible block and
        retry.
      - Report any irreversible migrations in the PR description.

      ### 4. Validate schema file is up-to-date
      After running migrations, diff `db/schema.rb` (or `structure.sql`)
      against the version in the PR. If they differ, regenerate the schema
      file and include it in the commit.

      ### 5. Run model tests
      Execute `bin/rails test test/models/` to catch validations or
      associations broken by schema changes. All tests must pass before
      the PR is opened.
      ```

      Once this file is committed, Devin sees it as an available skill. Whenever a session touches migration files in this repo, Devin can trigger the checklist automatically — or you can invoke it manually at any point.
    </Step>

    <Step title="See the skill trigger on a real migration">
      When Devin works on a task that adds or modifies a migration file, it reads the diff, matches the migration checklist skill, and follows the checklist before opening the PR. Here's what that looks like in practice:

      1. **Scans the diff** — Devin sees a new file in `db/migrate/` and activates the migration checklist skill
      2. **Flags a destructive operation** — The migration removes a `legacy_email` column. Devin adds a PR comment:
         > `remove_column :users, :legacy_email` is a destructive operation.
         > Verified: migration includes a data backup step copying values to
         > `user_archives` before removal.
      3. **Adds a missing index** — The migration adds `account_id` to the `invoices` table but has no index. Devin appends `add_index :invoices, :account_id` to the migration file
      4. **Runs rollback** — Devin executes `bin/rails db:migrate:rollback STEP=1` against the test database. It passes
      5. **Regenerates the schema** — Devin runs `bin/rails db:schema:dump`, detects a diff in `db/schema.rb`, and includes the updated file in the commit
      6. **Runs model tests** — All model tests pass. Devin opens the PR with a summary of each check

      The PR description includes a checklist showing what passed and what Devin fixed, so reviewers can focus on the business logic instead of the migration mechanics.
    </Step>

    <Step title="Adapt the skill for your ORM and stack">
      The checklist above targets Rails, but the same structure works for any ORM. Ask Devin to rewrite the skill for your stack:

      <PromptBlock>
        ```txt Adapt for Django theme={null}
        Rewrite the migration checklist skill for our Django project:
        - Scan files in `apps/*/migrations/` for destructive operations
          like RemoveField, DeleteModel, and AlterField with data loss
        - After running `python manage.py migrate`, verify that
          `python manage.py showmigrations` shows no unapplied migrations
        - Run `python manage.py test --tag=models` to validate schema changes
        - Check that migrations have a `reverse_code` or `RunSQL` reverse
          for rollback safety
        ```
      </PromptBlock>

      <PromptBlock>
        ```txt Adapt for Prisma theme={null}
        Rewrite the migration checklist skill for our Prisma project:
        - Scan files in `prisma/migrations/` for DROP TABLE, DROP COLUMN,
          and ALTER COLUMN that reduces field width
        - Run `npx prisma migrate deploy` against the test database and
          confirm it succeeds
        - Run `npx prisma migrate diff` to verify schema.prisma matches
          the applied migration state
        - Execute `npm test -- --grep "model"` to catch broken relations
        ```
      </PromptBlock>
    </Step>

    <Step title="Extend the checklist over time">
      Every migration incident reveals a gap the checklist didn't cover. After each one, add a rule — it's a one-line commit to the skill file.

      Here are common additions teams make after real incidents:

      ```markdown theme={null}
      ### 6. Enforce migration naming conventions
      Reject migrations that don't follow the pattern
      `YYYYMMDDHHMMSS_verb_noun.rb` (e.g. `add_index_to_invoices`).
      Rename the file if needed.

      ### 7. Check for long-running locks
      Flag any `add_column` on tables with >1M rows that doesn't use
      `disable_ddl_transaction!` (Postgres) or `ALGORITHM=INPLACE`
      (MySQL). Large tables need non-blocking migrations.

      ### 8. Require a migration test
      Ensure a corresponding test file exists at
      `test/migrations/YYYYMMDDHHMMSS_migration_name_test.rb`.
      If missing, generate a skeleton test that runs the migration
      up and down.
      ```

      Because the skill file lives in your repo, these rules go through code review — your entire team agrees on what gets checked, and it's always in sync with your migration tooling.
    </Step>
  </Steps>
</div>
