Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Custom Index Options in GORM Annotations (e.g., jsonb_path_ops for GIN Indexes) #7372

Open
MohammadEsf95 opened this issue Feb 17, 2025 · 0 comments
Assignees
Labels
type:feature_request feature request

Comments

@MohammadEsf95
Copy link

MohammadEsf95 commented Feb 17, 2025

Describe the feature

GORM should allow specifying custom index options in struct annotations. Currently, when defining an index using the gorm:"index" tag, GORM only allows specifying the index type (e.g., GIN, BTREE) inside parentheses but does not support adding additional options for more advanced configurations.

For example, some databases allow specifying additional operator classes or storage parameters when creating an index, but GORM does not currently provide a way to include these options within the annotation.

Example of a query that cannot be fully represented using GORM's current struct tags:

CREATE INDEX IF NOT EXISTS idx_users_metadata ON users USING GIN (metadata jsonb_path_ops);

If trying to define this in GORM:

type SomeStruct struct {
Metadata json.RawMessage `gorm:"column:metadata;type:jsonb;index:,type:gin,option:jsonb_path_ops"`
}

GORM only includes the index type (GIN) but does not allow jsonb_path_ops to be included inside the parentheses.

Motivation

Improved Flexibility: Many databases support additional index options that can optimize query performance, but GORM does not currently allow specifying them.
Better Performance: Certain indexing options can significantly enhance efficiency, especially for complex data types such as JSONB, array columns, and full-text search.
Schema Management Consistency: Without support for custom index options, users are forced to manually execute raw SQL migrations, which goes against the purpose of using GORM for schema management.

Related Issues

None.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature_request feature request
Projects
None yet
Development

No branches or pull requests

2 participants