@willianevl/dbsetup
v0.1.1
Published
CLI to drop, recreate, migrate and seed databases — configurable per project and framework
Maintainers
Readme
dbsetup
CLI to drop, recreate, migrate, and seed databases — configurable per project and migration framework.
Point it at a project, pick an environment (or branch), and it handles the git checkout, database reset, migrations, and seeding in one command.
Requirements
- Node.js >= 18
gitin PATH- PostgreSQL (
pg_dump) or MySQL (mysqldump) client tools, if using--backup
Installation
npm install -g @willianevl/dbsetupOr link during development:
npm linkQuick Start
# 1. Register a project
dbsetup configure
# 2. Run against an environment
dbsetup myapp devCommands
dbsetup configure (alias: config)
Interactively add or edit a project configuration.
dbsetup configure
dbsetup configure -p myapp # jump directly to a project (creates or edits)You will be prompted for:
| Field | Description |
|---|---|
| Project name | Identifier used in all other commands |
| Project path | Absolute path or ~/... to the project root |
| DB type | PostgreSQL or MySQL / MariaDB |
| Migration framework | See Frameworks |
| Migrate command | Defaults to the framework standard; editable |
| Seed command | Optional; leave blank to skip seeding |
| Branch mapping | Which git branch maps to dev, hlg, and prod |
| Env var names | Names of DB connection vars in the project .env |
Configuration is saved to:
- Linux / macOS:
~/.config/db-setup/config.json - Windows:
%APPDATA%\db-setup\config.json
dbsetup run [project] [env]
Drop, recreate, migrate, and seed a project database. This is the default command — dbsetup myapp dev is equivalent to dbsetup run myapp dev.
dbsetup myapp dev
dbsetup myapp hlg
dbsetup myapp prod
dbsetup myapp feature/my-branch # any remote branch name
dbsetup # prompts for project and environmentOptions:
| Flag | Description |
|---|---|
| --skip-seed | Run migrations but skip the seed step |
| --migrate-only | Skip drop/recreate and seed — only run migrations |
| --dry-run | Print the steps that would run without executing anything |
| --backup | Dump the database before dropping it (saved to ~/db-setup-backups/) |
What it does:
- Stashes any uncommitted changes in the project
- Fetches and checks out the target branch
- (if
--backup) Dumps the database withpg_dumpormysqldump - Drops and recreates the database
- Runs the migrate command
- Runs the seed command (unless skipped)
- Restores the original branch and stash
DB credentials are read from the project's .env file using the env var names configured per project.
dbsetup list
List all configured projects with their path, framework, and DB type.
dbsetup listdbsetup info [project]
Show full configuration for a project.
dbsetup info
dbsetup info myappdbsetup remove <project>
Remove a project from the configuration (prompts for confirmation).
dbsetup remove myappFrameworks
| Framework | Default migrate command | Default seed command |
|---|---|---|
| Knex | npm run migrations | npm run seeds |
| Prisma | npx prisma migrate deploy | npx prisma db seed |
| Flyway | flyway migrate | (none) |
| Liquibase | liquibase update | (none) |
| Django | python3 manage.py migrate | python3 manage.py loaddata fixtures/ |
| Alembic | alembic upgrade head | (none) |
| Laravel | php artisan migrate | php artisan db:seed |
| Custom | (user-defined) | (user-defined) |
All commands are editable during configure — the framework selection just fills in sensible defaults.
Example .env (default var names)
DB_HOST=localhost
DB_PORT=5432
DB_DATABASE=myapp_dev
DB_USER=postgres
DB_PASSWORD=secretEnv var names are configurable per project if yours differ (e.g. DATABASE_URL, PGUSER, etc.).
