Lint Example
This example demonstrates how to use SchemaCrawler Lint to identify potential database design issues, such as missing primary keys, tables without indexes, and inconsistent naming conventions.
How to Run
Before running this example, complete the setup in Getting Started.
- Run the command:
schemacrawler \
--server postgresql \
--host postgresql \
--database schemacrawler \
--user schemacrawler \
--password schemacrawler \
--info-level standard \
--command=lint
- Generate the Lint report in HTML format:
schemacrawler \
--server postgresql \
--host postgresql \
--database schemacrawler \
--user schemacrawler \
--password schemacrawler \
--info-level standard \
--command=lint \
--output-format=html \
--output-file=share/lint-report.html
- Generate the Lint report in JSON or YAML format:
schemacrawler \
--server postgresql \
--host postgresql \
--database schemacrawler \
--user schemacrawler \
--password schemacrawler \
--info-level standard \
--command=lint \
--output-format=json \
--output-file=share/lint-report.json
Replace json with yaml to get YAML output instead.
How to Experiment
- See help on all available lints:
schemacrawler command:lint --help
-
Use a custom linter configuration file:
-
Create a file called “schemacrawler-linter-configs.yaml” with the contents shown below.
-
Run with the custom configuration:
schemacrawler \ --server postgresql \ --host postgresql \ --database schemacrawler \ --user schemacrawler \ --password schemacrawler \ --info-level standard \ --command=lint \ --linter-configs=share/schemacrawler-linter-configs.yaml -
To write your own custom lints, see SchemaCrawler Lint for details on the Lint API and how to package and deploy custom linter jars.
Resource Files
schemacrawler-linter-configs.yaml
- id: schemacrawler.tools.linter.LinterTableSql
config:
message: Lint message A
sql: SELECT TOP 1 1 FROM ${table}
# The same linter can be configured multiple times with different options
- id: schemacrawler.tools.linter.LinterTableSql
table-exclusion-pattern: .*BOOKS
config:
message: Lint message A
sql: SELECT TOP 1 2 FROM ${table}
- id: schemacrawler.tools.linter.LinterTableSql
# Linters can be turned off with the "run" option
run: false
config:
message: message D
sql: SELECT TOP 1 2 FROM ${table}
- id: schemacrawler.tools.linter.LinterCatalogSql
config:
message: message for SQL catalog lint
sql: SELECT TOP 1 1 FROM INFORMATION_SCHEMA.TABLES
- id: schemacrawler.tools.linter.LinterForeignKeyMismatch
# All available linters run by default, so they need to be explicitly turned off
run: false
- id: schemacrawler.tools.linter.LinterForeignKeyWithNoIndexes
# You can override severity and threshold (numer of allowed failures)
severity: critical
threshold: 0
- id: schemacrawler.tools.linter.LinterNullColumnsInIndex
run: false
- id: schemacrawler.tools.linter.LinterNullIntendedColumns
run: false
- id: schemacrawler.tools.linter.LinterRedundantIndexes
run: false
- id: schemacrawler.tools.linter.LinterTableCycles
run: false
- id: schemacrawler.tools.linter.LinterTableWithIncrementingColumns
run: false
- id: schemacrawler.tools.linter.LinterTableWithNoIndexes
run: false
- id: schemacrawler.tools.linter.LinterTableWithQuotedNames
run: true
# Certain columns can be excluded from the linter
column-exclusion-pattern: .*\.\"UPDATE\"
- id: schemacrawler.tools.linter.LinterTableWithSingleColumn
run: true
- id: schemacrawler.tools.linter.LinterTooManyLobs
run: false
- id: schemacrawler.tools.linter.LinterColumnTypes
run: false
- id: schemacrawler.tools.linter.LinterTableEmpty
run: false
- id: schemacrawler.tools.linter.LinterTableWithNoPrimaryKey
run: false
- id: schemacrawler.tools.linter.LinterTableAllNullableColumns
run: false
- id: schemacrawler.tools.linter.LinterTableWithNoRemarks
run: false
- id: schemacrawler.tools.linter.LinterTableWithPrimaryKeyNotFirst
run: false
- id: schemacrawler.tools.linter.LinterTableWithNoSurrogatePrimaryKey
run: false