All rules
Safety
postgresql/
Require an explicit `ON DELETE` clause on every foreign-key constraint.
Why this matters
Without `ON DELETE`, the default is `NO ACTION` — but it is rarely the deliberate choice. Forcing the author to write the action makes intent visible at the call site. Covers both inline `REFERENCES` and `ALTER TABLE ADD CONSTRAINT FOREIGN KEY`. With the `allowed` option, the rule additionally fails when the action is not in an opt-in list.
Examples
Incorrect
CREATE TABLE t (
fid integer REFERENCES other(id)
);ALTER TABLE t ADD CONSTRAINT fk FOREIGN KEY (fid) REFERENCES other(id);Correct
CREATE TABLE t (
fid integer REFERENCES other(id) ON DELETE RESTRICT
);ALTER TABLE t ADD CONSTRAINT fk FOREIGN KEY (fid) REFERENCES other(id) ON DELETE SET NULL;Configure it
// eslint.config.js
import postgresql from "eslint-plugin-postgresql";
export default [
{
files: ["**/*.sql"],
languageOptions: {
parser: postgresql.configs.recommended.languageOptions.parser,
},
plugins: { postgresql },
rules: {
"postgresql/require-on-delete-action": [
"warn",
{
allowed: [],
},
],
},
},
]; Options
Edit the SQL — only require-on-delete-action is enabled.
Pre-filled with the first incorrect example. Toggle off in the rule shelf to see how the diagnostic disappears.
Diagnostics
No issues found.
2 rules enabled.
Rule under test
require-on-delete-action — plus no-syntax-error as a safety net.