Skip to content
wvengen edited this page Jan 4, 2016 · 10 revisions

Foodsoft has a multicoops feature, which allows different foodcoops to run on a single Foodsoft installation. This is generally called multi-tenancy. In the foodcoop configuration config/app_config.yml the multicoops feature can be enabled with the multi_coop_install parameter, giving each foodcoop its own configuration key.

To illustrate this, here is an abridged config/app_config.yml showing how configuration works:

default: &defaults
  multi_coop_install: true   # need to set this to `true` for the multicoops feature
  default_scope: yummycoop   # redirect to this coop when none is specified in the url
  # other settings common to all coops, like the mailer configuration
  protocol: https
  host: app.foodcoops.test

yummycoop:
  # use defaults as a template, then override settings specific for this coop
  <<: *defaults
  name: Yummy Coop
  homepage: http://yummycoop.test/
  help_url: https://yummecoop.test/foodsoft-help/
  # each coop needs to have its own database
  database:
    database: fs_yummycoop
    username: fs_yummycoop
    password: v3rys1cret  

bread-and-butter:
  <<: *defaults
  name: Bread and Butter
  database:
    database: fs_breadbutter
    username: fs_breadbutter
    password: s0meth1ng3lse

# environment setting needed for starting the webserver
production:
  <<: *defaults

With this, visiting https://app.foodcoops.test/ will redirect to Yummy Coop's Foodsoft at https://app.foodcoops.test/yummycoop/, while Bread and Butter's Foodsoft is reachable at https://app.foodcoops.test/breand-and-butter/.

Rake tasks

To run rake tasks for multiple coops - e.g. rake db:migrate after upgrading Foodsoft -, you can use rake multicoops:run TASK=db:migrate (or whatever task you want to run). Running a task for a single coop can be done using something like rake multicoops:run_single FOODCOOP=yummycoop TASK=db:migrate:status. Please note that you don't need to change your cronjobs (they run for all coops by default).

Shared database

If you're running multiple foodcoops on a single server, Foodsoft's shared database feature may be interesting to you.

Different approaches

This section is for developers.

This is called schema-based multi-tenancy, where each tenant (foodcoop) has its own database. There are pros and cons for both the schema- and role-based approach.

The multishared plugin was an experiment to bring role-based multi-tenancy to foodsoft, adding a scope column to several models. This is far from polished, but worked. In practice, something like Open Food Network may be more suitable here.

Role-based multi-tenancy prepares the way to

  • allow different foodcoops to work together, e.g. sharing orders;
  • move users between foodcoops;
  • extract statistics over multiple foodcoops (e.g. popular articles, turnover).

Links

Clone this wiki locally