Registry / database / postgres-shift

postgres-shift

JSON →
library0.1.0jsnpmunverified

A simple forwards-only migration tool designed specifically for postgres.js. Version 0.1.0 provides a single function to run SQL migrations in order. It is lightweight, has no external dependencies beyond postgres.js, and follows the philosophy of the parent library. Ideal for projects already using postgres.js who want minimal migration overhead without the complexity of other tools.

npm install postgres-shift
INSTALL
IMPORT
SIG · POSTGRES-SHIFT
P
postgres-shift
databasejavascriptv0.1.0
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.

shift
import { shift } from 'postgres-shift'
const shift = require('postgres-shift')
The library is ESM-only; CommonJS require will fail. Use import or dynamic import.

Imports the shift function, connects to PostgreSQL using postgres.js, and runs migrations from a local directory.

import { shift } from 'postgres-shift'; import postgres from 'postgres'; const sql = postgres(process.env.DATABASE_URL ?? ''); // Run all pending migrations from the 'migrations' folder await shift({ sql, path: './migrations' }); // Optional: specify a custom migrations table name await shift({ sql, path: './migrations', table: '_migrations' }); console.log('Migrations complete');
Debug
Known issues
breakingThe library is ESM-only and does not support CommonJS. Using require() will throw an error.
fix
Use import { shift } from 'postgres-shift' or dynamic import('postgres-shift') instead of require().
affects: >=0.1.0
gotchaThe shift function expects a postgres.js sql object, not a pg client or any other database driver. Using an incompatible driver will cause errors.
fix
Ensure you import and create a postgres.js instance with postgres(connectionString) and pass sql to shift.
affects: >=0.1.0
gotchaThe migration file naming convention matters; files are sorted alphabetically and applied in order. Non-standard sorting may lead to unexpected migration order.
fix
Name migration files with a timestamp or sequential number (e.g., 001_create_users.sql, 002_add_email.sql).
affects: >=0.1.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module not supported
Trying to use require() instead of import for the ESM-only package.
fix
Use import { shift } from 'postgres-shift' in your code, or if using CommonJS, use dynamic import: const { shift } = await import('postgres-shift');
TypeError: sql is not a function
The shift function received an incorrect object instead of a postgres.js sql instance.
fix
Ensure you have imported postgres from 'postgres' and created the sql object correctly: const sql = postgres(connectionString); Then pass sql to shift().
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies
postgresrequiredRuntime peer dependency; postgres-shift requires a postgres.js sql instance to execute migrations
Agent activity
10 hits · last 30 days
node
8
Resources
postgres-shift — npm install postgres-shift · libregistry