docs: add MatchMIS function to naming convention design
This commit is contained in:
@@ -1,11 +1,15 @@
|
|||||||
# Stored Procedure Naming Convention Design
|
# SQL Object Naming Convention Design
|
||||||
|
|
||||||
## Goal
|
## 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
|
## Current State
|
||||||
|
|
||||||
|
### Stored Procedures
|
||||||
|
|
||||||
| Current Name | Has `usp_` Prefix |
|
| Current Name | Has `usp_` Prefix |
|
||||||
|--------------|-------------------|
|
|--------------|-------------------|
|
||||||
| `SubmitSearch` | No |
|
| `SubmitSearch` | No |
|
||||||
@@ -14,8 +18,26 @@ Rename stored procedures to follow SQL Server best practice `usp_` prefix conven
|
|||||||
| `ResetPartialSearches` | No |
|
| `ResetPartialSearches` | No |
|
||||||
| `usp_ValidateSearchCriteria` | Yes (already correct) |
|
| `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
|
## Target State
|
||||||
|
|
||||||
|
### Stored Procedures
|
||||||
|
|
||||||
| Current | New |
|
| Current | New |
|
||||||
|---------|-----|
|
|---------|-----|
|
||||||
| `SubmitSearch` | `usp_SubmitSearch` |
|
| `SubmitSearch` | `usp_SubmitSearch` |
|
||||||
@@ -23,53 +45,77 @@ Rename stored procedures to follow SQL Server best practice `usp_` prefix conven
|
|||||||
| `CompleteSearch` | `usp_CompleteSearch` |
|
| `CompleteSearch` | `usp_CompleteSearch` |
|
||||||
| `ResetPartialSearches` | `usp_ResetPartialSearches` |
|
| `ResetPartialSearches` | `usp_ResetPartialSearches` |
|
||||||
|
|
||||||
|
### Functions
|
||||||
|
|
||||||
|
| Current | New |
|
||||||
|
|---------|-----|
|
||||||
|
| `MatchMIS` | `fn_MatchMIS` |
|
||||||
|
|
||||||
## Implementation Approach
|
## Implementation Approach
|
||||||
|
|
||||||
### 1. SQL Scripts (Modify Existing)
|
### 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`
|
- `040_CreateSubmitSearchProcedure.sql` → `usp_SubmitSearch`
|
||||||
- `041_CreateStartSearchProcedure.sql` → `usp_StartSearch`
|
- `041_CreateStartSearchProcedure.sql` → `usp_StartSearch`
|
||||||
- `042_CreateCompleteSearchProcedure.sql` → `usp_CompleteSearch`
|
- `042_CreateCompleteSearchProcedure.sql` → `usp_CompleteSearch`
|
||||||
- `043_CreateResetPartialSearchesProcedure.sql` → `usp_ResetPartialSearches`
|
- `043_CreateResetPartialSearchesProcedure.sql` → `usp_ResetPartialSearches`
|
||||||
|
|
||||||
|
**Functions:**
|
||||||
|
- `044_CreateMatchMisFunction.sql` → `fn_MatchMIS`
|
||||||
|
|
||||||
### 2. Docker Database (Manual Update)
|
### 2. Docker Database (Manual Update)
|
||||||
|
|
||||||
Since DbUp won't re-run already-executed scripts:
|
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
|
2. Execute updated CREATE statements directly
|
||||||
|
|
||||||
### 3. C# Constants Class (New File)
|
### 3. C# Constants Class (New File)
|
||||||
|
|
||||||
Create `StoredProcedures.cs` in `JdeScoping.DataAccess`:
|
Create `SqlObjects.cs` in `JdeScoping.DataAccess`:
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
namespace JdeScoping.DataAccess;
|
namespace JdeScoping.DataAccess;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constants for stored procedure names.
|
/// Constants for SQL stored procedure and function names.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class StoredProcedures
|
public static class SqlObjects
|
||||||
{
|
{
|
||||||
|
// Stored Procedures
|
||||||
public const string SubmitSearch = "usp_SubmitSearch";
|
public const string SubmitSearch = "usp_SubmitSearch";
|
||||||
public const string StartSearch = "usp_StartSearch";
|
public const string StartSearch = "usp_StartSearch";
|
||||||
public const string CompleteSearch = "usp_CompleteSearch";
|
public const string CompleteSearch = "usp_CompleteSearch";
|
||||||
public const string ResetPartialSearches = "usp_ResetPartialSearches";
|
public const string ResetPartialSearches = "usp_ResetPartialSearches";
|
||||||
public const string ValidateSearchCriteria = "usp_ValidateSearchCriteria";
|
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
|
```csharp
|
||||||
// Before
|
// Before
|
||||||
await using var command = new SqlCommand("SubmitSearch", connection)
|
await using var command = new SqlCommand("SubmitSearch", connection)
|
||||||
|
|
||||||
// After
|
// 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
|
### 5. Documentation Updates
|
||||||
@@ -88,9 +134,9 @@ Update all files mentioning procedure names:
|
|||||||
|
|
||||||
| Category | Files |
|
| Category | Files |
|
||||||
|----------|-------|
|
|----------|-------|
|
||||||
| SQL Scripts | 4 files (040-043) |
|
| SQL Scripts | 5 files (040-044) |
|
||||||
| C# New | 1 file (`StoredProcedures.cs`) |
|
| C# New | 1 file (`SqlObjects.cs`) |
|
||||||
| C# Modified | 1 file (`LotFinderRepository.SearchManagement.cs`) |
|
| C# Modified | 2 files (`LotFinderRepository.SearchManagement.cs`, `MisQueryBuilder.cs`) |
|
||||||
| Documentation | ~5 files |
|
| Documentation | ~5 files |
|
||||||
| Docker | Manual SQL execution |
|
| Docker | Manual SQL execution |
|
||||||
|
|
||||||
@@ -98,5 +144,6 @@ Update all files mentioning procedure names:
|
|||||||
|
|
||||||
1. Build succeeds
|
1. Build succeeds
|
||||||
2. All existing tests pass
|
2. All existing tests pass
|
||||||
3. Docker database has renamed procedures
|
3. Docker database has renamed objects:
|
||||||
4. `SELECT name FROM sys.procedures` shows `usp_` prefix on all procedures
|
- `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
|
||||||
|
|||||||
Reference in New Issue
Block a user