knex-db-manager-continued
raw JSON → 0.7.1 verified Sat Apr 25 auth: no javascript
A database management utility for knex that provides administrative operations like creating/dropping databases and users, truncating tables, and copying databases. Version 0.7.1 supports PostgreSQL, MySQL, and SQLite3, and is compatible with knex 0.x, 1.x, and 2.x. It is a maintained fork of the original knex-db-manager, updated to work with newer knex versions. Key differentiators: uses superuser credentials for privileged operations, supports collation and seed patterns, and includes truncate with ignore tables. Release cadence: sporadic.
Common errors
error Error: Cannot find module 'knex-db-manager' ↓
cause Misspelled package name (original vs continued).
fix
Install knex-db-manager-continued: npm install knex-db-manager-continued
error ERR_REQUIRE_ESM: require() of ES Module ↓
cause Using require on a package that is ESM-only. This package is CJS, but users sometimes mistake for ESM.
fix
Use require() correctly; no fix needed if using CJS. For ESM, use import syntax.
error TypeError: databaseManagerFactory is not a function ↓
cause Importing default instead of named export.
fix
Use const { databaseManagerFactory } = require('knex-db-manager-continued');
Warnings
gotcha Requires superuser credentials (superUser, superPassword) for admin operations; using limited user will cause permission errors. ↓
fix Ensure your knex connection user is a superuser or provide separate superuser credentials in dbManager config.
breaking Default export removed in this fork; use named export databaseManagerFactory instead. ↓
fix Change const dbManager = require('knex-db-manager-continued') to const { databaseManagerFactory } = require('knex-db-manager-continued'); const dbManager = databaseManagerFactory(config);
gotcha On MySQL, copyDb method throws 'Not supported' error. ↓
fix Avoid calling copyDb for MySQL databases. Use pg_dump or other MySQL-specific tools for copying.
gotcha truncateDb may fail if foreign key constraints exist; requires disabling triggers or cascade option which is not built-in. ↓
fix Temporarily disable foreign key checks before calling truncateDb, or use DELETE with cascade manually.
deprecated collate config option only works with PostgreSQL; on MySQL it is ignored. ↓
fix For MySQL, omit collate option or set to empty array.
Install
npm install knex-db-manager-continued yarn add knex-db-manager-continued pnpm add knex-db-manager-continued Imports
- databaseManagerFactory wrong
const dbManager = require('knex-db-manager-continued').databaseManagerFactory;correctimport { databaseManagerFactory } from 'knex-db-manager-continued' - KnexDbManager wrong
import KnexDbManager from 'knex-db-manager-continued'correctimport { KnexDbManager } from 'knex-db-manager-continued' - default wrong
const { default } = require('knex-db-manager-continued')correctimport dbManagerAdmin from 'knex-db-manager-continued'
Quickstart
const config = {
knex: {
client: 'postgres',
connection: {
host: 'localhost',
database: 'appdb',
user: 'dbowner',
password: 'pass',
},
pool: { min: 0, max: 10 },
migrations: { directory: './migrations' },
},
dbManager: {
collate: ['fi_FI.UTF-8', 'Finnish_Finland.1252'],
superUser: 'superuser',
superPassword: 'superpass',
populatePathPattern: 'data/**/*.js',
},
};
const { databaseManagerFactory } = require('knex-db-manager-continued');
const dbManager = databaseManagerFactory(config);
dbManager.createDbOwnerIfNotExist().then(() => {
console.log('User created');
return dbManager.createDb('testdb');
}).then(() => console.log('Database created')).catch(err => console.error(err));