A utility library for Knex.js (v2.0.0) that simplifies running database migrations across multiple schemas. While Knex supports per-query schema references via `withSchema()`, its built-in `knex.migrate` API lacks native multi-schema support. This library fills that gap by providing `createSchema`, `executeSchemaMigration`, and `executeSchemaMigrationFromDir` functions. It accepts a Knex instance, schema name, and a dictionary of migration objects or a directory of migration files, executing only pending migrations per schema. Released under MIT, actively maintained on GitHub. Key differentiator: enables programmatic schema-scoped migrations without manual schema tracking or external orchestration.
npm install knex-migration-with-schemaNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a new schema, defines a migration with up/down methods, and executes pending migrations against that schema using a Knex instance.
Wrap your migration object in a function that takes schemaName and returns { up, down } as shown in the documentation.If you need the migration table in the same schema as the migrations, use Knex's migration config or manually set the schema before calling executeSchemaMigration.
Ensure each migration file has a default export: `export default (schemaName: string): Knex.Migration => ({ up, down })`.Use `import { executeSchemaMigration } from 'knex-migration-with-schema'` instead of `import executeSchemaMigration from '...'`.Configure Knex migration table explicitly via `knex.migrate.config` or set the search path accordingly. Or ensure the target schema exists before running migrations.
Run `npm install knex-migration-with-schema` and ensure your bundler resolves node_modules correctly.