Skip to content

Manager for multiple DB (PostgreSQL) to easy create/switch/delete for multiple features/branches and don't have Migrations conflicts

Notifications You must be signed in to change notification settings

kosiakMD/db-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Database Management

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.

Prerequisites

Ensure you have the following installed:

Setup and Usage

Run the Docker DB-Manager

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

Example Workflow

1. Run the DB-Manager to Manage Containers

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.

2. Run the DB-Manager to Create a New Container

- Without Environment Variables

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.

- Using Environment Variables

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.

Examples:

Main menu

Screenshot 2024-10-31 at 17 56 28

Run menu

Screenshot 2024-10-31 at 17 58 55 Screenshot 2024-10-31 at 17 57 42

List

Screenshot 2024-10-31 at 17 59 57

Start menu

Screenshot 2024-10-31 at 17 59 45

Stop menu

Screenshot 2024-10-31 at 17 59 19

About

Manager for multiple DB (PostgreSQL) to easy create/switch/delete for multiple features/branches and don't have Migrations conflicts

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages