$ show Artur-Sulej/excellent_migrations
Excellent Migrations is an Elixir library that analyzes Ecto migration files to detect potentially dangerous database operations that could cause downtime or data loss. It provides a Credo check, Mix tasks, and direct API usage to identify issues such as adding columns with default values, removing columns, running raw SQL, and more. The tool allows marking operations as safe via special comments or configuration to avoid false positives. The architecture is centered around AST parsing of migration files, with separate modules for detecting dangers, parsing safety comments, and filtering results. Key components like the AST parser and comment parser are well-crafted and reusable in other contexts.
The LLM identified 4 files worth highlighting for reuse:
Parses the AST of Ecto migration files to detect dangerous operations such as adding columns with defaults, removing columns, and executing raw SQL. Uses Macro.postwalk for thorough tree traversal and precise pattern matching for Ecto's DSL, demonstrating non-obvious skill in AST manipulation.
Detects concurrent index creations that are missing the required @disable_ddl_transaction and/or @disable_migration_lock module attributes. Implements a state machine via Macro.postwalk to track attribute settings across the module, showcasing advanced AST traversal techniques for context-dependent checks.
Extracts special comments from migration source code to mark operations as safe (e.g., excellent_migrations:safety-assured-for-next-line). Uses regex and stream processing to parse comments line-by-line, providing a clean and reusable mechanism for configurable code annotations.
Filters out detected dangers that have been marked as safe via comments or configuration, and handles the deprecated @safety_assured module attribute. Implements robust logic for line-based filtering (for next-line comments) and global exemptions, demonstrating careful attention to edge cases in risk management.