Skip to content

Conversation

@bensalilijames
Copy link
Collaborator

@bensalilijames bensalilijames commented Nov 26, 2016

The idea of this change is to allow you to be able to host multiple bots on a single database - a change likely to benefit those who are building platforms around SuperScript.

Description

Now, if you want to use multitenancy, you can do:

import SuperScript from 'superscript';
const options = { useMultitenancy: true };
SuperScript.setup(options, (err, instance) => {
  const myBot = instance.getBot('myBot');
  const myBot2 = instance.getBot('myBot2');
  // Then you can use the bot as normal
  myBot.reply(...);
});

If you don't want to use multitenancy, simply don't include it in the options when setting up SuperScript, and then instead of an instance, setup will provide you with a bot in the 'master' tenancy.

Under the hood, all the models/db and fact system connections are shared between bots as part of an instance, so getting a new bot is really fast and virtually no cost.

You can still have multiple instances referencing completely different databases, and each instance can have bots that are multitenanted or not (i.e. share a database or not). So you can still do:

SuperScript.setup({ db: "mongodb://localhost/myDB1" }, (err, bot) => {
// ...
});
SuperScript.setup({ db: "mongodb://localhost/myDB2" }, (err, bot) => {
// ...
});
// Or mix and match!
SuperScript.setup({ db: "mongodb://localhost/myDB3", useMultitenancy: true }, (err, instance) => {
// ...
});

Motivation and Context

This addresses certain concerns like #287 and #288.

How Has This Been Tested?

This needs unit tests to ensure that you can't accidentally populate from a different tenancy. Need to do this before merge.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@coveralls
Copy link

coveralls commented Nov 26, 2016

Coverage Status

Coverage increased (+0.1%) to 70.269% when pulling 95390b2 on benhjames:multitenant into b01d191 on superscriptjs:v1.0.0.

@coveralls
Copy link

coveralls commented Nov 27, 2016

Coverage Status

Coverage increased (+0.2%) to 70.309% when pulling c69fd01 on benhjames:multitenant into b01d191 on superscriptjs:v1.0.0.

@coveralls
Copy link

coveralls commented Nov 28, 2016

Coverage Status

Coverage increased (+0.2%) to 70.309% when pulling adeb356 on benhjames:multitenant into 1a7fe77 on superscriptjs:v1.0.0.

@bensalilijames bensalilijames merged commit d101f07 into superscriptjs:v1.0.0 Nov 28, 2016
duffrind pushed a commit to duffrind/superscript that referenced this pull request Aug 29, 2017
* Add ability to have several bots on a single Mongo server (multitenancy)

* Add lib for now

* Make model names less prone to collision (most likely User)

* Remove lib folder and clean up ignores

* Allow multiple bot instances per server again

* Update clients to use setup method

* Add multitenant test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants