Giter Club home page Giter Club logo

multi-tenant-application's People

Contributors

anishlushte07 avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

multi-tenant-application's Issues

Multi Tenancy for existing nodejs applications

mailtrain version 1 focussed on building email campaign manager

v2(https://github.com/Mailtrain-org/mailtrain/tree/development) focussed on making multi tenancy,

Is there any way without changing the code of existing nodejs app, we can add multi tenancy to a nodejs/express app already built

Benefits

  • running multiple instances of nodejs consumes more memory and cpu, multi tenancy will load only sequelize multiple times, express and other modules load once
  • automation of migrations will greatly reduces installation costs and people can signup and start using

Current Challenges while setup

  1. DB Creation - we do in manually phpmyadmin, can be easily automated as we using common db to keep track of tenants https://github.com/AnishLushte07/multi-tenant-application/blob/master/sample.env#L7
  2. Migration - we do manually via ssh - need feature #2
  3. Load models: additional api need to developed to add connections on the fly https://github.com/AnishLushte07/multi-tenant-application/blob/master/server/conn/sqldb/dynamicConnection.js#L46

With above 3 steps we can automate setup process,

Expectation is run migration of another existing nodejs application so we can add a add a field sequelizerc in client(tenant) table

sequelizerc: DataTypes.JSON

above field will be updated with

{
"config": "./server/config/sequelize.js",
"migrations-path": "./server/conn/sqldb/tenant-migrations",
"seeders-path": "./server/conn/sqldb/seeders"
}

https://github.com/AnishLushte07/multi-tenant-application/blob/master/server/api/client/client.property.js#L11

NOTE: In other words, if we make a provisioning tool, then it will help developers to focus on domain, Automatic Provisioning tool will automate tenant signup process

Procedure to add tenant dynamically or run migration automatically

as the tenant db connection details written in .env file,

adding tenant dynamically requires restart

I can achieve graceful restart using https://gist.github.com/manjeshpv/60924207056773954f6a346db6cc5249

is there any possibilities to dynamically bootup sequelize models inside running memory

https://github.com/AnishLushte07/multi-tenant-application/blob/master/server/conn/sqldb/dynamicConnection.js#L76

buildDynamicConnection(db);

so migrations will run on tenant create api, instead of connection details .env and manually running migrations

MYSQL_TENANT1='mysql://<user_name>:<pass>@192.168.0.200/<db_name>'

Flow

Customer signup with email id and password(CommonDb.users id:1 email: [email protected] )
POST /api//users

const mainDomain = 'tenantapp.com';
const linodeIp = '120.120.120.120'
// either we can use this function of we can keep *.tenantapp.com -> 120.120.120.120
// linode centos server with ip 120.120.120.120
const createDNS = (subdomain) => {
  rp({
    url: `https://api.digitalocean.com/api/domains/${mainDomain}/A`,
    method: POST',
    body: { subdomain, ip: linodeIp }
  })
}

export async function create(req, res, next) {
  const user = await CommonDb.User.create({ email: req.body.email }); // id:1
  const domain = req.body.email.split('@')[1];
  const subdomain = domain.split('.')[0];

  const project = 'nps_feedback';
  const connectionString = await MySQLApi.createDb(`${subdomain}_${project}`);

  const client = await CommonDb.Client.create({ user_id: user.id, name:  subdomain, connectionString   });
  await SequelizeApi.migrateDb(connectionString);
  await SequelizeApi.seedDb(connectionString);

  // all subdomains pointing to one machine as wildcard dns entry
  user.update({ client_id: client.id });
  res.json({ message: 'Signup successful, Provisioning done from http://${subdomain}.${mainDomain}'})

}
domain: flipkart.tenantapp.com


1. dbinfo = DB Creation Script
2. dbId = saveDbInfoToCommonDbClientsTable(dbInfo)
3. 

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.