COREmanager Documentation
en En
es Es

How to add additional table fields

Sometimes when creating plugins, it is necessary to save additional parameters for built-in objects. COREmanager (Class mgr_db::Cache) allows adding additional fields to database (DB) tables without making changes to the application code. Added fields are processed by standard algorithms. The system automatically tracks the presence of a field in the table and its type. If necessary, the field will be added or its type will be changed. Values of such fields can be changed via the edit form or displayed in the record list. To do this, it is sufficient to add the corresponding field to the metadata.

Adding a field

We recommend to create a backup of your data before modifying the DB schema

To add an additional field to a table, create the directory /usr/local/mgr5/etc/sql/{product_name}.{table_name}.addon or /usr/local/mgr5/etc/sql/{table_name}.addon. Each file in these directories describes a separate table field. The field name matches the file name. By default, a field of type string with the maximum possible length (VARCHAR(255)) will be created. You can:

  • specify a different data type;
  • define a default value;
  • define access parameters corresponding to the structure Struct mgr_db::TableDesc::Field.
Example file:
type=string
size=40
access_read=registered
access_write=admin+
default=0.0.0.0

type — determines the field type. Values correspond to the names of classes inherited from Class mgr_db::Field. For example, string creates a field of type class mgr_db::StringField, and intclass mgr_db::IntField. Possible values:

  • string — string. The parameter size sets the maximum cell length. Default: 255;
  • int — integer field;
  • bool — boolean value: on or off;
  • decimal — field for storing fixed-point numbers;
  • date — field for storing dates;
  • money — field for storing currency values with automatic formatting;
  • text — text field;
  • idn — field for storing internationalized domain names (IDN);
  • long — integer field of increased length;
  • datetime — field for storing time with date.

size — field size for class mgr_db::StringField. Default: 255.

access_read — restricts read access to the field value by user access levels (see namespace mgr access). By default, the field is available to all users.

access_write — restricts write access. Analogous to access_read.

access — sets read and write permissions simultaneously. Overrides the values of access_read and access_write.

default — sets the default value. To set the value NULL specify the parameter:

default null

Applying changes

After creating or editing files, clear the cache and restart the panel:

rm -rf /usr/local/mgr5/var/.db.cache*
killall core

Diagnostics

To ensure that changes are applied, connect to the DBMS and verify that the field has been added:

mysql mgrName -e "DESC <MYTABLE>"
Explanation