Giter Site home page Giter Site logo

mjunaidahmad / multitenant-migration-cli Goto Github PK

View Code? Open in Web Editor NEW
9.0 3.0 0.0 577 KB

Run sequelize migration for more than one databases with a single command.

License: MIT License

JavaScript 100.00%
multitenancy multitenant-applications sequelize-migration databases multi-tenant-database multi-tenant-migrations multi-tenant multi-tenancy

multitenant-migration-cli's Introduction

Problem Statement

When running a multi-tenant application i.e. one databse per tenant, it is hard to manage database structure of each tenant database seperately. Altough Sequelize provide us with a great option of migrations & seeders but it does not support the multi-tenant option out the box because every system can have a different approach to implement multi-tenancy.

Solution

This package is a cli base wrapper written on the top of the sequelize cli.

Supported Usecase

Following use case are supported for now:

  1. You need to have a master database where we need a table named as "tenants" with the following columns: username, password, db, host. You need to have the information decsribed above for every tenant database. You can clone this repo and run npm install.

More will be added soon...


migration-cli

  • ๐Ÿš€ Supports sequelize commands out of the box
  • ๐Ÿคฏ Supports mysql, Postgres, Microsoft SQL Server, Sqlite, mariadb
  • ๐Ÿ“Ÿ Sequelize cli output reporting

Install

# Clone this repo:
git clone https://github.com/MJunaidAhmad/multitenant-migration-cli.git

# cd to the clonned repo folder:
cd multitenant-migration-cli-master

# Install npm modules:
npm install

# Run this command in the clonned folder:
node index.js help

sequelize connection setup

You can define your master database connection settings in config/config.json file.

Usage

node index.js <command> [--option]

Commands

run         Run the Sequelize command provided in the option
help        Show help

Options

    --db, --d       To specify the database from where we need to load tenant information. Supported values test,
                    development or production as defined in the config/config.js
--command, --c      To specify the sequelize command to run. For now, supported value are:
		    'db:migrate'
                    'db: migrate: undo'
                    'db: migrate: undo: all'
                    'db: seed: all'
                    'db: seed: undo'
                    'db: seed: undo: all'

Examples

node index.js run --db 'development' --command 'db:migrate'

But in a real world scenario you may want to create a migration first using sequelize-cli e.g. sequelize migration:create --name sometablename

CLI Help

# Display the help data.
    node index.js help

Changelog

Soon to be updated!


Roadmap

  1. Support better error handling.
  2. Run a migration to only specified tenant rather than every tenant.
  3. Advance options for migrations e.g storage, dialect options.
  4. Migration status of every tenant i.e. how many migrations have been run on this tenants.
  5. Support --to (sequelize-cli) option for migrations & seeders.
  6. Support --except (custom) option for running migrations except specified tenants.
  7. Support to load tenants credentials from json file, api or redis rather than database.
  8. Support to check if every database is up to date with migrations.

Feel free to create an issue if you have something in your mind related to this package.


License & Conduct

Sources

  1. Sequelize CLI

Connect

GitHub @mjunaidahmadย (follow)

Twitter @junaidahnmad_12ย (follow)

LinkedIn @JunaidAhmadย (connect) On the LinkedIn profile y'all

Tags

Multi-tenant Multitenant Multi-tenancy Multitenancy Nodejs Multi-tenancy with sequelize & Nodejs Migrations for Multitenant System

multitenant-migration-cli's People

Contributors

mjunaidahmad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.