Skip to content

SQL-based Tests

Compliance with the rules in the dbLinter repository can be verified using checks, SQL-based tests, or both. In a SQL-based test, an SQL query is run against a non-production database via a configured read-only connection. The returned rows are treated as violations of the rule. Optionally, each result row may contain a migration script to fix the violation.

In order to run SQL-based tests, you must first configure read-only access.

Whether a SQL-based test is shown in the VS Code extension depends on the following:

  1. Is the rule enabled in the configuration?
  2. Is the test compatible with the connected DBMS?
  3. Does the database version fall within the minimal and maximal ranges defined for test?

The SQL-based test is only considered applicable if all questions can be answered with ‘yes’.

The applicable SQL-based tests are determined either when you run a check or when you open the dbLinter view container.

Clicking on the dbLinter symbol

dbLinter symbol

in the activity bar opens the dbLinter view container. SQL-BASED TESTS is the first view in this container.

Tests Activated

To run all tests, right-click anywhere in the view and select Run All Tests. To run selected tests, right-click on one of the selected tests and select the Run Test option. Alternatively, click the run button to the right of each test.

Run Selected Tests

The found rule violations are visualised as children in the tree.

Test Results

If you are unable to resolve a rule violation reported by an SQL-based test, or if you choose not to, you can ignore selected test results. This ensures that the rule violations will not appear in subsequent test runs.

To perform this action, your access token must have either the Configurator or Tenant-Admin role.

Ignore Test Results

After selecting the test results to be ignored, you must provide a reason why these results should be excluded from future runs.

Ignore Test Result Reason

You can manage the test results to be ignored in the Web GUI.

Ignore Test Results in Web GUI

If the SQL-based test produces a migration script, you can show it in a new editor tab.

Show Migration Script

The following migration script is shown in this case:

Generated Migration Script

The SQL-based test for G-1240: Try to index foreign key columns uses the IF NOT EXISTS clause only if applicable to the used database version.