Model Validation
Model validation finds problems in your database design before they reach the database. DbSchema checks the model after every change and counts what it found in the toolbar. You can add rules of your own, such as "every table has a comment".
See what the checks found
The checks run on their own, so you see a problem as soon as you make it.
- Look at the warning sign at the right of the toolbar. The number next to it counts the warnings.
- Click it. The Model checks window opens.
The window groups the findings by check and by schema. The Message column says what is wrong and how to fix it.
Select a finding, then use the buttons at the bottom of the window:
- Open editor: opens the dialog of the table or column, so you can fix it.
- Show in diagram: shows the table on the diagram.
- Silence this check here: this check skips the table from now on. DbSchema adds the check to the table's checks tag.
- Silence every check on the table, in the menu of the same button: no check looks at the table, its columns, its keys or its indexes.
- Configure checks...: opens the Model Validation dialog.
The buttons show icons. Hover over a button to see its name.
Switch a check on or off
Some checks may not fit your project. For example, a hint about tables with no comment.
- Choose Model → Model Validation.
- Stay on the Model checks tab.
- Untick Enabled next to the check.
- Press OK.
The dialog at the top of this page shows the tab. Each check has a Level: a Warning is a likely error, a Hint is a suggestion. A check that reads Not for PostgreSQL does not apply to the database of your model. Restore defaults switches every check back to how DbSchema ships it.
Write your own validation rule
A rule checks something that your team agreed on, such as a naming convention. Writing and running your own rules needs DbSchema Pro.
- Choose Model → Model Validation.
- Click the + tab and type a name for the rule, such as
Comments. Press OK. - Select Iterate Schemas and press Iteration. Choose Iterate Tables.
- Select Iterate Tables and press Check. Choose Has Description.
- Press Validate.
A rule is a tree of steps:
- Iteration chooses what the rule walks through: schemas, tables, then columns, indexes, foreign keys or constraints.
- Check is the condition that each item must meet, such as Has Primary Key or Name Matches RegExp.
- Filter limits the rule to some items, for example tables whose name starts with
tmp_.
For a condition that the list does not have, choose Java Groovy Check and write a short script.
The script gets the variable unit, the table or column being checked.
It returns true when the item passes.
Press OK to keep the rule. DbSchema keeps the rule in its own configuration folder, not in the model file. So the rule is there for every model you open.
Read the validation result
Validate opens the Validation Result window. It lists the findings of your rules next to those of the built-in checks. Each row of your rule is one item that failed it.
The button with the disk icon saves the findings to a file.
Validate before you save
DbSchema can run your rules each time you save the model file.
- Choose Edit → Settings.
- On the General tab, select Project File.
- Tick Validate Before Save and press OK.
When a rule fails, the Validation Result window opens before the save. OK saves the model anyway. Cancel goes back without saving. The built-in checks never block a save.
Run Model Checks on the same page turns the built-in checks on or off for every model.