Plug multiple schemas
A schema is an organizational layer to better structure your SQL database.
At installation, you may only choose 1 schema:
If you're not using specific schemas, you don't have to fill this advanced option.

Forest Admin can display collections from multiple schemas

To achieve this, proceed to install using 1 of your schemas. Only the models of this schema will be generated in your models directory.
Let's take a model example:
models/addresses.js
1
// This model was generated by Lumber. However, you remain in control of your models.
2
// Learn how here: https://docs.forestadmin.com/documentation/v/v5/reference-guide/models/enrich-your-models
3
module.exports = (sequelize, DataTypes) => {
4
const { Sequelize } = sequelize;
5
// This section contains the fields of your model, mapped to your table's columns.
6
// Learn more here: https://docs.forestadmin.com/documentation/v/v5/reference-guide/models/enrich-your-models#declaring-a-new-field-in-a-model
7
const Addresses = sequelize.define('addresses', {
8
addressLine: {
9
type: DataTypes.STRING,
10
field: 'address',
11
},
12
addressCity: {
13
type: DataTypes.STRING,
14
},
15
country: {
16
type: DataTypes.STRING,
17
},
18
createdAt: {
19
type: DataTypes.DATE,
20
},
21
}, {
22
tableName: 'addresses',
23
underscored: true,
24
schema: process.env.DATABASE_SCHEMA,
25
});
26
27
return Addresses;
28
};
Copied!
On line 24, you'll notice schema: process.env.DATABASE_SCHEMA.
It uses the environment variable DATABASE_SCHEMA set in your .env file. You'll have to edit this to match your schemas. For instance, if you have 2 schemas:
.env
1
DATABASE_SCHEMA_1: name_of_the_first_schema
2
DATABASE_SCHEMA_2: name_of_the_second_schema
Copied!
Once this is done, follow those steps:

Step 1: Edit your current models

Because you have changed your environment variable name from DATABASE_SCHEMA to DATABASE_SCHEMA_1, you need to update it in all your models' file in the models directory (same line as line 24 in the above example).

Step 2: Create new models

For each of your other schemas' models, you'll need to create a file in models. This must be done manually and the schema line must be set to DATABASE_SCHEMA_2 as per above example.
If your other schemas have a lot of models, a quick way to generate the models is to create a another project using those other schemas (1 project for each schema).
Last modified 1yr ago