Libraries
    Preparing search index...

    Function generateCreateTableSource

    • Generate up and down TypeScript code strings (4-space-indented\n * fragments) for creating a table from a schema.

      Unlike generateCreateTable (which returns a Knex callback), the output is plain source text suitable for writing into a migration file. The fragments are designed to be embedded directly inside up() / down() functions.

      Parameters

      • schema: ObjectSchemaBuilder<any, any, any, any, any, any, any>

        An ObjectSchemaBuilder with .hasTableName() and column DDL extensions.

      Returns { down: string; up: string }

      { up, down } source fragments.

      const { up, down } = generateCreateTableSource(UserSchema);
      // up: " await knex.schema.createTable('users', (table) => { … });"
      // down: " await knex.schema.dropTableIfExists('users');"