Embedded Rhai in a Postgres migration linter for custom lint rules #1078
ayarotsky
started this conversation in
Show and tell
Replies: 1 comment 3 replies
-
|
Wonderful work and a need that fits a scripting engine perfectly. Some suggestions on idiomatic Rhai: let stmt = node.IndexStmt;
if stmt == () { return; }
let name = stmt.idxname;
if name == "" { return; }Can be more concisely written as: let stmt = node.IndexStmt ?? return;
let name = stmt.idxname ?? return;Or even: let name = node.IndexStmt?.idxname;
if name?.starts_with("idx_") ?? true { return; }
#{
operation: `Index naming violation: ${name}`,
problem: `Index '${name}' does not follow naming convention. Names must start with 'idx_'.`,
safe_alternative: `Rename: CREATE INDEX idx_${name} ON ...;`
}Come to think of it, perhaps many of the builtin lints can also be converted into scripts such that they can be easily updated / tweaked. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I recently added Rhai as a scripting engine to diesel-guard, a Rust CLI linter for Postgres migrations.
The goal was to let teams enforce their own conventions and migration policies.
I shared my thoughts and integration guide in this write-up.
Beta Was this translation helpful? Give feedback.
All reactions