Hello,
I just create a new folder using forest projects:bundle:sql "aFolderName"
and the run it using docker on my local dev.
Feature(s) impacted
migrating from v9 to new agent
Observed behavior
Expected behavior
I changed the index.ts adding a field to collection appointment, but when I start/restart the server the forestadmin-schema.json is not being updated, I dont find the new field in there. I even tried to rename some fields but I always dont see the changes on the forest schema.
this is my index file:
import type { SslMode } from '@forestadmin/datasource-sql';
import type { Schema } from './typings';
import 'dotenv/config';
import { createAgent } from '@forestadmin/agent';
import { createSqlDataSource } from '@forestadmin/datasource-sql';
import { convertToSnakeCase } from './utils';
// This object allows to configure your Forest Admin panel
const agent = createAgent<Schema>({
// Security tokens
authSecret: process.env.FOREST_AUTH_SECRET!,
envSecret: process.env.FOREST_ENV_SECRET!,
// Make sure to set NODE_ENV to 'production' when you deploy your project
isProduction: false,
// Autocompletion of collection names and fields
typingsPath: './typings.ts',
typingsMaxDepth: 5,
});
// Connect your datasources
// All options are documented at https://docs.forestadmin.com/developer-guide-agents-nodejs/data-sources/connection
agent.addDataSource(
createSqlDataSource({
uri: process.env.DATABASE_URL,
schema: process.env.DATABASE_SCHEMA,
sslMode: process.env.DATABASE_SSL_MODE as SslMode,
}),
{
rename(oldCollectionName) {
return convertToSnakeCase(oldCollectionName);
},
}
);
agent.customizeCollection('appointments', collection => {
collection.renameField('date_action', 'dateActionTest');
collection.addField('displayEventEmail', {
// Type of the new field
columnType: 'String',
// Dependencies which are needed to compute the new field (must not be empty)
dependencies: ['email', 'date_action'],
// Compute function for the new field
// Note that the function computes the new values in batches: the return value
// must be an array which contains the new values in the same order than the
// provided records.
getValues: (records, context) =>
records.map(r => `${r.email}: ${r.date_action}`),
});
})
// Add customizations here.
// For instance, you can code custom actions, charts, create new fields or relationships, load plugins.
// As your project grows, you will need to split it into multiple files!
//
// Here is some code to get your started
//
// agent.customizeCollection('products', collection => {
// // Actions are documented here:
// // https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/actions
// collection.addAction('Order new batch from supplier', {
// scope: 'Single', // This action can be triggered product by product
// form: [{ label: 'Quantity', type: 'Number', isRequired: true }],
// execute: async (context, resultBuilder) => {
// const product = await context.getRecord(['id', 'name'])
// const quantity = context.formValues['Quantity'];
// // ... Perform work here ...
// return resultBuilder.success(`Your order for a batch of ${quantity} '${product.name}' was sent`);
// }
// });
// // Search customization is documented here:
// // https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/search
// collection.replaceSearch(searchString => {
// // user has most likely typed a product id, let's search only that column
// if (searchString.match(/^prdid[\d]{8}/$))
// return { field: 'id', operator: 'Equal', value: searchString };
// // Otherwise assume that user wants to search for a product by name
// return { field: 'name', operator: 'Contains', value: searchString };
// });
// });
// Expose an HTTP endpoint.
agent.mountOnStandaloneServer(Number(process.env.APPLICATION_PORT));
// Start the agent.
agent.start().catch(error => {
console.error('\x1b[31merror:\x1b[0m Forest Admin agent failed to start\n');
console.error('');
console.error(error.stack);
process.exit(1);
});
Failure Logs
Context
- Project name: clevermate
- Environment name: Development | adeldjidjik (my-dev)
- Agent technology: (nodejs
- Agent (forest package) name & version: new agent v1
- Database type: postgres