diff --git a/lib/query-interface.d.ts b/lib/query-interface.d.ts index 94786f0..f0da143 100644 --- a/lib/query-interface.d.ts +++ b/lib/query-interface.d.ts @@ -1,5 +1,5 @@ import { DataType } from './data-types' -import { Logging, Model, ModelAttributeColumnOptions, ModelAttributes, Transactionable } from './model' +import { Logging, Model, ModelAttributeColumnOptions, ModelAttributes, Transactionable, WhereOptions } from './model' import { Promise } from './promise' import QueryTypes = require('./query-types') import { Sequelize } from './sequelize' @@ -77,6 +77,7 @@ export interface QueryOptionsWithType { export interface QueryInterfaceOptions extends Logging, Transactionable {} export interface QueryInterfaceCreateTableOptions extends QueryInterfaceOptions { + collate?: string engine?: string charset?: string /** @@ -111,6 +112,41 @@ export interface QueryInterfaceIndexOptions extends QueryInterfaceOptions { indexType?: string } +export interface AddUniqueConstraintOptions { + type: 'unique' + name?: string +} + +export interface AddDefaultConstraintOptions { + type: 'default' + name?: string + defaultValue?: any +} + +export interface AddCheckConstraintOptions { + type: 'check' + name?: string + where?: WhereOptions +} + +export interface AddPrimaryKeyConstraintOptions { + type: 'primary key' + name?: string +} + +export interface AddForeignKeyConstraintOptions { + type: 'foreign key' + name?: string + references?: { + table: string + field: string + } + onDelete: string + onUpdate: string +} + +export type AddConstraintOptions = AddUniqueConstraintOptions | AddDefaultConstraintOptions | AddCheckConstraintOptions | AddPrimaryKeyConstraintOptions | AddForeignKeyConstraintOptions + /** * The interface that Sequelize uses to talk to all databases. * @@ -275,6 +311,16 @@ export class QueryInterface { */ public removeIndex(tableName: string, indexName: string, options?: QueryInterfaceIndexOptions): Promise public removeIndex(tableName: string, attributes: string[], options?: QueryInterfaceIndexOptions): Promise + + /** + * Adds constraints to a table + */ + public addConstraint(tableName: string, attributes: string[], options?: AddConstraintOptions | QueryInterfaceOptions): Promise + + /** + * Removes constraints from a table + */ + public removeConstraint(tableName: string, constraintName: string, options?: QueryInterfaceOptions): Promise /** * Shows the index of a table diff --git a/test/query-interface.ts b/test/query-interface.ts index e3b748d..ac05800 100644 --- a/test/query-interface.ts +++ b/test/query-interface.ts @@ -39,6 +39,12 @@ queryInterface.createTable( engine: 'MYISAM', // default: 'InnoDB' charset: 'latin1', // default: null } + }, + { + engine: 'MYISAM', // default: 'InnoDB' + collate: 'latin1_general_ci', + charset: 'latin1' // default: null + } ) queryInterface.dropTable('nameOfTheExistingTable') @@ -133,3 +139,10 @@ queryInterface.removeIndex('Person', 'SuperDuperIndex') // or queryInterface.removeIndex('Person', ['firstname', 'lastname']) + +queryInterface.addConstraint('Person', ['firstname', 'lastname'], { + type: 'unique', + name: 'firstnamexlastname' +}) + +queryInterface.removeConstraint('Person', 'firstnamexlastname') \ No newline at end of file