Connecting to multiple data sources
Cube supports connecting to multiple data sources, so that different cubes reference data from different databases. Usually, data sources are configured statically (see below). However, Cube can also lookup data sources dynamically which is useful in complex scenarios involving multitenancy.Environment variables
Declare the list of data sources using theCUBEJS_DATASOURCES environment
variable, then use
decorated environment variables to configure
each data source:
Cube expects that the
default data source is always defined. Ensure that
CUBEJS_DB_* environment variables are set or that the default data
source is defined using driverFactory in your
cube.js file.Decorated environment variables
Cube allows database-specific environment variables to be decorated with a data source name:datasource1 data source, CUBEJS_DB_TYPE could be
decorated as:
Data model
Use thedata_source
property to set a data source for each cube:
Cube Cloud
Follow these steps to connect to multiple data sources in Cube Cloud:- Set up the
defaultdatabase connection when creating a new deployment. - Ensure you have the correct
multitenancy configuration in
your
cube.jsfile. - Configure the corresponding environment variables in Settings → Environment variables.