Skip to content

feat(review): Add EffectiveDialect, lock-risk rule variants, and dialect scope helper#122

Merged
mhiro2 merged 4 commits intomainfrom
feat/review-effective-dialect-types
May 1, 2026
Merged

feat(review): Add EffectiveDialect, lock-risk rule variants, and dialect scope helper#122
mhiro2 merged 4 commits intomainfrom
feat/review-effective-dialect-types

Conversation

@mhiro2
Copy link
Copy Markdown
Owner

@mhiro2 mhiro2 commented May 1, 2026

Summary

  • Introduce EffectiveDialect so review rules can reason about a concrete dialect instead of SqlDialect::Auto, with bidirectional From impls and an is_lock_risk_capable() predicate that gates lock-risk evaluation to PostgreSQL/MySQL.
  • Register four new ReviewRuleId variants for upcoming lock-risk rules (AddIndexOnLargeTable, AddFkOnExisting, AlterColumnType, RewriteTable) with caution defaults and dialect-aware descriptions; surface them via --list-rules text/JSON.
  • Add an internal DialectScope helper and ReviewRuleId::dialect_scope() so the dispatcher can skip rules whose dialect scope does not match, ready to wire in the follow-up PR.

Changes

  • b660516 : feat(review): add EffectiveDialect type for rule evaluation
    • Add EffectiveDialect enum mirroring SqlDialect plus From round-trips and Default == Auto.
    • Provide is_lock_risk_capable() so future rule dispatchers can fast-path to no-op for non-lock-risk dialects.
    • Re-export EffectiveDialect from relune-core for downstream crates.
  • 034165d : feat(review): register four lock-risk rule ids
    • Add AddIndexOnLargeTable, AddFkOnExisting, AlterColumnType, RewriteTable variants with stable risk/... ids, caution defaults, and dialect-flavored descriptions.
    • Wire the new ids through as_str / parse / default_severity / description / all_rules / all_metadata so --list-rules text and JSON outputs cover them.
    • Update CLI integration tests to expect 12 rules and pin the new severity/description metadata.
  • fd585af : feat(review): add DialectScope helper for rule dispatch gating
    • Introduce a pub(crate) DialectScope enum (Any vs OneOf(&'static [SqlDialect])) and a const fn dialect_scope() mapping each rule id to its scope.
    • Cover existing Phase 1–3 rules as Any, scope the new lock-risk rules to PostgreSQL/MySQL, and restrict RewriteTable to MySQL.
    • Marked #[allow(dead_code)] while the dispatcher wiring lands in the follow-up PR.
  • 405ba43 : fix(review): polish lock-risk rule descriptions and lock down metadata
    • Reword AddIndexOnLargeTable description so the non-CONCURRENT/INPLACE clause reads naturally and matches the list-rules wording.
    • Pin default_severity and description for each new lock-risk rule in the JSON list-rules integration test instead of only checking the rule count.

mhiro2 added 4 commits May 1, 2026 14:44
EffectiveDialect is the single dialect input rule evaluation will
consult, kept distinct from the parser dialect carried by InputSource.
The lock-risk rules added in Phase 4 require a concrete Postgres or
MySQL setting and skip otherwise, so is_lock_risk_capable() is exposed
upfront for callers and the rule dispatcher to gate evaluation. The
type bridges to SqlDialect via From/Into in both directions so the
existing CLI / TOML / wasm dialect inputs flow through unchanged.
Register risk/add-index-on-large-table, risk/add-fk-on-existing,
risk/alter-column-type, and risk/rewrite-table on ReviewRuleId, all
with the Caution default severity. The variants are appended to
all_rules() so existing CLI listing / fixture / metadata ordering stays
stable while the rule catalog grows from 8 to 12 entries. The actual
detection logic and dialect gating land in follow-up work; this commit
only wires up identifiers, descriptions, and the catalog-size
assertions in the CLI integration tests.
DialectScope is a pub(crate) sibling to ReviewSeverity that the rule
dispatcher will consult to silently filter lock-risk rules out when the
effective dialect does not match. The helper is gated to the crate so
it does not leak into ReviewRuleMetadata: the public listing surface
still emits every rule, while skip semantics live behind a per-request
runtime decision. Eight Phase 1-3 rules report DialectScope::Any, the
PG/MySQL trio reports OneOf both, and the MySQL-only rewrite-table
rule reports OneOf the single dialect. The helper is dead-code allowed
until the run_rules wiring that consumes it lands in a follow-up.
- Reword AddIndexOnLargeTable description so the non-CONCURRENT/INPLACE
  build clause reads naturally and aligns with the list-rules wording.
- Pin default_severity and description for each new lock-risk rule
  (AddIndexOnLargeTable, AddFkOnExisting, AlterColumnType, RewriteTable)
  in the JSON list-rules integration test rather than only checking the
  rule count.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

Code Metrics Report

main (ce7084c) #122 (771f74f) +/-
Coverage 94.6% 94.6% -0.1%
Test Execution Time 1m34s 1m34s 0s
Details
  |                     | main (ce7084c) | #122 (771f74f) |  +/-  |
  |---------------------|----------------|----------------|-------|
- | Coverage            |          94.6% |          94.6% | -0.1% |
  |   Files             |             81 |             81 |     0 |
  |   Lines             |          37324 |          37420 |   +96 |
+ |   Covered           |          35344 |          35431 |   +87 |
  | Test Execution Time |          1m34s |          1m34s |    0s |

Code coverage of files in pull request scope (94.7% → 93.6%)

Files Coverage +/- Status
crates/relune-core/src/review.rs 93.6% -1.2% modified

Reported by octocov

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

Schema review

Tip

✅ No risk findings — schema changes look safe to merge.

@mhiro2 mhiro2 self-assigned this May 1, 2026
@mhiro2 mhiro2 added the enhancement New feature or request label May 1, 2026
@mhiro2 mhiro2 merged commit 3a88bcf into main May 1, 2026
6 checks passed
@mhiro2 mhiro2 deleted the feat/review-effective-dialect-types branch May 1, 2026 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant