Skip to content

nimish-nimishmittal/mydb-cli

Repository files navigation

MyDB CLI Tool [draft]

MyDB is a powerful database management tool that provides Git-like branching functionality for MySQL databases. It allows developers to create isolated database environments, manage migrations, and merge changes between branches.

📚 Related Documentation:

Table of Contents

Features

  • 🌳 Git-like branching for databases
  • 📊 Table creation and management
  • 🔄 Database migrations with up/down support
  • 🔀 Branch merging capabilities
  • 📱 GUI interface via MyDB Studio
  • 🔒 Automated schema tracking
  • 📝 Detailed migration history

Prerequisites

  • Python 3.7+
  • MySQL Server 5.7+ or 8.0+
  • pip (Python package manager)

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/mydb-cli.git
cd mydb-cli
  1. Create and activate a virtual environment (recommended):
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install the package in development mode:
pip install -e .
  1. Install required dependencies:
pip install -r requirements.txt
  1. Make the CLI tool accessible system-wide:
# Add to your .bashrc or .zshrc:
export PATH="$PATH:/path/to/mydb-cli/bin"

# On Windows, add the bin directory to your system PATH

Getting Started

  1. Initialize your database configuration:
mydb-cli status

This will create a default configuration file at .mydb/config.json.

  1. Update the configuration file with your MySQL credentials:
{
    "connection": {
        "user": "your_username",
        "password": "your_password",
        "host": "localhost",
        "port": 3306,
        "database": "your_database",
        "auth_plugin": "mysql_native_password"
    }
}

Usage

Branch Management

Create a new branch:

mydb-cli create-branch --branch dev

List all branches:

mydb-cli list-branches

Switch to a different branch:

mydb-cli switch-branch --branch dev

Delete a branch:

mydb-cli delete-branch --branch old_feature

Merge branches:

mydb-cli merge-branch --source feature --target main

Table Operations

Create a new table:

mydb-cli create-table --name users
# Follow the interactive prompts to define columns

List all tables:

mydb-cli list-tables

Describe table structure:

mydb-cli describe-table --name users

Drop a table:

mydb-cli drop-table --name old_table

Migration Management

Create a new migration:

mydb-cli create-migration --name add_users_table --description "Create users table with basic fields"

Apply migrations:

mydb-cli migrate-up          # Apply next pending migration
mydb-cli apply-migration --number 1  # Apply specific migration

Rollback migrations:

mydb-cli migrate-down  # Rollback last applied migration

Check migration status:

mydb-cli migration-status

GUI Interface

Launch the MyDB Studio interface:

mydb-cli studio

Screenshots

Branch Management

Branch Management

Migration Status

Migration Status

MyDB Studio

MyDB Studio

Project Structure

.
├── LICENSE
├── README.md
├── assets
│   ├── index-BKO7flFT.css
│   └── index-D0-aluUL.js
├── image-1.png
├── image.png
├── index.html
├── main.py
├── migrations/
├── requirements.txt
├── streamlit.png
├── studio.py
├── testsqlcode01.txt
├── testsqlcode02.txt
└── vite.svg

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the BSD 3-Clause License - see the LICENSE file for details. This would allow me to make some features of this tool to be served on a proprietory basis as well where i'll earn by providing subscriptions for my dev tool features.

Support

If you encounter any issues or have questions, please open an issue on GitHub.

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •