Conversation
dantownsend
left a comment
There was a problem hiding this comment.
I like the API - using CompositeIndex.
I agree that using strings is just much easier than actual column references.
class Album(Table):
name = Varchar()
released = Boolean(default=False)
name_released_idx = CompositeIndex(["name", "released"])Is there a way to specify the index type?
It looks like B-tree, GiST, GIN, and BRIN can be used with multi-column indexes:
https://www.postgresql.org/docs/current/indexes-multicolumn.html
|
@dantownsend Great idea. I'll try to implement it. Thanks |
| @engines_only("postgres", "cockroach") | ||
| def test_add_table_with_composite_index(self): |
There was a problem hiding this comment.
I added a new commit with the index type in CompositeIndex. I didn't write any test because for that we need to create an extension for each of those index types (except B-tree) either in Github workflows or in PostgresEngine. I tried it locally and it works. The test would be the same as this, except we add e.g. "index_type": IndexMethod.gin instead of the default "index_type": IndexMethod.btree and create the extension with
CREATE EXTENSION pg_trgm;
CREATE EXTENSION btree_gin; for that index type.
|
Tests pass locally without any problems. Maybe the next update with the master branch will be better. |
Related to #1188. This is almost identical PR as for composite unique constraints, only it doesn't use custom ddl but modified Piccolo methods
create_indexanddrop_index. Although it serves a different purpose, feel free to remove it if it represents too much code duplication and adds complexity, as adding and dropping a composite index can easily be done with manual migrations as described in the comment.Usage is: