-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Problem
The current strata validate checks structural integrity of schemas (foreign key references, duplicate ENUM values, etc.), but does not enforce quality rules such as naming conventions, missing indexes, or cross-dialect type consistency. In large projects, naming inconsistencies and performance risks are easily overlooked.
Proposed Solution
Extend SchemaValidatorService with a linting layer. Add a lint category to the existing validation (errors/warnings) system, accessible via strata validate --lint or a dedicated strata lint command.
Lint Rules to Implement
| Rule ID | Category | Description |
|---|---|---|
naming/table-case |
Naming | Table names must be snake_case |
naming/column-case |
Naming | Column names must be snake_case |
naming/index-prefix |
Naming | Index names must have idx_ prefix |
perf/fk-index |
Performance | Foreign key columns must have an index |
safety/nullable-fk |
Safety | Warn on nullable foreign key columns |
safety/ambiguous-default |
Safety | Nullable columns should have explicit default values |
consistency/cross-dialect-type |
Consistency | Suggest dialect-agnostic alternatives for DialectSpecific types |
Implementation Plan
-
New module: Create
src/db/src/services/schema_linter/mod.rs—SchemaLinterService(rule registration and execution)naming_rules.rs— Naming convention rulesperformance_rules.rs— Performance rules (FK index checks)safety_rules.rs— Safety rulesconsistency_rules.rs— Consistency rules
-
Rule interface: Trait-based design for extensibility
pub trait LintRule { fn id(&self) -> &str; fn severity(&self) -> LintSeverity; // Error, Warning, Info fn check(&self, schema: &Schema, dialect: &Dialect) -> Vec<LintDiagnostic>; }
-
Configuration: Add a
lintsection to.strata.yamlfor enabling/disabling rules and adjusting severitylint: rules: naming/table-case: warn perf/fk-index: error safety/nullable-fk: off
-
CLI integration: Add
--lintflag tostrata validate, or create astrata lintsubcommand -
Output: Extend the existing
ValidationResultto include lint diagnostics in both text and JSON output
Files Affected
src/db/src/services/schema_linter/(new)src/core/src/core/config.rs— Add lint configurationsrc/cli/src/cli/commands/validate.rs— Display lint resultssrc/cli/src/cli/cli.rs— Add CLI arguments
Alternatives Considered
- External tool integration: Considered integrating with external linters like eslint, but domain knowledge (dialects, constraints) makes a built-in solution more appropriate
- YAML Schema validation only: JSON Schema can check naming conventions, but cannot express semantic rules like FK index checks
Additional Context
- The existing
SchemaValidatorServicehas 8 modular sub-validators, so the linting layer can follow the same pattern - Corresponds to the "Schema Linting" section in ROADMAP.md