Skip to content

Instantly share code, notes, and snippets.

@blak3r
Last active June 2, 2022 15:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blak3r/ce20a51c00c960466780062515d1b97d to your computer and use it in GitHub Desktop.
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';`
'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');
}
};
@blak3r
Copy link
Author

blak3r commented Feb 5, 2019

Verifying the index was created as expected:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment