Skip to content

EmeaAppGbb/appmodlab-spec-driven-database-migration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

9 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘                                                                   โ•‘
โ•‘   โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—                               โ•‘
โ•‘   โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ•โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ•โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ•                               โ•‘
โ•‘   โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ•โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—  โ–ˆโ–ˆโ•‘                                    โ•‘
โ•‘   โ•šโ•โ•โ•โ•โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ•โ• โ–ˆโ–ˆโ•”โ•โ•โ•  โ–ˆโ–ˆโ•‘                                    โ•‘
โ•‘   โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘     โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ•šโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—                               โ•‘
โ•‘   โ•šโ•โ•โ•โ•โ•โ•โ•โ•šโ•โ•     โ•šโ•โ•โ•โ•โ•โ•โ• โ•šโ•โ•โ•โ•โ•โ•                               โ•‘
โ•‘                                                                   โ•‘
โ•‘         ๐Ÿ—ƒ๏ธ  SPEC-DRIVEN DB MIGRATION ๐Ÿ—ƒ๏ธ                          โ•‘
โ•‘                                                                   โ•‘
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

๐Ÿ”ฌ STORED PROCS ANALYZED โ†’ ๐Ÿง  BUSINESS RULES EXTRACTED โ†’ ๐Ÿ“ SCHEMA MIGRATED!

MISSION: Reverse-engineer a LEGACY DATABASE BEHEMOTH with Spec2Cloud! Extract 80+ stored procedures, decode 30+ triggers, and migrate to modern cloud โ€” WITHOUT LOSING A SINGLE BUSINESS RULE! ๐Ÿš€๐Ÿ—„๏ธ


๐ŸŽฎ LEVEL SELECT

๐ŸŒพ BUSINESS DOMAIN: GreenHarvest Agricultural Cooperative
๐Ÿ“‚ CATEGORY: Spec-Driven Development
โšก PRIORITY: P3
๐Ÿ› ๏ธ TECH STACK: SQL Server โ€ข PostgreSQL โ€ข Python โ€ข Spec2Cloud
๐Ÿข ORG: EmeaAppGbb


๐Ÿ•น๏ธ PLAYER STATS

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  BEFORE (SQL Server 2012) ๐Ÿ—„๏ธ                โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  ๐Ÿ“Š 120+ tables (decades of schema evolution)โ”‚
โ”‚  ๐Ÿ”ฎ 80+ stored procedures (hidden logic)    โ”‚
โ”‚  โšก 30+ triggers (implicit dependencies)    โ”‚
โ”‚  ๐Ÿงฎ Computed columns (complex formulas)     โ”‚
โ”‚  ๐Ÿ”— Cross-DB references (commodity pricing) โ”‚
โ”‚  ๐Ÿ“… SQL Agent jobs for batch sync           โ”‚
โ”‚  ๐Ÿคท Business rules? Only the DB knows...    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  AFTER (Cloud PostgreSQL) โ˜๏ธโœจ              โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  ๐Ÿ“‹ Complete spec: every table, proc, triggerโ”‚
โ”‚  ๐Ÿง  Business rules extracted & documented   โ”‚
โ”‚  ๐Ÿ˜ Modern PostgreSQL schema                โ”‚
โ”‚  ๐Ÿ Python services (from stored procs)     โ”‚
โ”‚  โœ… Validated migration (100% coverage)     โ”‚
โ”‚  ๐Ÿ“– Living documentation (Spec2Cloud spec)  โ”‚
โ”‚  ๐ŸŽฏ Zero business logic lost!               โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ’ฅ BOSS BATTLES

Defeat these database migration demons:

๐Ÿ‘พ BOSS ๐Ÿ’€ ATTACK PATTERN โš”๏ธ YOUR WEAPON
The Stored Proc Fortress 80+ procedures hiding business logic Spec2Cloud extraction
The Trigger Tangle Implicit execution order dependencies Specification mapping
The Computed Column Chaos Complex formulas everywhere Formula documentation
The Cross-DB Dragon Linked servers and remote queries Spec-driven refactor
The Lost Knowledge "Only Bob knows how this works" Automated reverse engineering
The Validation Void Did we migrate everything? ๐Ÿคท Spec-generated test suite

๐ŸŽฏ QUEST OBJECTIVES

๐Ÿ† Explore Legacy DB โ€” Review schema, run stored procs
๐Ÿ† Schema Analysis โ€” Spec2Cloud extracts tables & relationships
๐Ÿ† Business Rule Extraction โ€” Analyze procs, triggers, UDFs
๐Ÿ† Generate Migration Spec โ€” Complete specification with targets
๐Ÿ† Create Target Schema โ€” PostgreSQL DDL from spec
๐Ÿ† Extract Logic โ€” Python services from stored procedures
๐Ÿ† Migrate Data โ€” Execute data migration scripts
๐Ÿ† Replace Triggers โ€” Event handlers or PostgreSQL triggers
๐Ÿ† Validate โ€” Spec-generated validation queries


๐ŸŽจ ARCADE THEMES

โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘  ๐Ÿ”Š SOUND EFFECTS:                     โ•‘
โ•‘                                        โ•‘
โ•‘  ๐Ÿ”ฌ "STORED PROCS ANALYZED!"           โ•‘
โ•‘  ๐Ÿง  "BUSINESS RULES EXTRACTED!"        โ•‘
โ•‘  ๐Ÿ“ "SCHEMA MIGRATED!"                 โ•‘
โ•‘  ๐Ÿ” "TRIGGER DECODED!"                 โ•‘
โ•‘  ๐Ÿ˜ "POSTGRESQL SCHEMA LIVE!"          โ•‘
โ•‘  โœ… "VALIDATION PASSED!"               โ•‘
โ•‘  ๐ŸŽฏ "ZERO DATA LOSS!"                  โ•‘
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

๐Ÿš€ POWER-UPS UNLOCKED

Complete this migration and gain:

  • ๐Ÿ”ฌ Database Reverse Engineering โ€” Spec2Cloud mastery
  • ๐Ÿง  Business Rule Extraction โ€” From stored procedures
  • ๐Ÿ“‹ Spec-Driven Migration โ€” Spec = plan + acceptance criteria
  • ๐Ÿ˜ PostgreSQL Migration โ€” Modern cloud database
  • ๐Ÿ Stored Proc โ†’ Python โ€” Extract logic to services
  • โšก Trigger Replacement โ€” Event-driven architecture
  • โœ… Migration Validation โ€” Automated completeness checks

โฑ๏ธ SPEEDRUN TIME

Estimated Duration: 5โ€“7 hours โณ

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  ๐Ÿฅ‰ BRONZE:  Schema migrated         โ”‚
โ”‚  ๐Ÿฅˆ SILVER:  +All business rules extractedโ”‚
โ”‚  ๐Ÿฅ‡ GOLD:    +100% validation passingโ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ› ๏ธ STARTER PACK (Prerequisites)

Gear up for migration:

  • โœ… SQL Server experience (T-SQL, stored procedures, triggers)
  • โœ… Basic PostgreSQL knowledge
  • โœ… Python experience (for extracted logic)
  • โœ… Docker Desktop (for SQL Server + PostgreSQL)

๐Ÿ“‚ LOOT TABLE (Key Files)

greenharvest-db/
โ”œโ”€โ”€ Schema/
โ”‚   โ”œโ”€โ”€ Tables/
โ”‚   โ”‚   โ”œโ”€โ”€ CropManagement/        # ๐ŸŒพ 30+ crop tables
โ”‚   โ”‚   โ”œโ”€โ”€ Inventory/             # ๐Ÿ“ฆ 25+ inventory tables
โ”‚   โ”‚   โ”œโ”€โ”€ Members/               # ๐Ÿ‘ฅ 15+ member tables
โ”‚   โ”‚   โ”œโ”€โ”€ Trading/               # ๐Ÿ’ฐ 20+ trading tables
โ”‚   โ”‚   โ””โ”€โ”€ Reference/            # ๐Ÿ“š 30+ reference tables
โ”‚   โ”œโ”€โ”€ StoredProcedures/
โ”‚   โ”‚   โ”œโ”€โ”€ ๐ŸŒฑ CropPlanning/       # Rotation & planning
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“Š Inventory/          # Stock management
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ’ต Pricing/            # Price calculations
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿงฎ Settlement/         # Coop settlements
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“ˆ Reporting/          # Report data
โ”‚   โ”œโ”€โ”€ Triggers/
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ AuditTriggers/      # Change tracking
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ›ก๏ธ  IntegrityTriggers/  # Business rules
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ”„ SyncTriggers/       # Data sync
โ”‚   โ””โ”€โ”€ Functions/
โ”‚       โ”œโ”€โ”€ ๐Ÿงฎ Scalar/             # Calculations
โ”‚       โ””โ”€โ”€ ๐Ÿ“Š TableValued/        # Complex filtering
โ”œโ”€โ”€ Specs/                         # โ† SPEC2CLOUD OUTPUT!
โ”‚   โ”œโ”€โ”€ ๐Ÿ“‹ schema-spec/
โ”‚   โ”œโ”€โ”€ ๐Ÿง  business-rules/
โ”‚   โ”œโ”€โ”€ ๐Ÿ—บ๏ธ  migration-plan/
โ”‚   โ””โ”€โ”€ โœ… validation/
โ””โ”€โ”€ Migration/
    โ”œโ”€โ”€ ๐Ÿ˜ PostgreSQL/             # โ† YOUR TARGET!
    โ”‚   โ”œโ”€โ”€ schema.sql
    โ”‚   โ””โ”€โ”€ data-migration.sql
    โ””โ”€โ”€ ๐Ÿ Python/
        โ””โ”€โ”€ services/              # Extracted logic

๐ŸŒŠ LEVEL PROGRESSION

๐ŸŽฎ BRANCH FLOW

            main (๐Ÿ Complete lab)
              โ”‚
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
 legacy     step-1   step-2   step-3   step-4   step-5
  (๐Ÿ—„๏ธ)        โ†“        โ†“        โ†“        โ†“        โ†“
          Schema   Business  Migration  Target   Validate
          Analysis  Rules    Spec       Impl

Migration Phases:

  1. ๐Ÿ” Schema Analysis โ€” Reverse-engineer 120+ tables
  2. ๐Ÿง  Business Rule Extraction โ€” 80+ stored procs decoded
  3. ๐Ÿ“‹ Migration Spec โ€” Complete specification generated
  4. ๐Ÿ˜ Target Implementation โ€” PostgreSQL + Python services
  5. โœ… Validation โ€” Prove migration completeness

๐Ÿ—ƒ๏ธ DATABASE COMPLEXITY

By The Numbers ๐Ÿ“Š

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  120+ tables                       โ”‚
โ”‚   80+ stored procedures            โ”‚
โ”‚   30+ triggers                     โ”‚
โ”‚   20+ user-defined functions       โ”‚
โ”‚   40+ views (some indexed)         โ”‚
โ”‚  dozens of computed columns        โ”‚
โ”‚  decades of business knowledge ๐Ÿง   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Sample Business Rules ๐ŸŒพ

  • ๐Ÿ”„ Crop rotation calculated by soil type + previous crops
  • ๐ŸŒก๏ธ Planting dates enforced by growing season constraints
  • ๐Ÿ“ Yield per acre computed from harvest data
  • โš–๏ธ Unit conversions (bushels โ†” tonnes โ†” hundredweight)
  • ๐Ÿ’ฐ Settlement calculations based on grade/quality matrices

๐ŸŽฏ ACHIEVEMENT UNLOCKED CONDITIONS

  • โœ… SQL Server DB created with 120+ tables
  • โœ… Stored procedures execute with sample data
  • โœ… Triggers fire and enforce business rules
  • โœ… Spec2Cloud generates complete schema spec
  • โœ… Business rules extracted from stored procs
  • โœ… PostgreSQL schema created from spec
  • โœ… Python services replicate stored proc logic
  • โœ… Data migration completes successfully
  • โœ… Validation queries pass (100% coverage)
  • โœ… APPMODLAB.md complete with frontmatter

๐ŸŒŸ FINAL BOSS: THE VALIDATION SUITE

โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘                                              โ•‘
โ•‘   Run spec-generated validation tests:      โ•‘
โ•‘                                              โ•‘
โ•‘   โœ… Table count matches                    โ•‘
โ•‘   โœ… Row counts match                       โ•‘
โ•‘   โœ… Computed values match                  โ•‘
โ•‘   โœ… Business logic produces same results   โ•‘
โ•‘   โœ… Triggers enforce same rules            โ•‘
โ•‘                                              โ•‘
โ•‘   100% PASS = MIGRATION COMPLETE! ๐Ÿ†        โ•‘
โ•‘                                              โ•‘
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

๐ŸŽŠ VICTORY SCREEN

YOU DEFEATED:

  • ๐Ÿ—„๏ธ Legacy SQL Server 2012
  • ๐Ÿ”ฎ Hidden business logic in stored procs
  • โšก Implicit trigger dependencies
  • ๐Ÿงฎ Undocumented computed columns
  • ๐Ÿคท "Tribal knowledge" syndrome

YOU UNLOCKED:

  • ๐Ÿ“‹ Complete database specification
  • ๐Ÿง  Documented business rules
  • ๐Ÿ˜ Modern PostgreSQL schema
  • ๐Ÿ Extracted Python services
  • โœ… Validated, lossless migration
  • ๐Ÿ“– Living documentation!
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                                         โ”‚
โ”‚   ๐ŸŽฎ DATABASE MIGRATION MASTERED ๐ŸŽฎ     โ”‚
โ”‚                                         โ”‚
โ”‚   From chaos to clarity! ๐ŸŒŸ             โ”‚
โ”‚                                         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐ŸŽต Now playing: Data Dreams by Spec Master ๐Ÿ’ฟ
๐Ÿ”ฌ Status: 120 TABLES ANALYZED โ€” ZERO BUSINESS RULES LOST!

๐Ÿ“– Full lab guide: See APPMODLAB.md for spec-driven migration walkthrough
๐Ÿ† Credits: Built with ๐Ÿ—ƒ๏ธ by EmeaAppGbb


๐Ÿ“‹ SOLUTION WALKTHROUGH

Complete step-by-step execution using GitHub Copilot CLI (gh copilot).
All outputs are on the solution-final branch under assets/outputs/.

Setup

cd C:\code\gbb\labs\appmodlab-spec-driven-database-migration
git checkout main && git checkout -b solution-final
New-Item -ItemType Directory -Force -Path assets/outputs

Step 01 โ€” Explore Legacy Database

Tag: step-01-explore-legacy-db ยท Output: assets/outputs/step-01-explore-legacy-db.md

gh copilot -- -p "Analyze the GreenHarvest Agricultural Co-op legacy SQL Server database in this repository. Explore Schema/ directory (Tables, StoredProcedures, Functions, Triggers, Views), Data/ (SeedData, SampleData), Specs/, and Migration/ folders. Produce a comprehensive analysis document at assets/outputs/step-01-explore-legacy-db.md covering: 1) Complete inventory of all database objects (6 tables across CropManagement, Members, Inventory, Trading schemas), 2) Column details with data types, constraints, defaults, indexes, 3) Foreign key relationships and referential integrity map, 4) Stored procedures with business rule extraction, 5) Scalar function fn_CalculateYieldBushels with conversion factors, 6) Trigger tr_AuditHarvestChanges behavior and audit log structure, 7) View vw_FieldProductivity definition and joins, 8) Data patterns from seed/sample data, 9) SQL Server-specific features (GEOGRAPHY, IDENTITY, MONEY, computed columns, PERSISTED, GETDATE, SUSER_SNAME, FOR JSON AUTO)." --allow-all-tools --yolo 2>&1 | Tee-Object -FilePath "assets/outputs/step-01.txt"
git add assets/outputs/step-01* && git commit -m "Step 01: Explore Legacy Database" && git tag step-01-explore-legacy-db

Step 02 โ€” Generate Database Specification

Tag: step-02-generate-db-spec ยท Output: assets/outputs/step-02-database-specification.md

gh copilot -- -p "Generate a comprehensive database specification document for the GreenHarvest Agricultural Co-op SQL Server database. Read all files in Schema/, Data/, and Specs/. Create a detailed spec at assets/outputs/step-02-database-specification.md with: complete table catalog (every column, type, constraint), PK/FK relationships, index inventory, stored procedure signatures with business rules, scalar function spec, trigger spec, view definition, cross-reference matrix, and SQL Server-specific feature catalog." --allow-all-tools --yolo 2>&1 | Tee-Object -FilePath "assets/outputs/step-02.txt"
git add assets/outputs/step-02* && git commit -m "Step 02: Generate Database Specification" && git tag step-02-generate-db-spec

Step 03 โ€” Analyze Migration Complexity

Tag: step-03-analyze-complexity ยท Output: assets/outputs/step-03-migration-complexity.md

gh copilot -- -p "Analyze the migration complexity for migrating the GreenHarvest SQL Server database to PostgreSQL. Create assets/outputs/step-03-migration-complexity.md with: per-table/proc complexity ratings (Low/Medium/High/Critical), SQL Server to PostgreSQL feature mapping table, identified blockers and risks, effort estimation per object, recommended migration order, and risk mitigation strategies." --allow-all-tools --yolo 2>&1 | Tee-Object -FilePath "assets/outputs/step-03.txt"
git add assets/outputs/step-03* && git commit -m "Step 03: Analyze Migration Complexity" && git tag step-03-analyze-complexity

Step 04 โ€” Design Target Schema

Tag: step-04-design-target-schema ยท Output: assets/outputs/step-04-target-schema.md

gh copilot -- -p "Design the modern target PostgreSQL schema for the GreenHarvest database migration. Create assets/outputs/step-04-target-schema.md with: design principles, schema mapping to snake_case, complete target DDL for all 6 tables, data type conversion table, PL/pgSQL functions, PostgreSQL trigger functions, view definitions, index strategy, and PostGIS extension requirements." --allow-all-tools --yolo 2>&1 | Tee-Object -FilePath "assets/outputs/step-04.txt"
git add assets/outputs/step-04* && git commit -m "Step 04: Design Target Schema" && git tag step-04-design-target-schema

Step 05 โ€” Generate Migration Scripts

Tag: step-05-migration-scripts ยท Output: assets/outputs/step-05-migration-scripts.md

gh copilot -- -p "Generate complete migration scripts for the GreenHarvest SQL Server to PostgreSQL migration. Create assets/outputs/step-05-migration-scripts.md with: DDL migration (CREATE statements, indexes, constraints, PostGIS), PL/pgSQL functions, audit trigger, view creation, DML seed data conversion, stored procedure migration to PL/pgSQL, rollback scripts, and execution order." --allow-all-tools --yolo 2>&1 | Tee-Object -FilePath "assets/outputs/step-05.txt"
git add assets/outputs/step-05* && git commit -m "Step 05: Generate Migration Scripts" && git tag step-05-migration-scripts

Step 06 โ€” Create Data Validation

Tag: step-06-data-validation ยท Output: assets/outputs/step-06-data-validation.md

gh copilot -- -p "Create comprehensive data validation queries for the GreenHarvest database migration. Create assets/outputs/step-06-data-validation.md with: row count validation, schema validation, computed column verification, FK integrity checks, index existence verification, stored procedure output comparison, trigger behavior validation, view output comparison, seed data verification, and edge case tests." --allow-all-tools --yolo 2>&1 | Tee-Object -FilePath "assets/outputs/step-06.txt"
git add assets/outputs/step-06* && git commit -m "Step 06: Create Data Validation" && git tag step-06-data-validation

Step 07 โ€” Document Migration Plan

Tag: step-07-migration-plan ยท Output: assets/outputs/step-07-migration-plan.md

gh copilot -- -p "Create a comprehensive migration plan for the GreenHarvest SQL Server to PostgreSQL migration. Create assets/outputs/step-07-migration-plan.md with: executive summary, pre-migration phase (docker-compose setup), migration phases with timeline, rollback procedures, risk register, validation checklist, communication plan, post-migration tasks, and go/no-go decision criteria." --allow-all-tools --yolo 2>&1 | Tee-Object -FilePath "assets/outputs/step-07.txt"
git add assets/outputs/step-07* && git commit -m "Step 07: Document Migration Plan" && git tag step-07-migration-plan

Push

git push origin solution-final --tags

Output Summary

Step Output File Description
01 step-01-explore-legacy-db.md Legacy database exploration and analysis
02 step-02-database-specification.md Comprehensive database specification
03 step-03-migration-complexity.md Migration complexity assessment
04 step-04-target-schema.md Target PostgreSQL schema design
05 step-05-migration-scripts.md DDL + DML migration scripts
06 step-06-data-validation.md Data validation queries and procedures
07 step-07-migration-plan.md Full migration plan with rollback

๐ŸŒŒ May your schemas be normalized and your migrations be lossless! ๐ŸŒŒ

About

๐Ÿ•น๏ธ AppMod Lab: Spec-driven database migration with business rule extraction โ€” Insurance policy system

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors