@thierrynakoa/fire-flow 12.2.1 → 13.0.1
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.
- package/CREDITS.md +25 -0
- package/DOMINION-FLOW-OVERVIEW.md +182 -38
- package/README.md +399 -455
- package/TROUBLESHOOTING.md +264 -264
- package/agents/fire-debugger.md +54 -0
- package/agents/fire-executor.md +1610 -1033
- package/agents/fire-fact-checker.md +1 -1
- package/agents/fire-planner.md +85 -17
- package/agents/fire-project-researcher.md +1 -1
- package/agents/fire-researcher.md +4 -22
- package/agents/{fire-phoenix-analyst.md → fire-resurrection-analyst.md} +394 -394
- package/agents/fire-reviewer.md +552 -499
- package/agents/fire-verifier.md +114 -19
- package/bin/cli.js +18 -101
- package/commands/fire-0-orient.md +2 -2
- package/commands/fire-1a-new.md +50 -15
- package/commands/fire-1c-setup.md +33 -5
- package/commands/fire-1d-discuss.md +87 -1
- package/commands/fire-2-plan.md +556 -527
- package/commands/fire-3-execute.md +2046 -1356
- package/commands/fire-4-verify.md +975 -906
- package/commands/fire-5-handoff.md +46 -5
- package/commands/fire-6-resume.md +2 -31
- package/commands/fire-add-new-skill.md +138 -19
- package/commands/fire-autonomous.md +14 -2
- package/commands/fire-complete-milestone.md +1 -1
- package/commands/fire-cost.md +179 -183
- package/commands/fire-debug.md +1 -6
- package/commands/fire-loop-resume.md +2 -2
- package/commands/fire-loop-stop.md +1 -1
- package/commands/fire-loop.md +2 -15
- package/commands/fire-map-codebase.md +1 -1
- package/commands/fire-migrate-database.md +548 -0
- package/commands/fire-new-milestone.md +1 -1
- package/commands/fire-reflect.md +1 -2
- package/commands/fire-research.md +142 -21
- package/commands/{fire-phoenix.md → fire-resurrect.md} +859 -603
- package/commands/fire-scaffold.md +297 -0
- package/commands/fire-search.md +1 -2
- package/commands/fire-security-scan.md +483 -484
- package/commands/fire-setup.md +359 -0
- package/commands/fire-skill.md +770 -0
- package/commands/fire-skills-diff.md +506 -506
- package/commands/fire-skills-history.md +388 -388
- package/commands/fire-skills-rollback.md +7 -7
- package/commands/fire-skills-sync.md +470 -470
- package/commands/fire-test.md +5 -5
- package/commands/fire-todos.md +1 -1
- package/commands/fire-update.md +5 -5
- package/commands/fire-validate-skills.md +282 -0
- package/commands/fire-vuln-scan.md +492 -493
- package/hooks/run-hook.sh +8 -8
- package/hooks/run-session-end.sh +7 -7
- package/hooks/session-end.sh +90 -90
- package/hooks/session-start.sh +1 -1
- package/package.json +4 -24
- package/plugin.json +7 -7
- package/references/autonomy-levels.md +235 -0
- package/references/behavioral-directives.md +95 -3
- package/references/blocker-tracking.md +1 -1
- package/references/circuit-breaker.md +93 -2
- package/references/context-engineering.md +227 -9
- package/references/honesty-protocols.md +70 -1
- package/references/issue-to-pr-pipeline.md +149 -150
- package/references/metrics-and-trends.md +1 -2
- package/references/research-improvements.md +4 -108
- package/references/sdlc-mapping.md +73 -0
- package/references/state-machine.md +151 -0
- package/skills-library/AVAILABLE_TOOLS_REFERENCE.md +333 -0
- package/skills-library/SKILLS-INDEX.md +57 -558
- package/skills-library/SKILLS_LIBRARY_INDEX.md +532 -0
- package/skills-library/_general/api-patterns/api-field-name-mismatch.md +107 -0
- package/skills-library/_general/api-patterns/streaming-command-timeout.md +122 -0
- package/skills-library/_general/api-patterns/streaming-proxy-cors-bypass.md +102 -0
- package/skills-library/_general/automation/settings-gui-generator.md +172 -0
- package/skills-library/_general/database-solutions/data-type-mapping-reference.md +181 -0
- package/skills-library/_general/database-solutions/mysql-limit-offset-string-coercion.md +102 -0
- package/skills-library/_general/database-solutions/mysql-to-pg-migration.md +195 -0
- package/skills-library/_general/database-solutions/orm-schema-portability.md +193 -0
- package/skills-library/_general/database-solutions/persistent-analysis-storage.md +207 -0
- package/skills-library/_general/database-solutions/pg-to-mysql-schema-migration-methodology.md +190 -0
- package/skills-library/_general/database-solutions/sql-dialect-compatibility-matrix.md +306 -0
- package/skills-library/_general/database-solutions/sqlite-to-pg-migration.md +219 -0
- package/skills-library/_general/frontend/canvas-bubble-animation-grouping.md +270 -0
- package/skills-library/_general/frontend/color-token-migration.md +112 -0
- package/skills-library/_general/frontend/framer-motion-layoutid-grouping.md +150 -0
- package/skills-library/_general/frontend/pyqt6-settings-dialog.md +191 -0
- package/skills-library/_general/frontend/react-flow-animated-layout-switching.md +101 -0
- package/skills-library/_general/frontend/react-hooks-order-debugging.md +141 -0
- package/skills-library/_general/frontend/redux-localstorage-auth-desync.md +126 -0
- package/skills-library/_general/frontend/safari-csp-theme-color-debugging.md +124 -0
- package/skills-library/_general/frontend/safari-sw-cache-poisoning.md +138 -0
- package/skills-library/_general/frontend/svg-sparkline-no-charting-library.md +131 -0
- package/skills-library/_general/growth-marketing/oss-daily-growth-intelligence.md +224 -0
- package/skills-library/_general/integrations/claude-code-local-mcp-integration.md +250 -0
- package/skills-library/_general/integrations/mcp-composite-tool-orchestration.md +200 -0
- package/skills-library/_general/methodology/AGENT_SDK_STANDALONE_TOOLING.md +181 -0
- package/skills-library/_general/methodology/AGENT_TEAMS_GUIDE.md +169 -0
- package/skills-library/_general/methodology/ALAS_STATEFUL_EXECUTION.md +207 -0
- package/skills-library/_general/methodology/AUTO_REVIEWER_SUBAGENT.md +211 -0
- package/skills-library/_general/methodology/CONSISTENCY_CHECK_AMBIGUITY_GATE.md +96 -0
- package/skills-library/_general/methodology/DEAD_ENDS_SHELF.md +4 -4
- package/skills-library/_general/methodology/DISTILL_NOT_DUMP.md +108 -0
- package/skills-library/_general/methodology/EXECUTION_PROGRESS_MONITOR.md +157 -0
- package/skills-library/_general/methodology/HIERARCHICAL_REVIEW_MARS.md +122 -0
- package/skills-library/_general/methodology/MCP_INTER_AGENT_BRIDGE.md +207 -0
- package/skills-library/_general/methodology/MERMAID_WIZARD_DIAGRAMS.md +77 -0
- package/skills-library/_general/methodology/MISSING_DIMENSION_DETECTOR.md +89 -0
- package/skills-library/_general/methodology/MULTI_AGENT_COORDINATION.md +397 -0
- package/skills-library/_general/methodology/OBSERVATION_MASKING.md +100 -0
- package/skills-library/_general/methodology/PHOENIX_REBUILD_METHODOLOGY.md +82 -11
- package/skills-library/_general/methodology/REVIEW_BACKTRACK_PANEL.md +140 -0
- package/skills-library/_general/methodology/REVIEW_FIX_LOOP.md +117 -0
- package/skills-library/_general/methodology/VOTING_VERDICT_ARBITRATION.md +155 -0
- package/skills-library/_general/methodology/ZERO_FRICTION_CLI_SETUP.md +2 -2
- package/skills-library/_general/methodology/dead-code-activation.md +123 -0
- package/skills-library/_general/methodology/debug-swarm-researcher-escape-hatch.md +240 -240
- package/skills-library/_general/methodology/shell-autonomous-loop-fixplan.md +1 -1
- package/skills-library/_general/patterns-standards/GOF_DESIGN_PATTERNS_FOR_AI_AGENTS.md +5 -5
- package/skills-library/_general/patterns-standards/cascading-failure-diagnosis.md +119 -0
- package/skills-library/_general/patterns-standards/domain-specific-layout-algorithms.md +209 -0
- package/skills-library/_general/patterns-standards/python-desktop-app-architecture.md +399 -0
- package/skills-library/_general/patterns-standards/realtime-monitoring-dashboard.md +457 -0
- package/skills-library/_general/patterns-standards/togglable-processing-pipeline.md +169 -0
- package/skills-library/_general/performance/liveclock-extraction.md +112 -0
- package/skills-library/_general/performance/ref-based-canvas-animation.md +117 -0
- package/skills-library/_general/performance/use-visible-interval.md +131 -0
- package/skills-library/_general/testing/playwright-firefox-withcredentials-auth-issue.md +104 -0
- package/skills-library/_quarantine/README.md +30 -0
- package/skills-library/api-patterns/BROADCAST_SCHEDULER_SHARED_EXECUTE_FUNCTION.md +150 -0
- package/skills-library/api-patterns/ERROR_RESPONSE_STANDARDS.md +145 -0
- package/skills-library/api-patterns/EXPRESS_ROUTE_ORDERING_MIDDLEWARE_INTERCEPTION.md +326 -0
- package/skills-library/api-patterns/PAGINATION_PATTERNS.md +137 -0
- package/skills-library/api-patterns/PODCAST_PROGRESS_TRACKING_THREE_ROOT_CAUSES.md +277 -0
- package/skills-library/api-patterns/RATE_LIMITING_TOGGLE.md +155 -0
- package/skills-library/api-patterns/graphql-content-queries.md +708 -0
- package/skills-library/appointment-scheduler-design.md +423 -0
- package/skills-library/automation/AUTO_POPULATE_COMPLETE_GUIDE.md +631 -0
- package/skills-library/automation/CC_WORKFLOW_STUDIO.md +83 -0
- package/skills-library/automation/CLAUDE_CODE_SWARM_MODE.md +95 -0
- package/skills-library/automation/DAEMON_TRIGGER_FILE_IPC.md +195 -0
- package/skills-library/automation/scheduled-content-publishing.md +608 -0
- package/skills-library/awesome-workflows/Blogging-Platform-Instructions/view_commands.md +25 -0
- package/skills-library/awesome-workflows/CREDENTIAL-SECURITY-WORKFLOW.md +109 -0
- package/skills-library/awesome-workflows/DEBUGGING-WORKFLOW.md +124 -0
- package/skills-library/awesome-workflows/Design-Review-Workflow/README.md +31 -0
- package/skills-library/awesome-workflows/Design-Review-Workflow/design-principles-example.md +129 -0
- package/skills-library/awesome-workflows/Design-Review-Workflow/design-review-agent.md +107 -0
- package/skills-library/awesome-workflows/Design-Review-Workflow/design-review-claude-md-snippet.md +24 -0
- package/skills-library/awesome-workflows/Design-Review-Workflow/design-review-slash-command.md +38 -0
- package/skills-library/awesome-workflows/PARALLEL-RESEARCH-WORKFLOW.md +89 -0
- package/skills-library/awesome-workflows/PHASE-EXECUTION-WORKFLOW.md +97 -0
- package/skills-library/awesome-workflows/SESSION-HANDOFF-WORKFLOW.md +116 -0
- package/skills-library/cms-patterns/content-branch-preview.md +515 -0
- package/skills-library/cms-patterns/inline-visual-editing.md +666 -0
- package/skills-library/cms-patterns/mdx-component-content.md +649 -0
- package/skills-library/cms-patterns/media-manager-abstraction.md +827 -0
- package/skills-library/cms-patterns/schema-driven-form-generator.md +838 -0
- package/skills-library/complexity-metrics/complexity-divider.md +707 -0
- package/skills-library/complexity-metrics/work-with-complexity.md +193 -0
- package/skills-library/creative-multimedia/animation-stack-guide.md +577 -0
- package/skills-library/creative-multimedia/audio-enhancement-pipeline.md +625 -0
- package/skills-library/creative-multimedia/content-repurposing-pipeline.md +1146 -0
- package/skills-library/creative-multimedia/data-visualization-generator.md +862 -0
- package/skills-library/creative-multimedia/doc-to-podcast-pipeline.md +2184 -0
- package/skills-library/creative-multimedia/ffmpeg-command-generator.md +405 -0
- package/skills-library/creative-multimedia/image-optimization-pipeline.md +605 -0
- package/skills-library/creative-multimedia/multi-format-content-generator.md +1759 -0
- package/skills-library/creative-multimedia/og-image-generator.md +635 -0
- package/skills-library/creative-multimedia/podcast-audio-composition.md +1355 -0
- package/skills-library/creative-multimedia/podcast-quality-evaluation.md +1452 -0
- package/skills-library/creative-multimedia/podcast-script-generation.md +1841 -0
- package/skills-library/creative-multimedia/svg-generation.md +750 -0
- package/skills-library/creative-multimedia/text-to-speech-provider-selector.md +1414 -0
- package/skills-library/creative-multimedia/transcription-pipeline-selector.md +677 -0
- package/skills-library/creative-multimedia/video-streaming-setup.md +559 -0
- package/skills-library/database-solutions/AI_RESPONSE_DATABASE_CACHING.md +520 -0
- package/skills-library/database-solutions/CONDITIONAL_SQL_MIGRATION_PATTERN.md +119 -0
- package/skills-library/database-solutions/DATABASE_COLUMN_NAME_MISMATCH.md +393 -0
- package/skills-library/database-solutions/DATABASE_SCHEMA.md +394 -0
- package/skills-library/database-solutions/DATABASE_SCHEMA_VERIFICATION_GUIDE.md +348 -0
- package/skills-library/database-solutions/DATABASE_STRATEGY.md +71 -0
- package/skills-library/database-solutions/ES_MODULE_SEED_SCRIPT_PATTERN.md +52 -0
- package/skills-library/database-solutions/MIGRATION_GUIDE.md +3 -0
- package/skills-library/database-solutions/PLPGSQL_VARIABLE_CONFLICT_FIX.md +208 -0
- package/skills-library/database-solutions/POSTGRESQL_JSONB_DOUBLE_STRINGIFY_FIX.md +245 -0
- package/skills-library/database-solutions/POSTGRESQL_LICENSE_TABLE_DESIGN.md +393 -0
- package/skills-library/database-solutions/POSTGRESQL_UUID_DOCUMENT_RAG_DUAL_SCOPE.md +732 -0
- package/skills-library/database-solutions/POSTGRES_SQL_TEMPLATE_BINDING_ERROR.md +240 -0
- package/skills-library/database-solutions/PRISMA_DB_PUSH_DATA_LOSS_PREVENTION.md +141 -0
- package/skills-library/database-solutions/PRODUCTION_QUERY_OPTIMIZATION_RESTART_FIX.md +389 -0
- package/skills-library/database-solutions/RLS_SECURITY_GUIDE.md +107 -0
- package/skills-library/database-solutions/SCHEMA_ENHANCEMENTS_GUIDE.md +373 -0
- package/skills-library/database-solutions/SCHEMA_MIGRATION_GUIDE.md +368 -0
- package/skills-library/database-solutions/SCHEMA_VERIFICATION_QUICK_REFERENCE.md +104 -0
- package/skills-library/database-solutions/ai-erd-generator.md +1213 -0
- package/skills-library/database-solutions/content-publishing-states.md +631 -0
- package/skills-library/database-solutions/database-schema-designer.md +522 -0
- package/skills-library/database-solutions/er-diagram-components.md +569 -0
- package/skills-library/database-solutions/er-to-ddl-mapping.md +1405 -0
- package/skills-library/database-solutions/erd-creator-textbook-research.md +433 -0
- package/skills-library/database-solutions/erd-react-flow-architecture.md +1965 -0
- package/skills-library/database-solutions/mariadb-aggregate-function-replacement.md +145 -0
- package/skills-library/database-solutions/normalization-validator.md +778 -0
- package/skills-library/database-solutions/postgres-full-text-search-content.md +494 -0
- package/skills-library/database-solutions/postgresql-to-mysql-runtime-translation.md +286 -0
- package/skills-library/database-solutions/regex-alternation-ordering-sql-types.md +92 -0
- package/skills-library/database-solutions/reserved-word-context-aware-quoting.md +142 -0
- package/skills-library/database-solutions/sql-ddl-generator.md +756 -0
- package/skills-library/database-solutions/supabase-connection-pooler-fix.md +102 -0
- package/skills-library/deployment-security/CPANEL_NODE_DEPLOYMENT.md +166 -0
- package/skills-library/deployment-security/DEPLOYMENT.md +275 -0
- package/skills-library/deployment-security/DEPLOYMENT_CHECKLIST.md +363 -0
- package/skills-library/deployment-security/DEPLOYMENT_PLAN.md +669 -0
- package/skills-library/deployment-security/KNEX_DATABASE_ABSTRACTION.md +444 -0
- package/skills-library/deployment-security/LICENSE_KEY_SYSTEM.md +206 -0
- package/skills-library/deployment-security/NODE18_DEPENDENCY_COMPATIBILITY.md +284 -0
- package/skills-library/deployment-security/PHP_INSTALLER_WIZARD_GUIDE.md +315 -0
- package/skills-library/deployment-security/PM2_ENVIRONMENT_VARIABLE_CACHING.md +256 -0
- package/skills-library/deployment-security/PM2_MEMORY_EXHAUSTION_FIX.md +370 -0
- package/skills-library/deployment-security/PRODUCTION_DEPLOYMENT_GUIDE.md +592 -0
- package/skills-library/deployment-security/PRODUCTION_HARDENING_DOCUMENTATION.md +307 -0
- package/skills-library/deployment-security/PRODUCTION_RECOVERY_CHERRY_PICK_PATTERN.md +202 -0
- package/skills-library/deployment-security/PYINSTALLER_CUDA_WHISPER_BUNDLING.md +236 -0
- package/skills-library/deployment-security/SECURITY.md +41 -0
- package/skills-library/deployment-security/SMTP_SSL_HOSTNAME_MISMATCH_SHARED_HOSTING.md +220 -0
- package/skills-library/deployment-security/SPA_SEO_OPTIMIZATION_CPANEL.md +200 -0
- package/skills-library/deployment-security/SUPABASE_EDGE_FUNCTIONS.md +338 -0
- package/skills-library/deployment-security/VERCEL_GITHUB_DEPLOYMENT_GUIDE.md +858 -0
- package/skills-library/deployment-security/VPS_DEPLOYMENT_READINESS.md +356 -0
- package/skills-library/deployment-security/deployment-changes-not-applying.md +241 -0
- package/skills-library/deployment-security/env-file-management-production-local.md +203 -0
- package/skills-library/deployment-security/express-secure-file-downloads.md +413 -0
- package/skills-library/deployment-security/react-production-deployment-desktop-guide.md +2011 -0
- package/skills-library/deployment-security/self-hosted-supabase-coolify-guide.md +1684 -0
- package/skills-library/deployment-security/unique-features-ai-strategy-plaid-security.md +1613 -0
- package/skills-library/deployment-security/vps-deployment.md +135 -0
- package/skills-library/document-processing/WORD_EXPORT_MARKDOWN_FORMATTING.md +482 -0
- package/skills-library/document-processing/document-ai-landingai-integration.md +677 -0
- package/skills-library/document-processing/express-secure-file-downloads-mern.md +413 -0
- package/skills-library/document-processing/express-secure-file-downloads.md +413 -0
- package/skills-library/document-processing/md-to-word-converter.md +318 -0
- package/skills-library/document-processing/pdf-forms-integration/README.md +101 -0
- package/skills-library/document-processing/pdf-forms-integration/SKILL.md +662 -0
- package/skills-library/ecommerce/ADMIN_PRODUCTS_GUIDE.md +428 -0
- package/skills-library/ecommerce/ECOMMERCE_API_REFERENCE.md +776 -0
- package/skills-library/ecommerce/ECOMMERCE_COMPLETION_SUMMARY.md +673 -0
- package/skills-library/ecommerce/ECOMMERCE_IMPLEMENTATION_GUIDE.md +729 -0
- package/skills-library/ecommerce/ECOMMERCE_QUICK_REFERENCE.md +521 -0
- package/skills-library/ecommerce/ECOMMERCE_TESTING_CHECKLIST.md +565 -0
- package/skills-library/ecommerce/ECOMMERCE_WORKFLOW_GUIDE.md +1059 -0
- package/skills-library/ecommerce/PRODUCT_CREATION_EXPANDED.md +522 -0
- package/skills-library/ecommerce/agentic-commerce-protocol.md +203 -0
- package/skills-library/ecommerce/cart-abandonment-recovery.md +236 -0
- package/skills-library/ecommerce/cart-architecture-patterns.md +300 -0
- package/skills-library/ecommerce/cart-item-count-indicator.md +264 -0
- package/skills-library/ecommerce/checkout-ux-conversion.md +227 -0
- package/skills-library/ecommerce/composable-commerce-selection.md +166 -0
- package/skills-library/ecommerce/ecommerce-analytics-patterns.md +167 -0
- package/skills-library/ecommerce/fraud-detection-patterns.md +179 -0
- package/skills-library/ecommerce/inventory-stock-management.md +270 -0
- package/skills-library/ecommerce/order-saga-state-machine.md +336 -0
- package/skills-library/ecommerce/payment-provider-abstraction.md +245 -0
- package/skills-library/ecommerce/pci-compliance-checklist.md +192 -0
- package/skills-library/ecommerce/refund-chargeback-handling.md +177 -0
- package/skills-library/ecommerce/shipping-carrier-integration.md +218 -0
- package/skills-library/ecommerce/webhook-idempotency-patterns.md +253 -0
- package/skills-library/excalidraw-diagrams/.github/workflows/ci.yml +558 -0
- package/skills-library/excalidraw-diagrams/.github/workflows/prompt-gallery.yml +448 -0
- package/skills-library/excalidraw-diagrams/.github/workflows/release.yml +42 -0
- package/skills-library/excalidraw-diagrams/.github/workflows/test-reusable-ci.yml +25 -0
- package/skills-library/excalidraw-diagrams/CLAUDE.md +57 -0
- package/skills-library/excalidraw-diagrams/LICENSE +21 -0
- package/skills-library/excalidraw-diagrams/README.md +178 -0
- package/skills-library/excalidraw-diagrams/SKILL.md +715 -0
- package/skills-library/form-solutions/BUTTON_TYPE_FORM_SUBMISSION.md +336 -0
- package/skills-library/form-solutions/FILLABLE_PDF_IMPLEMENTATION.md +226 -0
- package/skills-library/form-solutions/SURVEYJS_QUESTIONNAIRE_SYSTEM.md +367 -0
- package/skills-library/form-solutions/tiptap-minimal-setup.md +690 -0
- package/skills-library/frontend/scholarly-classification-bubble-map.md +149 -0
- package/skills-library/infrastructure/ci-cd-pipeline-builder.md +517 -0
- package/skills-library/infrastructure/observability-designer.md +264 -0
- package/skills-library/infrastructure/performance-profiler.md +621 -0
- package/skills-library/installer-wizard-patterns.md +249 -0
- package/skills-library/integrations/CLAUDE_CODE_TOKEN_ANALYTICS.md +160 -0
- package/skills-library/integrations/CONFIGURABLE_AI_PROVIDER_SELECTION.md +728 -0
- package/skills-library/integrations/SOCKET_IO_BROADCAST_ALL_VS_ROOM.md +141 -0
- package/skills-library/integrations/VIRTUAL_MEETINGS_IMPLEMENTATION.md +374 -0
- package/skills-library/integrations/WORDPRESS_LEARNDASH_DATA_RECOVERY.md +53 -0
- package/skills-library/integrations/YOUTUBE_API_SETUP.md +141 -0
- package/skills-library/integrations/YOUTUBE_BOOKMARKING_EXPLANATION.md +252 -0
- package/skills-library/integrations/YOUTUBE_BOOKMARKING_SOLUTION.md +268 -0
- package/skills-library/integrations/YOUTUBE_OAUTH_SETUP_GUIDE.md +200 -0
- package/skills-library/integrations/YOUTUBE_VIDEO_FIX_COMPLETE.md +192 -0
- package/skills-library/integrations/ai-ml/GEMINI_AI_RAG_PIPELINE_COMPLETE_GUIDE.md +195 -0
- package/skills-library/integrations/ai-ml/GEMINI_IMAGE_GENERATION_SETUP.md +64 -0
- package/skills-library/integrations/cloudflare/cloudflare-turnstile-debugging.md +202 -0
- package/skills-library/integrations/cloudflare/cloudflare-turnstile-implementation.md +476 -0
- package/skills-library/integrations/cloudflare-turnstile-debugging.md +202 -0
- package/skills-library/integrations/cloudflare-turnstile-implementation.md +476 -0
- package/skills-library/integrations/ghost-creator-monetization-pattern.md +454 -0
- package/skills-library/integrations/headless-cms-architecture.md +484 -0
- package/skills-library/integrations/headless-cms-stack-selection.md +183 -0
- package/skills-library/integrations/payload-cms-patterns.md +674 -0
- package/skills-library/integrations/realtimestt-openwakeword-cuda-windows.md +229 -0
- package/skills-library/integrations/rss-podcast-integration.md +300 -0
- package/skills-library/integrations/wordpress/WORDPRESS_LEARNDASH_DATA_RECOVERY.md +53 -0
- package/skills-library/integrations/youtube/YOUTUBE_API_SETUP.md +141 -0
- package/skills-library/integrations/youtube/YOUTUBE_BOOKMARKING_EXPLANATION.md +252 -0
- package/skills-library/integrations/youtube/YOUTUBE_BOOKMARKING_SOLUTION.md +268 -0
- package/skills-library/integrations/youtube/YOUTUBE_OAUTH_SETUP_GUIDE.md +200 -0
- package/skills-library/integrations/youtube/YOUTUBE_VIDEO_FIX_COMPLETE.md +192 -0
- package/skills-library/marketing/campaign-analytics.md +97 -0
- package/skills-library/marketing/content-creator.md +105 -0
- package/skills-library/marketing/marketing-strategy-pmm.md +94 -0
- package/skills-library/marketing/social-media-analyzer.md +81 -0
- package/skills-library/methodology/ADVANCED_ORCHESTRATION_PATTERNS.md +401 -0
- package/skills-library/methodology/AGENT_SELF_IMPROVEMENT_LOOP.md +179 -0
- package/skills-library/methodology/BREATH_BASED_PARALLEL_EXECUTION.md +1 -1
- package/skills-library/methodology/CLEANSING_CYCLE.md +358 -0
- package/skills-library/methodology/CONFIDENCE_ANNOTATION_PATTERN.md +143 -0
- package/skills-library/methodology/CRITICAL_PATTERNS_DOCUMENTATION_COMPLETE.md +204 -0
- package/skills-library/methodology/DELIVERABLES_SUMMARY.md +341 -0
- package/skills-library/methodology/DIFFICULTY_AWARE_AGENT_ROUTING.md +252 -0
- package/skills-library/methodology/EVOLUTIONARY_SKILL_SYNTHESIS.md +219 -0
- package/skills-library/methodology/GLOMERULUS_DECISION_GATE.md +223 -0
- package/skills-library/methodology/HIBERNATION_SYSTEM.md +231 -0
- package/skills-library/methodology/INSTRUMENTATION_OVER_RESTRICTION.md +192 -0
- package/skills-library/methodology/MASTER_COMPLETION_SUMMARY.md +444 -0
- package/skills-library/methodology/MASTER_SESSION_COMPLETION.md +743 -0
- package/skills-library/methodology/MERN_QUICK_REFERENCE.md +358 -0
- package/skills-library/methodology/ORGAN_AGENT_MAPPING.md +177 -0
- package/skills-library/methodology/PARALLEL_WAVE_BASED_REFACTORING.md +440 -0
- package/skills-library/methodology/QUICK_REFERENCE.md +358 -0
- package/skills-library/methodology/SDFT_ONPOLICY_SELF_DISTILLATION.md +186 -0
- package/skills-library/methodology/SELF_QUESTIONING_TASK_GENERATION.md +270 -0
- package/skills-library/methodology/SESSION_COMPLETION_SUMMARY.md +304 -0
- package/skills-library/methodology/SESSION_SUMMARY.md +432 -0
- package/skills-library/methodology/WARRIOR_WORKFLOW_DEBUGGING_PROTOCOL.md +252 -0
- package/skills-library/methodology/tech-debt-tracker.md +570 -0
- package/skills-library/parallel-debug/SKILL.md +60 -0
- package/skills-library/patterns-standards/API_PATTERN_FIX_SUMMARY.md +236 -0
- package/skills-library/patterns-standards/BATCH_OPERATIONS_WITH_PROGRESS_MODAL.md +362 -0
- package/skills-library/patterns-standards/CRITICAL_CODING_PATTERNS.md +639 -0
- package/skills-library/patterns-standards/DARK_MODE_MODAL_VISIBILITY.md +258 -0
- package/skills-library/patterns-standards/ERROR_RESILIENCE_IMPLEMENTATION.md +375 -0
- package/skills-library/patterns-standards/ES_MODULE_IMPORT_HOISTING_DOTENV.md +298 -0
- package/skills-library/patterns-standards/NESTED_BACKDROP_FILTER_CSS_ARTIFACT_FIX.md +76 -0
- package/skills-library/patterns-standards/ORDERED_DETECTOR_PIPELINE_GRACEFUL_FALLBACK.md +333 -0
- package/skills-library/patterns-standards/PHASE_IMPORT_ERROR_DEBUGGING.md +271 -0
- package/skills-library/patterns-standards/PYNPUT_GLOBAL_HOTKEY_VK_MATCHING.md +252 -0
- package/skills-library/patterns-standards/REACT_USEEFFECT_CASCADE_RESET_FIX.md +132 -0
- package/skills-library/patterns-standards/SUBMENU_HOVER_DROPDOWN_PATTERN.md +225 -0
- package/skills-library/patterns-standards/TAILWIND_TEXT_VISIBILITY_OVERRIDE.md +322 -0
- package/skills-library/patterns-standards/THEME_AWARE_CSS_VARIABLES_PATTERN.md +209 -0
- package/skills-library/patterns-standards/THEME_USER_OBJECT_PROPERTY_NAMING.md +194 -0
- package/skills-library/patterns-standards/TOOLTIP_BLOCKING_CLICKS_FIX.md +267 -0
- package/skills-library/patterns-standards/claude-code-plugin-structure.md +235 -0
- package/skills-library/patterns-standards/react-i18next-setup.md +429 -0
- package/skills-library/patterns-standards/thesys-c1-generative-ui-integration.md +967 -0
- package/skills-library/plugin-development/CLAUDE_CODE_COMMAND_REGISTRATION_SILENT_FAILURE.md +315 -0
- package/skills-library/plugin-development/plugin-command-namespace-vs-global.md +390 -0
- package/skills-library/plugin-development/plugin-doc-auto-generation.md +172 -0
- package/skills-library/security/GITHUB_REPO_SECURITY_AUDIT.md +115 -0
- package/skills-library/security/admin-deletion-safety.md +396 -0
- package/skills-library/security/application-vuln-patterns.md +477 -0
- package/skills-library/security/env-secrets-manager.md +686 -0
- package/skills-library/security/secure-ai-application-templates.md +347 -0
- package/skills-library/security/sql-injection-prevention-postgresjs.md +151 -0
- package/skills-library/supabase-connection-pooler-fix.md +102 -0
- package/skills-library/system-context/POWERSHELL_BASH_INTEROP.md +82 -0
- package/skills-library/system-context/SERVICE_LIFECYCLE_MANAGEMENT.md +119 -0
- package/skills-library/system-context/SKILL.md +40 -0
- package/skills-library/system-context/WINDOWS_DEV_ENVIRONMENT.md +73 -0
- package/skills-library/testing/E2E_PLAYWRIGHT_PATTERNS.md +99 -0
- package/skills-library/testing/INTEGRATION_TEST_STRATEGY.md +82 -0
- package/skills-library/testing/RED_GREEN_BUGFIX_GATE.md +203 -0
- package/skills-library/testing/TEST_DATA_MANAGEMENT.md +69 -0
- package/skills-library/testing/VITEST_UNIT_TEST_PATTERNS.md +75 -0
- package/skills-library/testing/playwright-api-security-tests.md +202 -0
- package/skills-library/toolbox/SKILL.md +84 -0
- package/skills-library/toolbox/code-graph-and-web-scraping-mcps.md +237 -0
- package/skills-library/ui-ux-pro-max/ACCESSIBILITY_ESSENTIALS.md +115 -0
- package/skills-library/ui-ux-pro-max/DESIGN_SYSTEM_SCAFFOLDING.md +133 -0
- package/skills-library/ui-ux-pro-max/RESPONSIVE_LAYOUT_PATTERNS.md +119 -0
- package/skills-library/ui-ux-pro-max/SKILL.md +386 -0
- package/skills-library/ui-ux-pro-max/data/charts.csv +26 -0
- package/skills-library/ui-ux-pro-max/data/colors.csv +97 -0
- package/skills-library/ui-ux-pro-max/data/icons.csv +101 -0
- package/skills-library/ui-ux-pro-max/data/landing.csv +31 -0
- package/skills-library/ui-ux-pro-max/data/products.csv +97 -0
- package/skills-library/ui-ux-pro-max/data/react-performance.csv +45 -0
- package/skills-library/ui-ux-pro-max/data/stacks/astro.csv +54 -0
- package/skills-library/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
- package/skills-library/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
- package/skills-library/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
- package/skills-library/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
- package/skills-library/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
- package/skills-library/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
- package/skills-library/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
- package/skills-library/ui-ux-pro-max/data/stacks/react.csv +54 -0
- package/skills-library/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
- package/skills-library/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
- package/skills-library/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
- package/skills-library/ui-ux-pro-max/data/stacks/vue.csv +50 -0
- package/skills-library/ui-ux-pro-max/data/styles.csv +68 -0
- package/skills-library/ui-ux-pro-max/data/typography.csv +58 -0
- package/skills-library/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
- package/skills-library/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
- package/skills-library/ui-ux-pro-max/data/web-interface.csv +31 -0
- package/skills-library/wordpress-style-theme-components.md +1526 -0
- package/templates/ASSUMPTIONS.md +1 -1
- package/templates/DECISION_LOG.md +0 -1
- package/templates/phase-prompt.md +1 -1
- package/templates/phoenix-comparison.md +6 -6
- package/templates/skill-api-integration.md +106 -0
- package/templates/skill-architecture-pattern.md +92 -0
- package/templates/skill-debug-pattern.md +98 -0
- package/templates/skill-devops-recipe.md +107 -0
- package/templates/skill-general.md +65 -0
- package/templates/skill-ui-component.md +113 -0
- package/tools/uat-runner.py +179 -0
- package/version.json +7 -3
- package/workflows/handoff-session.md +2 -2
- package/workflows/new-project.md +2 -2
- package/workflows/plan-phase.md +1 -1
- package/.claude-plugin/plugin.json +0 -64
- package/skills-library/_general/methodology/LIVE_BREADCRUMB_PROTOCOL.md +0 -242
- package/skills-library/_general/methodology/llm-judge-memory-crud.md +0 -241
- package/skills-library/methodology/REFLEXION_MEMORY_PATTERN.md +0 -183
- package/skills-library/methodology/RESEARCH_BACKED_WORKFLOW_UPGRADE.md +0 -263
- package/skills-library/methodology/SABBATH_REST_PATTERN.md +0 -267
- package/skills-library/methodology/STONE_AND_SCAFFOLD.md +0 -220
- package/skills-library/specialists/api-architecture/api-designer.md +0 -49
- package/skills-library/specialists/api-architecture/graphql-architect.md +0 -49
- package/skills-library/specialists/api-architecture/mcp-developer.md +0 -51
- package/skills-library/specialists/api-architecture/microservices-architect.md +0 -50
- package/skills-library/specialists/api-architecture/websocket-engineer.md +0 -48
- package/skills-library/specialists/backend/django-expert.md +0 -52
- package/skills-library/specialists/backend/fastapi-expert.md +0 -52
- package/skills-library/specialists/backend/laravel-specialist.md +0 -52
- package/skills-library/specialists/backend/nestjs-expert.md +0 -51
- package/skills-library/specialists/backend/rails-expert.md +0 -53
- package/skills-library/specialists/backend/spring-boot-engineer.md +0 -56
- package/skills-library/specialists/data-ml/fine-tuning-expert.md +0 -48
- package/skills-library/specialists/data-ml/ml-pipeline.md +0 -47
- package/skills-library/specialists/data-ml/pandas-pro.md +0 -47
- package/skills-library/specialists/data-ml/rag-architect.md +0 -51
- package/skills-library/specialists/data-ml/spark-engineer.md +0 -47
- package/skills-library/specialists/frontend/angular-architect.md +0 -52
- package/skills-library/specialists/frontend/flutter-expert.md +0 -51
- package/skills-library/specialists/frontend/nextjs-developer.md +0 -54
- package/skills-library/specialists/frontend/react-native-expert.md +0 -50
- package/skills-library/specialists/frontend/vue-expert.md +0 -51
- package/skills-library/specialists/infrastructure/chaos-engineer.md +0 -74
- package/skills-library/specialists/infrastructure/cloud-architect.md +0 -70
- package/skills-library/specialists/infrastructure/database-optimizer.md +0 -64
- package/skills-library/specialists/infrastructure/devops-engineer.md +0 -70
- package/skills-library/specialists/infrastructure/kubernetes-specialist.md +0 -52
- package/skills-library/specialists/infrastructure/monitoring-expert.md +0 -70
- package/skills-library/specialists/infrastructure/sre-engineer.md +0 -70
- package/skills-library/specialists/infrastructure/terraform-engineer.md +0 -51
- package/skills-library/specialists/languages/cpp-pro.md +0 -74
- package/skills-library/specialists/languages/csharp-developer.md +0 -69
- package/skills-library/specialists/languages/dotnet-core-expert.md +0 -54
- package/skills-library/specialists/languages/golang-pro.md +0 -51
- package/skills-library/specialists/languages/java-architect.md +0 -49
- package/skills-library/specialists/languages/javascript-pro.md +0 -68
- package/skills-library/specialists/languages/kotlin-specialist.md +0 -68
- package/skills-library/specialists/languages/php-pro.md +0 -49
- package/skills-library/specialists/languages/python-pro.md +0 -52
- package/skills-library/specialists/languages/react-expert.md +0 -51
- package/skills-library/specialists/languages/rust-engineer.md +0 -50
- package/skills-library/specialists/languages/sql-pro.md +0 -56
- package/skills-library/specialists/languages/swift-expert.md +0 -69
- package/skills-library/specialists/languages/typescript-pro.md +0 -51
- package/skills-library/specialists/platform/atlassian-mcp.md +0 -52
- package/skills-library/specialists/platform/embedded-systems.md +0 -53
- package/skills-library/specialists/platform/game-developer.md +0 -53
- package/skills-library/specialists/platform/salesforce-developer.md +0 -53
- package/skills-library/specialists/platform/shopify-expert.md +0 -49
- package/skills-library/specialists/platform/wordpress-pro.md +0 -49
- package/skills-library/specialists/quality/code-documenter.md +0 -51
- package/skills-library/specialists/quality/code-reviewer.md +0 -67
- package/skills-library/specialists/quality/debugging-wizard.md +0 -51
- package/skills-library/specialists/quality/fullstack-guardian.md +0 -51
- package/skills-library/specialists/quality/legacy-modernizer.md +0 -50
- package/skills-library/specialists/quality/playwright-expert.md +0 -65
- package/skills-library/specialists/quality/spec-miner.md +0 -56
- package/skills-library/specialists/quality/test-master.md +0 -65
- package/skills-library/specialists/security/secure-code-guardian.md +0 -55
- package/skills-library/specialists/security/security-reviewer.md +0 -53
- package/skills-library/specialists/workflow/architecture-designer.md +0 -53
- package/skills-library/specialists/workflow/cli-developer.md +0 -70
- package/skills-library/specialists/workflow/feature-forge.md +0 -65
- package/skills-library/specialists/workflow/prompt-engineer.md +0 -54
- package/skills-library/specialists/workflow/the-fool.md +0 -62
- /package/skills-library/{performance → _general/performance}/cache-augmented-generation.md +0 -0
- /package/skills-library/{debugging → parallel-debug}/FAILURE_TAXONOMY_CLASSIFICATION.md +0 -0
- /package/skills-library/{debugging → parallel-debug}/THREE_AGENT_HYPOTHESIS_DEBUGGING.md +0 -0
|
@@ -0,0 +1,756 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: sql-ddl-generator
|
|
3
|
+
category: database-solutions
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
contributed: 2026-03-09
|
|
6
|
+
contributor: fire-research
|
|
7
|
+
tags: [sql, ddl, postgresql, mysql, sqlite, code-generation, database, schema, migration]
|
|
8
|
+
difficulty: medium
|
|
9
|
+
usage_count: 0
|
|
10
|
+
success_rate: 100
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# SQL DDL Generator
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
## Problem
|
|
17
|
+
|
|
18
|
+
You need to generate correct, dialect-specific SQL DDL (Data Definition Language) from a schema model. Each database engine has different syntax for auto-increment, UUIDs, booleans, JSON, and constraints. Manually writing DDL for multiple targets is error-prone and repetitive — especially when converting between dialects or maintaining parallel schemas for PostgreSQL (production) and SQLite (testing).
|
|
19
|
+
|
|
20
|
+
## CREATE DATABASE Template
|
|
21
|
+
|
|
22
|
+
```sql
|
|
23
|
+
-- PostgreSQL
|
|
24
|
+
CREATE DATABASE university_system
|
|
25
|
+
WITH ENCODING = 'UTF8'
|
|
26
|
+
LC_COLLATE = 'en_US.UTF-8'
|
|
27
|
+
LC_CTYPE = 'en_US.UTF-8'
|
|
28
|
+
TEMPLATE = template0;
|
|
29
|
+
|
|
30
|
+
-- MySQL
|
|
31
|
+
CREATE DATABASE IF NOT EXISTS university_system
|
|
32
|
+
CHARACTER SET utf8mb4
|
|
33
|
+
COLLATE utf8mb4_unicode_ci;
|
|
34
|
+
|
|
35
|
+
-- SQLite (databases are just files)
|
|
36
|
+
-- No CREATE DATABASE — open/create with: sqlite3 university_system.db
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## CREATE TABLE Template
|
|
40
|
+
|
|
41
|
+
Full annotated template showing every DDL element:
|
|
42
|
+
|
|
43
|
+
```sql
|
|
44
|
+
CREATE TABLE table_name (
|
|
45
|
+
-- Column definitions: name type [column_constraints]
|
|
46
|
+
column_name DATA_TYPE [NOT NULL] [DEFAULT value] [UNIQUE] [CHECK (expr)]
|
|
47
|
+
[PRIMARY KEY]
|
|
48
|
+
[REFERENCES other_table(column) [ON DELETE action] [ON UPDATE action]],
|
|
49
|
+
|
|
50
|
+
-- More columns...
|
|
51
|
+
another_col DATA_TYPE NOT NULL DEFAULT 'value',
|
|
52
|
+
|
|
53
|
+
-- Table-level constraints (named, reusable, shown in error messages)
|
|
54
|
+
CONSTRAINT pk_table PRIMARY KEY (column_name),
|
|
55
|
+
CONSTRAINT fk_table_other FOREIGN KEY (other_id) REFERENCES other_table(id)
|
|
56
|
+
ON DELETE CASCADE ON UPDATE CASCADE,
|
|
57
|
+
CONSTRAINT uq_table_email UNIQUE (email),
|
|
58
|
+
CONSTRAINT ck_table_age CHECK (age >= 0 AND age <= 150),
|
|
59
|
+
|
|
60
|
+
-- Composite constraints
|
|
61
|
+
CONSTRAINT uq_table_compound UNIQUE (org_id, slug),
|
|
62
|
+
CONSTRAINT pk_junction PRIMARY KEY (left_id, right_id)
|
|
63
|
+
);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
**Rule of thumb:** Use table-level (named) constraints for anything you will reference in error handling, migration rollbacks, or documentation. Use inline constraints for simple NOT NULL / DEFAULT on single columns.
|
|
67
|
+
|
|
68
|
+
## Column Constraints Reference
|
|
69
|
+
|
|
70
|
+
| Constraint | Syntax | Example | Notes |
|
|
71
|
+
|-----------|--------|---------|-------|
|
|
72
|
+
| NOT NULL | `col TYPE NOT NULL` | `email VARCHAR(255) NOT NULL` | Rejects NULL inserts/updates |
|
|
73
|
+
| DEFAULT | `col TYPE DEFAULT val` | `status VARCHAR(20) DEFAULT 'draft'` | Value when column omitted |
|
|
74
|
+
| UNIQUE | `col TYPE UNIQUE` | `slug VARCHAR(100) UNIQUE` | Creates unique index |
|
|
75
|
+
| CHECK | `col TYPE CHECK (expr)` | `age INT CHECK (age >= 0)` | Row-level validation |
|
|
76
|
+
| PRIMARY KEY | `col TYPE PRIMARY KEY` | `id SERIAL PRIMARY KEY` | Inline PK (single column only) |
|
|
77
|
+
| REFERENCES | `col TYPE REFERENCES tbl(col)` | `user_id INT REFERENCES users(id)` | Inline FK |
|
|
78
|
+
|
|
79
|
+
**DEFAULT value types:**
|
|
80
|
+
```sql
|
|
81
|
+
DEFAULT 'string_literal' -- text
|
|
82
|
+
DEFAULT 0 -- numeric
|
|
83
|
+
DEFAULT TRUE -- boolean (PG); DEFAULT 1 (MySQL)
|
|
84
|
+
DEFAULT CURRENT_TIMESTAMP -- all dialects
|
|
85
|
+
DEFAULT (UUID()) -- MySQL 8+
|
|
86
|
+
DEFAULT gen_random_uuid() -- PostgreSQL 13+
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Table Constraints Reference
|
|
90
|
+
|
|
91
|
+
### PRIMARY KEY
|
|
92
|
+
```sql
|
|
93
|
+
-- Single column
|
|
94
|
+
CONSTRAINT pk_users PRIMARY KEY (id)
|
|
95
|
+
|
|
96
|
+
-- Composite (junction tables)
|
|
97
|
+
CONSTRAINT pk_enrollment PRIMARY KEY (student_id, course_id)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### FOREIGN KEY
|
|
101
|
+
```sql
|
|
102
|
+
CONSTRAINT fk_tasks_project FOREIGN KEY (project_id)
|
|
103
|
+
REFERENCES projects(id)
|
|
104
|
+
ON DELETE CASCADE -- delete children when parent deleted
|
|
105
|
+
ON UPDATE CASCADE -- update FK when parent PK changes
|
|
106
|
+
|
|
107
|
+
-- ON DELETE options:
|
|
108
|
+
-- CASCADE — delete child rows
|
|
109
|
+
-- SET NULL — set FK column to NULL (column must be nullable)
|
|
110
|
+
-- SET DEFAULT — set FK to its DEFAULT value
|
|
111
|
+
-- RESTRICT — block delete if children exist (checked immediately)
|
|
112
|
+
-- NO ACTION — block delete if children exist (checked at txn end, default)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### UNIQUE
|
|
116
|
+
```sql
|
|
117
|
+
-- Single column
|
|
118
|
+
CONSTRAINT uq_users_email UNIQUE (email)
|
|
119
|
+
|
|
120
|
+
-- Composite (e.g., unique slug per organization)
|
|
121
|
+
CONSTRAINT uq_posts_org_slug UNIQUE (organization_id, slug)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### CHECK
|
|
125
|
+
```sql
|
|
126
|
+
CONSTRAINT ck_products_price CHECK (price >= 0)
|
|
127
|
+
CONSTRAINT ck_users_role CHECK (role IN ('admin', 'instructor', 'student'))
|
|
128
|
+
CONSTRAINT ck_events_dates CHECK (end_date > start_date)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Naming Conventions
|
|
132
|
+
|
|
133
|
+
| Prefix | Constraint Type | Example |
|
|
134
|
+
|--------|----------------|---------|
|
|
135
|
+
| `pk_` | Primary Key | `pk_users` |
|
|
136
|
+
| `fk_` | Foreign Key | `fk_tasks_project` |
|
|
137
|
+
| `uq_` | Unique | `uq_users_email` |
|
|
138
|
+
| `ck_` | Check | `ck_products_price` |
|
|
139
|
+
| `idx_` | Index | `idx_tasks_status_created` |
|
|
140
|
+
|
|
141
|
+
Pattern: `{prefix}_{table}_{column(s)}` — keeps constraint names deterministic and greppable.
|
|
142
|
+
|
|
143
|
+
## Data Type Cross-Reference
|
|
144
|
+
|
|
145
|
+
| Concept | PostgreSQL | MySQL | SQLite | MSSQL |
|
|
146
|
+
|---------|-----------|-------|--------|-------|
|
|
147
|
+
| Auto-increment PK | `SERIAL` / `BIGSERIAL` | `INT AUTO_INCREMENT` | `INTEGER PRIMARY KEY` | `INT IDENTITY(1,1)` |
|
|
148
|
+
| UUID PK | `UUID DEFAULT gen_random_uuid()` | `CHAR(36) DEFAULT (UUID())` | `TEXT` | `UNIQUEIDENTIFIER DEFAULT NEWID()` |
|
|
149
|
+
| Short text | `VARCHAR(n)` | `VARCHAR(n)` | `TEXT` | `NVARCHAR(n)` |
|
|
150
|
+
| Long text | `TEXT` | `TEXT` / `LONGTEXT` | `TEXT` | `NVARCHAR(MAX)` |
|
|
151
|
+
| Integer | `INTEGER` | `INT` | `INTEGER` | `INT` |
|
|
152
|
+
| Big integer | `BIGINT` | `BIGINT` | `INTEGER` | `BIGINT` |
|
|
153
|
+
| Small integer | `SMALLINT` | `SMALLINT` | `INTEGER` | `SMALLINT` |
|
|
154
|
+
| Decimal | `NUMERIC(p,s)` | `DECIMAL(p,s)` | `REAL` | `DECIMAL(p,s)` |
|
|
155
|
+
| Float | `DOUBLE PRECISION` | `DOUBLE` | `REAL` | `FLOAT` |
|
|
156
|
+
| Boolean | `BOOLEAN` | `TINYINT(1)` | `INTEGER` (0/1) | `BIT` |
|
|
157
|
+
| Date | `DATE` | `DATE` | `TEXT` (ISO 8601) | `DATE` |
|
|
158
|
+
| Time | `TIME` | `TIME` | `TEXT` | `TIME` |
|
|
159
|
+
| Timestamp (tz) | `TIMESTAMPTZ` | `DATETIME` | `TEXT` (ISO 8601) | `DATETIMEOFFSET` |
|
|
160
|
+
| Timestamp (no tz) | `TIMESTAMP` | `DATETIME` | `TEXT` | `DATETIME2` |
|
|
161
|
+
| JSON | `JSONB` | `JSON` | `TEXT` | `NVARCHAR(MAX)` |
|
|
162
|
+
| Binary | `BYTEA` | `BLOB` / `LONGBLOB` | `BLOB` | `VARBINARY(MAX)` |
|
|
163
|
+
| Array | `TYPE[]` (native) | `JSON` (workaround) | `TEXT` (JSON) | `NVARCHAR(MAX)` (JSON) |
|
|
164
|
+
| Enum | `CREATE TYPE ... AS ENUM` | `ENUM('a','b','c')` | `TEXT + CHECK` | `NVARCHAR + CHECK` |
|
|
165
|
+
|
|
166
|
+
**Critical gotcha (from MINISTRY-LMS migration):** MySQL `CHAR(36) DEFAULT (UUID())` returns `LAST_INSERT_ID() = 0` because MySQL only tracks auto-increment IDs. When using UUID PKs in MySQL, generate the UUID in application code and include `id` in the INSERT column list. See skill: `pg-to-mysql-schema-migration-methodology.md`.
|
|
167
|
+
|
|
168
|
+
## Dialect-Specific Syntax
|
|
169
|
+
|
|
170
|
+
### PostgreSQL
|
|
171
|
+
|
|
172
|
+
```sql
|
|
173
|
+
-- Auto-increment (preferred: IDENTITY in PG 10+)
|
|
174
|
+
CREATE TABLE users (
|
|
175
|
+
id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
|
176
|
+
-- or legacy: id SERIAL PRIMARY KEY
|
|
177
|
+
name VARCHAR(100) NOT NULL
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
-- UUID primary key
|
|
181
|
+
CREATE TABLE documents (
|
|
182
|
+
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
|
|
183
|
+
title TEXT NOT NULL,
|
|
184
|
+
metadata JSONB DEFAULT '{}',
|
|
185
|
+
tags TEXT[] DEFAULT '{}',
|
|
186
|
+
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
-- Generated/computed columns (PG 12+)
|
|
190
|
+
ALTER TABLE products ADD COLUMN
|
|
191
|
+
search_vector TSVECTOR GENERATED ALWAYS AS (
|
|
192
|
+
to_tsvector('english', coalesce(title, '') || ' ' || coalesce(description, ''))
|
|
193
|
+
) STORED;
|
|
194
|
+
|
|
195
|
+
-- Partial index
|
|
196
|
+
CREATE INDEX idx_tasks_active ON tasks (status) WHERE deleted_at IS NULL;
|
|
197
|
+
|
|
198
|
+
-- ENUM type
|
|
199
|
+
CREATE TYPE user_role AS ENUM ('admin', 'instructor', 'student');
|
|
200
|
+
CREATE TABLE users (
|
|
201
|
+
id SERIAL PRIMARY KEY,
|
|
202
|
+
role user_role NOT NULL DEFAULT 'student'
|
|
203
|
+
);
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### MySQL
|
|
207
|
+
|
|
208
|
+
```sql
|
|
209
|
+
-- Auto-increment
|
|
210
|
+
CREATE TABLE users (
|
|
211
|
+
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
212
|
+
name VARCHAR(100) NOT NULL,
|
|
213
|
+
email VARCHAR(255) NOT NULL
|
|
214
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
|
215
|
+
|
|
216
|
+
-- UUID primary key (generate in app code, not DEFAULT)
|
|
217
|
+
CREATE TABLE documents (
|
|
218
|
+
id CHAR(36) NOT NULL PRIMARY KEY,
|
|
219
|
+
title TEXT NOT NULL,
|
|
220
|
+
metadata JSON DEFAULT NULL,
|
|
221
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
-- Boolean (stored as TINYINT)
|
|
225
|
+
ALTER TABLE users ADD COLUMN is_active TINYINT(1) NOT NULL DEFAULT 1;
|
|
226
|
+
|
|
227
|
+
-- Inline ENUM
|
|
228
|
+
CREATE TABLE tasks (
|
|
229
|
+
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
230
|
+
status ENUM('draft', 'active', 'done') NOT NULL DEFAULT 'draft'
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
-- Full-text index
|
|
234
|
+
ALTER TABLE articles ADD FULLTEXT INDEX ft_articles_content (title, body);
|
|
235
|
+
|
|
236
|
+
-- IMPORTANT: Always specify ENGINE=InnoDB for FK support
|
|
237
|
+
-- IMPORTANT: Use utf8mb4 (not utf8) — utf8 is only 3 bytes, misses emoji
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### SQLite
|
|
241
|
+
|
|
242
|
+
```sql
|
|
243
|
+
-- Auto-increment (INTEGER PRIMARY KEY is implicit rowid alias)
|
|
244
|
+
CREATE TABLE users (
|
|
245
|
+
id INTEGER PRIMARY KEY, -- auto-increments automatically
|
|
246
|
+
name TEXT NOT NULL,
|
|
247
|
+
email TEXT NOT NULL UNIQUE
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
-- AUTOINCREMENT keyword (prevents rowid reuse, slightly slower)
|
|
251
|
+
CREATE TABLE audit_log (
|
|
252
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
253
|
+
action TEXT NOT NULL,
|
|
254
|
+
ts TEXT DEFAULT (datetime('now'))
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
-- Type affinity: SQLite stores any type in any column
|
|
258
|
+
-- These declarations are hints, not enforced:
|
|
259
|
+
-- TEXT, INTEGER, REAL, BLOB, NUMERIC
|
|
260
|
+
|
|
261
|
+
-- Boolean emulation
|
|
262
|
+
CREATE TABLE tasks (
|
|
263
|
+
id INTEGER PRIMARY KEY,
|
|
264
|
+
is_done INTEGER NOT NULL DEFAULT 0 CHECK (is_done IN (0, 1))
|
|
265
|
+
);
|
|
266
|
+
|
|
267
|
+
-- Date/time as ISO 8601 text
|
|
268
|
+
CREATE TABLE events (
|
|
269
|
+
id INTEGER PRIMARY KEY,
|
|
270
|
+
start_date TEXT NOT NULL, -- '2026-03-09'
|
|
271
|
+
created_at TEXT DEFAULT (datetime('now'))
|
|
272
|
+
);
|
|
273
|
+
|
|
274
|
+
-- FK enforcement (OFF by default!)
|
|
275
|
+
PRAGMA foreign_keys = ON;
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
## Generated DDL Example
|
|
279
|
+
|
|
280
|
+
A complete `university_system` schema with multiple tables, foreign keys, and constraints:
|
|
281
|
+
|
|
282
|
+
```sql
|
|
283
|
+
-- ============================================================
|
|
284
|
+
-- University System DDL — PostgreSQL dialect
|
|
285
|
+
-- ============================================================
|
|
286
|
+
|
|
287
|
+
CREATE TABLE departments (
|
|
288
|
+
id SERIAL PRIMARY KEY,
|
|
289
|
+
name VARCHAR(100) NOT NULL,
|
|
290
|
+
code CHAR(4) NOT NULL,
|
|
291
|
+
budget NUMERIC(12, 2) DEFAULT 0.00,
|
|
292
|
+
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
|
|
293
|
+
|
|
294
|
+
CONSTRAINT uq_departments_code UNIQUE (code),
|
|
295
|
+
CONSTRAINT ck_departments_budget CHECK (budget >= 0)
|
|
296
|
+
);
|
|
297
|
+
|
|
298
|
+
CREATE TABLE instructors (
|
|
299
|
+
id SERIAL PRIMARY KEY,
|
|
300
|
+
department_id INT NOT NULL,
|
|
301
|
+
first_name VARCHAR(50) NOT NULL,
|
|
302
|
+
last_name VARCHAR(50) NOT NULL,
|
|
303
|
+
email VARCHAR(255) NOT NULL,
|
|
304
|
+
hire_date DATE NOT NULL DEFAULT CURRENT_DATE,
|
|
305
|
+
|
|
306
|
+
CONSTRAINT fk_instructors_department FOREIGN KEY (department_id)
|
|
307
|
+
REFERENCES departments(id) ON DELETE RESTRICT ON UPDATE CASCADE,
|
|
308
|
+
CONSTRAINT uq_instructors_email UNIQUE (email)
|
|
309
|
+
);
|
|
310
|
+
|
|
311
|
+
CREATE TABLE courses (
|
|
312
|
+
id SERIAL PRIMARY KEY,
|
|
313
|
+
department_id INT NOT NULL,
|
|
314
|
+
instructor_id INT,
|
|
315
|
+
code VARCHAR(10) NOT NULL,
|
|
316
|
+
title VARCHAR(200) NOT NULL,
|
|
317
|
+
credits SMALLINT NOT NULL DEFAULT 3,
|
|
318
|
+
max_enrollment INT NOT NULL DEFAULT 30,
|
|
319
|
+
description TEXT,
|
|
320
|
+
is_active BOOLEAN NOT NULL DEFAULT TRUE,
|
|
321
|
+
|
|
322
|
+
CONSTRAINT fk_courses_department FOREIGN KEY (department_id)
|
|
323
|
+
REFERENCES departments(id) ON DELETE RESTRICT,
|
|
324
|
+
CONSTRAINT fk_courses_instructor FOREIGN KEY (instructor_id)
|
|
325
|
+
REFERENCES instructors(id) ON DELETE SET NULL,
|
|
326
|
+
CONSTRAINT uq_courses_code UNIQUE (code),
|
|
327
|
+
CONSTRAINT ck_courses_credits CHECK (credits BETWEEN 1 AND 6),
|
|
328
|
+
CONSTRAINT ck_courses_enrollment CHECK (max_enrollment > 0)
|
|
329
|
+
);
|
|
330
|
+
|
|
331
|
+
CREATE TABLE students (
|
|
332
|
+
id SERIAL PRIMARY KEY,
|
|
333
|
+
first_name VARCHAR(50) NOT NULL,
|
|
334
|
+
last_name VARCHAR(50) NOT NULL,
|
|
335
|
+
email VARCHAR(255) NOT NULL,
|
|
336
|
+
gpa NUMERIC(3, 2) DEFAULT 0.00,
|
|
337
|
+
enrolled_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
|
|
338
|
+
|
|
339
|
+
CONSTRAINT uq_students_email UNIQUE (email),
|
|
340
|
+
CONSTRAINT ck_students_gpa CHECK (gpa >= 0.00 AND gpa <= 4.00)
|
|
341
|
+
);
|
|
342
|
+
|
|
343
|
+
CREATE TABLE enrollments (
|
|
344
|
+
student_id INT NOT NULL,
|
|
345
|
+
course_id INT NOT NULL,
|
|
346
|
+
enrolled_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
|
|
347
|
+
grade CHAR(2),
|
|
348
|
+
|
|
349
|
+
CONSTRAINT pk_enrollments PRIMARY KEY (student_id, course_id),
|
|
350
|
+
CONSTRAINT fk_enrollments_student FOREIGN KEY (student_id)
|
|
351
|
+
REFERENCES students(id) ON DELETE CASCADE,
|
|
352
|
+
CONSTRAINT fk_enrollments_course FOREIGN KEY (course_id)
|
|
353
|
+
REFERENCES courses(id) ON DELETE CASCADE,
|
|
354
|
+
CONSTRAINT ck_enrollments_grade CHECK (
|
|
355
|
+
grade IN ('A+', 'A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'D', 'F', 'W', 'I')
|
|
356
|
+
)
|
|
357
|
+
);
|
|
358
|
+
|
|
359
|
+
-- Indexes for common queries
|
|
360
|
+
CREATE INDEX idx_instructors_department ON instructors (department_id);
|
|
361
|
+
CREATE INDEX idx_courses_department ON courses (department_id);
|
|
362
|
+
CREATE INDEX idx_courses_instructor ON courses (instructor_id);
|
|
363
|
+
CREATE INDEX idx_enrollments_course ON enrollments (course_id);
|
|
364
|
+
CREATE INDEX idx_students_email ON students (email);
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
## AI-Assisted Dialect Conversion
|
|
368
|
+
|
|
369
|
+
When you need to convert DDL between dialects, use an LLM prompt template based on ChartDB's approach (schema as structured JSON, LLM generates target dialect):
|
|
370
|
+
|
|
371
|
+
### Prompt Template
|
|
372
|
+
|
|
373
|
+
```
|
|
374
|
+
You are a SQL DDL expert. Convert the following {source_dialect} DDL
|
|
375
|
+
to valid {target_dialect} DDL.
|
|
376
|
+
|
|
377
|
+
Rules:
|
|
378
|
+
1. Map data types using standard equivalents (SERIAL → AUTO_INCREMENT, etc.)
|
|
379
|
+
2. Preserve all constraints with equivalent syntax
|
|
380
|
+
3. Preserve all naming conventions (pk_, fk_, uq_, ck_ prefixes)
|
|
381
|
+
4. Add dialect-specific requirements (ENGINE=InnoDB for MySQL, PRAGMA for SQLite)
|
|
382
|
+
5. Comment any features that have NO equivalent in the target dialect
|
|
383
|
+
6. For UUID columns in MySQL: add a comment noting app-side generation is required
|
|
384
|
+
|
|
385
|
+
Source DDL ({source_dialect}):
|
|
386
|
+
```sql
|
|
387
|
+
{paste_ddl_here}
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
Generate the equivalent {target_dialect} DDL.
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
### ChartDB's JSON Schema Approach
|
|
394
|
+
|
|
395
|
+
ChartDB feeds the schema as structured JSON to an AI agent, which generates dialect-specific DDL. This is more reliable than raw SQL→SQL conversion because the intermediate representation is unambiguous:
|
|
396
|
+
|
|
397
|
+
```json
|
|
398
|
+
{
|
|
399
|
+
"tables": [
|
|
400
|
+
{
|
|
401
|
+
"name": "users",
|
|
402
|
+
"columns": [
|
|
403
|
+
{ "name": "id", "type": "auto_increment_pk" },
|
|
404
|
+
{ "name": "email", "type": "varchar", "length": 255, "nullable": false, "unique": true },
|
|
405
|
+
{ "name": "created_at", "type": "timestamp_tz", "default": "now" }
|
|
406
|
+
],
|
|
407
|
+
"constraints": [
|
|
408
|
+
{ "type": "pk", "columns": ["id"], "name": "pk_users" }
|
|
409
|
+
]
|
|
410
|
+
}
|
|
411
|
+
],
|
|
412
|
+
"target_dialect": "mysql"
|
|
413
|
+
}
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
### dbdiagram.io DBML as Intermediate DSL
|
|
417
|
+
|
|
418
|
+
DBML (Database Markup Language) is a human-readable intermediate format. Write once, export to any dialect:
|
|
419
|
+
|
|
420
|
+
```dbml
|
|
421
|
+
Table users {
|
|
422
|
+
id int [pk, increment]
|
|
423
|
+
email varchar(255) [not null, unique]
|
|
424
|
+
role user_role [not null, default: 'student']
|
|
425
|
+
created_at timestamptz [default: `CURRENT_TIMESTAMP`]
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
Table courses {
|
|
429
|
+
id int [pk, increment]
|
|
430
|
+
instructor_id int [ref: > users.id]
|
|
431
|
+
title varchar(200) [not null]
|
|
432
|
+
credits smallint [not null, default: 3]
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
Enum user_role {
|
|
436
|
+
admin
|
|
437
|
+
instructor
|
|
438
|
+
student
|
|
439
|
+
}
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
## Migration Generation Patterns
|
|
443
|
+
|
|
444
|
+
### Knex.js Migration (from quick-erd pattern)
|
|
445
|
+
|
|
446
|
+
```javascript
|
|
447
|
+
// migrations/20260309_create_users.js
|
|
448
|
+
export async function up(knex) {
|
|
449
|
+
await knex.schema.createTable('users', (table) => {
|
|
450
|
+
table.increments('id').primary();
|
|
451
|
+
table.string('email', 255).notNullable().unique();
|
|
452
|
+
table.string('first_name', 50).notNullable();
|
|
453
|
+
table.string('last_name', 50).notNullable();
|
|
454
|
+
table.decimal('gpa', 3, 2).defaultTo(0.00);
|
|
455
|
+
table.timestamp('created_at').defaultTo(knex.fn.now());
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
await knex.schema.createTable('enrollments', (table) => {
|
|
459
|
+
table.integer('student_id').unsigned().notNullable();
|
|
460
|
+
table.integer('course_id').unsigned().notNullable();
|
|
461
|
+
table.string('grade', 2);
|
|
462
|
+
table.timestamp('enrolled_at').defaultTo(knex.fn.now());
|
|
463
|
+
|
|
464
|
+
table.primary(['student_id', 'course_id']);
|
|
465
|
+
table.foreign('student_id').references('users.id').onDelete('CASCADE');
|
|
466
|
+
table.foreign('course_id').references('courses.id').onDelete('CASCADE');
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
export async function down(knex) {
|
|
471
|
+
await knex.schema.dropTableIfExists('enrollments');
|
|
472
|
+
await knex.schema.dropTableIfExists('users');
|
|
473
|
+
}
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
### Raw SQL Migration (ERFlow checkpoint pattern)
|
|
477
|
+
|
|
478
|
+
```sql
|
|
479
|
+
-- migrations/V001__create_users.sql
|
|
480
|
+
-- Up
|
|
481
|
+
CREATE TABLE IF NOT EXISTS users (
|
|
482
|
+
id SERIAL PRIMARY KEY,
|
|
483
|
+
email VARCHAR(255) NOT NULL UNIQUE,
|
|
484
|
+
name VARCHAR(100) NOT NULL
|
|
485
|
+
);
|
|
486
|
+
|
|
487
|
+
-- migrations/V001__create_users_down.sql
|
|
488
|
+
-- Down
|
|
489
|
+
DROP TABLE IF EXISTS users;
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
### Drizzle Schema (TypeScript-first)
|
|
493
|
+
|
|
494
|
+
```typescript
|
|
495
|
+
// schema/users.ts
|
|
496
|
+
import { pgTable, serial, varchar, timestamp, boolean } from 'drizzle-orm/pg-core';
|
|
497
|
+
|
|
498
|
+
export const users = pgTable('users', {
|
|
499
|
+
id: serial('id').primaryKey(),
|
|
500
|
+
email: varchar('email', { length: 255 }).notNull().unique(),
|
|
501
|
+
firstName: varchar('first_name', { length: 50 }).notNull(),
|
|
502
|
+
lastName: varchar('last_name', { length: 50 }).notNull(),
|
|
503
|
+
isActive: boolean('is_active').notNull().default(true),
|
|
504
|
+
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow(),
|
|
505
|
+
});
|
|
506
|
+
```
|
|
507
|
+
|
|
508
|
+
### Idempotent ALTER Migration (MySQL safe pattern)
|
|
509
|
+
|
|
510
|
+
From MINISTRY-LMS lessons — always check before adding columns to prevent "column already exists" crashes on re-run:
|
|
511
|
+
|
|
512
|
+
```javascript
|
|
513
|
+
async function addColumnIfMissing(knex, table, column, alterSQL) {
|
|
514
|
+
const [rows] = await knex.raw(`DESCRIBE \`${table}\``);
|
|
515
|
+
const exists = rows.some((r) => r.Field === column);
|
|
516
|
+
if (!exists) {
|
|
517
|
+
await knex.raw(alterSQL);
|
|
518
|
+
console.log(` Added ${table}.${column}`);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// Usage in migration
|
|
523
|
+
export async function up(knex) {
|
|
524
|
+
await addColumnIfMissing(
|
|
525
|
+
knex, 'users', 'avatar_url',
|
|
526
|
+
"ALTER TABLE `users` ADD COLUMN `avatar_url` VARCHAR(500) DEFAULT NULL"
|
|
527
|
+
);
|
|
528
|
+
}
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
## Implementation: Multi-Dialect DDL Generator
|
|
532
|
+
|
|
533
|
+
A TypeScript generator function that takes a dialect-agnostic schema model and outputs DDL for any target. Based on DrawDB's separate-generator-per-dialect pattern:
|
|
534
|
+
|
|
535
|
+
```typescript
|
|
536
|
+
// ddl-generator.ts
|
|
537
|
+
|
|
538
|
+
type Dialect = 'postgresql' | 'mysql' | 'sqlite' | 'mssql';
|
|
539
|
+
|
|
540
|
+
interface Column {
|
|
541
|
+
name: string;
|
|
542
|
+
type: string; // abstract type: 'auto_pk', 'uuid_pk', 'varchar', 'text', 'int', 'decimal', 'boolean', 'date', 'timestamptz', 'jsonb'
|
|
543
|
+
length?: number; // for varchar
|
|
544
|
+
precision?: number; // for decimal
|
|
545
|
+
scale?: number; // for decimal
|
|
546
|
+
nullable?: boolean; // default: true
|
|
547
|
+
unique?: boolean;
|
|
548
|
+
default?: string | number | boolean | null;
|
|
549
|
+
check?: string; // raw SQL expression
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
interface Constraint {
|
|
553
|
+
type: 'pk' | 'fk' | 'unique' | 'check';
|
|
554
|
+
name: string;
|
|
555
|
+
columns: string[];
|
|
556
|
+
// FK-specific
|
|
557
|
+
refTable?: string;
|
|
558
|
+
refColumns?: string[];
|
|
559
|
+
onDelete?: 'CASCADE' | 'SET NULL' | 'RESTRICT' | 'NO ACTION' | 'SET DEFAULT';
|
|
560
|
+
onUpdate?: 'CASCADE' | 'SET NULL' | 'RESTRICT' | 'NO ACTION' | 'SET DEFAULT';
|
|
561
|
+
// CHECK-specific
|
|
562
|
+
expression?: string;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
interface TableDef {
|
|
566
|
+
name: string;
|
|
567
|
+
columns: Column[];
|
|
568
|
+
constraints: Constraint[];
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
// Data type mapping
|
|
572
|
+
const TYPE_MAP: Record<string, Record<Dialect, string>> = {
|
|
573
|
+
auto_pk: { postgresql: 'SERIAL', mysql: 'INT AUTO_INCREMENT', sqlite: 'INTEGER', mssql: 'INT IDENTITY(1,1)' },
|
|
574
|
+
uuid_pk: { postgresql: 'UUID DEFAULT gen_random_uuid()', mysql: 'CHAR(36)', sqlite: 'TEXT', mssql: 'UNIQUEIDENTIFIER DEFAULT NEWID()' },
|
|
575
|
+
varchar: { postgresql: 'VARCHAR', mysql: 'VARCHAR', sqlite: 'TEXT', mssql: 'NVARCHAR' },
|
|
576
|
+
text: { postgresql: 'TEXT', mysql: 'TEXT', sqlite: 'TEXT', mssql: 'NVARCHAR(MAX)' },
|
|
577
|
+
int: { postgresql: 'INTEGER', mysql: 'INT', sqlite: 'INTEGER', mssql: 'INT' },
|
|
578
|
+
bigint: { postgresql: 'BIGINT', mysql: 'BIGINT', sqlite: 'INTEGER', mssql: 'BIGINT' },
|
|
579
|
+
decimal: { postgresql: 'NUMERIC', mysql: 'DECIMAL', sqlite: 'REAL', mssql: 'DECIMAL' },
|
|
580
|
+
boolean: { postgresql: 'BOOLEAN', mysql: 'TINYINT(1)', sqlite: 'INTEGER', mssql: 'BIT' },
|
|
581
|
+
date: { postgresql: 'DATE', mysql: 'DATE', sqlite: 'TEXT', mssql: 'DATE' },
|
|
582
|
+
timestamptz: { postgresql: 'TIMESTAMPTZ', mysql: 'DATETIME', sqlite: 'TEXT', mssql: 'DATETIMEOFFSET' },
|
|
583
|
+
jsonb: { postgresql: 'JSONB', mysql: 'JSON', sqlite: 'TEXT', mssql: 'NVARCHAR(MAX)' },
|
|
584
|
+
};
|
|
585
|
+
|
|
586
|
+
function resolveType(col: Column, dialect: Dialect): string {
|
|
587
|
+
const base = TYPE_MAP[col.type]?.[dialect] ?? col.type.toUpperCase();
|
|
588
|
+
|
|
589
|
+
// Append length/precision
|
|
590
|
+
if (col.type === 'varchar' && col.length && dialect !== 'sqlite') {
|
|
591
|
+
return `${base}(${col.length})`;
|
|
592
|
+
}
|
|
593
|
+
if (col.type === 'decimal' && col.precision) {
|
|
594
|
+
if (dialect === 'sqlite') return 'REAL';
|
|
595
|
+
return `${base}(${col.precision},${col.scale ?? 0})`;
|
|
596
|
+
}
|
|
597
|
+
return base;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
function generateColumnDDL(col: Column, dialect: Dialect): string {
|
|
601
|
+
const parts: string[] = [col.name, resolveType(col, dialect)];
|
|
602
|
+
|
|
603
|
+
// auto_pk columns get PK inline for SQLite
|
|
604
|
+
if (col.type === 'auto_pk' && dialect === 'sqlite') {
|
|
605
|
+
return `${col.name} INTEGER PRIMARY KEY`;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
if (col.nullable === false) parts.push('NOT NULL');
|
|
609
|
+
if (col.unique) parts.push('UNIQUE');
|
|
610
|
+
|
|
611
|
+
if (col.default !== undefined && col.default !== null) {
|
|
612
|
+
if (typeof col.default === 'string' && col.default.startsWith('$RAW:')) {
|
|
613
|
+
parts.push(`DEFAULT ${col.default.slice(5)}`);
|
|
614
|
+
} else if (typeof col.default === 'string') {
|
|
615
|
+
parts.push(`DEFAULT '${col.default}'`);
|
|
616
|
+
} else if (typeof col.default === 'boolean') {
|
|
617
|
+
parts.push(`DEFAULT ${dialect === 'mysql' ? (col.default ? '1' : '0') : col.default}`);
|
|
618
|
+
} else {
|
|
619
|
+
parts.push(`DEFAULT ${col.default}`);
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
if (col.check) parts.push(`CHECK (${col.check})`);
|
|
624
|
+
|
|
625
|
+
return parts.join(' ');
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
function generateConstraintDDL(c: Constraint): string {
|
|
629
|
+
switch (c.type) {
|
|
630
|
+
case 'pk':
|
|
631
|
+
return `CONSTRAINT ${c.name} PRIMARY KEY (${c.columns.join(', ')})`;
|
|
632
|
+
case 'fk':
|
|
633
|
+
return [
|
|
634
|
+
`CONSTRAINT ${c.name} FOREIGN KEY (${c.columns.join(', ')})`,
|
|
635
|
+
` REFERENCES ${c.refTable}(${c.refColumns!.join(', ')})`,
|
|
636
|
+
c.onDelete ? ` ON DELETE ${c.onDelete}` : '',
|
|
637
|
+
c.onUpdate ? ` ON UPDATE ${c.onUpdate}` : '',
|
|
638
|
+
].filter(Boolean).join('\n ');
|
|
639
|
+
case 'unique':
|
|
640
|
+
return `CONSTRAINT ${c.name} UNIQUE (${c.columns.join(', ')})`;
|
|
641
|
+
case 'check':
|
|
642
|
+
return `CONSTRAINT ${c.name} CHECK (${c.expression})`;
|
|
643
|
+
default:
|
|
644
|
+
return `-- Unknown constraint type: ${c.type}`;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
export function generateDDL(tables: TableDef[], dialect: Dialect): string {
|
|
649
|
+
const output: string[] = [];
|
|
650
|
+
|
|
651
|
+
// SQLite foreign key pragma
|
|
652
|
+
if (dialect === 'sqlite') {
|
|
653
|
+
output.push('PRAGMA foreign_keys = ON;\n');
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
for (const table of tables) {
|
|
657
|
+
const lines: string[] = [];
|
|
658
|
+
|
|
659
|
+
for (const col of table.columns) {
|
|
660
|
+
lines.push(` ${generateColumnDDL(col, dialect)}`);
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
for (const constraint of table.constraints) {
|
|
664
|
+
// Skip inline PK for auto_pk in SQLite (already handled)
|
|
665
|
+
if (constraint.type === 'pk' && dialect === 'sqlite'
|
|
666
|
+
&& constraint.columns.length === 1
|
|
667
|
+
&& table.columns.find(c => c.name === constraint.columns[0])?.type === 'auto_pk') {
|
|
668
|
+
continue;
|
|
669
|
+
}
|
|
670
|
+
lines.push(` ${generateConstraintDDL(constraint)}`);
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
let createStmt = `CREATE TABLE ${table.name} (\n${lines.join(',\n')}\n)`;
|
|
674
|
+
|
|
675
|
+
// MySQL table options
|
|
676
|
+
if (dialect === 'mysql') {
|
|
677
|
+
createStmt += ' ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci';
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
output.push(`${createStmt};\n`);
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
return output.join('\n');
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
// ---- Usage Example ----
|
|
687
|
+
const schema: TableDef[] = [
|
|
688
|
+
{
|
|
689
|
+
name: 'users',
|
|
690
|
+
columns: [
|
|
691
|
+
{ name: 'id', type: 'auto_pk' },
|
|
692
|
+
{ name: 'email', type: 'varchar', length: 255, nullable: false, unique: true },
|
|
693
|
+
{ name: 'name', type: 'varchar', length: 100, nullable: false },
|
|
694
|
+
{ name: 'is_active', type: 'boolean', nullable: false, default: true },
|
|
695
|
+
{ name: 'created_at', type: 'timestamptz', default: '$RAW:CURRENT_TIMESTAMP' },
|
|
696
|
+
],
|
|
697
|
+
constraints: [
|
|
698
|
+
{ type: 'pk', name: 'pk_users', columns: ['id'] },
|
|
699
|
+
],
|
|
700
|
+
},
|
|
701
|
+
];
|
|
702
|
+
|
|
703
|
+
// Generate for each dialect
|
|
704
|
+
for (const dialect of ['postgresql', 'mysql', 'sqlite'] as Dialect[]) {
|
|
705
|
+
console.log(`-- ===== ${dialect.toUpperCase()} =====`);
|
|
706
|
+
console.log(generateDDL(schema, dialect));
|
|
707
|
+
}
|
|
708
|
+
```
|
|
709
|
+
|
|
710
|
+
## OSS Tools Reference
|
|
711
|
+
|
|
712
|
+
| Tool | What It Does | Use When |
|
|
713
|
+
|------|-------------|----------|
|
|
714
|
+
| **node-sql-parser** | Parse SQL → AST, `sqlify(ast)` back to SQL. Supports PG, MySQL, SQLite, MSSQL. | You need programmatic SQL manipulation or dialect conversion at the AST level |
|
|
715
|
+
| **sql-ddl-to-json-schema** | Parse DDL into JSON Schema using nearley grammar. Extensible for custom dialects. | You need to extract a machine-readable schema from existing DDL |
|
|
716
|
+
| **quick-erd** | Generate Knex migrations + TypeScript types from an ERD model. | Rapid prototyping — go from diagram to running migrations in minutes |
|
|
717
|
+
| **ChartDB** | AI agent converts DDL between dialects by feeding schema JSON to an LLM. | One-off dialect conversions where precision matters more than automation |
|
|
718
|
+
| **ERFlow** | Checkpoint-based migration generation for PG, MySQL, Laravel, Phinx. | When you need versioned migrations alongside your schema design tool |
|
|
719
|
+
| **DrawDB** | Visual ERD designer with separate code generator per dialect. | Non-technical stakeholders need to see/edit the schema visually |
|
|
720
|
+
| **dbdiagram.io** | DBML DSL for defining schemas, exports to multiple SQL dialects. | Quick schema documentation and sharing with a team |
|
|
721
|
+
|
|
722
|
+
## When to Use
|
|
723
|
+
|
|
724
|
+
- Generating CREATE TABLE statements for a new feature
|
|
725
|
+
- Converting DDL from PostgreSQL to MySQL (or vice versa) during a migration
|
|
726
|
+
- Creating Knex/Drizzle/Prisma migrations from a design document
|
|
727
|
+
- Building a code generator that outputs DDL for multiple database targets
|
|
728
|
+
- Teaching/documenting SQL DDL syntax and constraint naming conventions
|
|
729
|
+
|
|
730
|
+
## When NOT to Use
|
|
731
|
+
|
|
732
|
+
- Schema already exists and you only need to ALTER it — use the migration pattern directly
|
|
733
|
+
- You are using an ORM that generates DDL from models (Prisma, TypeORM) — define in the ORM, not raw DDL
|
|
734
|
+
- Performance tuning (indexes, partitioning, tablespaces) — that is a separate concern from DDL generation
|
|
735
|
+
- For runtime SQL translation between dialects — see `postgresql-to-mysql-runtime-translation.md`
|
|
736
|
+
|
|
737
|
+
## Related Skills
|
|
738
|
+
|
|
739
|
+
- `database-schema-designer.md` — full schema design process from requirements to migrations
|
|
740
|
+
- `postgresql-to-mysql-runtime-translation.md` — runtime SQL rewriting for dialect portability
|
|
741
|
+
- `pg-to-mysql-schema-migration-methodology.md` — battle-tested migration methodology
|
|
742
|
+
- `mysql-limit-offset-string-coercion.md` — MySQL LIMIT/OFFSET string handling
|
|
743
|
+
- `reserved-word-context-aware-quoting.md` — identifier quoting across dialects
|
|
744
|
+
- `erd-creator-textbook-research.md` — ERD design fundamentals
|
|
745
|
+
|
|
746
|
+
## References
|
|
747
|
+
|
|
748
|
+
- LibreTexts "Database Design" — CREATE DATABASE, CREATE TABLE, constraint syntax
|
|
749
|
+
- DrawDB GitHub — separate generator per dialect pattern
|
|
750
|
+
- ChartDB GitHub — AI-assisted schema-to-DDL via JSON intermediate
|
|
751
|
+
- ERFlow — checkpoint migration generation (PG, MySQL, Laravel, Phinx)
|
|
752
|
+
- dbdiagram.io — DBML DSL specification
|
|
753
|
+
- node-sql-parser npm — AST-based SQL parsing and generation
|
|
754
|
+
- sql-ddl-to-json-schema npm — nearley grammar DDL parser
|
|
755
|
+
- quick-erd npm — ERD → Knex + TypeScript generation
|
|
756
|
+
- MINISTRY-LMS migration logs — real-world PG→MySQL DDL conversion lessons
|