> For the complete documentation index, see [llms.txt](https://docs.flexbase.in/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flexbase.in/flexbase-mcp-ai-prompts/legacy-migration-stored-procedures-prompts.md).

# Legacy Migration Stored Procedures Prompts

> Extract stored procedures, triggers, computed columns, and embedded SQL patterns from legacy databases and source code. Map them to FlexBase features and subscribers.

## How to Use

This prompt is loaded automatically when the user says "extract stored procedures and triggers too" alongside a legacy migration request.

**Example prompts:**

```
Migrate this legacy application to FlexBase — extract stored procedures and triggers too
```

```
Extract the stored procedures and triggers from this database
```

```
Include database triggers in the migration analysis
```

***

## What Gets Extracted

The agent queries the database system catalogs and analyzes source code to extract:

| Category                   | What the Agent Finds                                             |
| -------------------------- | ---------------------------------------------------------------- |
| **Stored Procedures**      | All SPs in the database — not just ones referenced by app code   |
| **Triggers**               | INSERT, UPDATE, DELETE triggers on all tables                    |
| **Computed Columns**       | Database-level computed expressions                              |
| **Embedded SQL**           | Non-SP SQL patterns in application source code                   |
| **Validations from SPs**   | Guard clauses, existence checks, business rules inside SP bodies |
| **Business Flow from SPs** | Conditional logic, state transitions, cross-table updates        |

**Important:** The agent extracts ALL stored procedures from the database, even those not directly referenced by the application. Unmapped SPs are flagged for review.

***

## SP Migration Strategy

| Strategy                   | When Used                                         | What Happens                                            |
| -------------------------- | ------------------------------------------------- | ------------------------------------------------------- |
| **Move to Code** (DEFAULT) | Always, unless user overrides                     | SP logic translated to C# handler/query code in Phase 3 |
| **Keep Stored Procedure**  | User explicitly says "keep the stored procedures" | SP remains in database, handler calls it at runtime     |
| **Mixed**                  | Per-feature control                               | Some SPs move to code, others stay in database          |

***

## Trigger Mapping

| Trigger Type       | FlexBase Mapping                      |
| ------------------ | ------------------------------------- |
| INSERT trigger     | CREATE feature → OnSuccess subscriber |
| UPDATE trigger     | UPDATE feature → OnSuccess subscriber |
| DELETE trigger     | DELETE feature → OnSuccess subscriber |
| INSTEAD OF trigger | Pre-processor on the mapped feature   |

***

## Output

The agent generates `[ProjectName]_StoredProcedures_Triggers.md` containing:

* Complete SP documentation with source code and feature mapping
* Trigger documentation with subscriber mapping
* Computed column mappings
* Validations and business flow extracted from SP bodies
* Unmapped SPs/triggers flagged for review
* Migration strategy summary

**Supported databases:** SQL Server, PostgreSQL, Oracle, MySQL, DB2, SQLite

***

## Related

* **General migration:** [Legacy Migration → Markdown](/flexbase-mcp-ai-prompts/legacy-migration-prompts-md-file.md)
* **PowerBuilder analysis:** [PowerBuilder Project Analysis](/flexbase-mcp-ai-prompts/legacy-migration-pb-analysis-prompts.md)
* **After extraction:** [Implementation Completion](/flexbase-mcp-ai-prompts/implementation-completion-prompts.md)
