Node.js Developer Guide
Other documentationsDemoCommunityGitHub
  • Forest Admin
  • Getting started
    • How it works
    • Quick start
    • Install
      • Create your agent
      • Expose an HTTP endpoint
        • For standalone agents
        • On Express
        • On Koa
        • On Fastify
        • On NestJS
      • Autocompletion & Typings
      • Troubleshooting
    • Migrating legacy agents
      • What's new
      • Pre-requisites
      • Recommendations
      • Migration steps
        • Run new agent in parallel
        • Configure database connection
        • Code transformations
          • API Charts
          • Live Queries
          • Smart Charts
          • Route overrides
          • Smart Actions
          • Smart Fields
          • Smart Relationships
          • Smart Segments
        • Compare schemas
        • Swap agents
      • Post-migration
        • Dropping Sequelize
        • Optimize your agent
  • Data Sources
    • Getting Started
      • Collection selection
      • Naming conflicts
      • Cross-data source relationships
      • Query interface and Native Queries
        • Fields and projections
        • Filters
        • Aggregations
    • Provided data sources
      • SQL (without ORM)
      • Sequelize
      • Mongoose
      • MongoDB
    • Write your own
      • Replication strategy
        • Persistent cache
        • Updating the replica
          • Scheduled rebuilds
          • Change polling
          • Push & Webhooks
        • Schema & References
        • Write handlers
      • Translation strategy
        • Structure declaration
        • Capabilities declaration
        • Read implementation
        • Write implementation
        • Intra-data source Relationships
      • Contribute
  • Agent customization
    • Getting Started
    • Actions
      • Scope and context
      • Result builder
      • Static Forms
      • Widgets in Forms
      • Dynamic Forms
      • Form layout customization
      • Related data invalidation
    • Charts
      • Value
      • Objective
      • Percentage
      • Distribution
      • Leaderboard
      • Time-based
    • Fields
      • Add fields
      • Move, rename and remove fields
      • Override binary field mode
      • Override writing behavior
      • Override filtering behavior
      • Override sorting behavior
      • Validation
    • Hooks
      • Collection hook
      • Collection override
    • Pagination
    • Plugins
      • Provided plugins
        • AWS S3
        • Advanced Export
        • Flattener
      • Write your own
    • Relationships
      • To a single record
      • To multiple records
      • Computed foreign keys
      • Under the hood
    • Search
    • Segments
  • Frontend customization
    • Smart Charts
      • Create a table chart
      • Create a bar chart
      • Create a cohort chart
      • Create a density map
    • Smart Views
      • Create a Map view
      • Create a Calendar view
      • Create a Shipping view
      • Create a Gallery view
      • Create a custom tinder-like validation view
      • Create a custom moderation view
  • Deploying to production
    • Environments
      • Deploy on AWS
      • Deploy on Heroku
      • Deploy on GCP
      • Deploy on Ubuntu
      • Deploy on Azure
    • Development workflow
    • Using branches
    • Deploying your changes
    • Forest Admin CLI commands
      • init
      • login
      • branch
      • switch
      • set-origin
      • push
      • environments:create
      • environments:reset
      • deploy
  • Under the hood
    • .forestadmin-schema.json
    • Data Model
      • Typing
      • Relationships
    • Security & Privacy
Powered by GitBook
On this page
  • Checklist
  • Checking that the agents are compatible

Was this helpful?

  1. Getting started
  2. Migrating legacy agents
  3. Migration steps

Compare schemas

PreviousSmart SegmentsNextSwap agents

Last updated 1 year ago

Was this helpful?

This is the official documentation of the @forestadmin/agent Node.js agent.

Checklist

Checking that the agents are compatible

Making an agent which works is not enough: you also need to make sure that it generates a schema where the naming of most entities is the same as the old one.

This is because all the UI / and security customizations that you have made are identified by the name of the entity to which they are applied.

This is valid for:

  • Charts (in dashboards and the collection view)

  • Order and visibility of fields in table-view, detail-form, related data, segments

  • Roles and Scopes

  • Segments visibility

  • Summary views and Workspaces

Example

For instance, if you created a chart on the customers collection that displays the TOP 10 customers by number of orders, you will need to make sure that:

  • The customers collection still exists and has the same name

  • The orders collection still exists and has the same name

  • The customers collection still has a relationship called orders

Checking the compatibility with .forestadmin-schema.json, jq and diff

However, diffing two .forestadmin-schema.json files is extremely tedious: the file contains a lot of information that is not relevant to our objective.

Instead, we can choose to focus on the differences that matter the most: the name of the different entities.

Extracting the list of entities

Extracting the list of entities exported by an agent can be done with the following jq command.

Run this command in the directory of both your old and new agent: it will generate a file called agent-entities.txt in the current directory.

$ jq -r '.collections[] | (
    "Collection: \"\(.name)\"",
    "Action: \"\(.name)\" has \"\(.actions[].name)\"",
    "Field: \"\(.name)\" has \"\(.fields[] | select(.reference == null) | .field)\"",
    "Relationship: \"\(.name)\" has \"\(.fields[] | select(.reference) | .field)\"",
    "Segment: \"\(.name)\" has \"\(.segments[].name)\""
)' .forestadmin-schema.json | sort > agent-entities.txt
Equivalent Node.js script

You can also execute the following script to generate the same file:

const fs = require('fs');
const forestAdminSchema = require('./.forestadmin-schema.json');

const entities = forestAdminSchema.collections
  .map(collection => [
    `Collection: "${collection.name}"`,
    ...collection.actions.map(
      action => `Action: "${collection.name}" has "${action.name}"`,
    ),
    ...collection.fields
      .filter(field => !field.reference)
      .map(field => `Field: "${collection.name}" has "${field.field}"`),
    ...collection.fields
      .filter(field => field.reference)
      .map(field => `Relationship: "${collection.name}" has "${field.field}"`),
    ...collection.segments.map(
      segment => `Segment: "${collection.name}" has "${segment.name}"`,
    ),
  ])
  .flat()
  .sort();

fs.writeFileSync('agent-entities.txt', entities.join('\n'));

Comparing the list of entities

Once you have generated the agent-entities.txt file for both your old and new agent, you can diff them with the following command:

$ diff --side-by-side --suppress-common-lines --minimal [old-agent-folder]/agent-entities.txt [new-agent-folder]/agent-entities.txt
Collection: "account"                    <
Field: "account" has "_id"               <
Field: "account" has "firstname"         <
Field: "account" has "lastname"          <
Field: "account_address" has "_id"       <
Field: "account_address" has "country"   | Field: "account_address" has "Country"
Relationship: "account" has "address"    <
Relationship: "account" has "bills"      <
Relationship: "account" has "store"      <

Diff files are read using the following format:

  • >: line is present in the new file, but not in the old one

  • <: line is present in the old file, but not in the new one

  • '|': line is present in both files, but the content is different

Fixing differences

Once you have identified the differences, you can fix them by:

Danger level
Difference
Fix

🔴

Collections or fields have different names (i.e. camelCase vs snake_case)

🔴

Missing Smart features (actions, fields, relationships, segments, ...)

Port the missing smart features to your new agent

🟢

Extra collections

🟢

Extra fields

jq is a command line tool that allows you to manipulate JSON files. If you don't have it installed, you can install it with or .

diff is a command line tool that allows you to compare two files. It is installed by default on virtually all Unix systems, windows users can use .

To ensure agents are compatible, we have a tool at our disposal: .

Rename the collections in the new agent ()

You can remove them ()

You can remove them ()

one of the following methods ↗
use it online ↗
online versions ↗
the .forestadmin-schema.json file
docs
docs
docs
Broken chart after migration