Last active
June 2, 2022 15:22
-
-
Save blak3r/ce20a51c00c960466780062515d1b97d to your computer and use it in GitHub Desktop.
Create a gin gin_trgm_ops index, using a sequelize migration. Once created you can use this sql command to verify the index was created properly: `SELECT * FROM pg_indexes WHERE tablename = 'table_name';`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
module.exports = { | |
up: (queryInterface, Sequelize) => { | |
return queryInterface.addIndex('Parties', { | |
fields: [Sequelize.literal('name gin_trgm_ops')], // <-- name = field name, gin_trgm_ops comes after the field name | |
using: 'gin', | |
indexName: 'party_name_gin_trgm_idx', // specify the index name manually otherwise sequelize will create party_ | |
unique: false, | |
}) | |
}, | |
down: (queryInterface, Sequelize) => { | |
return queryInterface.removeIndex('Parties', 'party_name_gin_trgm_idx'); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Verifying the index was created as expected:
