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.
This package is a cli base wrapper written on the top of the sequelize cli.
Following use case are supported for now:
- 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...
- 🚀 Supports sequelize commands out of the box
- 🤯 Supports mysql, Postgres, Microsoft SQL Server, Sqlite, mariadb
- 📟 Sequelize cli output reporting
# 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
You can define your master database connection settings in config/config.json file.
node index.js <command> [--option]
run Run the Sequelize command provided in the option
help Show help
--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'
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
# Display the help data.
node index.js help
Soon to be updated!
- Support better error handling.
- Run a migration to only specified tenant rather than every tenant.
- Advance options for migrations e.g storage, dialect options.
- Migration status of every tenant i.e. how many migrations have been run on this tenants.
- Support --to (sequelize-cli) option for migrations & seeders.
- Support --except (custom) option for running migrations except specified tenants.
- Support to load tenants credentials from json file, api or redis rather than database.
- 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.
- MIT © Junaid Ahmad
- Code of Conduct
Multi-tenant Multitenant Multi-tenancy Multitenancy Nodejs Multi-tenancy with sequelize & Nodejs Migrations for Multitenant System