# Tasks: Migrate Database Schema ## Phase 0: Foundation Tables (Corrected) - [x] 001: Search table migration script - Source: `OLD/Database/Tables/Search.sql` - Note: Corrected to match legacy schema (ID, UserName, Name, Status, SubmitDT, StartDT, EndDT, Criteria, Results) - Location: `NEW/src/JdeScoping.Database/Scripts/001_CreateSearchTable.sql` - [x] 002: DataUpdate table migration script - Source: `OLD/Database/Tables/DataUpdate.sql` - Note: Corrected to match legacy schema (SourceSystem, SourceData, TableName, StartDT, EndDT, UpdateType, WasSuccessful, NumberRecords) - Location: `NEW/src/JdeScoping.Database/Scripts/002_CreateDataUpdateTable.sql` ## Phase 1: Reference Tables (No Dependencies) - [x] 003: Create Branch table migration script - Source: `OLD/Database/Tables/Branch.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/003_CreateBranchTable.sql` - [x] 004: Create StatusCode table migration script - Source: `OLD/Database/Tables/StatusCode.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/004_CreateStatusCodeTable.sql` - [x] 005: Create FunctionCode table migration script - Source: `OLD/Database/Tables/FunctionCode.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/005_CreateFunctionCodeTable.sql` - [x] 006: Create ProfitCenter table migration script - Source: `OLD/Database/Tables/ProfitCenter.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/006_CreateProfitCenterTable.sql` - [x] 007: Create WorkCenter table migration script - Source: `OLD/Database/Tables/WorkCenter.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/007_CreateWorkCenterTable.sql` - [x] 008: Create Item table migration script - Source: `OLD/Database/Tables/Item.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/008_CreateItemTable.sql` - [x] 009: Create JdeUser table migration script - Source: `OLD/Database/Tables/JdeUser.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/009_CreateJdeUserTable.sql` - [x] 010: Create OrgHierarchy table migration script - Source: `OLD/Database/Tables/OrgHierarchy.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/010_CreateOrgHierarchyTable.sql` - [x] 011: Create RouteMaster table migration script - Source: `OLD/Database/Tables/RouteMaster.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/011_CreateRouteMasterTable.sql` - [x] 012: Create MisData table migration script - Source: `OLD/Database/Tables/MisData.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/012_CreateMisDataTable.sql` ## Phase 2: Core Tables (Depend on Reference Tables) - [x] 013: Create Lot table migration script - Source: `OLD/Database/Tables/Lot.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/013_CreateLotTable.sql` - [x] 014: Create LotLocation table migration script - Source: `OLD/Database/Tables/LotLocation.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/014_CreateLotLocationTable.sql` - [x] 015: Create WorkOrder_Curr table migration script - Source: `OLD/Database/Tables/WorkOrder_Curr.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/015_CreateWorkOrderCurrTable.sql` - [x] 016: Create WorkOrder_Hist table migration script - Source: `OLD/Database/Tables/WorkOrder_Hist.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/016_CreateWorkOrderHistTable.sql` - [x] 017: Create WorkOrderStep_Curr table migration script - Source: `OLD/Database/Tables/WorkOrderStep_Curr.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/017_CreateWorkOrderStepCurrTable.sql` - [x] 018: Create WorkOrderStep_Hist table migration script - Source: `OLD/Database/Tables/WorkOrderStep_Hist.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/018_CreateWorkOrderStepHistTable.sql` - [x] 019: Create WorkOrderTime_Curr table migration script - Source: `OLD/Database/Tables/WorkOrderTime_Curr.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/019_CreateWorkOrderTimeCurrTable.sql` - [x] 020: Create WorkOrderTime_Hist table migration script - Source: `OLD/Database/Tables/WorkOrderTime_Hist.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/020_CreateWorkOrderTimeHistTable.sql` - [x] 021: Create WorkOrderComponent_Curr table migration script - Source: `OLD/Database/Tables/WorkOrderComponent_Curr.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/021_CreateWorkOrderComponentCurrTable.sql` - [x] 022: Create WorkOrderComponent_Hist table migration script - Source: `OLD/Database/Tables/WorkOrderComponent_Hist.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/022_CreateWorkOrderComponentHistTable.sql` - [x] 023: Create WorkOrderRouting table migration script - Source: `OLD/Database/Tables/WorkOrderRouting_Curr.sql` - Note: File creates `dbo.WorkOrderRouting` (no _Curr suffix, single table) - Location: `NEW/src/JdeScoping.Database/Scripts/023_CreateWorkOrderRoutingTable.sql` - [x] 024: Create LotUsage_Curr table migration script - Source: `OLD/Database/Tables/LotUsage_Curr.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/024_CreateLotUsageCurrTable.sql` - [x] 025: Create LotUsage_Hist table migration script - Source: `OLD/Database/Tables/LotUsage_Hist.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/025_CreateLotUsageHistTable.sql` ## Phase 3: Views (Depend on Tables) - [x] 026: Create WorkOrder view migration script - Source: `OLD/Database/Views/WorkOrder.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/026_CreateWorkOrderView.sql` - [x] 027: Create WorkOrderTime view migration script - Source: `OLD/Database/Views/WorkOrderTime.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/027_CreateWorkOrderTimeView.sql` - [x] 028: Create WorkOrderStep view migration script - Source: `OLD/Database/Views/WorkOrderStep.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/028_CreateWorkOrderStepView.sql` - [x] 029: Create WorkOrderComponent view migration script - Source: `OLD/Database/Views/WorkOrderComponent.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/029_CreateWorkOrderComponentView.sql` - [x] 030: Create LotUsage view migration script - Source: `OLD/Database/Views/LotUsage.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/030_CreateLotUsageView.sql` - [x] 031: Create WorkOrderTotalScrap view migration script - Source: `OLD/Database/Views/WorkOrderTotalScrap.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/031_CreateWorkOrderTotalScrapView.sql` - [x] 032: Create LastDataUpdates view migration script - Source: `OLD/Database/Views/LastDataUpdates.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/032_CreateLastDataUpdatesView.sql` ## Phase 4: Table-Valued Parameter Types - [x] 033: Create WorkOrderFilterParameter type migration script - Source: `OLD/Database/Types/WorkOrderFilterParameter.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/033_CreateWorkOrderFilterParameterType.sql` - [x] 034: Create ItemNumberFilterParameter type migration script - Source: `OLD/Database/Types/ItemNumberFilterParameter.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/034_CreateItemNumberFilterParameterType.sql` - [x] 035: Create ProfitCenterFilterParameter type migration script - Source: `OLD/Database/Types/ProfitCenterFilterParameter.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/035_CreateProfitCenterFilterParameterType.sql` - [x] 036: Create WorkCenterFilterParameter type migration script - Source: `OLD/Database/Types/WorkCenterFilterParameter.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/036_CreateWorkCenterFilterParameterType.sql` - [x] 037: Create OperatorFilterParameter type migration script - Source: `OLD/Database/Types/OperatorFilterParameter.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/037_CreateOperatorFilterParameterType.sql` - [x] 038: Create ComponentLotFilterParameter type migration script - Source: `OLD/Database/Types/ComponentLotFilterParameter.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/038_CreateComponentLotFilterParameterType.sql` - [x] 039: Create ItemOperationMisFilterParameter type migration script - Source: `OLD/Database/Types/ItemOperationMISFilterParameter.sql` - Note: Using lowercase "Mis" per Codex review naming convention - Location: `NEW/src/JdeScoping.Database/Scripts/039_CreateItemOperationMisFilterParameterType.sql` ## Phase 5: Stored Procedures - [x] 040: Create SubmitSearch stored procedure migration script - Source: `OLD/Database/StoredProcedures/SubmitSearch.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/040_CreateSubmitSearchProcedure.sql` - [x] 041: Create StartSearch stored procedure migration script - Source: `OLD/Database/StoredProcedures/StartSearch.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/041_CreateStartSearchProcedure.sql` - [x] 042: Create CompleteSearch stored procedure migration script - Source: `OLD/Database/StoredProcedures/CompleteSearch.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/042_CreateCompleteSearchProcedure.sql` - [x] 043: Create ResetPartialSearches stored procedure migration script - Source: `OLD/Database/StoredProcedures/ResetPartialSearches.sql` - Location: `NEW/src/JdeScoping.Database/Scripts/043_CreateResetPartialSearchesProcedure.sql` ## Phase 6: Functions - [x] 044: Create MatchMis table-valued function migration script - Source: `OLD/Database/Functions/MatchMis.sql` - Dependencies: Item, WorkOrder, WorkOrderRouting, RouteMaster, MisData tables - Location: `NEW/src/JdeScoping.Database/Scripts/044_CreateMatchMisFunction.sql` ## Phase 7: Verification - [x] 045: Run full migration against clean database - Validation: All 44 scripts executed in order without error - Command: `dotnet run --project NEW/src/JdeScoping.Host` - [x] 046: Verify all objects exist - Validation: Query sys.tables, sys.views, sys.procedures, sys.types - Results: 26 tables (25 + SchemaVersions), 7 views, 7 types, 4 procedures, 1 function - [x] 047: Codex MCP review of migration scripts - All scripts verified against legacy source during creation - DATETIME -> DATETIME2(7) conversion applied consistently