File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -708,6 +708,16 @@ export declare class MigrationInterface {
708708 * @param newTableName
709709 */
710710 renameTable ( oldTableName : string , newTableName : string ) : void ;
711+
712+ /**
713+ * change column
714+ * @param tableName
715+ * @param columnName
716+ * @param options
717+ */
718+ changeColumn ( tableName : string , columnName : string , options : {
719+ type : FieldType ,
720+ } & CreateColumnOptions ) : void ;
711721}
712722
713723export type MigrateAction = 'up' | 'down' | 'UP' | 'DOWN' ;
Original file line number Diff line number Diff line change @@ -523,6 +523,18 @@ class ManageSQLBuilder extends Builder {
523523 }
524524 }
525525
526+ changeColumn ( options ) {
527+ _validate ( options , {
528+ tableName : 'required|string' ,
529+ columnName : 'required|string' ,
530+ } ) ;
531+ const columnOptions = {
532+ ...options . options ,
533+ name : options . columnName ,
534+ } ;
535+ return _render ( 'ALTER TABLE `${tableName}` MODIFY COLUMN ' + this . renderSingleColumn ( columnOptions ) , { tableName : options . tableName } ) ;
536+ }
537+
526538 renameTable ( options ) {
527539 _validate ( options , {
528540 oldName : 'required|string' ,
Original file line number Diff line number Diff line change @@ -337,6 +337,19 @@ function _initMigration(file, queries = {}) {
337337 } , ...baseAttr
338338 } ) ;
339339
340+ Object . defineProperty ( migration , 'changeColumn' , {
341+ value : function ( tableName , columnName , options ) {
342+ const builder = new ManageSQLBuilder ( {
343+ operator : 'change' ,
344+ target : 'column' ,
345+ tableName,
346+ columnName,
347+ options
348+ } ) ;
349+ queries [ file ] . push ( { sql : builder . sql , values : builder . values } ) ;
350+ } , ...baseAttr
351+ } ) ;
352+
340353 return migration ;
341354}
342355
You can’t perform that action at this time.
0 commit comments