Why this matters
Useful for enforcing project-wide schema conventions — every table must carry the tenant key, audit columns (`created_at`, `created_by`, `updated_at`, `updated_by`), or any other set the project standardises on. The rule inspects every `CREATE TABLE` and reports one diagnostic per missing column. The `columns` option is required and lists the default required column names. `overrides` is an array of `{ pattern, columns }` entries — the first regex that matches the table name replaces the column list entirely (so an override of `[a, b]` does *not* require the default columns as well). `exclude` is a regex string for tables that should be skipped completely (e.g. audit / log tables, materialised views built via `CREATE TABLE AS`).
Examples
Incorrect
CREATE TABLE orders (
id bigserial PRIMARY KEY,
created_at timestamptz NOT NULL DEFAULT current_timestamp,
updated_at timestamptz NOT NULL DEFAULT current_timestamp
);Correct
CREATE TABLE orders (
id bigserial PRIMARY KEY,
tenant_id bigint NOT NULL,
created_at timestamptz NOT NULL DEFAULT current_timestamp,
created_by bigint NOT NULL,
updated_at timestamptz NOT NULL DEFAULT current_timestamp,
updated_by bigint NOT 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-table-columns": [
"warn",
{
columns: [],
overrides: [],
exclude: "",
},
],
},
},
]; Options
Edit the SQL — only require-table-columns is enabled.
Pre-filled with the first incorrect example. Toggle off in the rule shelf to see how the diagnostic disappears.
No issues found.
2 rules enabled.
require-table-columns — plus no-syntax-error as a safety net.