From 48fcde1d402d13eb8123cefc9ed618e126e74273 Mon Sep 17 00:00:00 2001 From: Olivier Cavadenti Date: Wed, 10 Nov 2021 21:22:42 +0100 Subject: [PATCH] Add callback doc for create table like (#359) --- sections/schema.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/sections/schema.js b/sections/schema.js index 8176442b..562c3f7e 100644 --- a/sections/schema.js +++ b/sections/schema.js @@ -46,14 +46,24 @@ export default [ { type: "method", method: "createTableLike", - example: "knex.schema.createTableLike(tableName, tableNameToCopy)", - description: "Creates a new table on the database based on another table. Copy only the structure : columns, keys and indexes (expected on SQL Server which only copy columns) and not the data.", + example: "knex.schema.createTableLike(tableName, tableNameToCopy, [callback])", + description: "Creates a new table on the database based on another table. Copy only the structure : columns, keys and indexes (expected on SQL Server which only copy columns) and not the data. Callback function can be specified to add columns in the duplicated table.", children: [ { type: "runnable", content: ` knex.schema.createTableLike('new_users', 'users') ` + }, + { + type: "runnable", + content: ` + // "new_users" table contains columns of users and two new columns 'age' and 'last_name'. + knex.schema.createTableLike('new_users', 'users', (table) => { + table.integer('age'); + table.string('last_name'); + }) + ` } ] },