Registry / database / migration-files

migration-files

JSON →
library0.4.3jsnpmunverified

Utilities for parsing SQL-based migration files with versioned up/down sections. Version 0.4.3 is stable, with infrequent releases. It provides functions like findMigrationFilenames, readMigrationFile, and parseMigrationFile to scan a directory for migration files of format `NNN-name.sql` and extract up/down SQL statements separated by `-- Up` / `-- Down` markers. Unlike heavier frameworks (e.g., knex, Sequelize migrations), this is a lightweight, file-oriented library focused solely on reading and parsing migration files, leaving execution to the user.

npm install migration-files
INSTALL
IMPORT
SIG · MIGRATION-FILES
M
migration-files
databasejavascriptv0.4.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

findMigrationFilenames
import { findMigrationFilenames } from 'migration-files'
const { findMigrationFilenames } = require('migration-files')
Package is ESM-only; CommonJS require will not work.
readMigrationFile
import { readMigrationFile } from 'migration-files'
import readMigrationFile from 'migration-files'
This is a named export, not default.
parseMigrationFile
import { parseMigrationFile } from 'migration-files'
Also a named export; synchronously parses content string.
IMigration
import type { IMigration } from 'migration-files'
import { IMigration } from 'migration-files'
Use type import for TypeScript interfaces.

Demonstrates scanning a directory for migration files and reading each into a structured object.

import { findMigrationFilenames, readMigrationFile } from 'migration-files'; import { map } from 'extra-promise'; async function loadMigrations() { const filenames = await findMigrationFilenames('./migrations'); const migrations = await map(filenames, readMigrationFile); console.log(migrations); } loadMigrations();
Debug
Known issues
gotchaMigration filename format must be exactly `NNN-name.sql`, where NNN is a version number. Files not matching the pattern are ignored by findMigrationFilenames.
fix
Rename files to match `\d+-.+\.sql` pattern, e.g., `001-initial.sql`.
affects: >=0.0.0
gotchaThe SQL separators `-- Up` and `-- Down` must be exactly 80 dashes with a single space after `--`. Incorrect formatting may cause parseMigrationFile to fail silently.
fix
Follow the exact format: 80 dashes, newline, `-- Up` (or `-- Down`), newline, 80 dashes.
affects: >=0.0.0
gotchaPackage is ESM-only; using `require()` will throw a Module not found error.
fix
Use `import` statements and ensure your project is configured for ESM (e.g., `"type": "module"` in package.json).
affects: >=0.0.0
Errors
Common errors & fixes
Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'migration-files'
Using CommonJS require with an ESM-only package.
fix
Use import syntax and set 'type':'module' in package.json.
SyntaxError: Unexpected token 'export'
Attempting to require an ESM package from a CommonJS context.
fix
Switch to ES modules or use dynamic import().
Upgrade
Version history
0.4.3latest on npm
Audit
Dependencies
extra-promiseoptionalUsed in examples for map utility to process migration files
Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
migration-files — npm install migration-files · libregistry