From dccf648e59c165614c420cf819582f0a7facf1fa Mon Sep 17 00:00:00 2001 From: Emmanuel Gautier Date: Tue, 14 May 2019 01:10:03 +0200 Subject: [PATCH] [Sequelize] update queryInterface addIndex (#35284) * fix sequelize addIndex * add deprecated sequelize index options * create sequelize IndexType --- types/sequelize/index.d.ts | 33 ++++++++++++++++++++++++++++-- types/sequelize/sequelize-tests.ts | 8 ++++++-- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/types/sequelize/index.d.ts b/types/sequelize/index.d.ts index debec7917d..c7d5c9a80d 100644 --- a/types/sequelize/index.d.ts +++ b/types/sequelize/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Sequelize 4.27.11 +// Type definitions for Sequelize 4.28.0 // Project: http://sequelizejs.com, https://github.com/sequelize/sequelize // Definitions by: samuelneff // Peter Harris @@ -17,6 +17,7 @@ // Antoine Boisadam // Dima Smirnov // Duy Truong +// Emmanuel Gautier // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 @@ -4337,6 +4338,7 @@ declare namespace sequelize { /** * Adds a new index to a table */ + addIndex(tableName: string | Object, options: DefineIndexOptions & { fields: string[] }, rawTablename?: string): Promise; addIndex(tableName: string | Object, attributes: string[], options?: DefineIndexOptions, rawTablename?: string): Promise; @@ -5001,17 +5003,34 @@ declare namespace sequelize { } + type IndexType = 'UNIQUE' | 'FULLTEXT' | 'SPATIAL'; + interface DefineIndexOptions { /** * The index type */ - indicesType?: 'UNIQUE' | 'FULLTEXT' | 'SPATIAL'; + indicesType?: IndexType; + + /** + * The index type + */ + type?: IndexType; /** * The name of the index. Default is __ */ indexName?: string; + /** + * Create a unique index + */ + unique?: boolean; + + /** + * The name of the index. Default is Default is __ + */ + name?: string; + /** * For FULLTEXT columns set your parser */ @@ -5027,6 +5046,16 @@ declare namespace sequelize { */ logging?: Function; + /** + * Create an unique index + */ + using?: string; + + /** + * Index operator + */ + operator?: string; + /** * A hash of attributes to limit your index(Filtered Indexes - MSSQL & PostgreSQL only) */ diff --git a/types/sequelize/sequelize-tests.ts b/types/sequelize/sequelize-tests.ts index 838a02df9e..50500df8de 100644 --- a/types/sequelize/sequelize-tests.ts +++ b/types/sequelize/sequelize-tests.ts @@ -1195,8 +1195,12 @@ queryInterface.createTable( 'table', { name : { type : Sequelize.STRING } }, { s queryInterface.addIndex( { schema : 'a', tableName : 'c' }, ['d', 'e'], { logging : function() {} }, 'schema_table' ); queryInterface.showIndex( { schema : 'schema', tableName : 'table' }, { logging : function() {} } ); queryInterface.addIndex( 'Group', ['from'] ); -queryInterface.addIndex( 'Group', ['from'], { indexName: 'group_from' } ); -queryInterface.addIndex("Group", ["from"], { concurrently: true }); +queryInterface.addIndex( 'Group', ['from'], { indexName: 'group_from' }); +queryInterface.addIndex( 'Group', ['from'], { type: 'FULLTEXT' }); +queryInterface.addIndex( 'Group', ['from'], { indicesType: 'FULLTEXT' } ); +queryInterface.addIndex( 'Group', ['from'], { concurrently: true } ); +queryInterface.addIndex( 'Group', ['data'], { using: 'gin', operator: 'jsonb_path_ops' } ); +queryInterface.addIndex( 'Group', { fields: ['data'], using: 'gin', operator: 'jsonb_path_ops' } ); queryInterface.describeTable( '_Users', { logging : function() {} } ); queryInterface.createTable( 's', { table_id : { type : Sequelize.INTEGER, primaryKey : true, autoIncrement : true } } ); /* NOTE https://github.com/DefinitelyTyped/DefinitelyTyped/pull/5590