Collection of administrative database operations for knex, supporting PostgreSQL, MySQL, and SQLite3. Version 0.7.0 (latest) provides APIs for creating, dropping, copying, truncating databases, and managing database owners via a privileged superuser connection. Helps with test setup, initializing fresh databases, and truncating between tests. Requires knex 0.x and the appropriate database driver. Differentiates from raw knex by offering high-level admin functions like copyDb and truncateDb.
npm install knex-db-managerVerified import paths — ran on the pinned version, not inferred.
Shows initialization and basic usage: create db owner, create database, truncate tables except migrations.
Add dbManager.close() after all operations to ensure clean exit.
Avoid copyDb for very large databases; use native tools.
Always provide dbManager.superUser and dbManager.superPassword.
Remove populatePathPattern and run seeds via knex commands.
Do not use copyDb with MySQL; implement your own copy logic.
Ensure all tables are listed; use ignoreTables for tables with dependencies.
Set collate to an array of collations that the database supports; can be empty array if unsure.
Ensure config.knex includes client: 'postgres' (or mysql/sqlite3).
Run: npm install pg-escape
Add superUser and superPassword to dbManager configuration object.
Use: const dbManager = databaseManagerFactory(config); then call dbManager.createDb().
Call await dbManager.createDbOwnerIfNotExist() before createDb().