Mantra how-to guide

Define differents data providers for dev and production

Your development environment is different than production one. You can choose different data providers for each environment

22-Mar-2022
A  A  A 

One of the main features of Mantra, is that components doesn't know how their data are persisted.

That is done using Mantra data object mapper (using RedEntities subproject), a fast and multi data provider layer.

Mantra has been designed so that the developers team can work easily in their local environments and the deployment and migration of the project can be as simple as posible.

You can have a productive environment when developing Mantra project, and its configuration doesn't need to be exactly the same then other environments (testing, pre-production, production, etc.).

First, you can have multiple versions of mantraconfig.json file in your project, for example:

  • dev.mantraconfig.json : for development

  • testing.mantraconfig.json : for testing

  • prod.mantraconfig.json : for production

You just need to create a symbolic link named "mantraconfig.json" pointing to the right final .json file depending on the environment (remember that mantraconfig.json file is where Mantra expects to find many of the project configuration values).

By doing so, your data providers configurations can be differents ("Entity" property at mantraconfig.json).

Consider this real example (extracted from Mantra site), where Entities inside dev.mantraconfig.json are defined like this:

"Entities": {
   "default": {
      "provider": "mysql",
      "host": "localhost",
      "database": "mantrajswebsite",
      "user": "mantrauser",
      "password": "xxxxxx"
   }
}

As we can see, all data providers for all components use the same MySql instance at localhost.

Instead, in production system, we got a different Entitiess configurations, like this:

"Entities": {
   "default": {
      "provider": "mysql",
      "host": "10.64.22.10",
      "database": "mantrajswebsite",
      "user": "mantrauser",
      "password": "xxxxxx"
   },
   "tagging": {
      "provider": "mysql",
      "host": "10.64.22.10",
      "database": "mantrajswebsite_tagging",
      "user": "mantrauser",
      "password": "xxxxxx",
      "components": ["tagging"]
   },
   "analytics": {
      "provider": "mysql",
      "host": "10.64.22.11",
      "database": "mantrajswebsite_analytics",
      "user": "mantrauser",
      "password": "xxxxxx",
      "components": ["analytics"]
   },
   "logs": {
      "provider": "mysql",
      "host": "10.64.22.11",
      "database": "mantrajswebsite_logs",
      "user": "mantrauser",
      "password": "xxxxxx",
      "components": ["logger"]
   }
}

As you can see, four differents MySql databases in two instances (located at privates IPs) are used in production system, scaling it better and allowing a much better performance.

On the other hand, each database has its own backup policy, adding a new level of flexibility when deploying your projects using Mantra.