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
17 changes: 17 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -688,9 +688,26 @@ export declare class MigrationInterface {
*/
dropForeignKey(tableName: string, foreign_key: string): void;

/**
* insert data into table
* @param table
* @param data
*/
insertData(table: string, data: any[]): void;

/**
* execute raw sql
* @param sql
* @param values
*/
raw(sql: string, values: any[]): void;

/**
* rename table
* @param oldTableName
* @param newTableName
*/
renameTable(oldTableName: string, newTableName: string): void;
}

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

renameTable(options) {
_validate(options, {
oldName: 'required|string',
newName: 'required|string',
});
return _render('RENAME TABLE `${oldName}` TO `${newName}`', options);
}

/**
* @param {import('./migration').ManageBuilderOptions} options
*/
Expand Down
12 changes: 12 additions & 0 deletions src/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,18 @@ function _initMigration(file, queries = {}) {
}, ...baseAttr
});

Object.defineProperty(migration, 'renameTable', {
value: function (oldTableName, newTableName) {
const builder = new ManageSQLBuilder({
operator: 'rename',
target: 'table',
oldName: oldTableName,
newName: newTableName
});
queries[file].push({ sql: builder.sql, values: builder.values });
}, ...baseAttr
});

return migration;
}

Expand Down
Loading