Oh boy! I just noticed there's not one mention of ...
# komapper
d
Oh boy! I just noticed there's not one mention of how to create indexes/unique indexes and foreign keys with komapper's schema creator...! Is this possible?
t
No, it is not possible. However you can use
QueryDsl.executeScript
. See the related discussion: https://github.com/komapper/komapper/discussions/602
d
I guess there's no plan to add that then?
t
Yes, there’s no plan.
d
And that's how you guys write your tests? Using executeScript? I would maybe consider at least having helper schema functions like QueryDsl.create for indexes, at least one testing against different backends like h2 (for fast tests) and postgresql (for slower, but more production-like tests), will have to write those statements only once...
In a nice dsl form instead of having to figure out the sql needed for each.
And it could use the already existing Meta objects...
t
You can implement your own SchemaStatementBuilder and return it from your dialect: https://github.com/komapper/komapper/blob/v1.5.0/komapper-dialect-h2/src/main/kotlin/org/komapper/dialect/h2/H2Dialect.kt#L25 The SchemaStatementBuilder instance is called from
QueryDsl.create
and
QueryDsl.drop
.
d
I'm not really sure what to do there... I don't see how I would specify the indexes that need to be made... I was thinking something like
QueryDsl.createIndex(...)