docs: add MatchMIS function to naming convention design

This commit is contained in:
Joseph Doherty
2026-01-06 15:45:24 -05:00
parent 5c1ef7136e
commit f138b1ae59
@@ -1,11 +1,15 @@
# Stored Procedure Naming Convention Design
# SQL Object Naming Convention Design
## Goal
Rename stored procedures to follow SQL Server best practice `usp_` prefix convention for consistency and clarity.
Rename stored procedures and functions to follow SQL Server best practice prefix conventions for consistency and clarity:
- `usp_` for user stored procedures
- `fn_` for functions (scalar and table-valued)
## Current State
### Stored Procedures
| Current Name | Has `usp_` Prefix |
|--------------|-------------------|
| `SubmitSearch` | No |
@@ -14,8 +18,26 @@ Rename stored procedures to follow SQL Server best practice `usp_` prefix conven
| `ResetPartialSearches` | No |
| `usp_ValidateSearchCriteria` | Yes (already correct) |
### Functions
| Current Name | Type | Has `fn_` Prefix |
|--------------|------|------------------|
| `fn_GetSearchMinimumDt` | Scalar | Yes (already correct) |
| `fn_GetSearchMaximumDt` | Scalar | Yes (already correct) |
| `fn_GetSearchExtractMisData` | Scalar | Yes (already correct) |
| `fn_GetSearchWorkOrders` | Inline TVF | Yes (already correct) |
| `fn_GetSearchItemNumbers` | Inline TVF | Yes (already correct) |
| `fn_GetSearchProfitCenters` | Inline TVF | Yes (already correct) |
| `fn_GetSearchWorkCenters` | Inline TVF | Yes (already correct) |
| `fn_GetSearchOperatorIDs` | Inline TVF | Yes (already correct) |
| `fn_GetSearchComponentLots` | Inline TVF | Yes (already correct) |
| `fn_GetSearchPartOperations` | Inline TVF | Yes (already correct) |
| `MatchMIS` | Multi-statement TVF | No |
## Target State
### Stored Procedures
| Current | New |
|---------|-----|
| `SubmitSearch` | `usp_SubmitSearch` |
@@ -23,53 +45,77 @@ Rename stored procedures to follow SQL Server best practice `usp_` prefix conven
| `CompleteSearch` | `usp_CompleteSearch` |
| `ResetPartialSearches` | `usp_ResetPartialSearches` |
### Functions
| Current | New |
|---------|-----|
| `MatchMIS` | `fn_MatchMIS` |
## Implementation Approach
### 1. SQL Scripts (Modify Existing)
Update scripts 040-043 directly with new procedure names:
Update scripts 040-044 directly with new names:
**Stored Procedures:**
- `040_CreateSubmitSearchProcedure.sql``usp_SubmitSearch`
- `041_CreateStartSearchProcedure.sql``usp_StartSearch`
- `042_CreateCompleteSearchProcedure.sql``usp_CompleteSearch`
- `043_CreateResetPartialSearchesProcedure.sql``usp_ResetPartialSearches`
**Functions:**
- `044_CreateMatchMisFunction.sql``fn_MatchMIS`
### 2. Docker Database (Manual Update)
Since DbUp won't re-run already-executed scripts:
1. Drop old procedures from Docker database
1. Drop old procedures and functions from Docker database
2. Execute updated CREATE statements directly
### 3. C# Constants Class (New File)
Create `StoredProcedures.cs` in `JdeScoping.DataAccess`:
Create `SqlObjects.cs` in `JdeScoping.DataAccess`:
```csharp
namespace JdeScoping.DataAccess;
/// <summary>
/// Constants for stored procedure names.
/// Constants for SQL stored procedure and function names.
/// </summary>
public static class StoredProcedures
public static class SqlObjects
{
// Stored Procedures
public const string SubmitSearch = "usp_SubmitSearch";
public const string StartSearch = "usp_StartSearch";
public const string CompleteSearch = "usp_CompleteSearch";
public const string ResetPartialSearches = "usp_ResetPartialSearches";
public const string ValidateSearchCriteria = "usp_ValidateSearchCriteria";
// Functions
public const string MatchMis = "fn_MatchMIS";
}
```
### 4. Repository Update
### 4. C# Code Updates
Update `LotFinderRepository.SearchManagement.cs` to use constant:
**`LotFinderRepository.SearchManagement.cs`** - Use constant for stored procedure:
```csharp
// Before
await using var command = new SqlCommand("SubmitSearch", connection)
// After
await using var command = new SqlCommand(StoredProcedures.SubmitSearch, connection)
await using var command = new SqlCommand(SqlObjects.SubmitSearch, connection)
```
**`MisQueryBuilder.cs`** - Use constant for function:
```csharp
// Before
dbo.MatchMIS(c.WorkOrderNumber, ...)
// After
dbo.{SqlObjects.MatchMis}(c.WorkOrderNumber, ...)
```
### 5. Documentation Updates
@@ -88,9 +134,9 @@ Update all files mentioning procedure names:
| Category | Files |
|----------|-------|
| SQL Scripts | 4 files (040-043) |
| C# New | 1 file (`StoredProcedures.cs`) |
| C# Modified | 1 file (`LotFinderRepository.SearchManagement.cs`) |
| SQL Scripts | 5 files (040-044) |
| C# New | 1 file (`SqlObjects.cs`) |
| C# Modified | 2 files (`LotFinderRepository.SearchManagement.cs`, `MisQueryBuilder.cs`) |
| Documentation | ~5 files |
| Docker | Manual SQL execution |
@@ -98,5 +144,6 @@ Update all files mentioning procedure names:
1. Build succeeds
2. All existing tests pass
3. Docker database has renamed procedures
4. `SELECT name FROM sys.procedures` shows `usp_` prefix on all procedures
3. Docker database has renamed objects:
- `SELECT name FROM sys.procedures` shows `usp_` prefix on all procedures
- `SELECT name FROM sys.objects WHERE type IN ('FN','TF')` shows `fn_` prefix on all functions