icdev 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- icdev/__init__.py +18 -0
- icdev/_paths.py +85 -0
- icdev/_version.py +3 -0
- icdev/data/__init__.py +1 -0
- icdev/data/args/__init__.py +1 -0
- icdev/data/args/agent_authority.yaml +61 -0
- icdev/data/args/agent_config.yaml +355 -0
- icdev/data/args/agentic_fitness.yaml +31 -0
- icdev/data/args/ai_governance_config.yaml +137 -0
- icdev/data/args/atlas_critique_config.yaml +66 -0
- icdev/data/args/bedrock_models.yaml +63 -0
- icdev/data/args/cicd_config.yaml +82 -0
- icdev/data/args/classification_config.yaml +232 -0
- icdev/data/args/cli_config.yaml +154 -0
- icdev/data/args/cloud_config.yaml +63 -0
- icdev/data/args/code_pattern_config.yaml +151 -0
- icdev/data/args/code_quality_config.yaml +47 -0
- icdev/data/args/companion_registry.yaml +202 -0
- icdev/data/args/context_config.yaml +82 -0
- icdev/data/args/csp_monitor_config.yaml +268 -0
- icdev/data/args/cui_markings.yaml +35 -0
- icdev/data/args/db_config.yaml +40 -0
- icdev/data/args/deployment_profiles.yaml +248 -0
- icdev/data/args/dev_profile_config.yaml +144 -0
- icdev/data/args/devsecops_config.yaml +286 -0
- icdev/data/args/endpoint_security_config.yaml +137 -0
- icdev/data/args/extension_config.yaml +79 -0
- icdev/data/args/file_access_tiers.yaml +88 -0
- icdev/data/args/framework_registry.yaml +415 -0
- icdev/data/args/innovation_config.yaml +431 -0
- icdev/data/args/installation_manifest.yaml +1087 -0
- icdev/data/args/llm_config.yaml +495 -0
- icdev/data/args/maintenance_config.yaml +55 -0
- icdev/data/args/memory_config.yaml +83 -0
- icdev/data/args/monitoring_config.yaml +127 -0
- icdev/data/args/mosa_config.yaml +190 -0
- icdev/data/args/nlq_config.yaml +35 -0
- icdev/data/args/observability_config.yaml +39 -0
- icdev/data/args/observability_tracing_config.yaml +170 -0
- icdev/data/args/oscal_tools_config.yaml +43 -0
- icdev/data/args/owasp_agentic_config.yaml +171 -0
- icdev/data/args/phase_registry.yaml +618 -0
- icdev/data/args/project_defaults.yaml +235 -0
- icdev/data/args/prompt_chains.yaml +163 -0
- icdev/data/args/resilience_config.yaml +50 -0
- icdev/data/args/ricoas_config.yaml +191 -0
- icdev/data/args/role_personas.yaml +362 -0
- icdev/data/args/scaling_config.yaml +176 -0
- icdev/data/args/security_gates.yaml +685 -0
- icdev/data/args/skill_injection_config.yaml +322 -0
- icdev/data/args/spec_config.yaml +53 -0
- icdev/data/args/supply_chain_config.yaml +76 -0
- icdev/data/args/translation_config.yaml +228 -0
- icdev/data/args/workflow_templates/ato_acceleration.yaml +54 -0
- icdev/data/args/workflow_templates/build_deploy.yaml +63 -0
- icdev/data/args/workflow_templates/full_compliance.yaml +43 -0
- icdev/data/args/workflow_templates/security_hardening.yaml +55 -0
- icdev/data/args/worktree_config.yaml +34 -0
- icdev/data/args/zta_config.yaml +247 -0
- icdev/data/context/__init__.py +1 -0
- icdev/data/context/agent/__init__.py +1 -0
- icdev/data/context/agent/response_schemas/__init__.py +1 -0
- icdev/data/context/agent/response_schemas/debate_position.json +46 -0
- icdev/data/context/agent/response_schemas/fitness_scorecard.json +74 -0
- icdev/data/context/agent/response_schemas/review_decision.json +39 -0
- icdev/data/context/agent/response_schemas/task_decomposition.json +82 -0
- icdev/data/context/agent/response_schemas/veto_decision.json +40 -0
- icdev/data/context/agentic/__init__.py +1 -0
- icdev/data/context/agentic/architecture_patterns.md +269 -0
- icdev/data/context/agentic/capability_registry.yaml +202 -0
- icdev/data/context/agentic/csp_mcp_registry.yaml +280 -0
- icdev/data/context/agentic/fitness_rubric.md +56 -0
- icdev/data/context/agentic/governance_baseline.md +205 -0
- icdev/data/context/ci/__init__.py +1 -0
- icdev/data/context/ci/worktree_templates.json +44 -0
- icdev/data/context/cloud/__init__.py +1 -0
- icdev/data/context/cloud/csp_service_registry.json +739 -0
- icdev/data/context/compliance/__init__.py +1 -0
- icdev/data/context/compliance/atlas_mitigations.json +293 -0
- icdev/data/context/compliance/atlas_techniques.json +833 -0
- icdev/data/context/compliance/cisa_sbd_requirements.json +432 -0
- icdev/data/context/compliance/cjis_security_policy.json +522 -0
- icdev/data/context/compliance/cmmc_practices.json +2494 -0
- icdev/data/context/compliance/cmmc_report_template.md +142 -0
- icdev/data/context/compliance/cnssi_1253_overlay.json +109 -0
- icdev/data/context/compliance/control_crosswalk.json +1914 -0
- icdev/data/context/compliance/control_families/__init__.py +1 -0
- icdev/data/context/compliance/csp_certifications.json +251 -0
- icdev/data/context/compliance/cssp_report_template.md +193 -0
- icdev/data/context/compliance/cui_templates/__init__.py +1 -0
- icdev/data/context/compliance/cui_templates/banner_block.txt +4 -0
- icdev/data/context/compliance/cui_templates/code_header.txt +8 -0
- icdev/data/context/compliance/cui_templates/document_template.md +35 -0
- icdev/data/context/compliance/data_type_framework_map.json +321 -0
- icdev/data/context/compliance/data_type_registry.json +147 -0
- icdev/data/context/compliance/dod_cssp_8530.json +463 -0
- icdev/data/context/compliance/eu_ai_act_annex_iii.json +108 -0
- icdev/data/context/compliance/export_templates/__init__.py +1 -0
- icdev/data/context/compliance/export_templates/emass_controls.csv.j2 +4 -0
- icdev/data/context/compliance/export_templates/evidence_package.md.j2 +39 -0
- icdev/data/context/compliance/export_templates/executive_summary.md.j2 +55 -0
- icdev/data/context/compliance/export_templates/poam_tracking.csv.j2 +4 -0
- icdev/data/context/compliance/fedramp_20x_ksi_schemas.json +133 -0
- icdev/data/context/compliance/fedramp_high_baseline.json +4370 -0
- icdev/data/context/compliance/fedramp_moderate_baseline.json +2183 -0
- icdev/data/context/compliance/fedramp_report_template.md +181 -0
- icdev/data/context/compliance/fips_200_areas.json +362 -0
- icdev/data/context/compliance/gao_ai_accountability.json +262 -0
- icdev/data/context/compliance/hipaa_security_rule.json +720 -0
- icdev/data/context/compliance/hitrust_csf_v11.json +930 -0
- icdev/data/context/compliance/impact_level_profiles.json +251 -0
- icdev/data/context/compliance/incident_response_template.md +1110 -0
- icdev/data/context/compliance/iso27001_2022_controls.json +750 -0
- icdev/data/context/compliance/iso27001_nist_bridge.json +382 -0
- icdev/data/context/compliance/iso42001_controls.json +254 -0
- icdev/data/context/compliance/ivv_checklist_template.md +80 -0
- icdev/data/context/compliance/ivv_report_template.md +116 -0
- icdev/data/context/compliance/ivv_requirements.json +372 -0
- icdev/data/context/compliance/mosa_crosswalk.json +327 -0
- icdev/data/context/compliance/mosa_framework.json +250 -0
- icdev/data/context/compliance/narrative_templates/AC.md.j2 +101 -0
- icdev/data/context/compliance/narrative_templates/AU.md.j2 +106 -0
- icdev/data/context/compliance/narrative_templates/IA.md.j2 +104 -0
- icdev/data/context/compliance/narrative_templates/SC.md.j2 +102 -0
- icdev/data/context/compliance/narrative_templates/SI.md.j2 +111 -0
- icdev/data/context/compliance/narrative_templates/__init__.py +1 -0
- icdev/data/context/compliance/narrative_templates/default.md.j2 +50 -0
- icdev/data/context/compliance/narrative_templates/executive_summary.j2 +27 -0
- icdev/data/context/compliance/narrative_templates/poam_milestone.j2 +19 -0
- icdev/data/context/compliance/narrative_templates/ssp_section.j2 +11 -0
- icdev/data/context/compliance/nist_800_171_controls.json +1552 -0
- icdev/data/context/compliance/nist_800_207_crosswalk.json +399 -0
- icdev/data/context/compliance/nist_800_207_zta.json +258 -0
- icdev/data/context/compliance/nist_800_53.json +324 -0
- icdev/data/context/compliance/nist_ai_600_1_genai.json +326 -0
- icdev/data/context/compliance/nist_ai_rmf.json +206 -0
- icdev/data/context/compliance/nist_sp_800_60_types.json +1667 -0
- icdev/data/context/compliance/omb_m25_21_high_impact_ai.json +248 -0
- icdev/data/context/compliance/omb_m26_04_unbiased_ai.json +262 -0
- icdev/data/context/compliance/owasp_agentic_asi.json +133 -0
- icdev/data/context/compliance/owasp_agentic_threats.json +285 -0
- icdev/data/context/compliance/owasp_llm_top10.json +274 -0
- icdev/data/context/compliance/pci_dss_v4.json +510 -0
- icdev/data/context/compliance/poam_template.md +117 -0
- icdev/data/context/compliance/safeai_controls.json +512 -0
- icdev/data/context/compliance/sbd_report_template.md +77 -0
- icdev/data/context/compliance/siem_config_templates/__init__.py +1 -0
- icdev/data/context/compliance/siem_config_templates/filebeat.yml +213 -0
- icdev/data/context/compliance/siem_config_templates/log_sources.json +208 -0
- icdev/data/context/compliance/soc2_trust_criteria.json +661 -0
- icdev/data/context/compliance/ssp_template.md +432 -0
- icdev/data/context/compliance/stig_templates/__init__.py +1 -0
- icdev/data/context/compliance/stig_templates/webapp_stig.json +139 -0
- icdev/data/context/compliance/xai_requirements.json +108 -0
- icdev/data/context/dashboard/__init__.py +1 -0
- icdev/data/context/dashboard/nlq_examples.json +50 -0
- icdev/data/context/dashboard/schema_descriptions.json +23 -0
- icdev/data/context/integration/__init__.py +1 -0
- icdev/data/context/integration/approval_workflows.json +32 -0
- icdev/data/context/integration/gitlab_field_mappings.json +33 -0
- icdev/data/context/integration/jira_field_mappings.json +32 -0
- icdev/data/context/integration/reqif_export_schema.json +23 -0
- icdev/data/context/integration/servicenow_field_mappings.json +22 -0
- icdev/data/context/languages/__init__.py +1 -0
- icdev/data/context/languages/framework_patterns.json +205 -0
- icdev/data/context/languages/language_registry.json +279 -0
- icdev/data/context/llm/__init__.py +1 -0
- icdev/data/context/llm/example_provider.py +86 -0
- icdev/data/context/mbse/__init__.py +1 -0
- icdev/data/context/mbse/des_report_template.md +162 -0
- icdev/data/context/mbse/des_requirements.json +411 -0
- icdev/data/context/mbse/digital_thread_patterns.json +403 -0
- icdev/data/context/mbse/reqif_schema.json +280 -0
- icdev/data/context/mbse/sysml_element_types.json +432 -0
- icdev/data/context/modernization/__init__.py +1 -0
- icdev/data/context/modernization/db_type_mappings.json +148 -0
- icdev/data/context/modernization/decomposition_patterns.json +284 -0
- icdev/data/context/modernization/framework_migration_patterns.json +359 -0
- icdev/data/context/modernization/migration_report_template.md +168 -0
- icdev/data/context/modernization/seven_rs_catalog.json +369 -0
- icdev/data/context/modernization/version_upgrade_rules.json +279 -0
- icdev/data/context/oscal/NIST_SP-800-53_rev5_catalog.json +254987 -0
- icdev/data/context/oscal/README.md +43 -0
- icdev/data/context/patterns/__init__.py +1 -0
- icdev/data/context/profiles/__init__.py +1 -0
- icdev/data/context/profiles/dod_baseline_v1.yaml +145 -0
- icdev/data/context/profiles/fedramp_baseline_v1.yaml +143 -0
- icdev/data/context/profiles/financial_baseline_v1.yaml +142 -0
- icdev/data/context/profiles/healthcare_baseline_v1.yaml +135 -0
- icdev/data/context/profiles/law_enforcement_v1.yaml +129 -0
- icdev/data/context/profiles/startup_v1.yaml +134 -0
- icdev/data/context/requirements/__init__.py +1 -0
- icdev/data/context/requirements/ambiguity_patterns.json +97 -0
- icdev/data/context/requirements/boundary_impact_rules.json +123 -0
- icdev/data/context/requirements/default_constitutions.json +67 -0
- icdev/data/context/requirements/document_extraction_rules.json +58 -0
- icdev/data/context/requirements/gap_patterns.json +108 -0
- icdev/data/context/requirements/readiness_rubric.json +78 -0
- icdev/data/context/requirements/red_alternative_patterns.json +210 -0
- icdev/data/context/requirements/safe_templates.json +72 -0
- icdev/data/context/requirements/spec_quality_checklist.json +122 -0
- icdev/data/context/simulation/__init__.py +1 -0
- icdev/data/context/simulation/architecture_patterns.json +36 -0
- icdev/data/context/simulation/coa_templates.json +38 -0
- icdev/data/context/simulation/cost_models.json +23 -0
- icdev/data/context/simulation/risk_categories.json +46 -0
- icdev/data/context/supply_chain/__init__.py +1 -0
- icdev/data/context/supply_chain/isa_templates.json +129 -0
- icdev/data/context/supply_chain/nist_800_161_controls.json +247 -0
- icdev/data/context/supply_chain/scrm_risk_matrix.json +147 -0
- icdev/data/context/templates/__init__.py +1 -0
- icdev/data/context/templates/ansible/__init__.py +1 -0
- icdev/data/context/templates/ansible/playbooks/__init__.py +1 -0
- icdev/data/context/templates/ansible/roles/__init__.py +1 -0
- icdev/data/context/templates/gitlab_ci/__init__.py +1 -0
- icdev/data/context/templates/grafana/__init__.py +1 -0
- icdev/data/context/templates/kubernetes/__init__.py +1 -0
- icdev/data/context/templates/project/__init__.py +1 -0
- icdev/data/context/templates/project/api/__init__.py +1 -0
- icdev/data/context/templates/project/cli/__init__.py +1 -0
- icdev/data/context/templates/project/data_pipeline/__init__.py +1 -0
- icdev/data/context/templates/project/iac/__init__.py +1 -0
- icdev/data/context/templates/project/javascript_frontend/__init__.py +1 -0
- icdev/data/context/templates/project/javascript_frontend/src/__init__.py +1 -0
- icdev/data/context/templates/project/javascript_frontend/tests/__init__.py +1 -0
- icdev/data/context/templates/project/microservice/__init__.py +1 -0
- icdev/data/context/templates/project/python_backend/__init__.py +1 -0
- icdev/data/context/templates/project/python_backend/src/__init__.py +1 -0
- icdev/data/context/templates/project/python_backend/tests/__init__.py +1 -0
- icdev/data/context/templates/project/python_backend/tests/features/__init__.py +1 -0
- icdev/data/context/templates/project/python_backend/tests/steps/__init__.py +1 -0
- icdev/data/context/templates/terraform/__init__.py +1 -0
- icdev/data/context/templates/terraform/govcloud_base/__init__.py +1 -0
- icdev/data/context/templates/terraform/modules/__init__.py +1 -0
- icdev/data/context/tone/__init__.py +1 -0
- icdev/data/context/translation/dependency_mappings.json +186 -0
- icdev/data/context/translation/type_mappings.json +149 -0
- icdev/data/docs/README.md +187 -0
- icdev/data/docs/__init__.py +1 -0
- icdev/data/docs/admin/gateway-guide.md +338 -0
- icdev/data/docs/admin/marketplace-guide.md +396 -0
- icdev/data/docs/admin/monitoring-guide.md +509 -0
- icdev/data/docs/architecture/compliance-framework.md +764 -0
- icdev/data/docs/architecture/database-schema.md +689 -0
- icdev/data/docs/architecture/gotcha-framework.md +518 -0
- icdev/data/docs/architecture/multi-agent-system.md +603 -0
- icdev/data/docs/dx/README.md +106 -0
- icdev/data/docs/dx/__init__.py +1 -0
- icdev/data/docs/dx/ci-cd-integration.md +378 -0
- icdev/data/docs/dx/claude-code-guide.md +213 -0
- icdev/data/docs/dx/companion-guide.md +232 -0
- icdev/data/docs/dx/dev-profiles.md +309 -0
- icdev/data/docs/dx/icdev-yaml-spec.md +219 -0
- icdev/data/docs/dx/integration-tiers.md +279 -0
- icdev/data/docs/dx/llm-routing-guide.md +456 -0
- icdev/data/docs/dx/quickstart.md +192 -0
- icdev/data/docs/dx/sdk-reference.md +356 -0
- icdev/data/docs/dx/unified-mcp-setup.md +525 -0
- icdev/data/docs/features/__init__.py +1 -0
- icdev/data/docs/features/phase-01-gotcha-framework.md +249 -0
- icdev/data/docs/features/phase-02-atlas-build-workflow.md +223 -0
- icdev/data/docs/features/phase-03-tdd-bdd-testing.md +261 -0
- icdev/data/docs/features/phase-04-nist-compliance.md +255 -0
- icdev/data/docs/features/phase-05-security-scanning.md +229 -0
- icdev/data/docs/features/phase-06-infrastructure-deployment.md +288 -0
- icdev/data/docs/features/phase-07-code-review-gates.md +276 -0
- icdev/data/docs/features/phase-08-self-healing.md +223 -0
- icdev/data/docs/features/phase-09-monitoring-observability.md +230 -0
- icdev/data/docs/features/phase-10-dashboard-web-ui.md +218 -0
- icdev/data/docs/features/phase-11-multi-agent-architecture.md +272 -0
- icdev/data/docs/features/phase-12-integration-testing.md +228 -0
- icdev/data/docs/features/phase-13-cicd-integration.md +257 -0
- icdev/data/docs/features/phase-14-secure-by-design-ivv.md +240 -0
- icdev/data/docs/features/phase-15-maintenance-audit.md +192 -0
- icdev/data/docs/features/phase-16-ato-acceleration.md +228 -0
- icdev/data/docs/features/phase-17-multi-framework-compliance.md +223 -0
- icdev/data/docs/features/phase-18-mbse-integration.md +242 -0
- icdev/data/docs/features/phase-19-agentic-generation.md +202 -0
- icdev/data/docs/features/phase-20-fips-security-categorization.md +198 -0
- icdev/data/docs/features/phase-21-saas-multi-tenancy.md +273 -0
- icdev/data/docs/features/phase-22-federated-gotcha-marketplace.md +242 -0
- icdev/data/docs/features/phase-23-universal-compliance-platform.md +238 -0
- icdev/data/docs/features/phase-24-devsecops-pipeline-security.md +198 -0
- icdev/data/docs/features/phase-25-zero-trust-architecture.md +220 -0
- icdev/data/docs/features/phase-26-dod-mosa.md +205 -0
- icdev/data/docs/features/phase-27-cli-capabilities.md +222 -0
- icdev/data/docs/features/phase-28-remote-command-gateway.md +235 -0
- icdev/data/docs/features/phase-29-proactive-monitoring.md +212 -0
- icdev/data/docs/features/phase-30-dashboard-auth.md +215 -0
- icdev/data/docs/features/phase-31-dashboard-ux-low-impact.md +188 -0
- icdev/data/docs/features/phase-32-dashboard-ux-medium-impact.md +223 -0
- icdev/data/docs/features/phase-33-modular-installation.md +218 -0
- icdev/data/docs/features/phase-34-dev-profiles.md +239 -0
- icdev/data/docs/features/phase-35-innovation-engine.md +257 -0
- icdev/data/docs/features/phase-36-evolutionary-intelligence.md +351 -0
- icdev/data/docs/features/phase-37-mitre-atlas-integration.md +485 -0
- icdev/data/docs/features/phase-38-cloud-agnostic-architecture.md +1033 -0
- icdev/data/docs/features/phase-39-observability-operations.md +178 -0
- icdev/data/docs/features/phase-40-nlq-compliance-queries.md +176 -0
- icdev/data/docs/features/phase-41-parallel-cicd.md +169 -0
- icdev/data/docs/features/phase-42-framework-planning.md +177 -0
- icdev/data/docs/features/phase-43-cross-language-translation.md +225 -0
- icdev/data/docs/features/phase-44-innovation-adaptation.md +227 -0
- icdev/data/docs/features/phase-45-owasp-agentic-security.md +239 -0
- icdev/data/docs/features/phase-46-observability-traceability-xai.md +240 -0
- icdev/data/docs/features/phase-47-unified-mcp-gateway.md +257 -0
- icdev/data/docs/features/phase-48-ai-transparency.md +203 -0
- icdev/data/docs/features/phase-49-ai-accountability.md +243 -0
- icdev/data/docs/features/phase-50-ai-governance-intake-chat.md +195 -0
- icdev/data/docs/features/phase-51-unified-chat-dashboard.md +240 -0
- icdev/data/docs/features/phase-52-code-intelligence.md +244 -0
- icdev/data/docs/features/phase-53-fedramp-20x-owasp-asi.md +359 -0
- icdev/data/docs/features/phase-54-slsa-swft-orchestration.md +379 -0
- icdev/data/docs/features/phase-55-a2a-v03-mcp-oauth.md +322 -0
- icdev/data/docs/features/phase-56-evidence-lineage.md +352 -0
- icdev/data/docs/features/phase-57-eu-ai-act-iron-bank.md +319 -0
- icdev/data/docs/features/phase-58-creative-engine.md +370 -0
- icdev/data/docs/features/phase-59-govcon-intelligence.md +535 -0
- icdev/data/docs/features/phase-60-cpmp.md +528 -0
- icdev/data/docs/features/phase-61-orchestration-improvements.md +534 -0
- icdev/data/docs/operations/dashboard-guide.md +354 -0
- icdev/data/docs/operations/deployment-guide.md +556 -0
- icdev/data/docs/operations/saas-admin-guide.md +439 -0
- icdev/data/docs/operations/security-operations-guide.md +733 -0
- icdev/data/docs/runbooks/backup-restore.md +412 -0
- icdev/data/docs/runbooks/troubleshooting.md +499 -0
- icdev/data/features/__init__.py +1 -0
- icdev/data/features/cicd_integration.feature +41 -0
- icdev/data/features/compliance_gates.feature +46 -0
- icdev/data/features/dashboard.feature +72 -0
- icdev/data/features/environment.py +25 -0
- icdev/data/features/project_management.feature +32 -0
- icdev/data/features/requirements_intake.feature +42 -0
- icdev/data/features/saas_platform.feature +53 -0
- icdev/data/features/security_scanning.feature +36 -0
- icdev/data/features/steps/__init__.py +1 -0
- icdev/data/features/steps/cicd_steps.py +465 -0
- icdev/data/features/steps/compliance_steps.py +308 -0
- icdev/data/features/steps/dashboard_steps.py +88 -0
- icdev/data/features/steps/project_steps.py +126 -0
- icdev/data/features/steps/requirements_intake_steps.py +689 -0
- icdev/data/features/steps/saas_platform_steps.py +572 -0
- icdev/data/features/steps/security_steps.py +236 -0
- icdev/data/features/steps/testing_steps.py +226 -0
- icdev/data/features/testing_pipeline.feature +42 -0
- icdev/data/goals/__init__.py +1 -0
- icdev/data/goals/agent_management.md +144 -0
- icdev/data/goals/agentic_generation.md +345 -0
- icdev/data/goals/agentic_threat_model.md +309 -0
- icdev/data/goals/ai_accountability.md +90 -0
- icdev/data/goals/ai_governance_intake.md +132 -0
- icdev/data/goals/ai_transparency.md +76 -0
- icdev/data/goals/atlas_integration.md +405 -0
- icdev/data/goals/ato_acceleration.md +139 -0
- icdev/data/goals/boundary_supply_chain.md +206 -0
- icdev/data/goals/build_app.md +544 -0
- icdev/data/goals/cicd_integration.md +86 -0
- icdev/data/goals/claude_dir_maintenance.md +77 -0
- icdev/data/goals/cli_capabilities.md +340 -0
- icdev/data/goals/cloud_agnostic.md +312 -0
- icdev/data/goals/code_intelligence.md +197 -0
- icdev/data/goals/code_review.md +94 -0
- icdev/data/goals/compliance_workflow.md +858 -0
- icdev/data/goals/continuous_harmonization.md +140 -0
- icdev/data/goals/cross_language_translation.md +171 -0
- icdev/data/goals/dashboard.md +142 -0
- icdev/data/goals/deploy_workflow.md +390 -0
- icdev/data/goals/devsecops_workflow.md +408 -0
- icdev/data/goals/evolutionary_intelligence.md +305 -0
- icdev/data/goals/external_integration.md +113 -0
- icdev/data/goals/framework_planning.md +63 -0
- icdev/data/goals/init_project.md +235 -0
- icdev/data/goals/innovation_engine.md +199 -0
- icdev/data/goals/integration_testing.md +189 -0
- icdev/data/goals/maintenance_audit.md +196 -0
- icdev/data/goals/manifest.md +56 -0
- icdev/data/goals/mbse_integration.md +504 -0
- icdev/data/goals/modernization_workflow.md +618 -0
- icdev/data/goals/monitoring.md +126 -0
- icdev/data/goals/mosa_workflow.md +463 -0
- icdev/data/goals/multi_agent_orchestration.md +68 -0
- icdev/data/goals/nlq_compliance.md +63 -0
- icdev/data/goals/observability.md +64 -0
- icdev/data/goals/observability_traceability_xai.md +154 -0
- icdev/data/goals/owasp_agentic_security.md +395 -0
- icdev/data/goals/parallel_cicd.md +61 -0
- icdev/data/goals/requirements_intake.md +213 -0
- icdev/data/goals/sbd_ivv_workflow.md +195 -0
- icdev/data/goals/security_categorization.md +133 -0
- icdev/data/goals/security_scan.md +381 -0
- icdev/data/goals/self_healing.md +120 -0
- icdev/data/goals/simulation_engine.md +111 -0
- icdev/data/goals/tdd_workflow.md +403 -0
- icdev/data/goals/zero_trust_architecture.md +403 -0
- icdev/data/hardprompts/__init__.py +1 -0
- icdev/data/hardprompts/agent/__init__.py +1 -0
- icdev/data/hardprompts/agent/agentic_architect.md +100 -0
- icdev/data/hardprompts/agent/debate_prompt.md +32 -0
- icdev/data/hardprompts/agent/fitness_evaluation.md +48 -0
- icdev/data/hardprompts/agent/governance_review.md +214 -0
- icdev/data/hardprompts/agent/reviewer_prompt.md +34 -0
- icdev/data/hardprompts/agent/skill_design.md +172 -0
- icdev/data/hardprompts/agent/task_decomposition.md +275 -0
- icdev/data/hardprompts/agent/veto_check_prompt.md +33 -0
- icdev/data/hardprompts/architect/__init__.py +1 -0
- icdev/data/hardprompts/architect/api_design.md +283 -0
- icdev/data/hardprompts/architect/data_model.md +277 -0
- icdev/data/hardprompts/architect/system_design.md +180 -0
- icdev/data/hardprompts/builder/__init__.py +1 -0
- icdev/data/hardprompts/builder/code_generation.md +59 -0
- icdev/data/hardprompts/builder/refactor.md +58 -0
- icdev/data/hardprompts/builder/scaffold_project.md +69 -0
- icdev/data/hardprompts/builder/test_generation.md +87 -0
- icdev/data/hardprompts/ci/__init__.py +1 -0
- icdev/data/hardprompts/ci/worktree_setup.md +35 -0
- icdev/data/hardprompts/compliance/__init__.py +1 -0
- icdev/data/hardprompts/compliance/cmmc_assessment.md +63 -0
- icdev/data/hardprompts/compliance/cssp_assessment.md +75 -0
- icdev/data/hardprompts/compliance/cui_marking.md +86 -0
- icdev/data/hardprompts/compliance/fedramp_assessment.md +55 -0
- icdev/data/hardprompts/compliance/ivv_assessment.md +96 -0
- icdev/data/hardprompts/compliance/poam_generation.md +57 -0
- icdev/data/hardprompts/compliance/sbd_assessment.md +101 -0
- icdev/data/hardprompts/compliance/security_categorization.md +74 -0
- icdev/data/hardprompts/compliance/ssp_generation.md +56 -0
- icdev/data/hardprompts/compliance/stig_evaluation.md +63 -0
- icdev/data/hardprompts/dashboard/__init__.py +1 -0
- icdev/data/hardprompts/dashboard/nlq_system_prompt.md +26 -0
- icdev/data/hardprompts/infra/__init__.py +1 -0
- icdev/data/hardprompts/infra/k8s_manifests.md +118 -0
- icdev/data/hardprompts/infra/pipeline_generation.md +160 -0
- icdev/data/hardprompts/infra/terraform_generation.md +92 -0
- icdev/data/hardprompts/integration/__init__.py +1 -0
- icdev/data/hardprompts/integration/approval_review.md +17 -0
- icdev/data/hardprompts/integration/jira_mapping.md +25 -0
- icdev/data/hardprompts/integration/servicenow_mapping.md +14 -0
- icdev/data/hardprompts/knowledge/__init__.py +1 -0
- icdev/data/hardprompts/knowledge/pattern_detection.md +73 -0
- icdev/data/hardprompts/knowledge/recommendation_engine.md +90 -0
- icdev/data/hardprompts/knowledge/root_cause_analysis.md +91 -0
- icdev/data/hardprompts/maintenance/__init__.py +1 -0
- icdev/data/hardprompts/maintenance/maintenance_assessment.md +82 -0
- icdev/data/hardprompts/mbse/__init__.py +1 -0
- icdev/data/hardprompts/mbse/digital_thread.md +67 -0
- icdev/data/hardprompts/mbse/model_import.md +62 -0
- icdev/data/hardprompts/mbse/model_to_code.md +65 -0
- icdev/data/hardprompts/modernization/__init__.py +1 -0
- icdev/data/hardprompts/modernization/legacy_analysis.md +93 -0
- icdev/data/hardprompts/modernization/migration_planning.md +150 -0
- icdev/data/hardprompts/modernization/seven_r_assessment.md +107 -0
- icdev/data/hardprompts/requirements/__init__.py +1 -0
- icdev/data/hardprompts/requirements/bdd_generation.md +35 -0
- icdev/data/hardprompts/requirements/clarification_prioritization.md +29 -0
- icdev/data/hardprompts/requirements/decomposition.md +60 -0
- icdev/data/hardprompts/requirements/document_extraction.md +45 -0
- icdev/data/hardprompts/requirements/gap_detection.md +70 -0
- icdev/data/hardprompts/requirements/intake_conversation.md +101 -0
- icdev/data/hardprompts/requirements/readiness_assessment.md +39 -0
- icdev/data/hardprompts/requirements/spec_quality.md +33 -0
- icdev/data/hardprompts/requirements/traceability_analysis.md +23 -0
- icdev/data/hardprompts/security/__init__.py +1 -0
- icdev/data/hardprompts/security/endpoint_security.md +78 -0
- icdev/data/hardprompts/security/threat_model.md +70 -0
- icdev/data/hardprompts/security/vulnerability_assessment.md +81 -0
- icdev/data/hardprompts/simulation/__init__.py +1 -0
- icdev/data/hardprompts/simulation/architecture_impact.md +27 -0
- icdev/data/hardprompts/simulation/coa_alternative.md +27 -0
- icdev/data/hardprompts/simulation/coa_generation.md +25 -0
- icdev/data/hardprompts/simulation/compliance_impact.md +28 -0
- icdev/data/hardprompts/simulation/cost_estimation.md +33 -0
- icdev/data/hardprompts/simulation/risk_assessment.md +28 -0
- icdev/data/hardprompts/translation/code_translation.md +68 -0
- icdev/data/hardprompts/translation/dependency_suggestion.md +44 -0
- icdev/data/hardprompts/translation/test_translation.md +64 -0
- icdev/data/hardprompts/translation/translation_repair.md +59 -0
- icdev/py.typed +0 -0
- icdev/tools/__init__.py +1 -0
- icdev/tools/_gen_formatter.py +12 -0
- icdev/tools/a2a/__init__.py +1 -0
- icdev/tools/a2a/agent_cards/architect.json +43 -0
- icdev/tools/a2a/agent_cards/builder.json +50 -0
- icdev/tools/a2a/agent_cards/compliance.json +57 -0
- icdev/tools/a2a/agent_cards/devsecops.json +71 -0
- icdev/tools/a2a/agent_cards/infra.json +57 -0
- icdev/tools/a2a/agent_cards/integration.json +57 -0
- icdev/tools/a2a/agent_cards/knowledge.json +43 -0
- icdev/tools/a2a/agent_cards/mbse.json +57 -0
- icdev/tools/a2a/agent_cards/modernization.json +50 -0
- icdev/tools/a2a/agent_cards/monitor.json +43 -0
- icdev/tools/a2a/agent_cards/orchestrator.json +36 -0
- icdev/tools/a2a/agent_cards/requirements_analyst.json +64 -0
- icdev/tools/a2a/agent_cards/security.json +50 -0
- icdev/tools/a2a/agent_cards/simulation.json +57 -0
- icdev/tools/a2a/agent_cards/supply_chain.json +50 -0
- icdev/tools/a2a/agent_client.py +349 -0
- icdev/tools/a2a/agent_registry.py +412 -0
- icdev/tools/a2a/agent_server.py +579 -0
- icdev/tools/a2a/task.py +200 -0
- icdev/tools/agent/__init__.py +2 -0
- icdev/tools/agent/a2a_agent_card_generator.py +285 -0
- icdev/tools/agent/a2a_discovery_server.py +250 -0
- icdev/tools/agent/agent_executor.py +529 -0
- icdev/tools/agent/agent_memory.py +557 -0
- icdev/tools/agent/agent_models.py +51 -0
- icdev/tools/agent/atlas_critique.py +908 -0
- icdev/tools/agent/authority.py +443 -0
- icdev/tools/agent/bedrock_client.py +1075 -0
- icdev/tools/agent/collaboration.py +871 -0
- icdev/tools/agent/dispatcher_mode.py +665 -0
- icdev/tools/agent/mailbox.py +575 -0
- icdev/tools/agent/prompt_chain_executor.py +1064 -0
- icdev/tools/agent/session_purpose.py +350 -0
- icdev/tools/agent/skill_router.py +638 -0
- icdev/tools/agent/skill_selector.py +486 -0
- icdev/tools/agent/team_orchestrator.py +1108 -0
- icdev/tools/agent/token_tracker.py +290 -0
- icdev/tools/analysis/__init__.py +1 -0
- icdev/tools/analysis/code_analyzer.py +780 -0
- icdev/tools/analysis/runtime_feedback.py +389 -0
- icdev/tools/audit/__init__.py +1 -0
- icdev/tools/audit/audit_logger.py +196 -0
- icdev/tools/audit/audit_query.py +157 -0
- icdev/tools/audit/decision_recorder.py +72 -0
- icdev/tools/builder/__init__.py +1 -0
- icdev/tools/builder/agentic_fitness.py +534 -0
- icdev/tools/builder/agentic_test_templates/test_a2a_callback.py +117 -0
- icdev/tools/builder/agentic_test_templates/test_a2a_lifecycle.feature +52 -0
- icdev/tools/builder/agentic_test_templates/test_agent_card.feature +37 -0
- icdev/tools/builder/agentic_test_templates/test_agent_health.py +128 -0
- icdev/tools/builder/agentic_test_templates/test_memory_system.feature +50 -0
- icdev/tools/builder/agentic_test_templates/test_skill_execution.feature +40 -0
- icdev/tools/builder/app_blueprint.py +1583 -0
- icdev/tools/builder/child_app_generator.py +2852 -0
- icdev/tools/builder/claude_md_generator.py +1734 -0
- icdev/tools/builder/code_generator.py +3703 -0
- icdev/tools/builder/db_init_generator.py +1709 -0
- icdev/tools/builder/dev_profile_manager.py +954 -0
- icdev/tools/builder/formatter.py +768 -0
- icdev/tools/builder/goal_adapter.py +592 -0
- icdev/tools/builder/gotcha_validator.py +812 -0
- icdev/tools/builder/language_support.py +441 -0
- icdev/tools/builder/linter.py +976 -0
- icdev/tools/builder/profile_detector.py +657 -0
- icdev/tools/builder/profile_md_generator.py +723 -0
- icdev/tools/builder/scaffolder.py +1590 -0
- icdev/tools/builder/scaffolder_extended.py +1771 -0
- icdev/tools/builder/test_writer.py +950 -0
- icdev/tools/ci/__init__.py +2 -0
- icdev/tools/ci/connectors/__init__.py +2 -0
- icdev/tools/ci/connectors/base_connector.py +80 -0
- icdev/tools/ci/connectors/connector_registry.py +188 -0
- icdev/tools/ci/connectors/mattermost_connector.py +159 -0
- icdev/tools/ci/connectors/slack_connector.py +197 -0
- icdev/tools/ci/core/__init__.py +2 -0
- icdev/tools/ci/core/air_gap_detector.py +115 -0
- icdev/tools/ci/core/comment_handler.py +192 -0
- icdev/tools/ci/core/conversation_manager.py +479 -0
- icdev/tools/ci/core/event_envelope.py +500 -0
- icdev/tools/ci/core/event_router.py +443 -0
- icdev/tools/ci/core/failure_parser.py +397 -0
- icdev/tools/ci/core/recovery_engine.py +527 -0
- icdev/tools/ci/modules/__init__.py +2 -0
- icdev/tools/ci/modules/agent.py +271 -0
- icdev/tools/ci/modules/git_ops.py +175 -0
- icdev/tools/ci/modules/state.py +117 -0
- icdev/tools/ci/modules/vcs.py +303 -0
- icdev/tools/ci/modules/workflow_ops.py +295 -0
- icdev/tools/ci/modules/worktree.py +340 -0
- icdev/tools/ci/pipeline_config_generator.py +558 -0
- icdev/tools/ci/triggers/__init__.py +2 -0
- icdev/tools/ci/triggers/gitlab_task_monitor.py +330 -0
- icdev/tools/ci/triggers/poll_trigger.py +237 -0
- icdev/tools/ci/triggers/webhook_server.py +356 -0
- icdev/tools/ci/workflows/__init__.py +2 -0
- icdev/tools/ci/workflows/icdev_build.py +140 -0
- icdev/tools/ci/workflows/icdev_comply.py +284 -0
- icdev/tools/ci/workflows/icdev_document.py +152 -0
- icdev/tools/ci/workflows/icdev_e2e.py +188 -0
- icdev/tools/ci/workflows/icdev_patch.py +186 -0
- icdev/tools/ci/workflows/icdev_plan.py +202 -0
- icdev/tools/ci/workflows/icdev_plan_build.py +41 -0
- icdev/tools/ci/workflows/icdev_plan_build_test.py +46 -0
- icdev/tools/ci/workflows/icdev_plan_build_test_review.py +47 -0
- icdev/tools/ci/workflows/icdev_review.py +126 -0
- icdev/tools/ci/workflows/icdev_sdlc.py +261 -0
- icdev/tools/ci/workflows/icdev_test.py +240 -0
- icdev/tools/cli/__init__.py +1 -0
- icdev/tools/cli/output_formatter.py +756 -0
- icdev/tools/cli_formatter.py +42 -0
- icdev/tools/cloud/__init__.py +11 -0
- icdev/tools/cloud/cloud_mode_manager.py +364 -0
- icdev/tools/cloud/csp_changelog.py +383 -0
- icdev/tools/cloud/csp_health_checker.py +268 -0
- icdev/tools/cloud/csp_monitor.py +951 -0
- icdev/tools/cloud/iam_provider.py +593 -0
- icdev/tools/cloud/kms_provider.py +346 -0
- icdev/tools/cloud/monitoring_provider.py +628 -0
- icdev/tools/cloud/provider_factory.py +376 -0
- icdev/tools/cloud/region_validator.py +345 -0
- icdev/tools/cloud/registry_provider.py +563 -0
- icdev/tools/cloud/secrets_provider.py +486 -0
- icdev/tools/cloud/storage_provider.py +446 -0
- icdev/tools/compat/__init__.py +21 -0
- icdev/tools/compat/cli_harmonizer.py +251 -0
- icdev/tools/compat/datetime_utils.py +18 -0
- icdev/tools/compat/db_utils.py +160 -0
- icdev/tools/compat/platform_utils.py +123 -0
- icdev/tools/compliance/__init__.py +1 -0
- icdev/tools/compliance/accountability_manager.py +397 -0
- icdev/tools/compliance/ai_accountability_audit.py +294 -0
- icdev/tools/compliance/ai_impact_assessor.py +273 -0
- icdev/tools/compliance/ai_incident_response.py +301 -0
- icdev/tools/compliance/ai_inventory_manager.py +239 -0
- icdev/tools/compliance/ai_reassessment_scheduler.py +256 -0
- icdev/tools/compliance/ai_transparency_audit.py +248 -0
- icdev/tools/compliance/atlas_assessor.py +278 -0
- icdev/tools/compliance/atlas_report_generator.py +1211 -0
- icdev/tools/compliance/base_assessor.py +597 -0
- icdev/tools/compliance/cato_monitor.py +1385 -0
- icdev/tools/compliance/cato_scheduler.py +699 -0
- icdev/tools/compliance/cjis_assessor.py +76 -0
- icdev/tools/compliance/classification_manager.py +1353 -0
- icdev/tools/compliance/cmmc_assessor.py +1491 -0
- icdev/tools/compliance/cmmc_report_generator.py +1100 -0
- icdev/tools/compliance/compliance_detector.py +463 -0
- icdev/tools/compliance/compliance_exporter.py +427 -0
- icdev/tools/compliance/compliance_status.py +825 -0
- icdev/tools/compliance/control_mapper.py +505 -0
- icdev/tools/compliance/crosswalk_engine.py +1203 -0
- icdev/tools/compliance/cssp_assessor.py +1045 -0
- icdev/tools/compliance/cssp_evidence_collector.py +729 -0
- icdev/tools/compliance/cssp_report_generator.py +1116 -0
- icdev/tools/compliance/cui_marker.py +388 -0
- icdev/tools/compliance/diagram_validator.py +600 -0
- icdev/tools/compliance/emass/__init__.py +2 -0
- icdev/tools/compliance/emass/emass_client.py +840 -0
- icdev/tools/compliance/emass/emass_export.py +777 -0
- icdev/tools/compliance/emass/emass_sync.py +826 -0
- icdev/tools/compliance/eu_ai_act_classifier.py +194 -0
- icdev/tools/compliance/evidence_collector.py +468 -0
- icdev/tools/compliance/fairness_assessor.py +316 -0
- icdev/tools/compliance/fedramp_assessor.py +1808 -0
- icdev/tools/compliance/fedramp_authorization_packager.py +137 -0
- icdev/tools/compliance/fedramp_ksi_generator.py +355 -0
- icdev/tools/compliance/fedramp_report_generator.py +1128 -0
- icdev/tools/compliance/fips199_categorizer.py +881 -0
- icdev/tools/compliance/fips200_validator.py +315 -0
- icdev/tools/compliance/gao_ai_assessor.py +231 -0
- icdev/tools/compliance/gao_evidence_builder.py +308 -0
- icdev/tools/compliance/hipaa_assessor.py +78 -0
- icdev/tools/compliance/hitrust_assessor.py +49 -0
- icdev/tools/compliance/incident_response_plan.py +718 -0
- icdev/tools/compliance/iso27001_assessor.py +92 -0
- icdev/tools/compliance/iso42001_assessor.py +114 -0
- icdev/tools/compliance/ivv_assessor.py +2327 -0
- icdev/tools/compliance/ivv_report_generator.py +1662 -0
- icdev/tools/compliance/model_card_generator.py +297 -0
- icdev/tools/compliance/mosa_assessor.py +117 -0
- icdev/tools/compliance/multi_regime_assessor.py +451 -0
- icdev/tools/compliance/narrative_generator.py +1013 -0
- icdev/tools/compliance/nist_800_207_assessor.py +191 -0
- icdev/tools/compliance/nist_ai_600_1_assessor.py +188 -0
- icdev/tools/compliance/nist_ai_rmf_assessor.py +110 -0
- icdev/tools/compliance/nist_lookup.py +245 -0
- icdev/tools/compliance/omb_m25_21_assessor.py +228 -0
- icdev/tools/compliance/omb_m26_04_assessor.py +188 -0
- icdev/tools/compliance/oscal_catalog_adapter.py +395 -0
- icdev/tools/compliance/oscal_generator.py +2170 -0
- icdev/tools/compliance/oscal_tools.py +1182 -0
- icdev/tools/compliance/owasp_agentic_assessor.py +226 -0
- icdev/tools/compliance/owasp_asi_assessor.py +200 -0
- icdev/tools/compliance/owasp_llm_assessor.py +244 -0
- icdev/tools/compliance/pci_dss_assessor.py +80 -0
- icdev/tools/compliance/pi_compliance_tracker.py +1461 -0
- icdev/tools/compliance/poam_generator.py +405 -0
- icdev/tools/compliance/resolve_marking.py +283 -0
- icdev/tools/compliance/sbd_assessor.py +2068 -0
- icdev/tools/compliance/sbd_report_generator.py +1236 -0
- icdev/tools/compliance/sbom_generator.py +1008 -0
- icdev/tools/compliance/siem_config_generator.py +674 -0
- icdev/tools/compliance/slsa_attestation_generator.py +490 -0
- icdev/tools/compliance/soc2_assessor.py +77 -0
- icdev/tools/compliance/ssp_generator.py +573 -0
- icdev/tools/compliance/stig_checker.py +727 -0
- icdev/tools/compliance/swft_evidence_bundler.py +337 -0
- icdev/tools/compliance/system_card_generator.py +309 -0
- icdev/tools/compliance/traceability_matrix.py +1281 -0
- icdev/tools/compliance/universal_classification_manager.py +1172 -0
- icdev/tools/compliance/xacta/__init__.py +2 -0
- icdev/tools/compliance/xacta/xacta_client.py +449 -0
- icdev/tools/compliance/xacta/xacta_export.py +557 -0
- icdev/tools/compliance/xacta/xacta_sync.py +333 -0
- icdev/tools/compliance/xai_assessor.py +231 -0
- icdev/tools/dashboard/__init__.py +1 -0
- icdev/tools/dashboard/api/__init__.py +1 -0
- icdev/tools/dashboard/api/_pipeline_state.py +17 -0
- icdev/tools/dashboard/api/activity.py +206 -0
- icdev/tools/dashboard/api/admin.py +176 -0
- icdev/tools/dashboard/api/agents.py +53 -0
- icdev/tools/dashboard/api/ai_accountability.py +163 -0
- icdev/tools/dashboard/api/ai_transparency.py +198 -0
- icdev/tools/dashboard/api/audit.py +58 -0
- icdev/tools/dashboard/api/batch.py +666 -0
- icdev/tools/dashboard/api/chat.py +241 -0
- icdev/tools/dashboard/api/cicd.py +219 -0
- icdev/tools/dashboard/api/code_quality.py +223 -0
- icdev/tools/dashboard/api/compliance.py +171 -0
- icdev/tools/dashboard/api/cpmp.py +915 -0
- icdev/tools/dashboard/api/diagrams.py +65 -0
- icdev/tools/dashboard/api/events.py +250 -0
- icdev/tools/dashboard/api/evidence.py +99 -0
- icdev/tools/dashboard/api/fedramp_20x.py +77 -0
- icdev/tools/dashboard/api/govcon.py +1095 -0
- icdev/tools/dashboard/api/intake.py +1171 -0
- icdev/tools/dashboard/api/lineage.py +163 -0
- icdev/tools/dashboard/api/metrics.py +155 -0
- icdev/tools/dashboard/api/nlq.py +72 -0
- icdev/tools/dashboard/api/orchestration.py +472 -0
- icdev/tools/dashboard/api/oscal.py +183 -0
- icdev/tools/dashboard/api/prod_audit.py +183 -0
- icdev/tools/dashboard/api/projects.py +191 -0
- icdev/tools/dashboard/api/proposals.py +1084 -0
- icdev/tools/dashboard/api/traces.py +363 -0
- icdev/tools/dashboard/api/usage.py +234 -0
- icdev/tools/dashboard/app.py +1986 -0
- icdev/tools/dashboard/auth.py +500 -0
- icdev/tools/dashboard/byok.py +245 -0
- icdev/tools/dashboard/chat_manager.py +675 -0
- icdev/tools/dashboard/config.py +116 -0
- icdev/tools/dashboard/diagram_definitions.py +642 -0
- icdev/tools/dashboard/nlq_processor.py +323 -0
- icdev/tools/dashboard/phase_loader.py +136 -0
- icdev/tools/dashboard/sse_manager.py +89 -0
- icdev/tools/dashboard/state_tracker.py +267 -0
- icdev/tools/dashboard/static/css/style.css +706 -0
- icdev/tools/dashboard/static/css/ux.css +2047 -0
- icdev/tools/dashboard/static/js/activity.js +322 -0
- icdev/tools/dashboard/static/js/api.js +161 -0
- icdev/tools/dashboard/static/js/batch.js +814 -0
- icdev/tools/dashboard/static/js/charts.js +618 -0
- icdev/tools/dashboard/static/js/chat.js +1514 -0
- icdev/tools/dashboard/static/js/kanban.js +113 -0
- icdev/tools/dashboard/static/js/live.js +569 -0
- icdev/tools/dashboard/static/js/mermaid-icdev.js +332 -0
- icdev/tools/dashboard/static/js/proposals.js +588 -0
- icdev/tools/dashboard/static/js/shortcuts.js +544 -0
- icdev/tools/dashboard/static/js/tables.js +652 -0
- icdev/tools/dashboard/static/js/tour.js +524 -0
- icdev/tools/dashboard/static/js/ux.js +942 -0
- icdev/tools/dashboard/templates/404.html +10 -0
- icdev/tools/dashboard/templates/activity.html +80 -0
- icdev/tools/dashboard/templates/admin/users.html +144 -0
- icdev/tools/dashboard/templates/ai_accountability.html +235 -0
- icdev/tools/dashboard/templates/ai_transparency.html +263 -0
- icdev/tools/dashboard/templates/base.html +104 -0
- icdev/tools/dashboard/templates/batch.html +23 -0
- icdev/tools/dashboard/templates/chat.html +332 -0
- icdev/tools/dashboard/templates/children.html +149 -0
- icdev/tools/dashboard/templates/cicd.html +253 -0
- icdev/tools/dashboard/templates/code_quality.html +214 -0
- icdev/tools/dashboard/templates/cpmp/cor_detail.html +220 -0
- icdev/tools/dashboard/templates/cpmp/cor_portal.html +91 -0
- icdev/tools/dashboard/templates/cpmp/deliverable_detail.html +197 -0
- icdev/tools/dashboard/templates/cpmp/detail.html +578 -0
- icdev/tools/dashboard/templates/cpmp/portfolio.html +202 -0
- icdev/tools/dashboard/templates/dev_profiles.html +304 -0
- icdev/tools/dashboard/templates/diagrams.html +224 -0
- icdev/tools/dashboard/templates/events/timeline.html +232 -0
- icdev/tools/dashboard/templates/evidence.html +134 -0
- icdev/tools/dashboard/templates/fedramp_20x.html +207 -0
- icdev/tools/dashboard/templates/gateway.html +244 -0
- icdev/tools/dashboard/templates/govcon/capabilities.html +135 -0
- icdev/tools/dashboard/templates/govcon/pipeline.html +214 -0
- icdev/tools/dashboard/templates/govcon/requirements.html +120 -0
- icdev/tools/dashboard/templates/index.html +254 -0
- icdev/tools/dashboard/templates/lineage.html +141 -0
- icdev/tools/dashboard/templates/login.html +51 -0
- icdev/tools/dashboard/templates/monitoring/overview.html +193 -0
- icdev/tools/dashboard/templates/orchestration/dashboard.html +545 -0
- icdev/tools/dashboard/templates/oscal.html +263 -0
- icdev/tools/dashboard/templates/phases.html +150 -0
- icdev/tools/dashboard/templates/prod_audit.html +280 -0
- icdev/tools/dashboard/templates/profile.html +183 -0
- icdev/tools/dashboard/templates/projects/detail.html +583 -0
- icdev/tools/dashboard/templates/projects/list.html +47 -0
- icdev/tools/dashboard/templates/proposals/detail.html +1253 -0
- icdev/tools/dashboard/templates/proposals/list.html +179 -0
- icdev/tools/dashboard/templates/proposals/section_detail.html +193 -0
- icdev/tools/dashboard/templates/provenance.html +181 -0
- icdev/tools/dashboard/templates/query/nlq.html +234 -0
- icdev/tools/dashboard/templates/quick_paths.html +69 -0
- icdev/tools/dashboard/templates/traces.html +155 -0
- icdev/tools/dashboard/templates/translation_detail.html +199 -0
- icdev/tools/dashboard/templates/translations.html +162 -0
- icdev/tools/dashboard/templates/usage.html +225 -0
- icdev/tools/dashboard/templates/wizard.html +539 -0
- icdev/tools/dashboard/templates/xai.html +208 -0
- icdev/tools/dashboard/ux_helpers.py +962 -0
- icdev/tools/dashboard/websocket.py +81 -0
- icdev/tools/db/__init__.py +1 -0
- icdev/tools/db/backup.py +312 -0
- icdev/tools/db/backup_manager.py +832 -0
- icdev/tools/db/init_icdev_db.py +5900 -0
- icdev/tools/db/migrate.py +178 -0
- icdev/tools/db/migration_runner.py +549 -0
- icdev/tools/db/migrations/001_baseline/meta.json +9 -0
- icdev/tools/db/migrations/001_baseline/up.py +68 -0
- icdev/tools/db/migrations/002_memory_enhancements/down.sql +8 -0
- icdev/tools/db/migrations/002_memory_enhancements/meta.json +9 -0
- icdev/tools/db/migrations/002_memory_enhancements/up.py +118 -0
- icdev/tools/db/migrations/003_dev_profiles/meta.json +8 -0
- icdev/tools/db/migrations/003_dev_profiles/up.py +93 -0
- icdev/tools/db/migrations/004_innovation_engine/down.py +19 -0
- icdev/tools/db/migrations/004_innovation_engine/up.py +227 -0
- icdev/tools/db/migrations/005_phase_37_ai_security/down.py +19 -0
- icdev/tools/db/migrations/005_phase_37_ai_security/up.py +258 -0
- icdev/tools/db/migrations/006_phase_36_evolution/down.py +21 -0
- icdev/tools/db/migrations/006_phase_36_evolution/up.py +323 -0
- icdev/tools/db/migrations/007_phase_38_cloud/down.py +14 -0
- icdev/tools/db/migrations/007_phase_38_cloud/up.py +110 -0
- icdev/tools/db/migrations/008_phase36_37_integration/up.py +55 -0
- icdev/tools/db/migrations/__init__.py +2 -0
- icdev/tools/devsecops/__init__.py +2 -0
- icdev/tools/devsecops/attestation_manager.py +458 -0
- icdev/tools/devsecops/network_segmentation_generator.py +614 -0
- icdev/tools/devsecops/pdp_config_generator.py +1256 -0
- icdev/tools/devsecops/pipeline_security_generator.py +484 -0
- icdev/tools/devsecops/policy_generator.py +653 -0
- icdev/tools/devsecops/profile_manager.py +388 -0
- icdev/tools/devsecops/service_mesh_generator.py +1073 -0
- icdev/tools/devsecops/zta_maturity_scorer.py +368 -0
- icdev/tools/devsecops/zta_terraform_generator.py +1303 -0
- icdev/tools/dx/__init__.py +3 -0
- icdev/tools/dx/companion.py +266 -0
- icdev/tools/dx/instruction_generator.py +753 -0
- icdev/tools/dx/mcp_config_generator.py +282 -0
- icdev/tools/dx/skill_translator.py +425 -0
- icdev/tools/dx/tool_detector.py +144 -0
- icdev/tools/extensions/__init__.py +21 -0
- icdev/tools/extensions/builtins/010_ai_governance_chat.py +277 -0
- icdev/tools/extensions/builtins/__init__.py +2 -0
- icdev/tools/extensions/extension_manager.py +455 -0
- icdev/tools/infra/__init__.py +1 -0
- icdev/tools/infra/ansible_generator.py +869 -0
- icdev/tools/infra/dockerfile_generator.py +361 -0
- icdev/tools/infra/infra_status.py +393 -0
- icdev/tools/infra/ironbank_metadata_generator.py +411 -0
- icdev/tools/infra/k8s_generator.py +1002 -0
- icdev/tools/infra/pipeline_generator.py +832 -0
- icdev/tools/infra/rollback.py +400 -0
- icdev/tools/infra/terraform_generator.py +1142 -0
- icdev/tools/infra/terraform_generator_azure.py +1254 -0
- icdev/tools/infra/terraform_generator_gcp.py +953 -0
- icdev/tools/infra/terraform_generator_ibm.py +360 -0
- icdev/tools/infra/terraform_generator_oci.py +919 -0
- icdev/tools/infra/terraform_generator_onprem.py +319 -0
- icdev/tools/innovation/__init__.py +8 -0
- icdev/tools/innovation/competitive_intel.py +492 -0
- icdev/tools/innovation/innovation_manager.py +681 -0
- icdev/tools/innovation/introspective_analyzer.py +774 -0
- icdev/tools/innovation/register_external_patterns.py +440 -0
- icdev/tools/innovation/signal_ranker.py +1038 -0
- icdev/tools/innovation/solution_generator.py +697 -0
- icdev/tools/innovation/standards_monitor.py +466 -0
- icdev/tools/innovation/trend_detector.py +1046 -0
- icdev/tools/innovation/triage_engine.py +1149 -0
- icdev/tools/innovation/web_scanner.py +894 -0
- icdev/tools/installer/__init__.py +1 -0
- icdev/tools/installer/compliance_configurator.py +637 -0
- icdev/tools/installer/installer.py +1711 -0
- icdev/tools/installer/module_registry.py +805 -0
- icdev/tools/installer/platform_setup.py +961 -0
- icdev/tools/integration/__init__.py +2 -0
- icdev/tools/integration/approval_manager.py +561 -0
- icdev/tools/integration/doors_exporter.py +627 -0
- icdev/tools/integration/gitlab_connector.py +784 -0
- icdev/tools/integration/jira_connector.py +774 -0
- icdev/tools/integration/servicenow_connector.py +693 -0
- icdev/tools/knowledge/__init__.py +1 -0
- icdev/tools/knowledge/knowledge_ingest.py +293 -0
- icdev/tools/knowledge/pattern_detector.py +693 -0
- icdev/tools/knowledge/recommendation_engine.py +461 -0
- icdev/tools/knowledge/self_heal_analyzer.py +504 -0
- icdev/tools/llm/__init__.py +72 -0
- icdev/tools/llm/anthropic_provider.py +170 -0
- icdev/tools/llm/azure_openai_provider.py +338 -0
- icdev/tools/llm/bedrock_provider.py +315 -0
- icdev/tools/llm/embedding_provider.py +438 -0
- icdev/tools/llm/gemini_provider.py +381 -0
- icdev/tools/llm/ibm_watsonx_provider.py +232 -0
- icdev/tools/llm/oci_genai_provider.py +462 -0
- icdev/tools/llm/ollama_provider.py +340 -0
- icdev/tools/llm/openai_provider.py +225 -0
- icdev/tools/llm/provider.py +355 -0
- icdev/tools/llm/provider_sdk.py +175 -0
- icdev/tools/llm/router.py +780 -0
- icdev/tools/llm/vertex_ai_provider.py +374 -0
- icdev/tools/maintenance/__init__.py +2 -0
- icdev/tools/maintenance/dependency_scanner.py +1030 -0
- icdev/tools/maintenance/maintenance_auditor.py +815 -0
- icdev/tools/maintenance/remediation_engine.py +966 -0
- icdev/tools/maintenance/vulnerability_checker.py +987 -0
- icdev/tools/mbse/__init__.py +3 -0
- icdev/tools/mbse/des_assessor.py +1186 -0
- icdev/tools/mbse/des_report_generator.py +800 -0
- icdev/tools/mbse/diagram_extractor.py +811 -0
- icdev/tools/mbse/digital_thread.py +1665 -0
- icdev/tools/mbse/model_code_generator.py +1122 -0
- icdev/tools/mbse/model_control_mapper.py +420 -0
- icdev/tools/mbse/pi_model_tracker.py +1093 -0
- icdev/tools/mbse/reqif_parser.py +1483 -0
- icdev/tools/mbse/sync_engine.py +1805 -0
- icdev/tools/mbse/xmi_parser.py +1573 -0
- icdev/tools/mcp/__init__.py +1 -0
- icdev/tools/mcp/base_server.py +535 -0
- icdev/tools/mcp/builder_server.py +725 -0
- icdev/tools/mcp/compliance_server.py +1407 -0
- icdev/tools/mcp/context_indexer.py +199 -0
- icdev/tools/mcp/context_server.py +305 -0
- icdev/tools/mcp/core_server.py +679 -0
- icdev/tools/mcp/devsecops_server.py +432 -0
- icdev/tools/mcp/gap_handlers.py +1079 -0
- icdev/tools/mcp/gateway_server.py +339 -0
- icdev/tools/mcp/generate_registry.py +623 -0
- icdev/tools/mcp/infra_server.py +264 -0
- icdev/tools/mcp/innovation_server.py +316 -0
- icdev/tools/mcp/integration_server.py +527 -0
- icdev/tools/mcp/knowledge_server.py +429 -0
- icdev/tools/mcp/maintenance_server.py +248 -0
- icdev/tools/mcp/marketplace_server.py +499 -0
- icdev/tools/mcp/mbse_server.py +398 -0
- icdev/tools/mcp/modernization_server.py +496 -0
- icdev/tools/mcp/observability_server.py +354 -0
- icdev/tools/mcp/requirements_server.py +415 -0
- icdev/tools/mcp/simulation_server.py +468 -0
- icdev/tools/mcp/standalone/__init__.py +2 -0
- icdev/tools/mcp/standalone/builder.py +59 -0
- icdev/tools/mcp/standalone/compliance.py +59 -0
- icdev/tools/mcp/standalone/core.py +59 -0
- icdev/tools/mcp/standalone/knowledge.py +59 -0
- icdev/tools/mcp/standalone/maintenance.py +59 -0
- icdev/tools/mcp/supply_chain_server.py +476 -0
- icdev/tools/mcp/tool_registry.py +2008 -0
- icdev/tools/mcp/unified_server.py +158 -0
- icdev/tools/memory/__init__.py +2 -0
- icdev/tools/memory/auto_capture.py +347 -0
- icdev/tools/memory/embed_memory.py +158 -0
- icdev/tools/memory/history_compressor.py +334 -0
- icdev/tools/memory/hybrid_search.py +236 -0
- icdev/tools/memory/maintenance_cron.py +289 -0
- icdev/tools/memory/memory_consolidation.py +444 -0
- icdev/tools/memory/memory_db.py +133 -0
- icdev/tools/memory/memory_read.py +102 -0
- icdev/tools/memory/memory_write.py +222 -0
- icdev/tools/memory/semantic_search.py +139 -0
- icdev/tools/memory/time_decay.py +435 -0
- icdev/tools/modernization/__init__.py +3 -0
- icdev/tools/modernization/architecture_extractor.py +734 -0
- icdev/tools/modernization/compliance_bridge.py +1499 -0
- icdev/tools/modernization/db_migration_planner.py +1385 -0
- icdev/tools/modernization/doc_generator.py +1428 -0
- icdev/tools/modernization/framework_migrator.py +1525 -0
- icdev/tools/modernization/legacy_analyzer.py +1948 -0
- icdev/tools/modernization/migration_code_generator.py +1639 -0
- icdev/tools/modernization/migration_report_generator.py +1653 -0
- icdev/tools/modernization/migration_tracker.py +1726 -0
- icdev/tools/modernization/monolith_decomposer.py +1508 -0
- icdev/tools/modernization/seven_r_assessor.py +1658 -0
- icdev/tools/modernization/strangler_fig_manager.py +1705 -0
- icdev/tools/modernization/ui_analyzer.py +771 -0
- icdev/tools/modernization/version_migrator.py +1392 -0
- icdev/tools/monitor/__init__.py +1 -0
- icdev/tools/monitor/alert_correlator.py +495 -0
- icdev/tools/monitor/auto_resolver.py +612 -0
- icdev/tools/monitor/health_checker.py +509 -0
- icdev/tools/monitor/heartbeat_daemon.py +792 -0
- icdev/tools/monitor/log_analyzer.py +516 -0
- icdev/tools/monitor/metric_collector.py +496 -0
- icdev/tools/mosa/__init__.py +10 -0
- icdev/tools/mosa/icd_generator.py +370 -0
- icdev/tools/mosa/modular_design_analyzer.py +683 -0
- icdev/tools/mosa/mosa_code_enforcer.py +349 -0
- icdev/tools/mosa/tsp_generator.py +265 -0
- icdev/tools/observability/__init__.py +100 -0
- icdev/tools/observability/genai_attributes.py +88 -0
- icdev/tools/observability/instrumentation.py +140 -0
- icdev/tools/observability/mlflow_exporter.py +194 -0
- icdev/tools/observability/otel_tracer.py +168 -0
- icdev/tools/observability/provenance/__init__.py +3 -0
- icdev/tools/observability/provenance/prov_recorder.py +324 -0
- icdev/tools/observability/shap/__init__.py +3 -0
- icdev/tools/observability/shap/agent_shap.py +275 -0
- icdev/tools/observability/sqlite_tracer.py +361 -0
- icdev/tools/observability/trace_context.py +205 -0
- icdev/tools/observability/tracer.py +230 -0
- icdev/tools/orchestration/__init__.py +2 -0
- icdev/tools/orchestration/workflow_composer.py +361 -0
- icdev/tools/project/__init__.py +1 -0
- icdev/tools/project/manifest_loader.py +418 -0
- icdev/tools/project/project_create.py +350 -0
- icdev/tools/project/project_list.py +174 -0
- icdev/tools/project/project_scaffold.py +1715 -0
- icdev/tools/project/project_status.py +479 -0
- icdev/tools/project/session_context_builder.py +757 -0
- icdev/tools/project/validate_manifest.py +55 -0
- icdev/tools/registry/__init__.py +10 -0
- icdev/tools/registry/absorption_engine.py +832 -0
- icdev/tools/registry/capability_evaluator.py +668 -0
- icdev/tools/registry/child_registry.py +617 -0
- icdev/tools/registry/cross_pollinator.py +1065 -0
- icdev/tools/registry/genome_manager.py +671 -0
- icdev/tools/registry/learning_collector.py +912 -0
- icdev/tools/registry/propagation_manager.py +942 -0
- icdev/tools/registry/staging_manager.py +742 -0
- icdev/tools/registry/telemetry_collector.py +423 -0
- icdev/tools/requirements/__init__.py +1 -0
- icdev/tools/requirements/ai_governance_scorer.py +208 -0
- icdev/tools/requirements/boundary_analyzer.py +1293 -0
- icdev/tools/requirements/clarification_engine.py +618 -0
- icdev/tools/requirements/complexity_scorer.py +387 -0
- icdev/tools/requirements/consistency_analyzer.py +803 -0
- icdev/tools/requirements/constitution_manager.py +605 -0
- icdev/tools/requirements/decomposition_engine.py +778 -0
- icdev/tools/requirements/document_extractor.py +1016 -0
- icdev/tools/requirements/elicitation_techniques.py +519 -0
- icdev/tools/requirements/gap_detector.py +271 -0
- icdev/tools/requirements/intake_engine.py +2188 -0
- icdev/tools/requirements/prd_generator.py +847 -0
- icdev/tools/requirements/prd_validator.py +595 -0
- icdev/tools/requirements/readiness_scorer.py +313 -0
- icdev/tools/requirements/spec_organizer.py +1029 -0
- icdev/tools/requirements/spec_quality_checker.py +1097 -0
- icdev/tools/requirements/traceability_builder.py +579 -0
- icdev/tools/resilience/__init__.py +34 -0
- icdev/tools/resilience/circuit_breaker.py +340 -0
- icdev/tools/resilience/correlation.py +150 -0
- icdev/tools/resilience/errors.py +81 -0
- icdev/tools/resilience/retry.py +95 -0
- icdev/tools/schemas/__init__.py +27 -0
- icdev/tools/schemas/chat.py +61 -0
- icdev/tools/schemas/compliance.py +56 -0
- icdev/tools/schemas/core.py +85 -0
- icdev/tools/schemas/innovation.py +37 -0
- icdev/tools/schemas/validation.py +109 -0
- icdev/tools/sdk/__init__.py +3 -0
- icdev/tools/sdk/icdev_client.py +218 -0
- icdev/tools/security/__init__.py +1 -0
- icdev/tools/security/agent_output_validator.py +330 -0
- icdev/tools/security/agent_trust_scorer.py +466 -0
- icdev/tools/security/ai_bom_generator.py +725 -0
- icdev/tools/security/ai_telemetry_logger.py +469 -0
- icdev/tools/security/atlas_red_team.py +543 -0
- icdev/tools/security/code_pattern_scanner.py +378 -0
- icdev/tools/security/confabulation_detector.py +271 -0
- icdev/tools/security/container_scanner.py +491 -0
- icdev/tools/security/dependency_auditor.py +944 -0
- icdev/tools/security/endpoint_security_scanner.py +579 -0
- icdev/tools/security/mcp_tool_authorizer.py +243 -0
- icdev/tools/security/prompt_injection_detector.py +737 -0
- icdev/tools/security/sast_runner.py +948 -0
- icdev/tools/security/secret_detector.py +378 -0
- icdev/tools/security/tool_chain_validator.py +357 -0
- icdev/tools/security/vuln_scanner.py +539 -0
- icdev/tools/simulation/__init__.py +2 -0
- icdev/tools/simulation/coa_generator.py +1552 -0
- icdev/tools/simulation/monte_carlo.py +758 -0
- icdev/tools/simulation/scenario_manager.py +1073 -0
- icdev/tools/simulation/simulation_engine.py +1104 -0
- icdev/tools/supply_chain/__init__.py +2 -0
- icdev/tools/supply_chain/cve_triager.py +705 -0
- icdev/tools/supply_chain/dependency_graph.py +645 -0
- icdev/tools/supply_chain/isa_manager.py +540 -0
- icdev/tools/supply_chain/scrm_assessor.py +546 -0
- icdev/tools/testing/__init__.py +2 -0
- icdev/tools/testing/acceptance_validator.py +411 -0
- icdev/tools/testing/claude_dir_validator.py +831 -0
- icdev/tools/testing/data_types.py +199 -0
- icdev/tools/testing/e2e_runner.py +715 -0
- icdev/tools/testing/fuzz_cli.py +306 -0
- icdev/tools/testing/health_check.py +483 -0
- icdev/tools/testing/platform_check.py +143 -0
- icdev/tools/testing/production_audit.py +1862 -0
- icdev/tools/testing/production_remediate.py +804 -0
- icdev/tools/testing/screenshot_validator.py +539 -0
- icdev/tools/testing/smoke_test.py +283 -0
- icdev/tools/testing/test_agent_models.py +117 -0
- icdev/tools/testing/test_orchestrator.py +957 -0
- icdev/tools/testing/utils.py +229 -0
- icdev/tools/translation/__init__.py +17 -0
- icdev/tools/translation/code_translator.py +550 -0
- icdev/tools/translation/dependency_mapper.py +277 -0
- icdev/tools/translation/feature_map.py +395 -0
- icdev/tools/translation/project_assembler.py +439 -0
- icdev/tools/translation/source_extractor.py +609 -0
- icdev/tools/translation/test_translator.py +333 -0
- icdev/tools/translation/translation_manager.py +582 -0
- icdev/tools/translation/translation_validator.py +662 -0
- icdev/tools/translation/type_checker.py +371 -0
- icdev-1.0.0.dist-info/METADATA +868 -0
- icdev-1.0.0.dist-info/RECORD +1105 -0
- icdev-1.0.0.dist-info/WHEEL +5 -0
- icdev-1.0.0.dist-info/entry_points.txt +9 -0
- icdev-1.0.0.dist-info/licenses/LICENSE +254 -0
- icdev-1.0.0.dist-info/licenses/NOTICE +268 -0
- icdev-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,1385 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# CUI // SP-CTI
|
|
3
|
+
"""Database Migration Planning Tool for ICDEV DoD Modernization.
|
|
4
|
+
|
|
5
|
+
Generates DDL scripts, data migration SQL, stored procedure translations, and
|
|
6
|
+
validation queries for migrating legacy databases to modern targets (PostgreSQL,
|
|
7
|
+
MySQL, Aurora). All output is generated as SQL files for DBA review — nothing
|
|
8
|
+
is executed directly (air-gap safe).
|
|
9
|
+
|
|
10
|
+
Reads legacy schema metadata from icdev.db (legacy_applications, legacy_db_schemas)
|
|
11
|
+
and type/function/syntax mappings from context/modernization/db_type_mappings.json.
|
|
12
|
+
|
|
13
|
+
All generated artifacts include CUI // SP-CTI banners as required for Controlled
|
|
14
|
+
Unclassified Information handling.
|
|
15
|
+
|
|
16
|
+
Usage:
|
|
17
|
+
python tools/modernization/db_migration_planner.py --app-id APP-001 --output-dir .tmp/migration --type all
|
|
18
|
+
python tools/modernization/db_migration_planner.py --app-id APP-001 --output-dir .tmp/migration --type schema
|
|
19
|
+
python tools/modernization/db_migration_planner.py --app-id APP-001 --output-dir .tmp/migration --type data
|
|
20
|
+
python tools/modernization/db_migration_planner.py --app-id APP-001 --output-dir .tmp/migration --type procedures --source-path /opt/legacy/sql
|
|
21
|
+
python tools/modernization/db_migration_planner.py --app-id APP-001 --output-dir .tmp/migration --type validation
|
|
22
|
+
python tools/modernization/db_migration_planner.py --app-id APP-001 --output-dir .tmp/migration --type all --json
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
import argparse
|
|
26
|
+
import json
|
|
27
|
+
import os
|
|
28
|
+
import re
|
|
29
|
+
import sqlite3
|
|
30
|
+
import sys
|
|
31
|
+
import textwrap
|
|
32
|
+
from collections import OrderedDict
|
|
33
|
+
from datetime import datetime
|
|
34
|
+
from pathlib import Path
|
|
35
|
+
from icdev._paths import get_project_root
|
|
36
|
+
|
|
37
|
+
# ---------------------------------------------------------------------------
|
|
38
|
+
# Constants
|
|
39
|
+
# ---------------------------------------------------------------------------
|
|
40
|
+
|
|
41
|
+
BASE_DIR = get_project_root()
|
|
42
|
+
DB_PATH = BASE_DIR / "data" / "icdev.db"
|
|
43
|
+
TYPE_MAPPINGS_PATH = BASE_DIR / "context" / "modernization" / "db_type_mappings.json"
|
|
44
|
+
|
|
45
|
+
CUI_BANNER = "CUI // SP-CTI"
|
|
46
|
+
SQL_CUI_HEADER = (
|
|
47
|
+
f"-- {'=' * 68}\n"
|
|
48
|
+
f"-- {CUI_BANNER}\n"
|
|
49
|
+
f"-- {'=' * 68}\n"
|
|
50
|
+
)
|
|
51
|
+
SQL_CUI_FOOTER = (
|
|
52
|
+
f"\n-- {'=' * 68}\n"
|
|
53
|
+
f"-- {CUI_BANNER}\n"
|
|
54
|
+
f"-- {'=' * 68}\n"
|
|
55
|
+
)
|
|
56
|
+
MD_CUI_HEADER = f"<!-- {CUI_BANNER} -->"
|
|
57
|
+
MD_CUI_FOOTER = f"<!-- {CUI_BANNER} -->"
|
|
58
|
+
|
|
59
|
+
# Estimated byte sizes per data type for volume estimation
|
|
60
|
+
TYPE_SIZE_ESTIMATES = {
|
|
61
|
+
"VARCHAR": 50,
|
|
62
|
+
"CHAR": 10,
|
|
63
|
+
"TEXT": 500,
|
|
64
|
+
"INTEGER": 8,
|
|
65
|
+
"INT": 8,
|
|
66
|
+
"SMALLINT": 4,
|
|
67
|
+
"BIGINT": 8,
|
|
68
|
+
"NUMERIC": 16,
|
|
69
|
+
"DECIMAL": 16,
|
|
70
|
+
"REAL": 4,
|
|
71
|
+
"FLOAT": 8,
|
|
72
|
+
"DOUBLE PRECISION": 8,
|
|
73
|
+
"BOOLEAN": 1,
|
|
74
|
+
"DATE": 4,
|
|
75
|
+
"TIMESTAMP": 8,
|
|
76
|
+
"TIMESTAMPTZ": 8,
|
|
77
|
+
"TIME": 8,
|
|
78
|
+
"BYTEA": 256,
|
|
79
|
+
"UUID": 16,
|
|
80
|
+
"JSON": 200,
|
|
81
|
+
"JSONB": 200,
|
|
82
|
+
"XML": 500,
|
|
83
|
+
"BLOB": 1024,
|
|
84
|
+
"CLOB": 1024,
|
|
85
|
+
"IMAGE": 1024,
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
# Normalised lookup key for migration path resolution
|
|
89
|
+
_PATH_ALIASES = {
|
|
90
|
+
"oracle": "oracle",
|
|
91
|
+
"mssql": "mssql",
|
|
92
|
+
"sqlserver": "mssql",
|
|
93
|
+
"sql server": "mssql",
|
|
94
|
+
"microsoft sql server": "mssql",
|
|
95
|
+
"db2": "db2",
|
|
96
|
+
"ibm db2": "db2",
|
|
97
|
+
"sybase": "sybase",
|
|
98
|
+
"sap sybase": "sybase",
|
|
99
|
+
"sap sybase ase": "sybase",
|
|
100
|
+
"mysql": "mysql",
|
|
101
|
+
"postgresql": "postgresql",
|
|
102
|
+
"postgres": "postgresql",
|
|
103
|
+
"aurora": "postgresql",
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
# ---------------------------------------------------------------------------
|
|
108
|
+
# Database helpers
|
|
109
|
+
# ---------------------------------------------------------------------------
|
|
110
|
+
|
|
111
|
+
def _get_db() -> sqlite3.Connection:
|
|
112
|
+
"""Return a sqlite3 connection with Row factory for dict-style access."""
|
|
113
|
+
if not DB_PATH.exists():
|
|
114
|
+
print(f"ERROR: Database not found at {DB_PATH}", file=sys.stderr)
|
|
115
|
+
print("Run 'python tools/db/init_icdev_db.py' first.", file=sys.stderr)
|
|
116
|
+
sys.exit(1)
|
|
117
|
+
conn = sqlite3.connect(str(DB_PATH))
|
|
118
|
+
conn.row_factory = sqlite3.Row
|
|
119
|
+
return conn
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def _normalise_db_name(name: str) -> str:
|
|
123
|
+
"""Normalise a database system name to a canonical key."""
|
|
124
|
+
return _PATH_ALIASES.get(name.lower().strip(), name.lower().strip())
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
# ---------------------------------------------------------------------------
|
|
128
|
+
# Type mapping loader
|
|
129
|
+
# ---------------------------------------------------------------------------
|
|
130
|
+
|
|
131
|
+
def load_type_mappings(source_db: str, target_db: str) -> dict:
|
|
132
|
+
"""Load type, function, and syntax mappings for a specific migration path.
|
|
133
|
+
|
|
134
|
+
Reads context/modernization/db_type_mappings.json and locates the matching
|
|
135
|
+
migration path entry (e.g., oracle_to_postgresql).
|
|
136
|
+
|
|
137
|
+
Returns a dict with keys: data_type_mappings, function_mappings,
|
|
138
|
+
syntax_mappings. Each value is a list of mapping dicts from the JSON.
|
|
139
|
+
Returns empty lists if no matching path is found.
|
|
140
|
+
"""
|
|
141
|
+
if not TYPE_MAPPINGS_PATH.exists():
|
|
142
|
+
print(f"WARNING: Type mappings file not found at {TYPE_MAPPINGS_PATH}",
|
|
143
|
+
file=sys.stderr)
|
|
144
|
+
return {
|
|
145
|
+
"data_type_mappings": [],
|
|
146
|
+
"function_mappings": [],
|
|
147
|
+
"syntax_mappings": [],
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
with open(TYPE_MAPPINGS_PATH, "r", encoding="utf-8") as fh:
|
|
151
|
+
data = json.load(fh)
|
|
152
|
+
|
|
153
|
+
src_key = _normalise_db_name(source_db)
|
|
154
|
+
tgt_key = _normalise_db_name(target_db)
|
|
155
|
+
|
|
156
|
+
migration_paths = data.get("migration_paths", {})
|
|
157
|
+
|
|
158
|
+
# Try exact path key first (e.g., "oracle_to_postgresql")
|
|
159
|
+
path_key = f"{src_key}_to_{tgt_key}"
|
|
160
|
+
if path_key in migration_paths:
|
|
161
|
+
entry = migration_paths[path_key]
|
|
162
|
+
return {
|
|
163
|
+
"data_type_mappings": entry.get("data_type_mappings", []),
|
|
164
|
+
"function_mappings": entry.get("function_mappings", []),
|
|
165
|
+
"syntax_mappings": entry.get("syntax_mappings", []),
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
# Fallback: iterate and match by source/target field values
|
|
169
|
+
for _key, entry in migration_paths.items():
|
|
170
|
+
entry_src = _normalise_db_name(entry.get("source", ""))
|
|
171
|
+
entry_tgt = _normalise_db_name(entry.get("target", ""))
|
|
172
|
+
if entry_src == src_key and entry_tgt == tgt_key:
|
|
173
|
+
return {
|
|
174
|
+
"data_type_mappings": entry.get("data_type_mappings", []),
|
|
175
|
+
"function_mappings": entry.get("function_mappings", []),
|
|
176
|
+
"syntax_mappings": entry.get("syntax_mappings", []),
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
print(f"WARNING: No migration path found for {source_db} -> {target_db}",
|
|
180
|
+
file=sys.stderr)
|
|
181
|
+
return {
|
|
182
|
+
"data_type_mappings": [],
|
|
183
|
+
"function_mappings": [],
|
|
184
|
+
"syntax_mappings": [],
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
# ---------------------------------------------------------------------------
|
|
189
|
+
# Data type conversion
|
|
190
|
+
# ---------------------------------------------------------------------------
|
|
191
|
+
|
|
192
|
+
def _map_data_type(source_type: str, source_db: str, target_db: str,
|
|
193
|
+
mappings: dict) -> str:
|
|
194
|
+
"""Convert a single data type from source to target using mappings.
|
|
195
|
+
|
|
196
|
+
Handles parametric types such as NUMBER(10,2) -> NUMERIC(10,2) and
|
|
197
|
+
VARCHAR2(100) -> VARCHAR(100). If no mapping is found the source type
|
|
198
|
+
is returned with a -- TODO comment appended.
|
|
199
|
+
"""
|
|
200
|
+
raw = source_type.strip()
|
|
201
|
+
|
|
202
|
+
# Extract base type and optional parameters — e.g. "NUMBER(10,2)" -> ("NUMBER", "(10,2)")
|
|
203
|
+
param_match = re.match(r'^([A-Za-z_][A-Za-z0-9_ ]*)\s*(\(.*\))?$', raw)
|
|
204
|
+
if param_match:
|
|
205
|
+
base_type = param_match.group(1).strip().upper()
|
|
206
|
+
params = param_match.group(2) or ""
|
|
207
|
+
else:
|
|
208
|
+
base_type = raw.upper()
|
|
209
|
+
params = ""
|
|
210
|
+
|
|
211
|
+
# Build a quick lookup from the data_type_mappings list
|
|
212
|
+
type_map = {}
|
|
213
|
+
for m in mappings.get("data_type_mappings", []):
|
|
214
|
+
src = m.get("source_type", "").upper().strip()
|
|
215
|
+
tgt = m.get("target_type", "").strip()
|
|
216
|
+
type_map[src] = tgt
|
|
217
|
+
|
|
218
|
+
if base_type in type_map:
|
|
219
|
+
target_base = type_map[base_type]
|
|
220
|
+
# If target already contains params (e.g. NUMERIC(19,4)), use as-is
|
|
221
|
+
if "(" in target_base:
|
|
222
|
+
return target_base
|
|
223
|
+
return f"{target_base}{params}" if params else target_base
|
|
224
|
+
|
|
225
|
+
# Try full type string match (e.g. "TINYINT(1)")
|
|
226
|
+
full_upper = raw.upper()
|
|
227
|
+
if full_upper in type_map:
|
|
228
|
+
return type_map[full_upper]
|
|
229
|
+
|
|
230
|
+
# No mapping found — return source with TODO
|
|
231
|
+
return f"{raw} -- TODO: unmapped type from {source_db}, review manually"
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
# ---------------------------------------------------------------------------
|
|
235
|
+
# Function translation
|
|
236
|
+
# ---------------------------------------------------------------------------
|
|
237
|
+
|
|
238
|
+
def translate_functions(app_id: str, target_db: str, content: str) -> str:
|
|
239
|
+
"""Translate built-in function calls within SQL content.
|
|
240
|
+
|
|
241
|
+
Applies regex-based replacements for common function conversions from
|
|
242
|
+
Oracle and MSSQL to PostgreSQL (or other target). Uses the function_mappings
|
|
243
|
+
from the context JSON where possible, supplemented by hard-coded patterns
|
|
244
|
+
for complex transforms that require regex.
|
|
245
|
+
"""
|
|
246
|
+
if not content:
|
|
247
|
+
return content
|
|
248
|
+
|
|
249
|
+
_normalise_db_name(target_db)
|
|
250
|
+
result = content
|
|
251
|
+
|
|
252
|
+
# ------- Oracle -> PostgreSQL translations -------
|
|
253
|
+
# NVL2(a, b, c) -> CASE WHEN a IS NOT NULL THEN b ELSE c END
|
|
254
|
+
result = re.sub(
|
|
255
|
+
r'\bNVL2\s*\(\s*([^,]+?)\s*,\s*([^,]+?)\s*,\s*([^)]+?)\s*\)',
|
|
256
|
+
r'CASE WHEN \1 IS NOT NULL THEN \2 ELSE \3 END',
|
|
257
|
+
result, flags=re.IGNORECASE
|
|
258
|
+
)
|
|
259
|
+
# NVL(a, b) -> COALESCE(a, b)
|
|
260
|
+
result = re.sub(
|
|
261
|
+
r'\bNVL\s*\(\s*([^,]+?)\s*,\s*([^)]+?)\s*\)',
|
|
262
|
+
r'COALESCE(\1, \2)',
|
|
263
|
+
result, flags=re.IGNORECASE
|
|
264
|
+
)
|
|
265
|
+
# DECODE(a, b, c, d) -> CASE WHEN a=b THEN c ELSE d END
|
|
266
|
+
result = re.sub(
|
|
267
|
+
r'\bDECODE\s*\(\s*([^,]+?)\s*,\s*([^,]+?)\s*,\s*([^,]+?)\s*,\s*([^)]+?)\s*\)',
|
|
268
|
+
r'CASE WHEN \1 = \2 THEN \3 ELSE \4 END',
|
|
269
|
+
result, flags=re.IGNORECASE
|
|
270
|
+
)
|
|
271
|
+
# TO_DATE(s, 'fmt') -> TO_TIMESTAMP(s, 'fmt')
|
|
272
|
+
result = re.sub(
|
|
273
|
+
r'\bTO_DATE\s*\(',
|
|
274
|
+
'TO_TIMESTAMP(',
|
|
275
|
+
result, flags=re.IGNORECASE
|
|
276
|
+
)
|
|
277
|
+
# SYSDATE -> CURRENT_TIMESTAMP
|
|
278
|
+
result = re.sub(
|
|
279
|
+
r'\bSYSDATE\b',
|
|
280
|
+
'CURRENT_TIMESTAMP',
|
|
281
|
+
result, flags=re.IGNORECASE
|
|
282
|
+
)
|
|
283
|
+
# SUBSTR(s, p, l) -> SUBSTRING(s FROM p FOR l)
|
|
284
|
+
result = re.sub(
|
|
285
|
+
r'\bSUBSTR\s*\(\s*([^,]+?)\s*,\s*([^,]+?)\s*,\s*([^)]+?)\s*\)',
|
|
286
|
+
r'SUBSTRING(\1 FROM \2 FOR \3)',
|
|
287
|
+
result, flags=re.IGNORECASE
|
|
288
|
+
)
|
|
289
|
+
# INSTR(s, sub) -> POSITION(sub IN s)
|
|
290
|
+
result = re.sub(
|
|
291
|
+
r'\bINSTR\s*\(\s*([^,]+?)\s*,\s*([^)]+?)\s*\)',
|
|
292
|
+
r'POSITION(\2 IN \1)',
|
|
293
|
+
result, flags=re.IGNORECASE
|
|
294
|
+
)
|
|
295
|
+
|
|
296
|
+
# ------- MSSQL -> PostgreSQL translations -------
|
|
297
|
+
# GETDATE() -> CURRENT_TIMESTAMP
|
|
298
|
+
result = re.sub(
|
|
299
|
+
r'\bGETDATE\s*\(\s*\)',
|
|
300
|
+
'CURRENT_TIMESTAMP',
|
|
301
|
+
result, flags=re.IGNORECASE
|
|
302
|
+
)
|
|
303
|
+
# ISNULL(a, b) -> COALESCE(a, b)
|
|
304
|
+
result = re.sub(
|
|
305
|
+
r'\bISNULL\s*\(\s*([^,]+?)\s*,\s*([^)]+?)\s*\)',
|
|
306
|
+
r'COALESCE(\1, \2)',
|
|
307
|
+
result, flags=re.IGNORECASE
|
|
308
|
+
)
|
|
309
|
+
# LEN(s) -> LENGTH(s)
|
|
310
|
+
result = re.sub(
|
|
311
|
+
r'\bLEN\s*\(',
|
|
312
|
+
'LENGTH(',
|
|
313
|
+
result, flags=re.IGNORECASE
|
|
314
|
+
)
|
|
315
|
+
# CHARINDEX(sub, s) -> POSITION(sub IN s)
|
|
316
|
+
result = re.sub(
|
|
317
|
+
r'\bCHARINDEX\s*\(\s*([^,]+?)\s*,\s*([^)]+?)\s*\)',
|
|
318
|
+
r'POSITION(\1 IN \2)',
|
|
319
|
+
result, flags=re.IGNORECASE
|
|
320
|
+
)
|
|
321
|
+
# DATEADD(day, n, d) -> d + INTERVAL 'n days'
|
|
322
|
+
result = re.sub(
|
|
323
|
+
r'\bDATEADD\s*\(\s*(\w+)\s*,\s*([^,]+?)\s*,\s*([^)]+?)\s*\)',
|
|
324
|
+
r"\3 + INTERVAL '\2 \1s'",
|
|
325
|
+
result, flags=re.IGNORECASE
|
|
326
|
+
)
|
|
327
|
+
# DATEDIFF(day, a, b) -> EXTRACT(DAY FROM b - a)
|
|
328
|
+
result = re.sub(
|
|
329
|
+
r'\bDATEDIFF\s*\(\s*(\w+)\s*,\s*([^,]+?)\s*,\s*([^)]+?)\s*\)',
|
|
330
|
+
r'EXTRACT(\1 FROM \3 - \2)',
|
|
331
|
+
result, flags=re.IGNORECASE
|
|
332
|
+
)
|
|
333
|
+
# CONVERT(type, val) -> CAST(val AS type)
|
|
334
|
+
result = re.sub(
|
|
335
|
+
r'\bCONVERT\s*\(\s*([^,]+?)\s*,\s*([^)]+?)\s*\)',
|
|
336
|
+
r'CAST(\2 AS \1)',
|
|
337
|
+
result, flags=re.IGNORECASE
|
|
338
|
+
)
|
|
339
|
+
|
|
340
|
+
return result
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
# ---------------------------------------------------------------------------
|
|
344
|
+
# Schema DDL generation
|
|
345
|
+
# ---------------------------------------------------------------------------
|
|
346
|
+
|
|
347
|
+
def generate_schema_ddl(app_id: str, target_db: str, output_dir: str) -> str:
|
|
348
|
+
"""Generate CREATE TABLE DDL for the target database.
|
|
349
|
+
|
|
350
|
+
Reads all legacy_db_schemas rows for the given app_id, groups by table,
|
|
351
|
+
maps data types, and produces a complete DDL script with primary key
|
|
352
|
+
constraints, NOT NULL, DEFAULT values, and foreign key constraints.
|
|
353
|
+
Also generates CREATE INDEX for foreign key columns.
|
|
354
|
+
|
|
355
|
+
Returns the path to the generated SQL file.
|
|
356
|
+
"""
|
|
357
|
+
conn = _get_db()
|
|
358
|
+
try:
|
|
359
|
+
rows = conn.execute(
|
|
360
|
+
"""SELECT lds.*, la.primary_language
|
|
361
|
+
FROM legacy_db_schemas lds
|
|
362
|
+
JOIN legacy_applications la ON la.id = lds.legacy_app_id
|
|
363
|
+
WHERE lds.legacy_app_id = ?
|
|
364
|
+
ORDER BY lds.schema_name, lds.table_name, lds.column_name""",
|
|
365
|
+
(app_id,)
|
|
366
|
+
).fetchall()
|
|
367
|
+
finally:
|
|
368
|
+
conn.close()
|
|
369
|
+
|
|
370
|
+
if not rows:
|
|
371
|
+
print(f"WARNING: No schema data found for app_id={app_id}", file=sys.stderr)
|
|
372
|
+
return ""
|
|
373
|
+
|
|
374
|
+
# Determine source DB type from first row
|
|
375
|
+
source_db = rows[0]["db_type"]
|
|
376
|
+
mappings = load_type_mappings(source_db, target_db)
|
|
377
|
+
|
|
378
|
+
# Group rows by (schema_name, table_name)
|
|
379
|
+
tables = OrderedDict()
|
|
380
|
+
for row in rows:
|
|
381
|
+
key = (row["schema_name"] or "public", row["table_name"])
|
|
382
|
+
if key not in tables:
|
|
383
|
+
tables[key] = []
|
|
384
|
+
tables[key].append(dict(row))
|
|
385
|
+
|
|
386
|
+
lines = []
|
|
387
|
+
lines.append(SQL_CUI_HEADER)
|
|
388
|
+
lines.append("-- DDL Migration Script")
|
|
389
|
+
lines.append(f"-- Source: {source_db} -> Target: {target_db}")
|
|
390
|
+
lines.append(f"-- Application ID: {app_id}")
|
|
391
|
+
lines.append(f"-- Generated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
|
392
|
+
lines.append("-- WARNING: Review before execution. Do NOT run unreviewed.")
|
|
393
|
+
lines.append(f"-- {'=' * 68}")
|
|
394
|
+
lines.append("")
|
|
395
|
+
|
|
396
|
+
index_statements = []
|
|
397
|
+
|
|
398
|
+
for (schema, table), columns in tables.items():
|
|
399
|
+
qualified = f"{schema}.{table}" if schema and schema != "public" else table
|
|
400
|
+
|
|
401
|
+
lines.append(f"-- Table: {qualified}")
|
|
402
|
+
lines.append(f"CREATE TABLE IF NOT EXISTS {qualified} (")
|
|
403
|
+
|
|
404
|
+
col_defs = []
|
|
405
|
+
pk_columns = []
|
|
406
|
+
fk_constraints = []
|
|
407
|
+
|
|
408
|
+
for col in columns:
|
|
409
|
+
mapped_type = _map_data_type(
|
|
410
|
+
col["data_type"], source_db, target_db, mappings
|
|
411
|
+
)
|
|
412
|
+
parts = [f" {col['column_name']}", mapped_type]
|
|
413
|
+
|
|
414
|
+
# NOT NULL
|
|
415
|
+
if not col["is_nullable"]:
|
|
416
|
+
parts.append("NOT NULL")
|
|
417
|
+
|
|
418
|
+
# DEFAULT
|
|
419
|
+
if col["default_value"]:
|
|
420
|
+
default_val = _translate_default(col["default_value"], source_db, target_db)
|
|
421
|
+
parts.append(f"DEFAULT {default_val}")
|
|
422
|
+
|
|
423
|
+
col_defs.append(" ".join(parts))
|
|
424
|
+
|
|
425
|
+
# Collect primary key columns
|
|
426
|
+
if col["is_primary_key"]:
|
|
427
|
+
pk_columns.append(col["column_name"])
|
|
428
|
+
|
|
429
|
+
# Collect foreign keys
|
|
430
|
+
if col["is_foreign_key"] and col["foreign_table"]:
|
|
431
|
+
fk_name = f"fk_{table}_{col['column_name']}"
|
|
432
|
+
fk_constraints.append(
|
|
433
|
+
f" CONSTRAINT {fk_name} FOREIGN KEY ({col['column_name']}) "
|
|
434
|
+
f"REFERENCES {col['foreign_table']}({col['foreign_column'] or 'id'})"
|
|
435
|
+
)
|
|
436
|
+
# Index for FK column
|
|
437
|
+
idx_name = f"idx_{table}_{col['column_name']}"
|
|
438
|
+
index_statements.append(
|
|
439
|
+
f"CREATE INDEX IF NOT EXISTS {idx_name} ON {qualified}({col['column_name']});"
|
|
440
|
+
)
|
|
441
|
+
|
|
442
|
+
# Add primary key constraint
|
|
443
|
+
if pk_columns:
|
|
444
|
+
pk_name = f"pk_{table}"
|
|
445
|
+
col_defs.append(
|
|
446
|
+
f" CONSTRAINT {pk_name} PRIMARY KEY ({', '.join(pk_columns)})"
|
|
447
|
+
)
|
|
448
|
+
|
|
449
|
+
# Add foreign key constraints
|
|
450
|
+
col_defs.extend(fk_constraints)
|
|
451
|
+
|
|
452
|
+
lines.append(",\n".join(col_defs))
|
|
453
|
+
lines.append(");")
|
|
454
|
+
lines.append("")
|
|
455
|
+
|
|
456
|
+
# Index statements
|
|
457
|
+
if index_statements:
|
|
458
|
+
lines.append("-- Foreign key indexes")
|
|
459
|
+
lines.extend(index_statements)
|
|
460
|
+
lines.append("")
|
|
461
|
+
|
|
462
|
+
lines.append(SQL_CUI_FOOTER)
|
|
463
|
+
|
|
464
|
+
# Write output
|
|
465
|
+
out_path = Path(output_dir)
|
|
466
|
+
out_path.mkdir(parents=True, exist_ok=True)
|
|
467
|
+
file_path = out_path / "schema_ddl.sql"
|
|
468
|
+
file_path.write_text("\n".join(lines), encoding="utf-8")
|
|
469
|
+
print(f"Schema DDL written to {file_path}")
|
|
470
|
+
return str(file_path)
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
def _translate_default(default_value: str, source_db: str, target_db: str) -> str:
|
|
474
|
+
"""Translate default value expressions from source to target dialect."""
|
|
475
|
+
val = default_value.strip()
|
|
476
|
+
src = _normalise_db_name(source_db)
|
|
477
|
+
|
|
478
|
+
# Oracle-specific defaults
|
|
479
|
+
if src == "oracle":
|
|
480
|
+
if val.upper() == "SYSDATE":
|
|
481
|
+
return "CURRENT_TIMESTAMP"
|
|
482
|
+
if val.upper() == "SYS_GUID()":
|
|
483
|
+
return "gen_random_uuid()"
|
|
484
|
+
# sequence.NEXTVAL -> nextval('sequence')
|
|
485
|
+
nextval_match = re.match(r"(\w+)\.NEXTVAL", val, re.IGNORECASE)
|
|
486
|
+
if nextval_match:
|
|
487
|
+
return f"nextval('{nextval_match.group(1)}')"
|
|
488
|
+
|
|
489
|
+
# MSSQL-specific defaults
|
|
490
|
+
if src == "mssql":
|
|
491
|
+
if val.upper() in ("GETDATE()", "(GETDATE())"):
|
|
492
|
+
return "CURRENT_TIMESTAMP"
|
|
493
|
+
if val.upper() in ("NEWID()", "(NEWID())"):
|
|
494
|
+
return "gen_random_uuid()"
|
|
495
|
+
# Strip outer parentheses common in MSSQL defaults
|
|
496
|
+
stripped = re.sub(r'^\((.+)\)$', r'\1', val)
|
|
497
|
+
if stripped != val:
|
|
498
|
+
return stripped
|
|
499
|
+
|
|
500
|
+
return val
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
# ---------------------------------------------------------------------------
|
|
504
|
+
# Data migration script generation
|
|
505
|
+
# ---------------------------------------------------------------------------
|
|
506
|
+
|
|
507
|
+
def generate_data_migration_scripts(app_id: str, target_db: str,
|
|
508
|
+
output_dir: str) -> str:
|
|
509
|
+
"""Generate INSERT/SELECT migration SQL for each table.
|
|
510
|
+
|
|
511
|
+
For each table produces:
|
|
512
|
+
- INSERT INTO target_table SELECT ... FROM source_table
|
|
513
|
+
- Type casts where data types changed
|
|
514
|
+
- Function translations (NVL->COALESCE, etc.)
|
|
515
|
+
- Row count validation queries
|
|
516
|
+
|
|
517
|
+
Returns the path to the generated SQL file.
|
|
518
|
+
"""
|
|
519
|
+
conn = _get_db()
|
|
520
|
+
try:
|
|
521
|
+
rows = conn.execute(
|
|
522
|
+
"""SELECT lds.*, la.primary_language
|
|
523
|
+
FROM legacy_db_schemas lds
|
|
524
|
+
JOIN legacy_applications la ON la.id = lds.legacy_app_id
|
|
525
|
+
WHERE lds.legacy_app_id = ?
|
|
526
|
+
ORDER BY lds.schema_name, lds.table_name, lds.column_name""",
|
|
527
|
+
(app_id,)
|
|
528
|
+
).fetchall()
|
|
529
|
+
finally:
|
|
530
|
+
conn.close()
|
|
531
|
+
|
|
532
|
+
if not rows:
|
|
533
|
+
print(f"WARNING: No schema data found for app_id={app_id}", file=sys.stderr)
|
|
534
|
+
return ""
|
|
535
|
+
|
|
536
|
+
source_db = rows[0]["db_type"]
|
|
537
|
+
mappings = load_type_mappings(source_db, target_db)
|
|
538
|
+
|
|
539
|
+
# Group by table
|
|
540
|
+
tables = OrderedDict()
|
|
541
|
+
for row in rows:
|
|
542
|
+
key = (row["schema_name"] or "public", row["table_name"])
|
|
543
|
+
if key not in tables:
|
|
544
|
+
tables[key] = []
|
|
545
|
+
tables[key].append(dict(row))
|
|
546
|
+
|
|
547
|
+
lines = []
|
|
548
|
+
lines.append(SQL_CUI_HEADER)
|
|
549
|
+
lines.append("-- Data Migration Script")
|
|
550
|
+
lines.append(f"-- Source: {source_db} -> Target: {target_db}")
|
|
551
|
+
lines.append(f"-- Application ID: {app_id}")
|
|
552
|
+
lines.append(f"-- Generated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
|
553
|
+
lines.append("-- WARNING: Review before execution. Do NOT run unreviewed.")
|
|
554
|
+
lines.append(f"-- {'=' * 68}")
|
|
555
|
+
lines.append("")
|
|
556
|
+
|
|
557
|
+
validation_lines = []
|
|
558
|
+
|
|
559
|
+
for (schema, table), columns in tables.items():
|
|
560
|
+
qualified = f"{schema}.{table}" if schema and schema != "public" else table
|
|
561
|
+
source_qualified = f"{schema}.{table}" if schema and schema != "public" else table
|
|
562
|
+
|
|
563
|
+
lines.append(f"-- Migrate data: {qualified}")
|
|
564
|
+
lines.append(f"-- Source table: {source_qualified}")
|
|
565
|
+
lines.append("")
|
|
566
|
+
|
|
567
|
+
# Build SELECT column list with casts where types changed
|
|
568
|
+
select_parts = []
|
|
569
|
+
col_names = []
|
|
570
|
+
for col in columns:
|
|
571
|
+
col_name = col["column_name"]
|
|
572
|
+
col_names.append(col_name)
|
|
573
|
+
|
|
574
|
+
source_type = col["data_type"].strip().upper()
|
|
575
|
+
mapped_type = _map_data_type(col["data_type"], source_db, target_db, mappings)
|
|
576
|
+
|
|
577
|
+
# Strip TODO comments for comparison
|
|
578
|
+
clean_mapped = mapped_type.split("--")[0].strip().upper()
|
|
579
|
+
|
|
580
|
+
# Extract base type from mapped for comparison
|
|
581
|
+
source_base = re.match(r'^([A-Za-z_][A-Za-z0-9_ ]*)', source_type)
|
|
582
|
+
target_base = re.match(r'^([A-Za-z_][A-Za-z0-9_ ]*)', clean_mapped)
|
|
583
|
+
source_base_str = source_base.group(1).strip() if source_base else source_type
|
|
584
|
+
target_base_str = target_base.group(1).strip() if target_base else clean_mapped
|
|
585
|
+
|
|
586
|
+
if source_base_str != target_base_str and "TODO" not in mapped_type:
|
|
587
|
+
# Type changed — add explicit CAST
|
|
588
|
+
select_parts.append(f"CAST({col_name} AS {clean_mapped}) AS {col_name}")
|
|
589
|
+
else:
|
|
590
|
+
select_parts.append(col_name)
|
|
591
|
+
|
|
592
|
+
# Apply function translations to the SELECT list
|
|
593
|
+
select_str = ",\n ".join(select_parts)
|
|
594
|
+
select_str = translate_functions(app_id, target_db, select_str)
|
|
595
|
+
|
|
596
|
+
target_cols = ", ".join(col_names)
|
|
597
|
+
|
|
598
|
+
lines.append(f"INSERT INTO {qualified} ({target_cols})")
|
|
599
|
+
lines.append(" SELECT")
|
|
600
|
+
lines.append(f" {select_str}")
|
|
601
|
+
lines.append(f" FROM {source_qualified};")
|
|
602
|
+
lines.append("")
|
|
603
|
+
|
|
604
|
+
# Row count validation
|
|
605
|
+
validation_lines.append(f"-- Validate row counts: {qualified}")
|
|
606
|
+
validation_lines.append(
|
|
607
|
+
f"SELECT 'source' AS side, COUNT(*) AS row_count FROM {source_qualified};"
|
|
608
|
+
)
|
|
609
|
+
validation_lines.append(
|
|
610
|
+
f"SELECT 'target' AS side, COUNT(*) AS row_count FROM {qualified};"
|
|
611
|
+
)
|
|
612
|
+
validation_lines.append("")
|
|
613
|
+
|
|
614
|
+
# Append validation section
|
|
615
|
+
lines.append(f"-- {'=' * 68}")
|
|
616
|
+
lines.append("-- ROW COUNT VALIDATION")
|
|
617
|
+
lines.append(f"-- {'=' * 68}")
|
|
618
|
+
lines.append("")
|
|
619
|
+
lines.extend(validation_lines)
|
|
620
|
+
|
|
621
|
+
lines.append(SQL_CUI_FOOTER)
|
|
622
|
+
|
|
623
|
+
out_path = Path(output_dir)
|
|
624
|
+
out_path.mkdir(parents=True, exist_ok=True)
|
|
625
|
+
file_path = out_path / "data_migration.sql"
|
|
626
|
+
file_path.write_text("\n".join(lines), encoding="utf-8")
|
|
627
|
+
print(f"Data migration script written to {file_path}")
|
|
628
|
+
return str(file_path)
|
|
629
|
+
|
|
630
|
+
|
|
631
|
+
# ---------------------------------------------------------------------------
|
|
632
|
+
# Stored procedure translation
|
|
633
|
+
# ---------------------------------------------------------------------------
|
|
634
|
+
|
|
635
|
+
def translate_stored_procedures(app_id: str, target_db: str,
|
|
636
|
+
source_path: str, output_dir: str) -> tuple:
|
|
637
|
+
"""Translate stored procedure and function SQL files to target dialect.
|
|
638
|
+
|
|
639
|
+
Scans source_path for .sql files containing CREATE PROCEDURE/FUNCTION,
|
|
640
|
+
applies syntax mappings (PL/SQL -> PL/pgSQL, T-SQL -> PL/pgSQL), and
|
|
641
|
+
writes translated output.
|
|
642
|
+
|
|
643
|
+
Returns (file_path, untranslatable_constructs) where
|
|
644
|
+
untranslatable_constructs is a list of strings describing items needing
|
|
645
|
+
manual review.
|
|
646
|
+
"""
|
|
647
|
+
src_dir = Path(source_path)
|
|
648
|
+
if not src_dir.exists():
|
|
649
|
+
print(f"WARNING: Source path does not exist: {source_path}", file=sys.stderr)
|
|
650
|
+
return ("", [])
|
|
651
|
+
|
|
652
|
+
# Collect .sql files that contain procedure/function definitions
|
|
653
|
+
sql_files = []
|
|
654
|
+
if src_dir.is_file() and src_dir.suffix.lower() == ".sql":
|
|
655
|
+
sql_files.append(src_dir)
|
|
656
|
+
elif src_dir.is_dir():
|
|
657
|
+
for root, _dirs, files in os.walk(str(src_dir)):
|
|
658
|
+
for fname in sorted(files):
|
|
659
|
+
if fname.lower().endswith(".sql"):
|
|
660
|
+
sql_files.append(Path(root) / fname)
|
|
661
|
+
|
|
662
|
+
if not sql_files:
|
|
663
|
+
print(f"WARNING: No .sql files found in {source_path}", file=sys.stderr)
|
|
664
|
+
return ("", [])
|
|
665
|
+
|
|
666
|
+
# Determine source DB from the app record
|
|
667
|
+
conn = _get_db()
|
|
668
|
+
try:
|
|
669
|
+
conn.execute(
|
|
670
|
+
"SELECT * FROM legacy_applications WHERE id = ?", (app_id,)
|
|
671
|
+
).fetchone()
|
|
672
|
+
schema_row = conn.execute(
|
|
673
|
+
"SELECT db_type FROM legacy_db_schemas WHERE legacy_app_id = ? LIMIT 1",
|
|
674
|
+
(app_id,)
|
|
675
|
+
).fetchone()
|
|
676
|
+
finally:
|
|
677
|
+
conn.close()
|
|
678
|
+
|
|
679
|
+
source_db = schema_row["db_type"] if schema_row else "oracle"
|
|
680
|
+
src_key = _normalise_db_name(source_db)
|
|
681
|
+
load_type_mappings(source_db, target_db)
|
|
682
|
+
|
|
683
|
+
untranslatable = []
|
|
684
|
+
translated_blocks = []
|
|
685
|
+
|
|
686
|
+
translated_blocks.append(SQL_CUI_HEADER)
|
|
687
|
+
translated_blocks.append("-- Stored Procedure Translation")
|
|
688
|
+
translated_blocks.append(f"-- Source: {source_db} -> Target: {target_db}")
|
|
689
|
+
translated_blocks.append(f"-- Application ID: {app_id}")
|
|
690
|
+
translated_blocks.append(f"-- Generated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
|
691
|
+
translated_blocks.append("-- WARNING: Review before execution. Manual review required.")
|
|
692
|
+
translated_blocks.append(f"-- {'=' * 68}")
|
|
693
|
+
translated_blocks.append("")
|
|
694
|
+
|
|
695
|
+
proc_pattern = re.compile(
|
|
696
|
+
r'\bCREATE\s+(OR\s+REPLACE\s+)?(PROCEDURE|FUNCTION)\b',
|
|
697
|
+
re.IGNORECASE
|
|
698
|
+
)
|
|
699
|
+
|
|
700
|
+
for sql_file in sql_files:
|
|
701
|
+
content = sql_file.read_text(encoding="utf-8", errors="replace")
|
|
702
|
+
|
|
703
|
+
# Only process files containing procedure/function definitions
|
|
704
|
+
if not proc_pattern.search(content):
|
|
705
|
+
continue
|
|
706
|
+
|
|
707
|
+
translated_blocks.append(f"-- Source file: {sql_file.name}")
|
|
708
|
+
translated_blocks.append(f"-- {'=' * 50}")
|
|
709
|
+
|
|
710
|
+
translated_content = content
|
|
711
|
+
|
|
712
|
+
# Apply Oracle PL/SQL -> PL/pgSQL conversions
|
|
713
|
+
if src_key == "oracle":
|
|
714
|
+
# IS -> AS (in procedure/function declarations)
|
|
715
|
+
translated_content = re.sub(
|
|
716
|
+
r'\b(CREATE\s+(?:OR\s+REPLACE\s+)?(?:PROCEDURE|FUNCTION)\s+\w+[^;]*?)\bIS\b',
|
|
717
|
+
r'\1AS',
|
|
718
|
+
translated_content, flags=re.IGNORECASE
|
|
719
|
+
)
|
|
720
|
+
# VARCHAR2 -> VARCHAR
|
|
721
|
+
translated_content = re.sub(
|
|
722
|
+
r'\bVARCHAR2\b', 'VARCHAR',
|
|
723
|
+
translated_content, flags=re.IGNORECASE
|
|
724
|
+
)
|
|
725
|
+
# NUMBER -> NUMERIC
|
|
726
|
+
translated_content = re.sub(
|
|
727
|
+
r'\bNUMBER\b', 'NUMERIC',
|
|
728
|
+
translated_content, flags=re.IGNORECASE
|
|
729
|
+
)
|
|
730
|
+
# DBMS_OUTPUT.PUT_LINE -> RAISE NOTICE
|
|
731
|
+
translated_content = re.sub(
|
|
732
|
+
r"\bDBMS_OUTPUT\.PUT_LINE\s*\(\s*'([^']*)'\s*\)",
|
|
733
|
+
r"RAISE NOTICE '\1'",
|
|
734
|
+
translated_content, flags=re.IGNORECASE
|
|
735
|
+
)
|
|
736
|
+
translated_content = re.sub(
|
|
737
|
+
r"\bDBMS_OUTPUT\.PUT_LINE\s*\(\s*([^)]+)\s*\)",
|
|
738
|
+
r"RAISE NOTICE '%', \1",
|
|
739
|
+
translated_content, flags=re.IGNORECASE
|
|
740
|
+
)
|
|
741
|
+
# sequence.NEXTVAL -> nextval('sequence')
|
|
742
|
+
translated_content = re.sub(
|
|
743
|
+
r'\b(\w+)\.NEXTVAL\b',
|
|
744
|
+
r"nextval('\1')",
|
|
745
|
+
translated_content, flags=re.IGNORECASE
|
|
746
|
+
)
|
|
747
|
+
# sequence.CURRVAL -> currval('sequence')
|
|
748
|
+
translated_content = re.sub(
|
|
749
|
+
r'\b(\w+)\.CURRVAL\b',
|
|
750
|
+
r"currval('\1')",
|
|
751
|
+
translated_content, flags=re.IGNORECASE
|
|
752
|
+
)
|
|
753
|
+
|
|
754
|
+
# Detect untranslatable constructs
|
|
755
|
+
if re.search(r'\bCONNECT\s+BY\b', translated_content, re.IGNORECASE):
|
|
756
|
+
untranslatable.append(
|
|
757
|
+
f"{sql_file.name}: CONNECT BY (hierarchical query) -> use WITH RECURSIVE CTE"
|
|
758
|
+
)
|
|
759
|
+
translated_content = re.sub(
|
|
760
|
+
r'\bCONNECT\s+BY\b',
|
|
761
|
+
'-- TODO: CONNECT BY requires manual rewrite to WITH RECURSIVE CTE\n-- CONNECT BY',
|
|
762
|
+
translated_content, flags=re.IGNORECASE
|
|
763
|
+
)
|
|
764
|
+
if re.search(r'\bCREATE\s+(OR\s+REPLACE\s+)?PACKAGE\b', translated_content, re.IGNORECASE):
|
|
765
|
+
untranslatable.append(
|
|
766
|
+
f"{sql_file.name}: PACKAGE -> split into schema + individual functions"
|
|
767
|
+
)
|
|
768
|
+
translated_content = re.sub(
|
|
769
|
+
r'\bCREATE\s+(OR\s+REPLACE\s+)?PACKAGE\b',
|
|
770
|
+
'-- TODO: PACKAGEs have no PostgreSQL equivalent; split into schema + functions\n-- CREATE PACKAGE',
|
|
771
|
+
translated_content, flags=re.IGNORECASE
|
|
772
|
+
)
|
|
773
|
+
if re.search(r'\bPRAGMA\b', translated_content, re.IGNORECASE):
|
|
774
|
+
untranslatable.append(
|
|
775
|
+
f"{sql_file.name}: PRAGMA directives have no PostgreSQL equivalent"
|
|
776
|
+
)
|
|
777
|
+
|
|
778
|
+
# Apply MSSQL T-SQL -> PL/pgSQL conversions
|
|
779
|
+
if src_key == "mssql":
|
|
780
|
+
# Remove SET NOCOUNT ON
|
|
781
|
+
translated_content = re.sub(
|
|
782
|
+
r'\bSET\s+NOCOUNT\s+ON\s*;?',
|
|
783
|
+
'-- SET NOCOUNT ON removed (not needed in PostgreSQL)',
|
|
784
|
+
translated_content, flags=re.IGNORECASE
|
|
785
|
+
)
|
|
786
|
+
# GO -> ; (statement separator)
|
|
787
|
+
translated_content = re.sub(
|
|
788
|
+
r'^\s*GO\s*$',
|
|
789
|
+
';',
|
|
790
|
+
translated_content, flags=re.MULTILINE | re.IGNORECASE
|
|
791
|
+
)
|
|
792
|
+
# DECLARE @var TYPE = value -> DECLARE var TYPE := value
|
|
793
|
+
translated_content = re.sub(
|
|
794
|
+
r'\bDECLARE\s+@(\w+)\s+(\w+(?:\([^)]*\))?)\s*=\s*',
|
|
795
|
+
r'DECLARE \1 \2 := ',
|
|
796
|
+
translated_content, flags=re.IGNORECASE
|
|
797
|
+
)
|
|
798
|
+
# DECLARE @var TYPE (without initial value)
|
|
799
|
+
translated_content = re.sub(
|
|
800
|
+
r'\bDECLARE\s+@(\w+)\s+',
|
|
801
|
+
r'DECLARE \1 ',
|
|
802
|
+
translated_content, flags=re.IGNORECASE
|
|
803
|
+
)
|
|
804
|
+
# @variable -> variable (remove @ prefix)
|
|
805
|
+
translated_content = re.sub(
|
|
806
|
+
r'@(\w+)',
|
|
807
|
+
r'\1',
|
|
808
|
+
translated_content
|
|
809
|
+
)
|
|
810
|
+
# PRINT 'message' -> RAISE NOTICE 'message'
|
|
811
|
+
translated_content = re.sub(
|
|
812
|
+
r'\bPRINT\s+',
|
|
813
|
+
'RAISE NOTICE ',
|
|
814
|
+
translated_content, flags=re.IGNORECASE
|
|
815
|
+
)
|
|
816
|
+
# TOP N -> needs rewrite to LIMIT
|
|
817
|
+
top_matches = re.findall(r'\bSELECT\s+TOP\s+(\d+)\b', translated_content, re.IGNORECASE)
|
|
818
|
+
if top_matches:
|
|
819
|
+
for n in top_matches:
|
|
820
|
+
translated_content = re.sub(
|
|
821
|
+
r'\bSELECT\s+TOP\s+' + n + r'\b',
|
|
822
|
+
f'SELECT /* TODO: add LIMIT {n} at end of query */',
|
|
823
|
+
translated_content, flags=re.IGNORECASE, count=1
|
|
824
|
+
)
|
|
825
|
+
untranslatable.append(
|
|
826
|
+
f"{sql_file.name}: SELECT TOP N -> requires LIMIT at end of query (manual placement)"
|
|
827
|
+
)
|
|
828
|
+
|
|
829
|
+
# Detect untranslatable constructs
|
|
830
|
+
if re.search(r'\bEXEC(?:UTE)?\s+sp_', translated_content, re.IGNORECASE):
|
|
831
|
+
untranslatable.append(
|
|
832
|
+
f"{sql_file.name}: System stored procedures (sp_*) need PostgreSQL equivalents"
|
|
833
|
+
)
|
|
834
|
+
if re.search(r'\bOPENJSON\b', translated_content, re.IGNORECASE):
|
|
835
|
+
untranslatable.append(
|
|
836
|
+
f"{sql_file.name}: OPENJSON -> use json_to_recordset or json_array_elements"
|
|
837
|
+
)
|
|
838
|
+
|
|
839
|
+
# Apply generic function translations
|
|
840
|
+
translated_content = translate_functions(app_id, target_db, translated_content)
|
|
841
|
+
|
|
842
|
+
translated_blocks.append(translated_content)
|
|
843
|
+
translated_blocks.append("")
|
|
844
|
+
|
|
845
|
+
translated_blocks.append(SQL_CUI_FOOTER)
|
|
846
|
+
|
|
847
|
+
out_path = Path(output_dir)
|
|
848
|
+
out_path.mkdir(parents=True, exist_ok=True)
|
|
849
|
+
file_path = out_path / "stored_procedures.sql"
|
|
850
|
+
file_path.write_text("\n".join(translated_blocks), encoding="utf-8")
|
|
851
|
+
print(f"Stored procedure translation written to {file_path}")
|
|
852
|
+
|
|
853
|
+
if untranslatable:
|
|
854
|
+
print(f" {len(untranslatable)} construct(s) need manual review:")
|
|
855
|
+
for item in untranslatable:
|
|
856
|
+
print(f" - {item}")
|
|
857
|
+
|
|
858
|
+
return (str(file_path), untranslatable)
|
|
859
|
+
|
|
860
|
+
|
|
861
|
+
# ---------------------------------------------------------------------------
|
|
862
|
+
# Migration validation queries
|
|
863
|
+
# ---------------------------------------------------------------------------
|
|
864
|
+
|
|
865
|
+
def generate_migration_validation(app_id: str, output_dir: str) -> str:
|
|
866
|
+
"""Generate comprehensive validation queries for post-migration checks.
|
|
867
|
+
|
|
868
|
+
For each table produces:
|
|
869
|
+
- Row count comparison between source and target
|
|
870
|
+
- Checksum (hash of primary key columns) comparison
|
|
871
|
+
- NULL count comparison per nullable column
|
|
872
|
+
- MIN/MAX value checks for numeric and date columns
|
|
873
|
+
|
|
874
|
+
Returns the path to the generated SQL file.
|
|
875
|
+
"""
|
|
876
|
+
conn = _get_db()
|
|
877
|
+
try:
|
|
878
|
+
rows = conn.execute(
|
|
879
|
+
"""SELECT * FROM legacy_db_schemas
|
|
880
|
+
WHERE legacy_app_id = ?
|
|
881
|
+
ORDER BY schema_name, table_name, column_name""",
|
|
882
|
+
(app_id,)
|
|
883
|
+
).fetchall()
|
|
884
|
+
finally:
|
|
885
|
+
conn.close()
|
|
886
|
+
|
|
887
|
+
if not rows:
|
|
888
|
+
print(f"WARNING: No schema data found for app_id={app_id}", file=sys.stderr)
|
|
889
|
+
return ""
|
|
890
|
+
|
|
891
|
+
# Group by table
|
|
892
|
+
tables = OrderedDict()
|
|
893
|
+
for row in rows:
|
|
894
|
+
key = (row["schema_name"] or "public", row["table_name"])
|
|
895
|
+
if key not in tables:
|
|
896
|
+
tables[key] = []
|
|
897
|
+
tables[key].append(dict(row))
|
|
898
|
+
|
|
899
|
+
lines = []
|
|
900
|
+
lines.append(SQL_CUI_HEADER)
|
|
901
|
+
lines.append("-- Migration Validation Queries")
|
|
902
|
+
lines.append(f"-- Application ID: {app_id}")
|
|
903
|
+
lines.append(f"-- Generated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
|
904
|
+
lines.append("-- Run these queries against BOTH source and target databases")
|
|
905
|
+
lines.append("-- and compare results to verify migration correctness.")
|
|
906
|
+
lines.append(f"-- {'=' * 68}")
|
|
907
|
+
lines.append("")
|
|
908
|
+
|
|
909
|
+
for (schema, table), columns in tables.items():
|
|
910
|
+
qualified = f"{schema}.{table}" if schema and schema != "public" else table
|
|
911
|
+
|
|
912
|
+
lines.append(f"-- {'=' * 50}")
|
|
913
|
+
lines.append(f"-- Validation: {qualified}")
|
|
914
|
+
lines.append(f"-- {'=' * 50}")
|
|
915
|
+
lines.append("")
|
|
916
|
+
|
|
917
|
+
# 1. Row count comparison
|
|
918
|
+
lines.append("-- Row count")
|
|
919
|
+
lines.append(f"SELECT '{qualified}' AS table_name, COUNT(*) AS row_count FROM {qualified};")
|
|
920
|
+
lines.append("")
|
|
921
|
+
|
|
922
|
+
# 2. Checksum on primary key columns
|
|
923
|
+
pk_cols = [c for c in columns if c["is_primary_key"]]
|
|
924
|
+
if pk_cols:
|
|
925
|
+
", ".join(c["column_name"] for c in pk_cols)
|
|
926
|
+
pk_concat = " || '|' || ".join(
|
|
927
|
+
f"COALESCE(CAST({c['column_name']} AS TEXT), 'NULL')" for c in pk_cols
|
|
928
|
+
)
|
|
929
|
+
lines.append("-- Primary key checksum")
|
|
930
|
+
lines.append(
|
|
931
|
+
f"SELECT '{qualified}' AS table_name, "
|
|
932
|
+
f"COUNT(DISTINCT ({pk_concat})) AS distinct_pk_count "
|
|
933
|
+
f"FROM {qualified};"
|
|
934
|
+
)
|
|
935
|
+
lines.append("")
|
|
936
|
+
|
|
937
|
+
# 3. NULL count comparison per nullable column
|
|
938
|
+
nullable_cols = [c for c in columns if c["is_nullable"]]
|
|
939
|
+
if nullable_cols:
|
|
940
|
+
lines.append("-- NULL counts per column")
|
|
941
|
+
null_selects = []
|
|
942
|
+
for col in nullable_cols:
|
|
943
|
+
null_selects.append(
|
|
944
|
+
f"SUM(CASE WHEN {col['column_name']} IS NULL THEN 1 ELSE 0 END) "
|
|
945
|
+
f"AS {col['column_name']}_nulls"
|
|
946
|
+
)
|
|
947
|
+
lines.append(
|
|
948
|
+
f"SELECT '{qualified}' AS table_name,\n"
|
|
949
|
+
f" {(',{}'.format(chr(10)) + ' ').join(null_selects)}\n"
|
|
950
|
+
f"FROM {qualified};"
|
|
951
|
+
)
|
|
952
|
+
lines.append("")
|
|
953
|
+
|
|
954
|
+
# 4. MIN/MAX checks for numeric and date columns
|
|
955
|
+
numeric_types = {
|
|
956
|
+
"NUMBER", "NUMERIC", "DECIMAL", "INTEGER", "INT", "BIGINT",
|
|
957
|
+
"SMALLINT", "FLOAT", "REAL", "DOUBLE", "MONEY", "TINYINT",
|
|
958
|
+
"BINARY_FLOAT", "BINARY_DOUBLE",
|
|
959
|
+
}
|
|
960
|
+
date_types = {"DATE", "TIMESTAMP", "DATETIME", "TIMESTAMPTZ", "TIME"}
|
|
961
|
+
|
|
962
|
+
minmax_cols = []
|
|
963
|
+
for col in columns:
|
|
964
|
+
base = re.match(r'^([A-Za-z_]+)', col["data_type"].upper())
|
|
965
|
+
base_type = base.group(1) if base else col["data_type"].upper()
|
|
966
|
+
if base_type in numeric_types or base_type in date_types:
|
|
967
|
+
minmax_cols.append(col)
|
|
968
|
+
|
|
969
|
+
if minmax_cols:
|
|
970
|
+
lines.append("-- MIN/MAX value checks")
|
|
971
|
+
mm_selects = []
|
|
972
|
+
for col in minmax_cols:
|
|
973
|
+
mm_selects.append(f"MIN({col['column_name']}) AS {col['column_name']}_min")
|
|
974
|
+
mm_selects.append(f"MAX({col['column_name']}) AS {col['column_name']}_max")
|
|
975
|
+
lines.append(
|
|
976
|
+
f"SELECT '{qualified}' AS table_name,\n"
|
|
977
|
+
f" {(',{}'.format(chr(10)) + ' ').join(mm_selects)}\n"
|
|
978
|
+
f"FROM {qualified};"
|
|
979
|
+
)
|
|
980
|
+
lines.append("")
|
|
981
|
+
|
|
982
|
+
lines.append(SQL_CUI_FOOTER)
|
|
983
|
+
|
|
984
|
+
out_path = Path(output_dir)
|
|
985
|
+
out_path.mkdir(parents=True, exist_ok=True)
|
|
986
|
+
file_path = out_path / "validation_queries.sql"
|
|
987
|
+
file_path.write_text("\n".join(lines), encoding="utf-8")
|
|
988
|
+
print(f"Validation queries written to {file_path}")
|
|
989
|
+
return str(file_path)
|
|
990
|
+
|
|
991
|
+
|
|
992
|
+
# ---------------------------------------------------------------------------
|
|
993
|
+
# Data volume estimation
|
|
994
|
+
# ---------------------------------------------------------------------------
|
|
995
|
+
|
|
996
|
+
def estimate_data_volume(app_id: str) -> dict:
|
|
997
|
+
"""Estimate data volume based on schema column types.
|
|
998
|
+
|
|
999
|
+
For each table estimates a per-row byte size based on column types and
|
|
1000
|
+
returns a summary dict. This is a schema-based estimate only — actual row
|
|
1001
|
+
counts are not known at planning time.
|
|
1002
|
+
|
|
1003
|
+
Returns:
|
|
1004
|
+
{
|
|
1005
|
+
"app_id": str,
|
|
1006
|
+
"tables": [
|
|
1007
|
+
{"name": str, "schema": str, "estimated_row_bytes": int,
|
|
1008
|
+
"column_count": int}
|
|
1009
|
+
],
|
|
1010
|
+
"total_estimated_bytes_per_row": int,
|
|
1011
|
+
"table_count": int
|
|
1012
|
+
}
|
|
1013
|
+
"""
|
|
1014
|
+
conn = _get_db()
|
|
1015
|
+
try:
|
|
1016
|
+
rows = conn.execute(
|
|
1017
|
+
"""SELECT * FROM legacy_db_schemas
|
|
1018
|
+
WHERE legacy_app_id = ?
|
|
1019
|
+
ORDER BY schema_name, table_name, column_name""",
|
|
1020
|
+
(app_id,)
|
|
1021
|
+
).fetchall()
|
|
1022
|
+
finally:
|
|
1023
|
+
conn.close()
|
|
1024
|
+
|
|
1025
|
+
if not rows:
|
|
1026
|
+
return {
|
|
1027
|
+
"app_id": app_id,
|
|
1028
|
+
"tables": [],
|
|
1029
|
+
"total_estimated_bytes_per_row": 0,
|
|
1030
|
+
"table_count": 0,
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
# Group by table
|
|
1034
|
+
tables_map = OrderedDict()
|
|
1035
|
+
for row in rows:
|
|
1036
|
+
key = (row["schema_name"] or "public", row["table_name"])
|
|
1037
|
+
if key not in tables_map:
|
|
1038
|
+
tables_map[key] = []
|
|
1039
|
+
tables_map[key].append(dict(row))
|
|
1040
|
+
|
|
1041
|
+
table_estimates = []
|
|
1042
|
+
total_bytes = 0
|
|
1043
|
+
|
|
1044
|
+
for (schema, table), columns in tables_map.items():
|
|
1045
|
+
row_bytes = 0
|
|
1046
|
+
for col in columns:
|
|
1047
|
+
dtype_upper = col["data_type"].upper().strip()
|
|
1048
|
+
|
|
1049
|
+
# Extract base type
|
|
1050
|
+
base_match = re.match(r'^([A-Za-z_][A-Za-z0-9_ ]*)', dtype_upper)
|
|
1051
|
+
base_type = base_match.group(1).strip() if base_match else dtype_upper
|
|
1052
|
+
|
|
1053
|
+
# Check for parametric length — e.g. VARCHAR(255) -> use 255
|
|
1054
|
+
param_match = re.match(r'.*\(\s*(\d+)', dtype_upper)
|
|
1055
|
+
if param_match and base_type in ("VARCHAR", "VARCHAR2", "NVARCHAR",
|
|
1056
|
+
"NVARCHAR2", "CHAR", "NCHAR"):
|
|
1057
|
+
# Use declared length as average estimate (halved for VARCHAR)
|
|
1058
|
+
declared = int(param_match.group(1))
|
|
1059
|
+
row_bytes += max(declared // 2, 10)
|
|
1060
|
+
elif base_type in TYPE_SIZE_ESTIMATES:
|
|
1061
|
+
row_bytes += TYPE_SIZE_ESTIMATES[base_type]
|
|
1062
|
+
else:
|
|
1063
|
+
# Unknown type — assume 50 bytes
|
|
1064
|
+
row_bytes += 50
|
|
1065
|
+
|
|
1066
|
+
# Add row overhead (tuple header, alignment)
|
|
1067
|
+
row_bytes += 24
|
|
1068
|
+
|
|
1069
|
+
table_estimates.append({
|
|
1070
|
+
"name": table,
|
|
1071
|
+
"schema": schema,
|
|
1072
|
+
"estimated_row_bytes": row_bytes,
|
|
1073
|
+
"column_count": len(columns),
|
|
1074
|
+
})
|
|
1075
|
+
total_bytes += row_bytes
|
|
1076
|
+
|
|
1077
|
+
return {
|
|
1078
|
+
"app_id": app_id,
|
|
1079
|
+
"tables": table_estimates,
|
|
1080
|
+
"total_estimated_bytes_per_row": total_bytes,
|
|
1081
|
+
"table_count": len(table_estimates),
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
|
|
1085
|
+
# ---------------------------------------------------------------------------
|
|
1086
|
+
# Full migration orchestration
|
|
1087
|
+
# ---------------------------------------------------------------------------
|
|
1088
|
+
|
|
1089
|
+
def generate_full_migration(app_id: str, target_db: str,
|
|
1090
|
+
source_path: str, output_dir: str) -> dict:
|
|
1091
|
+
"""Orchestrate all migration artifact generation.
|
|
1092
|
+
|
|
1093
|
+
Creates an output subdirectory and calls each generation function:
|
|
1094
|
+
- generate_schema_ddl
|
|
1095
|
+
- generate_data_migration_scripts
|
|
1096
|
+
- translate_stored_procedures (if source_path has .sql files)
|
|
1097
|
+
- generate_migration_validation
|
|
1098
|
+
- estimate_data_volume
|
|
1099
|
+
- Generates a migration_index.md linking all files
|
|
1100
|
+
|
|
1101
|
+
Returns a summary dict.
|
|
1102
|
+
"""
|
|
1103
|
+
migration_dir = Path(output_dir) / "db_migration"
|
|
1104
|
+
migration_dir.mkdir(parents=True, exist_ok=True)
|
|
1105
|
+
|
|
1106
|
+
summary = {
|
|
1107
|
+
"app_id": app_id,
|
|
1108
|
+
"target_db": target_db,
|
|
1109
|
+
"output_dir": str(migration_dir),
|
|
1110
|
+
"generated_at": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
|
1111
|
+
"artifacts": {},
|
|
1112
|
+
"untranslatable_constructs": [],
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
# Schema DDL
|
|
1116
|
+
ddl_path = generate_schema_ddl(app_id, target_db, str(migration_dir))
|
|
1117
|
+
if ddl_path:
|
|
1118
|
+
summary["artifacts"]["schema_ddl"] = ddl_path
|
|
1119
|
+
|
|
1120
|
+
# Data migration
|
|
1121
|
+
data_path = generate_data_migration_scripts(app_id, target_db, str(migration_dir))
|
|
1122
|
+
if data_path:
|
|
1123
|
+
summary["artifacts"]["data_migration"] = data_path
|
|
1124
|
+
|
|
1125
|
+
# Stored procedures
|
|
1126
|
+
proc_path = ""
|
|
1127
|
+
untranslatable = []
|
|
1128
|
+
if source_path:
|
|
1129
|
+
src = Path(source_path)
|
|
1130
|
+
has_sql = False
|
|
1131
|
+
if src.is_file() and src.suffix.lower() == ".sql":
|
|
1132
|
+
has_sql = True
|
|
1133
|
+
elif src.is_dir():
|
|
1134
|
+
for _root, _dirs, files in os.walk(str(src)):
|
|
1135
|
+
if any(f.lower().endswith(".sql") for f in files):
|
|
1136
|
+
has_sql = True
|
|
1137
|
+
break
|
|
1138
|
+
if has_sql:
|
|
1139
|
+
proc_path, untranslatable = translate_stored_procedures(
|
|
1140
|
+
app_id, target_db, source_path, str(migration_dir)
|
|
1141
|
+
)
|
|
1142
|
+
if proc_path:
|
|
1143
|
+
summary["artifacts"]["stored_procedures"] = proc_path
|
|
1144
|
+
if untranslatable:
|
|
1145
|
+
summary["untranslatable_constructs"] = untranslatable
|
|
1146
|
+
|
|
1147
|
+
# Validation
|
|
1148
|
+
val_path = generate_migration_validation(app_id, str(migration_dir))
|
|
1149
|
+
if val_path:
|
|
1150
|
+
summary["artifacts"]["validation_queries"] = val_path
|
|
1151
|
+
|
|
1152
|
+
# Volume estimation
|
|
1153
|
+
volume = estimate_data_volume(app_id)
|
|
1154
|
+
summary["volume_estimate"] = volume
|
|
1155
|
+
|
|
1156
|
+
# Generate index document
|
|
1157
|
+
index_path = _generate_migration_index(summary, str(migration_dir))
|
|
1158
|
+
summary["artifacts"]["migration_index"] = index_path
|
|
1159
|
+
|
|
1160
|
+
return summary
|
|
1161
|
+
|
|
1162
|
+
|
|
1163
|
+
def _generate_migration_index(summary: dict, output_dir: str) -> str:
|
|
1164
|
+
"""Generate a Markdown index document linking all migration artifacts."""
|
|
1165
|
+
lines = []
|
|
1166
|
+
lines.append(MD_CUI_HEADER)
|
|
1167
|
+
lines.append("")
|
|
1168
|
+
lines.append("# Database Migration Plan")
|
|
1169
|
+
lines.append("")
|
|
1170
|
+
lines.append(f"**Application ID:** {summary['app_id']}")
|
|
1171
|
+
lines.append(f"**Target Database:** {summary['target_db']}")
|
|
1172
|
+
lines.append(f"**Generated:** {summary['generated_at']}")
|
|
1173
|
+
lines.append("")
|
|
1174
|
+
lines.append("## Generated Artifacts")
|
|
1175
|
+
lines.append("")
|
|
1176
|
+
lines.append("| Artifact | File | Description |")
|
|
1177
|
+
lines.append("|----------|------|-------------|")
|
|
1178
|
+
|
|
1179
|
+
artifact_desc = {
|
|
1180
|
+
"schema_ddl": "CREATE TABLE DDL statements for target database",
|
|
1181
|
+
"data_migration": "INSERT/SELECT migration SQL with type casts and function translations",
|
|
1182
|
+
"stored_procedures": "Translated stored procedures and functions",
|
|
1183
|
+
"validation_queries": "Post-migration validation queries (row counts, checksums, MIN/MAX)",
|
|
1184
|
+
"migration_index": "This index document",
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
for key, path in summary.get("artifacts", {}).items():
|
|
1188
|
+
if key == "migration_index":
|
|
1189
|
+
continue
|
|
1190
|
+
desc = artifact_desc.get(key, key)
|
|
1191
|
+
filename = Path(path).name
|
|
1192
|
+
lines.append(f"| {key} | `{filename}` | {desc} |")
|
|
1193
|
+
|
|
1194
|
+
lines.append("")
|
|
1195
|
+
|
|
1196
|
+
# Volume estimates
|
|
1197
|
+
volume = summary.get("volume_estimate", {})
|
|
1198
|
+
if volume and volume.get("tables"):
|
|
1199
|
+
lines.append("## Data Volume Estimates (per row)")
|
|
1200
|
+
lines.append("")
|
|
1201
|
+
lines.append("| Table | Schema | Columns | Est. Row Size (bytes) |")
|
|
1202
|
+
lines.append("|-------|--------|---------|----------------------|")
|
|
1203
|
+
for t in volume["tables"]:
|
|
1204
|
+
lines.append(
|
|
1205
|
+
f"| {t['name']} | {t['schema']} | {t['column_count']} | "
|
|
1206
|
+
f"{t['estimated_row_bytes']:,} |"
|
|
1207
|
+
)
|
|
1208
|
+
lines.append("")
|
|
1209
|
+
lines.append(
|
|
1210
|
+
f"**Total tables:** {volume['table_count']} "
|
|
1211
|
+
)
|
|
1212
|
+
lines.append(
|
|
1213
|
+
f"**Combined est. row bytes:** {volume['total_estimated_bytes_per_row']:,}"
|
|
1214
|
+
)
|
|
1215
|
+
lines.append("")
|
|
1216
|
+
|
|
1217
|
+
# Untranslatable constructs
|
|
1218
|
+
constructs = summary.get("untranslatable_constructs", [])
|
|
1219
|
+
if constructs:
|
|
1220
|
+
lines.append("## Items Requiring Manual Review")
|
|
1221
|
+
lines.append("")
|
|
1222
|
+
for item in constructs:
|
|
1223
|
+
lines.append(f"- {item}")
|
|
1224
|
+
lines.append("")
|
|
1225
|
+
|
|
1226
|
+
lines.append("## DBA Review Checklist")
|
|
1227
|
+
lines.append("")
|
|
1228
|
+
lines.append("- [ ] Review schema_ddl.sql for correct data type mappings")
|
|
1229
|
+
lines.append("- [ ] Verify PRIMARY KEY and FOREIGN KEY constraints")
|
|
1230
|
+
lines.append("- [ ] Review data_migration.sql for correct type casts")
|
|
1231
|
+
lines.append("- [ ] Check stored_procedures.sql for TODO comments")
|
|
1232
|
+
lines.append("- [ ] Run validation_queries.sql after migration")
|
|
1233
|
+
lines.append("- [ ] Verify row counts match between source and target")
|
|
1234
|
+
lines.append("- [ ] Test application functionality against migrated database")
|
|
1235
|
+
lines.append("- [ ] Verify CUI markings on all generated artifacts")
|
|
1236
|
+
lines.append("")
|
|
1237
|
+
lines.append(MD_CUI_FOOTER)
|
|
1238
|
+
|
|
1239
|
+
out_path = Path(output_dir)
|
|
1240
|
+
file_path = out_path / "migration_index.md"
|
|
1241
|
+
file_path.write_text("\n".join(lines), encoding="utf-8")
|
|
1242
|
+
print(f"Migration index written to {file_path}")
|
|
1243
|
+
return str(file_path)
|
|
1244
|
+
|
|
1245
|
+
|
|
1246
|
+
# ---------------------------------------------------------------------------
|
|
1247
|
+
# CLI
|
|
1248
|
+
# ---------------------------------------------------------------------------
|
|
1249
|
+
|
|
1250
|
+
def main():
|
|
1251
|
+
"""CLI entry point for database migration planning."""
|
|
1252
|
+
parser = argparse.ArgumentParser(
|
|
1253
|
+
description="Database Migration Planner — generate DDL, data migration SQL, "
|
|
1254
|
+
"stored procedure translations, and validation queries for "
|
|
1255
|
+
"legacy database modernization.",
|
|
1256
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
1257
|
+
epilog=textwrap.dedent("""\
|
|
1258
|
+
Examples:
|
|
1259
|
+
# Generate all migration artifacts
|
|
1260
|
+
python tools/modernization/db_migration_planner.py \\
|
|
1261
|
+
--app-id APP-001 --output-dir .tmp/migration --type all
|
|
1262
|
+
|
|
1263
|
+
# Generate only schema DDL
|
|
1264
|
+
python tools/modernization/db_migration_planner.py \\
|
|
1265
|
+
--app-id APP-001 --output-dir .tmp/migration --type schema
|
|
1266
|
+
|
|
1267
|
+
# Translate stored procedures
|
|
1268
|
+
python tools/modernization/db_migration_planner.py \\
|
|
1269
|
+
--app-id APP-001 --output-dir .tmp/migration \\
|
|
1270
|
+
--type procedures --source-path /opt/legacy/sql
|
|
1271
|
+
|
|
1272
|
+
# JSON output for pipeline integration
|
|
1273
|
+
python tools/modernization/db_migration_planner.py \\
|
|
1274
|
+
--app-id APP-001 --output-dir .tmp/migration --type all --json
|
|
1275
|
+
"""),
|
|
1276
|
+
)
|
|
1277
|
+
|
|
1278
|
+
parser.add_argument(
|
|
1279
|
+
"--app-id", required=True,
|
|
1280
|
+
help="Legacy application ID from legacy_applications table"
|
|
1281
|
+
)
|
|
1282
|
+
parser.add_argument(
|
|
1283
|
+
"--target", default="postgresql",
|
|
1284
|
+
choices=["postgresql", "mysql", "aurora"],
|
|
1285
|
+
help="Target database platform (default: postgresql)"
|
|
1286
|
+
)
|
|
1287
|
+
parser.add_argument(
|
|
1288
|
+
"--source-path", default=None,
|
|
1289
|
+
help="Path to directory containing stored procedure .sql files"
|
|
1290
|
+
)
|
|
1291
|
+
parser.add_argument(
|
|
1292
|
+
"--output-dir", required=True,
|
|
1293
|
+
help="Directory to write generated migration artifacts"
|
|
1294
|
+
)
|
|
1295
|
+
parser.add_argument(
|
|
1296
|
+
"--type", default="all", dest="gen_type",
|
|
1297
|
+
choices=["schema", "data", "procedures", "validation", "all"],
|
|
1298
|
+
help="Type of artifacts to generate (default: all)"
|
|
1299
|
+
)
|
|
1300
|
+
parser.add_argument(
|
|
1301
|
+
"--json", action="store_true", dest="json_output",
|
|
1302
|
+
help="Output results as JSON to stdout"
|
|
1303
|
+
)
|
|
1304
|
+
|
|
1305
|
+
args = parser.parse_args()
|
|
1306
|
+
|
|
1307
|
+
# Validate app exists
|
|
1308
|
+
conn = _get_db()
|
|
1309
|
+
try:
|
|
1310
|
+
app = conn.execute(
|
|
1311
|
+
"SELECT * FROM legacy_applications WHERE id = ?", (args.app_id,)
|
|
1312
|
+
).fetchone()
|
|
1313
|
+
if not app:
|
|
1314
|
+
print(f"ERROR: Application '{args.app_id}' not found in legacy_applications.",
|
|
1315
|
+
file=sys.stderr)
|
|
1316
|
+
sys.exit(1)
|
|
1317
|
+
finally:
|
|
1318
|
+
conn.close()
|
|
1319
|
+
|
|
1320
|
+
# Map aurora -> postgresql for type mappings
|
|
1321
|
+
target_db = "postgresql" if args.target == "aurora" else args.target
|
|
1322
|
+
|
|
1323
|
+
result = {}
|
|
1324
|
+
|
|
1325
|
+
if args.gen_type == "all":
|
|
1326
|
+
result = generate_full_migration(
|
|
1327
|
+
app_id=args.app_id,
|
|
1328
|
+
target_db=target_db,
|
|
1329
|
+
source_path=args.source_path or "",
|
|
1330
|
+
output_dir=args.output_dir,
|
|
1331
|
+
)
|
|
1332
|
+
|
|
1333
|
+
elif args.gen_type == "schema":
|
|
1334
|
+
path = generate_schema_ddl(args.app_id, target_db, args.output_dir)
|
|
1335
|
+
result = {"artifact": "schema_ddl", "path": path}
|
|
1336
|
+
|
|
1337
|
+
elif args.gen_type == "data":
|
|
1338
|
+
path = generate_data_migration_scripts(args.app_id, target_db, args.output_dir)
|
|
1339
|
+
result = {"artifact": "data_migration", "path": path}
|
|
1340
|
+
|
|
1341
|
+
elif args.gen_type == "procedures":
|
|
1342
|
+
if not args.source_path:
|
|
1343
|
+
print("ERROR: --source-path is required for --type procedures",
|
|
1344
|
+
file=sys.stderr)
|
|
1345
|
+
sys.exit(1)
|
|
1346
|
+
path, untranslatable = translate_stored_procedures(
|
|
1347
|
+
args.app_id, target_db, args.source_path, args.output_dir
|
|
1348
|
+
)
|
|
1349
|
+
result = {
|
|
1350
|
+
"artifact": "stored_procedures",
|
|
1351
|
+
"path": path,
|
|
1352
|
+
"untranslatable_constructs": untranslatable,
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
elif args.gen_type == "validation":
|
|
1356
|
+
path = generate_migration_validation(args.app_id, args.output_dir)
|
|
1357
|
+
result = {"artifact": "validation_queries", "path": path}
|
|
1358
|
+
|
|
1359
|
+
# Output
|
|
1360
|
+
if args.json_output:
|
|
1361
|
+
print(json.dumps(result, indent=2, default=str))
|
|
1362
|
+
else:
|
|
1363
|
+
if args.gen_type == "all":
|
|
1364
|
+
print("\nMigration plan generated successfully.")
|
|
1365
|
+
print(f" Application: {args.app_id}")
|
|
1366
|
+
print(f" Target DB: {target_db}")
|
|
1367
|
+
print(f" Output: {result.get('output_dir', args.output_dir)}")
|
|
1368
|
+
print(f" Artifacts: {len(result.get('artifacts', {}))}")
|
|
1369
|
+
vol = result.get("volume_estimate", {})
|
|
1370
|
+
if vol and vol.get("table_count"):
|
|
1371
|
+
print(f" Tables: {vol['table_count']}")
|
|
1372
|
+
constructs = result.get("untranslatable_constructs", [])
|
|
1373
|
+
if constructs:
|
|
1374
|
+
print(f" Manual review items: {len(constructs)}")
|
|
1375
|
+
else:
|
|
1376
|
+
path = result.get("path", "")
|
|
1377
|
+
if path:
|
|
1378
|
+
print(f"\nArtifact generated: {path}")
|
|
1379
|
+
else:
|
|
1380
|
+
print("\nNo output generated — check warnings above.")
|
|
1381
|
+
|
|
1382
|
+
|
|
1383
|
+
if __name__ == "__main__":
|
|
1384
|
+
main()
|
|
1385
|
+
# [TEMPLATE: CUI // SP-CTI]
|