Skip to content

A CLI to manage database structures and ORM integrations with precision

License

Notifications You must be signed in to change notification settings

andrii-devs/mastermind-db

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mastermind-db icon

MasterMind-DB CLI

Test Status

MasterMind-DB is a versatile and extensible CLI tool designed for managing databases and ORM-based projects. It supports multiple ORMs, including Sequelize, and integrates seamlessly with Docker for containerized database management.


Features

  • Generate database structures, models, migrations, and seeders.
  • Supports multiple ORMs (Sequelize, Prisma, TypeORM).
  • Docker integration for starting and stopping containers.
  • Dynamic configuration management stored in .mastermindrc.
  • Interactive CLI with prompts and spinners for a smooth user experience.
  • Handles volumes and services directly in docker-compose.yml.
  • Allows custom configuration and project settings.

Prerequisites

  1. Node.js (v16 or later)

    sudo apt update
    sudo apt install nodejs npm
    node -v
    npm -v
  2. Docker (Latest Version)

    sudo apt update
    sudo apt install docker.io
    sudo systemctl start docker
    sudo systemctl enable docker
    docker --version
  3. Docker Compose (V2 recommended)

    sudo apt install docker-compose
    docker-compose --version

Installation

Global Installation

npm install -g mastermind-db

Project-Specific Installation

npm install mastermind-db

Commands and Usage

1. Initialize a Project Configuration

mastermind-db init
  • Prompts for:
    • Root directory for projects.
    • Service name.
    • ORM type.

2. Create a New Service

mastermind-db create
  • Guides through creating a database service.
  • Asks for database type (MySQL/PostgreSQL).
  • Prompts for ORM (Sequelize/Prisma/TypeORM).
  • Optionally generates a Docker Compose setup.
  • Optionally starts Docker containers if available.

3. Manage Existing Service

mastermind-db manage
  • Allows updating configurations or generating files (models, migrations, seeders) for existing services.

4. Delete a Service

mastermind-db delete
  • Selects and deletes a service.
  • Removes folders, updates .mastermindrc, and edits docker-compose.yml.
  • Stops and removes running Docker containers and volumes.

5. Configuration Settings

mastermind-db config
  • Allows managing root directories and ORM configurations.

Docker Integration

  • Automatically adds services to docker-compose.yml.
  • Handles starting and stopping Docker containers.
  • Ensures volume mappings for persistent storage.

Docker Commands

Check Docker Dependencies

mastermind-db check-docker
  • Verifies Docker and Docker Compose installation.

Start Docker Containers

mastermind-db start-docker <service-name>

Stop and Remove Docker Containers

mastermind-db delete
  • Deletes services, containers, and volumes.

Example Workflow

1. Initialize Project

mastermind-db init

2. Create a Service

mastermind-db create

Choose:

  • Database: MySQL
  • ORM: Sequelize
  • Generate Docker Compose: Yes
  • Start Docker Container: Yes

3. Generate Files

mastermind-db manage
  • Generate models, migrations, and seeders interactively.

4. Delete a Service

mastermind-db delete
  • Select service to delete.
  • Deletes files, config, and Docker containers/volumes.

Configuration File (.mastermindrc)

Example:

{
  "rootDir": "./src",
  "services": {
    "auth-service": {
      "orm": "Sequelize",
      "migrationsDir": "./src/auth-service/sequelize/migrations",
      "modelsDir": "./src/auth-service/sequelize/models",
      "seedersDir": "./src/auth-service/sequelize/seeders"
    }
  }
}

Troubleshooting

  1. Docker Not Installed:

    • Install Docker and Docker Compose as mentioned in prerequisites.
  2. Permission Denied for Docker Commands:

    • Add the user to the docker group.
    sudo usermod -aG docker $USER
    newgrp docker
  3. Configuration File Issues:

    • Run mastermind-db config to update settings.

Contributing

Contributions are welcome! Feel free to fork this repository and submit pull requests.


License

This project is licensed under the MIT License.


Contact

For any questions or feedback, please reach out to the repository maintainer.