A utility library for Knex.js that allows writing SQL migrations using .up.sql and .down.sql files instead of (or in addition to) programmatic schema methods. Version 2.0.0 is the latest stable release, with infrequent updates. It provides functions to load and execute SQL files as Knex raw queries, supporting both CommonJS and ESM modules. Key differentiators include zero-dependency generated migration files, simple integration with existing Knex setups, and type safety with TypeScript definitions.
npm install knex-migrate-sql-fileNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to use upSQL and downSQL functions in a Knex migration file to execute SQL files.
Use ESM imports (import ... from ...) or migrate to a CommonJS-compatible version (<2.0.0).
Ensure .up.sql and .down.sql files are adjacent to the migration file and have the exact same base name (e.g., migration.js -> migration.up.sql).
Use 'getMigrators' or switch to upSQL/downSQL functions. Check documentation for alternative.
Test SQL syntax against your specific database (PostgreSQL, MySQL, SQLite) before production deployment.
Always call upSQL/downSQL with the knex instance passed to migration's up/down functions.
Run 'npm install knex-migrate-sql-file' in your project directory.
Replace 'const getMigrators = require(...)' with 'import getMigrators from ...' and ensure your project uses ESM.
Create a .up.sql (and .down.sql) file in the same directory as the migration file with the matching base name.
No dependency data recorded yet.