Add new database
To connect a new database on your project, you need to follow the following steps:- Stop your agent. The following process will generate files and using nodemon while following this process can cause mis-generation of the
.forestadmin-schema.jsonfile. - Add a new environment variable, inside your
.envfile (It will beANOTHER_DB_URLin this example), which represents the connection url string of the database you want to add. - Edit the database config file located to
config/databases.jsto add a new object with the following syntax in the array:
- Run
forest schema:updatecommand and follow instructions.- It should generate all the required files. ⚠️ Be aware that existing files will remain untouched when switching from a single database to a multi-database setup. If you made any modifications in the models of your existing connection.
In this example, you may want to check the freshly generated models that will be located in the./models/your_first_database_connectionfolder. - As stated on the
forest schema:updatedocumentation, when switching from a single to a multiple database setup, existing models in the./modelsfolder will remain untouched, and you’ll need to move them to the correct location (According to youconfig/databases.jsfile) or simply remove them if you never made any modifications on the models themselves.
- It should generate all the required files. ⚠️ Be aware that existing files will remain untouched when switching from a single database to a multi-database setup. If you made any modifications in the models of your existing connection.
- Start the agent, and display the added models with the layout editor. Everything should work as expected