Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion lib/query-interface.d.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -77,6 +77,7 @@ export interface QueryOptionsWithType {
export interface QueryInterfaceOptions extends Logging, Transactionable {}

export interface QueryInterfaceCreateTableOptions extends QueryInterfaceOptions {
collate?: string
engine?: string
charset?: string
/**
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -275,6 +311,16 @@ export class QueryInterface {
*/
public removeIndex(tableName: string, indexName: string, options?: QueryInterfaceIndexOptions): Promise<void>
public removeIndex(tableName: string, attributes: string[], options?: QueryInterfaceIndexOptions): Promise<void>

/**
* Adds constraints to a table
*/
public addConstraint(tableName: string, attributes: string[], options?: AddConstraintOptions | QueryInterfaceOptions): Promise<void>

/**
* Removes constraints from a table
*/
public removeConstraint(tableName: string, constraintName: string, options?: QueryInterfaceOptions): Promise<void>

/**
* Shows the index of a table
Expand Down
13 changes: 13 additions & 0 deletions test/query-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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')