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

# Playbook: Instabile DB-Migrationen beheben

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="Ein fehleranfälliges DB-Migrations-Playbook beheben" description="Dein DB-Migrations-Playbook funktioniert mit einfachen Schemata, bricht aber bei Fremdschlüsseln zusammen. Übergib Devin vier Session-Links und lass es die Lücken schließen." prompt="Unser !db-migration-Playbook schlägt immer fehl, wenn Sessions auf Fremdschlüssel-Constraints stoßen. Hier sind 4 aktuelle Sessions – Sessions 1 und 2 waren bei eigenständigen Tabellen erfolgreich, aber Sessions 3 und 4 sind an FK-Fehlern gescheitert. Analysiere die fehlgeschlagenen Sessions, vergleiche sie mit den erfolgreichen und aktualisiere das Playbook so, dass es Fremdschlüsselabhängigkeiten (FK) vor jeder destruktiven Operation berücksichtigt." category="Devin-Optimierung" features="Advanced, Playbooks" agent="advanced" intent="improve" />

<div className="uc-detail-wrapper">
  <Tip>Möchtest du das nicht manuell einrichten? Füge einen Link zu dieser Seite in eine Devin-Session ein und bitte Devin, alles für dich einzurichten.</Tip>

  <Steps>
    <Step title="Muster über mehrere Sessions hinweg erkennen">
      Dein Team verwendet das `!db-migration` Playbook seit ein paar Wochen. Es hat das Umbenennen von Spalten und das Hinzufügen von Indizes problemlos gehandhabt – aber die letzten beiden Sessions sind mitten in der Migration abgestürzt, als versucht wurde, eine Spalte zu droppen, auf die andere Tabellen verweisen.

      Öffne jede Session und sieh dir die Fehlerstelle an. In diesem Fall sind die Sessions 3 und 4 beide an demselben Schritt fehlgeschlagen:

      ```
      ERROR: cannot drop column "account_id" because other objects depend on it
      DETAIL: constraint fk_orders_account_id on table orders depends on column account_id
      HINT: Use DROP ... CASCADE to drop dependent objects too.
      ```

      Du hast jetzt ein klares Signal: Das Playbook hat keinen Schritt, um Fremdschlüsselabhängigkeiten vor destruktiven Operationen zu prüfen. Zwei Sessions waren erfolgreich, weil sie nur eigenständige Tabellen bearbeitet haben; zwei sind fehlgeschlagen, weil sie das nicht taten.
    </Step>

    <Step title="Den Tab Improve Playbook mit Session-Links öffnen">
      Gehe zu [app.devin.ai](https://app.devin.ai/?utm_source=docs\&utm_medium=use-case-gallery) und klicke auf **Advanced** unter dem Eingabefeld. Wähle den Tab **Improve Playbook**.

      Wähle `!db-migration` aus dem Playbook-Dropdown und markiere dann alle vier Sessions im **Session-Multi-Dropdown** – sowohl die erfolgreichen als auch die fehlgeschlagenen. Erfolgreiche Sessions einzubeziehen ermöglicht es Devin zu sehen, was das Playbook gut macht, nicht nur, wo es fehlschlägt.

      <PromptBlock agent="advanced" intent="improve">
        ```txt Improve the db-migration playbook theme={null}
        Our !db-migration playbook works for simple table changes but fails
        when sessions hit foreign key constraints. Sessions 1 and 2 succeeded
        on standalone tables, but sessions 3 and 4 crashed on FK errors.

        Analyze all 4. Figure out what the successful sessions did differently
        (they hit standalone tables with no incoming FKs). Then update the
        playbook to:
        1. Query information_schema for FK dependencies before any DROP or ALTER
        2. Generate ALTER TABLE ... DROP CONSTRAINT statements when FKs exist
        3. Add a rollback step that re-creates dropped constraints if the
           migration fails partway through
        ```
      </PromptBlock>

      Was diesen Prompt effektiv macht:

      * **Nennt den genauen Fehler** – „Fremdschlüssel-Constraints“ statt „es schlägt manchmal fehl“
      * **Stellt Erfolge und Fehlschläge gegenüber** – Devin kann die Session-Transkripte vergleichen, um zu sehen, wo sie auseinanderlaufen
      * **Listet konkrete Fixes auf**, lässt aber Raum, damit Devin Probleme aufdeckt, die du übersehen hast
    </Step>

    <Step title="Das Playbook-Diff prüfen">
      Devin liest alle vier Session-Transkripte, identifiziert, wo sich die Fehlschläge von den Erfolgen unterscheiden, und schlägt gezielte Änderungen vor. Die Ausgabe sieht aus wie ein Changelog für dein Playbook:

      ```
      ## Analysis

      Sessions 1-2 succeeded because they only modified tables with no
      incoming foreign keys. Sessions 3-4 failed at step 4 ("Drop the
      old column") because the orders and invoices tables had FK
      references to the target column.

      ## Changes to !db-migration

      Added step 3a: "Before any DROP or ALTER that removes a column,
        query information_schema.key_column_usage to list dependent FKs.
        If any exist, generate ALTER TABLE ... DROP CONSTRAINT statements
        and execute them first. Save the original constraint DDL for
        rollback."

      Added step 7: "Rollback procedure — if any step after FK removal
        fails, re-create the dropped constraints using the saved DDL
        from step 3a."

      Updated Advice section: "Always run the migration against a staging
        database first. FK chains can be deeper than expected — a column
        in table A may be referenced by B, which is referenced by C.
        Query recursively."
      ```

      Das Playbook wird automatisch gespeichert. Wenn etwas nicht passt, antworte in derselben Session – zum Beispiel: „Füge außerdem einen Schritt hinzu, um den #database Slack-Channel zu benachrichtigen, bevor destruktive Migrationen ausgeführt werden.“
    </Step>

    <Step title="Den Fix an einer neuen Migration verifizieren">
      Du musst deine aktuelle Devin-Session nicht verlassen. Nachdem das Playbook-Update gespeichert wurde, verwende dieselbe Session, um eine Standard-Devin-Session zu starten, die das aktualisierte Playbook gegen genau das Szenario testet, das zuvor fehlgeschlagen ist:

      <PromptBlock>
        ```txt Test the updated playbook theme={null}
        Use the !db-migration playbook to drop the legacy_account_id column
        from the users table. This column is referenced by orders.account_id
        and invoices.billing_account_id — the playbook should handle the FK
        dependencies automatically.
        ```
      </PromptBlock>

      Wenn diese Session erfolgreich ist, funktioniert der Fix. Wenn sie auf einen neuen Randfall stößt (z. B. zirkuläre FK-Referenzen), gib diese Session für eine weitere Runde wieder in den Improve-Playbook-Tab ein.
    </Step>
  </Steps>
</div>
