This project includes a Docker-based DB-Manager script to simplify the management of multiple PostgreSQL instances for various features or environments.
You need to have the database dump and use the manager to handle your PostgreSQL Docker containers.
Ensure you have the following installed:
- Docker: Install Docker
Launch the interactive DB-Manager to manage your Docker containers.
'./path-to-file/db-manager.sh menu'
Or add a command to your e.g., package.json
{
"scripts": {
"infra:db-manager": "./path-to-bash-file.sh menu"
}
}
To run straightforwardly:
npm run infra:db:manage
Run npm script:
npm run infra:db:manage
Use the interactive menu after run DB-Manager to start, stop, remove, or list your PostgreSQL Docker containers as needed.
Menu Options:
1. Create Container
- Create a new PostgreSQL container.
2. Start Container
- Start an existing PostgreSQL container.
3. Stop Container
- Stop a running PostgreSQL container.
4. Remove Container
- Remove an existing PostgreSQL container.
5. List Container
- List all managed PostgreSQL containers.
6. Exit
- Exit the DB-Manager.
npm run infra:db:manage
- Select
1. Create Container
from the menu. - Provide Inputs When Prompted:
- [required] Feature Name:
feature-orders
- SQL Dump File Path: Press Enter to use
./db.sql
(default). - Database Suffix: e.g.,
orders
(optional) - Host Port for PostgreSQL:
5432
(default) - Database Name: Press Enter to use
db-local
(default) or enter a custom name. - Database User: Press Enter to use
user
(default) or enter a custom user. - Database Password: Press Enter to use
password
(default) or enter a custom password.
- [required] Feature Name:
DB_NAME="db-custom" DB_USER="admin" DB_PASSWORD="securepass" npm run infra:db-manager
Behavior: When selecting Create Container from the interactive menu, the script will automatically use db-custom
as the Database Name, admin as the Database User, and securepass
as the Database Password without prompting.