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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.flexbase.in/flexbase-mcp-ai-prompts/legacy-migration-stored-procedures-prompts.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
