# Migrate Database Schema ## Summary Migrate all SQL Server database objects from the legacy .sqlproj to DbUp migration scripts in the new .NET 10 solution. This establishes the data layer foundation for subsequent migration phases. ## Scope ### In Scope - 25 tables (23 remaining - Search and DataUpdate already migrated) - 7 views (union views for _Curr/_Hist tables, aggregation views) - 7 table-valued parameter types (filter parameters for search queries) - 4 stored procedures (SubmitSearch, StartSearch, CompleteSearch, ResetPartialSearches) - 1 table-valued function (MatchMis) ### Out of Scope - Application code changes - Connection string configuration - Data migration from existing databases - Index optimization (will be addressed separately) ## Why The legacy .sqlproj format is not compatible with .NET 10 and cross-platform development. DbUp provides: - Version-controlled, sequential migrations - Idempotent deployments - Cross-platform compatibility - Integration with application startup ## What Changes - **Added**: 44 DbUp migration scripts in `NEW/src/JdeScoping.Database/Scripts/` - **Modified**: All DATETIME columns converted to DATETIME2(7) for better precision - **Added**: Spec requirements for DbUp migration patterns and idempotency ## Acceptance Criteria 1. All 44 database objects exist as numbered DbUp migration scripts 2. Scripts run successfully against empty database 3. Scripts are idempotent (can re-run without error) 4. Schema matches legacy database with approved modernizations: - DATETIME → DATETIME2(7) for better precision - Non-clustered indexes included in table scripts 5. `openspec validate migrate-database-schema --strict` passes ## Dependencies - None (this is the foundation phase) ## Risks | Risk | Mitigation | |------|------------| | Schema drift from legacy | Codex MCP review against OLD/Database/ files | | Missing dependencies between objects | Order scripts by dependency (tables → views → types → procs) | | Data type mismatches | Use exact types from legacy schema | ## Related Specs - `database-schema` - Table definitions and relationships - `sql-views-types` - Views and TVP types - `sql-business-logic` - Stored procedures and functions