# Help with twin servers v7

**URL:** <https://community.forestadmin.com/t/help-with-twin-servers-v7/2892>\
**Category:** Help me!\
**Created:** [July 13, 2021, 8:51am UTC](https://community.forestadmin.com/t/help-with-twin-servers-v7/2892 "2021-07-13T08:51:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![didouche](https://avatars.discourse-cdn.com/v4/letter/d/0ea827/32.png) [@didouche](https://community.forestadmin.com/u/didouche)\
**Post date:** [July 13, 2021, 8:51am UTC](https://community.forestadmin.com/t/help-with-twin-servers-v7/2892/1 "2021-07-13T08:51:26Z")

</div>

Hello,

We have upgraded to forest v7 last week.  
We are using twin servers, server B was online and forest was working fine.

We have upgraded server A, which is a copy of server B, and we have this error on our logs when A is online:

![Capture d’écran 2021-07-13 à 10.43.01](https://europe1.discourse-cdn.com/flex013/uploads/forest/optimized/2X/4/40f6e81a6a421c1a2a6016aedc28c11bdeb9594d_2_690x40.png)

![Capture d’écran 2021-07-13 à 10.43.10](https://europe1.discourse-cdn.com/flex013/uploads/forest/optimized/2X/4/40a4b63ef55734de57b2a2ddaf402a330870018e_2_690x42.png)

We have those errors on several models, and that’s always the property `STRING` that can’t be read.

We also have a `404` on `forest/authentication`

 ![Capture d’écran 2021-07-13 à 10.45.57](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/5/5f9e48f15578e81f81a54e2f6350f3b9b9553cb3.png)

 ![Capture d’écran 2021-07-13 à 10.46.07](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/c/cb3e9e6127ee48d908fbcbe1ad92373286817b68.png)

When launching server B, everything is fine.

## Expected behavior

Be able to connect to forest admin.

## Actual behavior

Unable to be connected to `app.forestadmin.com`

 ![Capture d’écran 2021-07-13 à 10.48.04](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/e/e9357ca4df5f6f419ea1889bc708c63058820f90.png)

## Context

- Package Version: 7.11.2,
- Express Version: 4.17.1,
- Sequelize Version: 5.15.2,
- Database Dialect: postgres,
- Project Name: ZACK

Thanks for your help !

---

<div class="post-metadata">

**Author:** ![GuillaumeGautreau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaumegautreau/32/557_2.png) [@GuillaumeGautreau](https://community.forestadmin.com/u/GuillaumeGautreau)\
**Post date:** [July 13, 2021, 8:54am UTC](https://community.forestadmin.com/t/help-with-twin-servers-v7/2892/2 "2021-07-13T08:54:27Z")

</div>

Hello @didouche,

Thanks for your feedback and the details you are sharing with us.

With the v7, when you are deploying multiple instances of the server, you need to generate a static client ID that will be used for authentication.

Can you please follow this part of the documentation: [Upgrade to v7 - Documentation](https://docs.forestadmin.com/documentation/how-tos/maintain/upgrade-notes-sql-mongodb/upgrade-to-v7#running-up-multiple-server-instances)

You will need to:

1. Generate a client ID from your `FOREST_ENV_SECRET` and `APPLICATION_URL`
2. Set a new environment variable named `FOREST_CLIENT_ID` with this value

Please use the same value for all your instances.

---

<div class="post-metadata">

**Author:** ![didouche](https://avatars.discourse-cdn.com/v4/letter/d/0ea827/32.png) [@didouche](https://community.forestadmin.com/u/didouche)\
**Post date:** [July 13, 2021, 8:56am UTC](https://community.forestadmin.com/t/help-with-twin-servers-v7/2892/3 "2021-07-13T08:56:30Z")

</div>

Hello @GuillaumeGautreau and thanks for your answer !

Yes, that’s what we have done, and we did have used the same `FOREST_CLIENT_ID` for server A and B

---

<div class="post-metadata">

**Author:** ![GuillaumeGautreau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaumegautreau/32/557_2.png) [@GuillaumeGautreau](https://community.forestadmin.com/u/GuillaumeGautreau)\
**Post date:** [July 13, 2021, 9:04am UTC](https://community.forestadmin.com/t/help-with-twin-servers-v7/2892/4 "2021-07-13T09:04:22Z")

</div>

Are you sure that both servers are identical? The errors that are showing up point out a difference between the sequelize models.

Can you activate the logs on your servers, in order to have more details about the error?

Can you paste here the code that you are using on server B to initialize the agent? It seems that the property `STRING` is coming from the property `objectMapping`.

---

<div class="post-metadata">

**Author:** ![didouche](https://avatars.discourse-cdn.com/v4/letter/d/0ea827/32.png) [@didouche](https://community.forestadmin.com/u/didouche)\
**Post date:** [July 13, 2021, 9:13am UTC](https://community.forestadmin.com/t/help-with-twin-servers-v7/2892/5 "2021-07-13T09:13:33Z")

</div>

Here is a one of the logs complete

 ![Capture d’écran 2021-07-13 à 11.07.52](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/d/d6d6ce4381ce3578394c73b5fb1b9429097da8b5.png)

Here is the initialization code from server B:

```javascript
async function forestInitialization (app) {
    app.use(await Liana.init({
      envSecret: process.env.FOREST_ENV_SECRET,
      authSecret: process.env.FOREST_AUTH_SECRET,
      objectMapping: Sequelize,
      connections: { default: sequelize },
    }))
}
forestInitialization(app)

```

And so here is the `api/services/sequelize` file:

```javascript
const Sequelize =	require ('sequelize')
const config = require (`${process.env.PWD}/config/sequelize`)
const db = {}
global.Model = Sequelize.Model
global.Op = Sequelize.Op

Sequelize.DataTypes.postgres.DECIMAL.parse = parseFloat

config.logging = config.logging && (message => {
	if (message.includes ('CREATE')) {
		console.info (message.green)
	} else if (message.includes ('DELETE')) {
		console.info (message.red)
	} else if (message.includes ('UPDATE')) {
		console.info (message.blue)
	} else if (message.includes ('INSERT')) {
		console.info (message.green)
	} else {
		console.info (message.grey)
	}
}) || false

const namespace = require ('cls-hooked').createNamespace ('transaction_namespace')
Sequelize.useCLS (namespace)
const sequelize = new Sequelize (config.database, config.username, config.password, {
	...config,
	define: {
		underscored: true,
		paranoid: true,
		deletedAt: 'deleted_at',
		updatedAt: 'updated_at',
		createdAt: 'created_at',
		...(config.define || { }),
		hooks: {
			beforeCreate: async function (instance, { transaction }) { },
			afterCreate: async function (instance, { transaction }) { },
			beforeUpdate: async function (instance, { transaction }) { },
			afterUpdate: async function (instance, { transaction }) { }
		}
	}
})

sequelize.beforeDefine (function (attributes) {
	attributes.remarks = {
		type: data_type.JSON
	}
})

global.data_type = Sequelize
global.Sequelize = Sequelize
global.sequelize = sequelize

fs.readdirSync (`${process.env.PWD}/api/models`).filter (file => /^[a-z_]*.js/.test (file) ).map (file => {
	db[file.replace (/\.js$/, '')] = require (`${process.env.PWD}/api/models/${file}`).init (sequelize, Sequelize)
})

for (let model_name of Object.keys (db).filter (model_name => db[model_name].associate)) {
	db[model_name].associate (db)

	Object.keys (db[model_name].prototype).map (key => {
		if (typeof db[model_name].prototype[key] === 'function') {
			db[model_name].prototype[key.decamelized] = db[model_name].prototype[key]
		}
	})
}

try {
	sequelize.sync ({
		force: config.force,
		logging: config.logging
	}).catch (error => {
		console.error (error)
	})
} catch (error) {
	console.error (error)
}

sequelize.query = function () {
	let args = arguments

	return Sequelize.prototype.query.apply (this, arguments).catch (function (error) {
		throw console.error ({
			sql: (args[0].sql && args[0].sql.query || args[0].query || '').replace (/\$[0-9]+/g, pattern_found => {
				let element = args[0].bind[pattern_found.replace ('$', '') / 1 - 1]

				return typeof element === 'string' && `'${element}'` || element
			}) || args[0].sql || args[0],
			stack: (error.stack || '').split ('\n')[0],
			hint: arguments[0].original.hint
		})
	})
}

Model.prototype.add_remark = async function ({ remark, remarks = [] } = { }, { user = '' } = { }) {
	console.function_called (`[${this[this.constructor.primaryKeyAttributes[0]]}]`)

	await this.update ({
		remarks: {
			...[...remarks, remark].filter (Boolean).reduce ((result, remark) => {
				result[now_minimal ()] = `${user && `[${user}] ` || ''}${remark}`
				return result
			}, { }),
			...this.remarks
		}
	})
}

Sequelize.models = db
db.sequelize = sequelize
db.Sequelize = Sequelize
global.namespace = namespace
global.models = db

module.exports = db

```

---

<div class="post-metadata">

**Author:** ![GuillaumeGautreau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaumegautreau/32/557_2.png) [@GuillaumeGautreau](https://community.forestadmin.com/u/GuillaumeGautreau)\
**Post date:** [July 13, 2021, 11:50am UTC](https://community.forestadmin.com/t/help-with-twin-servers-v7/2892/6 "2021-07-13T11:50:07Z")

</div>

Are you sure that you deployed an updated version of `forest-express-sequelize` in the `node_modules` for your server B?

The initialization of your agent seems good, I don’t see how you could get this error otherwise.

Can you dump the file `node_modules/forest-express-sequelize/package.json` on your server, just to check?

---

<div class="post-metadata">

**Author:** ![didouche](https://avatars.discourse-cdn.com/v4/letter/d/0ea827/32.png) [@didouche](https://community.forestadmin.com/u/didouche)\
**Post date:** [July 13, 2021, 1:00pm UTC](https://community.forestadmin.com/t/help-with-twin-servers-v7/2892/7 "2021-07-13T13:00:53Z")

</div>

I have dumped and reinstalled and it now works on both servers ! 🥳

Thanks a lot guillaume !
