Per this question and its comments, in order to obtain constraints (I'm particularly interested in check constraints), one must do the following:
Include a
.jar
corresponding to their DB driver of choice, like schemacrawler-postgresql or schemacrawler-sqlite.Set detail level to
detailed
(or higher), like so:
val optionsBuilder = SchemaCrawlerOptionsBuilder.builder()
.withLoadOptions(LoadOptionsBuilder.builder()
.withSchemaInfoLevel(SchemaInfoLevelBuilder.detailed())
.toOptions()
)
val options = optionsBuilder.toOptions()
val catalog = SchemaCrawlerUtility.getCatalog(dataSource.get(), options)
- Use
Table.getTableConstraints()
method.
I have included .jar
files for PostgreSQL, SQLite, MySQL, but I only get the constraints for PostgreSQL, while for both SQLite and MySQL the results are empty (and there are not only check constraints, but also not null constraints, but no sign of them either; this info can be retrieved by checking if the column is nullable directly, but no such API for check constraints). Are there any additional steps I haven't considered? Including the .jar
for MySQL seemed to help the OP of the question linked above.
My dependencies are as follows:
implementation("us.fatehi:schemacrawler:16.9.3")
implementation("us.fatehi:schemacrawler-mysql:16.9.3")
implementation("us.fatehi:schemacrawler-sqlite:16.9.3")
implementation("us.fatehi:schemacrawler-postgresql:16.9.3")