API cheatsheet
| Legacy agent | New agent |
|---|---|
forest-express-sequelize | @forestadmin/agent + @forestadmin/datasource-sql |
forest-express-sequelize (with Sequelize models) | @forestadmin/agent + @forestadmin/datasource-sequelize |
forest-express-mongoose | @forestadmin/agent + @forestadmin/datasource-mongoose |
forest-rails (ActiveRecord) | forest_admin_agent + forest_admin_rails + forest_admin_datasource_active_record (+ toolkit, customizer) |
forest-rails (Mongoid) | forest_admin_agent + forest_admin_rails + forest_admin_datasource_mongoid (+ toolkit, customizer) |
Pick
datasource-sql or datasource-mongo if you want Forest to introspect the database directly. Pick datasource-sequelize, datasource-mongoose, or datasource-active-record if you want to reuse your existing ORM models (recommended when your application already defines them).Before (Node.js, forest-express-sequelize)
After (Node.js, reusing Sequelize models)
After (Node.js, direct SQL connection)
If you don’t want to reuse your ORM models, connect directly to the database. Forest introspects the schema automatically.Before (Ruby, forest-rails with ActiveRecord)
After (Ruby, ActiveRecord)
rails generate forest_admin_rails:install to scaffold the two configuration files.
Multi-datasource
The biggest payoff of migrating: the new agent can connect to multiple data sources at once.Configuration changes
| Concept | Legacy | New |
|---|---|---|
envSecret | FOREST_ENV_SECRET | FOREST_ENV_SECRET (unchanged) |
authSecret | FOREST_AUTH_SECRET | FOREST_AUTH_SECRET (unchanged) |
| Models directory | modelsDir option | Provided implicitly via the datasource (Sequelize / ActiveRecord) |
| Including / excluding tables | Manual model filtering | { include: [...], exclude: [...] } on addDataSource |
| Schema generation | Forest CLI / runtime | .forestadmin-schema.json written on agent start in development |
| Custom routes | Express routes | Hooks (see Hooks) |
Including or excluding collections
In v1, you’d manually filter the models passed in. In v2:Validate the migration
After swapping the datasource:Check schema generation
On first start in development, the agent writes a
.forestadmin-schema.json file. Confirm every collection you expect is listed.Point a test environment at the new agent
Update the agent URL in your Forest test environment. Browse collections. Every collection should appear with the same fields.
Common issues
A column shows up with a different name
A column shows up with a different name
Some legacy agents auto-converted snake_case to camelCase. The new agent preserves database column names by default. Use the
rename option or the field-rename customization API to align names.A relationship I had isn't appearing automatically
A relationship I had isn't appearing automatically
Foreign keys defined in the database are detected automatically. Relationships defined only in your ORM models (
belongsTo, hasMany) are detected when you use the ORM-backed datasources (datasource-sequelize, datasource-mongoose, datasource-active-record). Relationships that exist only in code paths the agent doesn’t see won’t be detected. Declare them explicitly with addManyToOneRelation, addOneToManyRelation, etc.The agent fails to connect to the database
The agent fails to connect to the database
Verify that
DATABASE_URL is set on the agent server, that the user has read permissions, and that SSL is configured if your database requires it. For SQL datasources, check sslMode.Next step
Migrate Smart Actions
Convert each Smart Action to the new
addAction API.