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
10 changes: 10 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,16 @@ export declare class MigrationInterface {
* @param newTableName
*/
renameTable(oldTableName: string, newTableName: string): void;

/**
* change column
* @param tableName
* @param columnName
* @param options
*/
changeColumn(tableName: string, columnName: string, options: {
type: FieldType,
} & CreateColumnOptions): void;
}

export type MigrateAction = 'up' | 'down' | 'UP' | 'DOWN';
Expand Down
12 changes: 12 additions & 0 deletions src/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,18 @@ class ManageSQLBuilder extends Builder {
}
}

changeColumn(options) {
_validate(options, {
tableName: 'required|string',
columnName: 'required|string',
});
const columnOptions = {
...options.options,
name: options.columnName,
};
Comment thread
cursor[bot] marked this conversation as resolved.
return _render('ALTER TABLE `${tableName}` MODIFY COLUMN ' + this.renderSingleColumn(columnOptions), { tableName: options.tableName });
}

renameTable(options) {
_validate(options, {
oldName: 'required|string',
Expand Down
13 changes: 13 additions & 0 deletions src/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,19 @@ function _initMigration(file, queries = {}) {
}, ...baseAttr
});

Object.defineProperty(migration, 'changeColumn', {
value: function (tableName, columnName, options) {
const builder = new ManageSQLBuilder({
operator: 'change',
target: 'column',
tableName,
columnName,
options
});
queries[file].push({ sql: builder.sql, values: builder.values });
}, ...baseAttr
});

return migration;
}

Expand Down
Loading