As of release 1.11, an update tool for the Generic OR mapper is available. The tool can apply changes to the configuration files to an existing database.
In case, no automated update is desired, the GenericORMapperUpdate provides a mode, that displays the update statements rather to execute them directly. For huge databases, manual update should be preferred. This is especially true, if index or row updates are included!
The following script shows, how the automated database update can be done with aim of the GenericORMapperUpdate tool. If you are searching for an example script, have a look at the /apps/modules/genericormapper/data/tools folder in the apf-codepack-* release. The file is named update.php and must be adapted to your application case:
// include page controller
require('../../apps/core/pagecontroller/pagecontroller.php');
// configure the registry if desired
Registry::register('apf::core','Environment','{ENVIRONMENT}');
// include SetupMapper
import('modules::genericormapper::data::tools','GenericORMapperUpdate');
// create update tool
$update = new GenericORMapperUpdate();
// set Context (important for the configuration files!)
$update->setContext('{CONTEXT}');
// adapt storage engine (default is MyISAM)
//$update->setStorageEngine('MyISAM|INNODB');
// adapt data type of the indexed columns, that are used for object and relation ids
//$update->setIndexColumnDataType('INT(5) UNSIGNED');
// update database layout
$update->updateDatabase('{CONFIG_NAMESPACE}','{CONFIG_NAME_AFFIX}','{CONNECTION_NAME}');
// display statements only
$update->updateDatabase('{CONFIG_NAMESPACE}','{CONFIG_NAME_AFFIX}','{CONNECTION_NAME}',false);The place holders within the script have the following meaning:
Further, it is important that the database, that should be initialized, must exist before setup is started. Additionally, the user connecting to the database must have CREATE TABLE, ALTER TABLE- and, if desired, ALTER INDEX-rights.Otherwise, the update could not be done. If no error is displayed during setup, the setup has finished successfully. The result can be checked by using phpMyAdmin or a MySQLAdmin tool.
JetBRAINS supports the development of the APF with PHPStorm licenses and we feel confidential that PHPStorm strongly influences the APF's quality. Use PHPStorm!
Proud to useIntelligent PHP IDE for coding, testing and debugging with pleasure