Adding extra charsets for ActionMailer unit tests, if you're looking to parse incomin...
[akelos.git] / lib / AkInstaller.php
blobff3ef8b5e4004dfac28e7691207e65b067fd7223
1 <?php
2 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4 // +----------------------------------------------------------------------+
5 // | Akelos Framework - http://www.akelos.org |
6 // +----------------------------------------------------------------------+
7 // | Copyright (c) 2002-2006, Akelos Media, S.L. & Bermi Ferrer Martinez |
8 // | Released under the GNU Lesser General Public License, see LICENSE.txt|
9 // +----------------------------------------------------------------------+
11 /**
12 * @package ActiveSupport
13 * @subpackage Installer
14 * @author Bermi Ferrer <bermi a.t akelos c.om>
15 * @copyright Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org
16 * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html>
19 require_once(AK_LIB_DIR.DS.'Ak.php');
20 require_once(AK_LIB_DIR.DS.'AkActiveRecord.php');
21 file_exists(AK_APP_DIR.DS.'shared_model.php') ? require_once(AK_APP_DIR.DS.'shared_model.php') : null;
22 defined('AK_APP_INSTALLERS_DIR') ? null : define('AK_APP_INSTALLERS_DIR', AK_APP_DIR.DS.'installers');
24 // Install scripts might use more RAM than normal requests.
25 @ini_set('memory_limit', -1);
27 /**
29 * == Column Types ==
31 * Akelos natively supports the following column data types.
33 * integer|int, float, decimal,
34 * string, text,
35 * datetime|timestamp, date,
36 * binary,
37 * boolean
39 * Caution: Because boolean is virtual tinyint on mysql, you can't use tinyint for other things!
42 * == Default settings for columns ==
44 * AkInstaller suggests some default values for the column-details.
46 * So
47 * <code>
48 * $this->createTable('Post','title,body,created_at,is_draft');
49 * </code>
51 * will actually create something like this:
53 * title => string(255), body => text, created_at => datetime, is_draft => boolean not null default 0 index
56 * column_name | default setting
57 * -------------------------------+--------------------------------------------
58 * id | integer not null auto_increment primary_key
59 * *_id,*_by | integer index
60 * description,content,body | text
61 * position | integer index
62 * *_count | integer default 0
63 * lock_version | integer default 1
64 * *_at | datetime
65 * *_on | date
66 * is_*,has_*,do_*,does_*,are_* | boolean not null default 0 index
67 * *somename | multilingual column => en_somename, es_somename
68 * default | string
71 class AkInstaller
73 var $db;
74 var $data_dictionary;
75 var $available_tables = array();
76 var $vervose = true;
77 var $module;
78 var $warn_if_same_version = true;
80 function AkInstaller($db_connection = null)
82 if(empty($db_connection)){
83 $this->db =& AkDbAdapter::getInstance();
84 }else {
85 $this->db =& $db_connection;
88 $this->data_dictionary =& $this->db->getDictionary();
89 $this->available_tables = $this->getAvailableTables();
92 function install($version = null, $options = array())
94 $version = (is_null($version)) ? max($this->getAvailableVersions()) : $version;
95 return $this->_upgradeOrDowngrade('up', $version , $options);
98 function up($version = null, $options = array())
100 return $this->_upgradeOrDowngrade('up', $version, $options);
103 function uninstall($version = null, $options = array())
105 $version = (is_null($version)) ? 0 : $version;
106 return $this->_upgradeOrDowngrade('down', $version, $options);
109 function down($version = null, $options = array())
111 return $this->_upgradeOrDowngrade('down', $version, $options);
114 function _upgradeOrDowngrade($action, $version = null, $options = array())
116 if(in_array('quiet',$options) && AK_ENVIRONMENT == 'development'){
117 $this->vervose = false;
118 }elseif(!empty($this->vervose) && AK_ENVIRONMENT == 'development'){
119 $this->debug(true);
122 $current_version = $this->getInstalledVersion($options);
123 $available_versions = $this->getAvailableVersions();
125 $action = stristr($action,'down') ? 'down' : 'up';
127 if($action == 'up'){
128 $newest_version = max($available_versions);
129 $version = isset($version[0]) && is_numeric($version[0]) ? $version[0] : $newest_version;
130 $versions = range($current_version+1,$version);
132 if($current_version > $version){
133 echo Ak::t("You can't upgrade to version %version, when you are currently on version %current_version", array('%version'=>$version,'%current_version'=>$current_version));
134 return false;
136 }else{
137 $version = !empty($version[0]) && is_numeric($version[0]) ? $version[0] : 0;
138 $versions = range($current_version, empty($version) ? 1 : $version+1);
140 if($current_version == 0){
141 return true;
142 }elseif($current_version < $version){
143 echo Ak::t("You can't downgrade to version %version, when you just have installed version %current_version", array('%version'=>$version,'%current_version'=>$current_version));
144 return false;
148 if($this->warn_if_same_version && $current_version == $version){
149 echo Ak::t("Can't go $action to version %version, you're already on version %version", array('%version'=>$version));
150 return false;
153 if(AK_CLI && !empty($this->vervose) && AK_ENVIRONMENT == 'development'){
154 echo Ak::t(ucfirst($action).'grading');
157 if(!empty($versions) && is_array($versions)){
158 foreach ($versions as $version){
159 if(!$this->_runInstallerMethod($action, $version, $options)){
160 return false;
163 }else{
164 return false;
167 return true;
170 function installVersion($version, $options = array())
172 return $this->_runInstallerMethod('up', $version, $options);
175 function uninstallVersion($version, $options = array())
177 return $this->_runInstallerMethod('down', $version, $options);
181 * Runs a a dow_1, up_3 method and wraps it into a transaction.
183 function _runInstallerMethod($method_prefix, $version, $options = array(), $version_number = null)
185 $method_name = $method_prefix.'_'.$version;
186 if(!method_exists($this, $method_name)){
187 return false;
190 $version_number = empty($version_number) ? ($method_prefix=='down' ? $version-1 : $version) : $version_number;
192 $this->transactionStart();
193 if($this->$method_name($options) === false){
194 $this->transactionFail();
196 $success = !$this->transactionHasFailed();
197 $this->transactionComplete();
198 if($success){
199 $this->setInstalledVersion($version_number, $options);
201 return $success;
204 function getInstallerName()
206 return str_replace('installer','',strtolower(get_class($this)));
209 function _versionPath($options = array())
211 $mode = empty($options['mode']) ? AK_ENVIRONMENT : $options['mode'];
212 return AK_TMP_DIR.DS.'installer_versions'.DS.(empty($this->module)?'':$this->module.DS).$mode.'_'.$this->getInstallerName().'_version.txt';
215 // DEPRECATED
216 function _versionPath_Deprecated($options = array())
218 $mode = empty($options['mode']) ? AK_ENVIRONMENT : $options['mode'];
219 return AK_APP_INSTALLERS_DIR.DS.(empty($this->module)?'':$this->module.DS).'versions'.DS.$mode.'_'.$this->getInstallerName().'_version.txt';
222 // DEPRECATED
223 function _moveOldVersionsFileToNewLocation($options)
225 $old_filename = $this->_versionPath_Deprecated($options);
226 if (is_file($old_filename)){
227 $this->setInstalledVersion(Ak::file_get_contents($old_filename),$options);
228 Ak::file_delete($old_filename);
229 Ak::file_put_contents(AK_APP_INSTALLERS_DIR.DS.'versions'.DS.'NOTE',"Version information is now stored in the temp folder. \n\rYou can savely move this files here over there to tmp/installer_versions/* or delete this directory if empty.");
233 function getInstalledVersion($options = array())
235 $version_file = $this->_versionPath($options);
237 $this->_moveOldVersionsFileToNewLocation($options);
239 if(!is_file($version_file)){
240 $this->setInstalledVersion(0, $options);
242 return Ak::file_get_contents($this->_versionPath($options));
246 function setInstalledVersion($version, $options = array())
248 return Ak::file_put_contents($this->_versionPath($options), $version);
252 function getAvailableVersions()
254 $versions = array();
255 foreach(get_class_methods($this) as $method_name){
256 if(preg_match('/^up_([0-9]*)$/',$method_name, $match)){
257 $versions[] = $match[1];
260 sort($versions);
261 return $versions;
265 function modifyTable($table_name, $column_options = null, $table_options = array())
267 return $this->_createOrModifyTable($table_name, $column_options, $table_options);
271 * Adds a new column to the table called $table_name
273 function addColumn($table_name, $column_details)
275 $this->timestamps = false;
276 $column_details = $this->_getColumnsAsAdodbDataDictionaryString($column_details);
277 return $this->data_dictionary->ExecuteSQLArray($this->data_dictionary->AddColumnSQL($table_name, $column_details));
280 function changeColumn($table_name, $column_details)
282 $this->timestamps = false;
283 $column_details = $this->_getColumnsAsAdodbDataDictionaryString($column_details);
284 return $this->data_dictionary->ExecuteSQLArray($this->data_dictionary->AlterColumnSQL($table_name, $column_details));
287 function removeColumn($table_name, $column_name)
289 return $this->data_dictionary->ExecuteSQLArray($this->data_dictionary->DropColumnSQL($table_name, $column_name));
292 function renameColumn($table_name, $old_column_name, $new_column_name)
294 return $this->db->renameColumn($table_name, $old_column_name, $new_column_name);
298 function createTable($table_name, $column_options = null, $table_options = array())
300 if($this->tableExists($table_name)){
301 trigger_error(Ak::t('Table %table_name already exists on the database', array('%table_name'=>$table_name)), E_USER_NOTICE);
302 return false;
304 $this->timestamps = (!isset($table_options['timestamp']) || (isset($table_options['timestamp']) && $table_options['timestamp'])) &&
305 (!strstr($column_options, 'created') && !strstr($column_options, 'updated'));
306 return $this->_createOrModifyTable($table_name, $column_options, $table_options);
309 function _createOrModifyTable($table_name, $column_options = null, $table_options = array())
311 if(empty($column_options) && $this->_loadDbDesignerDbSchema()){
312 $column_options = $this->db_designer_schema[$table_name];
313 }elseif(empty($column_options)){
314 trigger_error(Ak::t('You must supply details for the table you are creating.'), E_USER_ERROR);
315 return false;
318 $column_options = is_string($column_options) ? array('columns'=>$column_options) : $column_options;
320 $default_column_options = array(
321 'sequence_table' => false
323 $column_options = array_merge($default_column_options, $column_options);
325 $default_table_options = array(
326 'mysql' => 'TYPE=InnoDB',
327 //'REPLACE'
329 $table_options = array_merge($default_table_options, $table_options);
331 $column_string = $this->_getColumnsAsAdodbDataDictionaryString($column_options['columns']);
333 $create_or_alter_table_sql = $this->data_dictionary->ChangeTableSQL($table_name, str_replace(array(' UNIQUE', ' INDEX', ' FULLTEXT', ' HASH'), '', $column_string), $table_options);
334 $result = $this->data_dictionary->ExecuteSQLArray($create_or_alter_table_sql, false);
336 if($result){
337 $this->available_tables[] = $table_name;
338 }else{
339 trigger_error(Ak::t("Could not create or alter table %name using the SQL \n--------\n%sql\n--------\n", array('%name'=>$table_name, '%sql'=>$create_or_alter_table_sql[0])), E_USER_ERROR);
342 $columns_to_index = $this->_getColumnsToIndex($column_string);
344 foreach ($columns_to_index as $column_to_index => $index_type){
345 $this->addIndex($table_name, $column_to_index.($index_type != 'INDEX' ? ' '.$index_type : ''));
348 if(isset($column_options['index_columns'])){
349 $this->addIndex($table_name, $column_options['index_columns']);
352 if($column_options['sequence_table'] || $this->_requiresSequenceTable($column_string)){
353 $this->createSequence($table_name);
356 return $result;
359 function dropTable($table_name, $options = array())
361 $result = $this->tableExists($table_name) ? $this->db->execute('DROP TABLE '.$table_name) : true;
362 if($result){
363 unset($this->available_tables[array_search($table_name, $this->available_tables)]);
364 if(!empty($options['sequence'])){
365 $this->dropSequence($table_name);
370 function dropTables()
372 $args = func_get_args();
373 if(!empty($args)){
374 $num_args = count($args);
375 $options = $num_args > 1 && is_array($args[$num_args-1]) ? array_shift($args) : array();
376 $tables = count($args) > 1 ? $args : (is_array($args[0]) ? $args[0] : Ak::toArray($args[0]));
377 foreach ($tables as $table){
378 $this->dropTable($table, $options);
383 function addIndex($table_name, $columns, $index_name = '')
385 $index_name = ($index_name == '') ? 'idx_'.$table_name.'_'.$columns : $index_name;
386 $index_options = array();
387 if(preg_match('/(UNIQUE|FULLTEXT|HASH)/',$columns,$match)){
388 $columns = trim(str_replace($match[1],'',$columns),' ');
389 $index_options[] = $match[1];
391 return $this->tableExists($table_name) ? $this->data_dictionary->ExecuteSQLArray($this->data_dictionary->CreateIndexSQL($index_name, $table_name, $columns, $index_options)) : false;
394 function removeIndex($table_name, $columns_or_index_name)
396 if(!$this->tableExists($table_name)){
397 return false;
399 $available_indexes = $this->db->getIndexes($table_name);
400 $index_name = isset($available_indexes[$columns_or_index_name]) ? $columns_or_index_name : 'idx_'.$table_name.'_'.$columns_or_index_name;
401 if(!isset($available_indexes[$index_name])){
402 trigger_error(Ak::t('Index %index_name does not exist.', array('%index_name'=>$index_name)), E_USER_NOTICE);
403 return false;
405 return $this->data_dictionary->ExecuteSQLArray($this->data_dictionary->DropIndexSQL($index_name, $table_name));
408 function dropIndex($table_name, $columns_or_index_name)
410 return $this->removeIndex($table_name,$columns_or_index_name);
413 function createSequence($table_name)
415 $result = $this->tableExists('seq_'.$table_name) ? false : $this->db->connection->CreateSequence('seq_'.$table_name);
416 $this->available_tables[] = 'seq_'.$table_name;
417 return $result;
420 function dropSequence($table_name)
422 $result = $this->tableExists('seq_'.$table_name) ? $this->db->connection->DropSequence('seq_'.$table_name) : true;
423 if($result){
424 unset($this->available_tables[array_search('seq_'.$table_name, $this->available_tables)]);
427 return $result;
430 function getAvailableTables()
432 if(empty($this->available_tables)){
433 $this->available_tables = $this->db->availableTables();
435 return $this->available_tables;
438 function tableExists($table_name)
440 return in_array($table_name,$this->getAvailableTables());
443 function _getColumnsAsAdodbDataDictionaryString($columns)
445 $columns = $this->_setColumnDefaults($columns);
446 $this->_ensureColumnNameCompatibility($columns);
448 $equivalences = array(
449 '/ ((limit|max|length) ?= ?)([0-9]+)([ \n\r,]+)/'=> ' (\3) ',
450 '/([ \n\r,]+)default([ =]+)([^\'^,^\n]+)/i'=> ' DEFAULT \'\3\'',
451 '/([ \n\r,]+)(integer|int)([( \n\r,]+)/'=> '\1 I \3',
452 '/([ \n\r,]+)float([( \n\r,]+)/'=> '\1 F \2',
453 '/([ \n\r,]+)decimal([( \n\r,]+)/'=> '\1 N \2',
454 '/([ \n\r,]+)datetime([( \n\r,]+)/'=> '\1 T \2',
455 '/([ \n\r,]+)date([( \n\r,]+)/'=> '\1 D \2',
456 '/([ \n\r,]+)timestamp([( \n\r,]+)/'=> '\1 T \2',
457 '/([ \n\r,]+)time([( \n\r,]+)/'=> '\1 T \2',
458 '/([ \n\r,]+)text([( \n\r,]+)/'=> '\1 XL \2',
459 '/([ \n\r,]+)string([( \n\r,]+)/'=> '\1 C \2',
460 '/([ \n\r,]+)binary([( \n\r,]+)/'=> '\1 B \2',
461 '/([ \n\r,]+)boolean([( \n\r,]+)/'=> '\1 L'.($this->db->type()=='mysql'?'(1)':'').' \2',
462 '/ NOT( |_)?NULL/i'=> ' NOTNULL',
463 '/ AUTO( |_)?INCREMENT/i'=> ' AUTO ',
464 '/ +/'=> ' ',
465 '/ ([\(,]+)/'=> '\1',
466 '/ INDEX| IDX/i'=> ' INDEX ',
467 '/ UNIQUE/i'=> ' UNIQUE ',
468 '/ HASH/i'=> ' HASH ',
469 '/ FULL_?TEXT/i'=> ' FULLTEXT ',
470 '/ ((PRIMARY( |_)?)?KEY|pk)/i'=> ' KEY',
473 return trim(preg_replace(array_keys($equivalences),array_values($equivalences), ' '.$columns.' '), ' ');
476 function _setColumnDefaults($columns)
478 $columns = Ak::toArray($columns);
479 foreach ((array)$columns as $column){
480 $column = trim($column, "\n\t\r, ");
481 if(!empty($column)){
482 $single_columns[$column] = $this->_setColumnDefault($column);
485 if(!empty($this->timestamps) && !isset($single_columns['created_at']) && !isset($single_columns['updated_at'])){
486 $single_columns['updated_at'] = $this->_setColumnDefault('updated_at');
487 $single_columns['created_at'] = $this->_setColumnDefault('created_at');
489 return join(",\n", $single_columns);
492 function _setColumnDefault($column)
494 return $this->_needsDefaultAttributes($column) ? $this->_setDefaultAttributes($column) : $column;
497 function _needsDefaultAttributes($column)
499 return preg_match('/^(([A-Z0-9_\(\)]+)|(.+ string[^\(.]*)|(\*.*))$/i',$column);
502 function _setDefaultAttributes($column)
504 $rules = $this->getDefaultColumnAttributesRules();
505 foreach ($rules as $regex=>$replacement){
506 if(is_string($replacement)){
507 $column = preg_replace($regex,$replacement,$column);
508 }elseif(preg_match($regex,$column,$match)){
509 $column = call_user_func_array($replacement,$match);
512 return $column;
516 * Returns a key => value pair of regular expressions that will trigger methods
517 * to cast database columns to their respective default values or a replacement expression.
519 function getDefaultColumnAttributesRules()
521 return array(
522 '/^\*(.*)$/i' => array(&$this,'_castToMultilingualColumn'),
523 '/^(description|content|body)$/i' => '\1 text',
524 '/^(lock_version)$/i' => '\1 integer default \'1\'',
525 '/^(.+_count)$/i' => '\1 integer default \'0\'',
526 '/^(id)$/i' => 'id integer not null auto_increment primary_key',
527 '/^(.+)_(id|by)$/i' => '\1_\2 integer index',
528 '/^(position)$/i' => '\1 integer index',
529 '/^(.+_at)$/i' => '\1 datetime',
530 '/^(.+_on)$/i' => '\1 date',
531 '/^(is_|has_|do_|does_|are_)([A-Z0-9_]+)$/i' => '\1\2 boolean not null default \'0\' index', //
532 '/^([A-Z0-9_]+) *(\([0-9]+\))?$/i' => '\1 string\2', // Everything else will default to string
533 '/^((.+ )string([^\(.]*))$/i' => '\2string(255)\3', // If we don't set the string lenght it will fail, so if not present will set it to 255
537 function _castToMultilingualColumn($found, $column)
539 $columns = array();
540 foreach (Ak::langs() as $lang){
541 $columns[] = $lang.'_'.ltrim($column);
543 return $this->_setColumnDefaults($columns);
546 function _getColumnsToIndex($column_string)
548 $columns_to_index = array();
549 foreach (explode(',',$column_string.',') as $column){
550 if(preg_match('/([A-Za-z0-9_]+) (.*) (INDEX|UNIQUE|FULLTEXT|HASH) ?(.*)$/i',$column,$match)){
551 $columns_to_index[$match[1]] = $match[3];
554 return $columns_to_index;
557 function _getUniqueValueColumns($column_string)
559 $unique_columns = array();
560 foreach (explode(',',$column_string.',') as $column){
561 if(preg_match('/([A-Za-z0-9_]+) (.*) UNIQUE ?(.*)$/',$column,$match)){
562 $unique_columns[] = $match[1];
565 return $unique_columns;
568 function _requiresSequenceTable($column_string)
570 if(in_array($this->db->type(),array('mysql','postgre'))){
571 return false;
573 foreach (explode(',',$column_string.',') as $column){
574 if(preg_match('/([A-Za-z0-9_]+) (.*) AUTO (.*)$/',$column)){
575 return true;
577 if(preg_match('/^id /',$column)){
578 return true;
581 return false;
586 * Transaction support for database operations
588 * Transactions are enabled automatically for Intaller objects, But you can nest transactions within models.
589 * This transactions are nested, and only the othermost will be executed
591 * $UserInstalller->transactionStart();
592 * $UserInstalller->addTable('id, name');
594 * if(!isCompatible()){
595 * $User->transactionFail();
598 * $User->transactionComplete();
600 function transactionStart()
602 return $this->db->startTransaction();
605 function transactionComplete()
607 return $this->db->stopTransaction();
610 function transactionFail()
612 return $this->db->failTransaction();
615 function transactionHasFailed()
617 return $this->db->hasTransactionFailed();
621 * Promts for a variable on console scripts
623 function promptUserVar($message, $options = array())
625 $f = fopen("php://stdin","r");
626 $default_options = array(
627 'default' => null,
628 'optional' => false,
631 $options = array_merge($default_options, $options);
633 echo "\n".$message.(empty($options['default'])?'': ' ['.$options['default'].']').': ';
634 $user_input = fgets($f, 25600);
635 $value = trim($user_input,"\n\r\t ");
636 $value = empty($value) ? $options['default'] : $value;
637 if(empty($value) && empty($options['optional'])){
638 echo "\n\nThis setting is not optional.";
639 fclose($f);
640 return $this->promptUserVar($message, $options);
642 fclose($f);
643 return empty($value) ? $options['default'] : $value;
646 //DEPRECATED
647 function promtUserVar($message, $options = array())
649 trigger_error(Ak::t('AkInstaller::promtUserVar is deprecated and will be removed on future versions. Please use AkInstaller::promptUserVar instead.'), E_USER_NOTICE);
650 return $this->promptUserVar($message, $options);
653 function _loadDbDesignerDbSchema()
655 if($path = $this->_getDbDesignerFilePath()){
656 $this->db_designer_schema = Ak::convert('DBDesigner','AkelosDatabaseDesign', Ak::file_get_contents($path));
657 return !empty($this->db_designer_schema);
659 return false;
662 function _getDbDesignerFilePath()
664 $path = AK_APP_INSTALLERS_DIR.DS.$this->getInstallerName().'.xml';
665 return file_exists($path) ? $path : false;
668 function _ensureColumnNameCompatibility($columns)
670 $columns = explode(',',$columns.',');
671 foreach ($columns as $column){
672 $column = trim($column);
673 $column = substr($column, 0, strpos($column.' ',' '));
674 $this->_canUseColumn($column);
678 function _canUseColumn($column_name)
680 $invalid_columns = $this->_getInvalidColumnNames();
681 if(in_array($column_name, $invalid_columns)){
683 $method_name_part = AkInflector::camelize($column_name);
684 require_once(AK_LIB_DIR.DS.'AkActiveRecord.php');
685 $method_name = (method_exists(new AkActiveRecord(), 'set'.$method_name_part)?'set':'get').$method_name_part;
687 trigger_error(Ak::t('A method named %method_name exists in the AkActiveRecord class'.
688 ' which will cause a recusion problem if you use the column %column_name in your database. '.
689 'You can disable automatic %type by setting the constant %constant to false '.
690 'in your configuration file.', array(
691 '%method_name'=> $method_name,
692 '%column_name' => $column_name,
693 '%type' => Ak::t($method_name[0] == 's' ? 'setters' : 'getters'),
694 '%constant' => Ak::t($method_name[0] == 's' ? 'AK_ACTIVE_RECORD_ENABLE_CALLBACK_SETTERS' : 'AK_ACTIVE_RECORD_ENABLE_CALLBACK_GETTERS'),
696 )), E_USER_ERROR);
700 function _getInvalidColumnNames()
702 return defined('AK_INVALID_ACTIVE_RECORD_COLUMNS') ? explode(',',AK_INVALID_ACTIVE_RECORD_COLUMNS) : array('sanitized_conditions_array','conditions','inheritance_column','inheritance_column',
703 'subclasses','attribute','attributes','attribute','attributes','accessible_attributes','protected_attributes',
704 'serialized_attributes','available_attributes','attribute_caption','primary_key','column_names','content_columns',
705 'attribute_names','combined_subattributes','available_combined_attributes','connection','connection','primary_key',
706 'table_name','table_name','only_available_atrributes','columns_for_atrributes','columns_with_regex_boundaries','columns',
707 'column_settings','column_settings','akelos_data_type','class_for_database_table_mapping','display_field','display_field',
708 'internationalized_columns','available_locales','current_locale','attribute_by_locale','attribute_locales',
709 'attribute_by_locale','attribute_locales','attributes_before_type_cast','attribute_before_type_cast','serialize_attribute',
710 'available_attributes_quoted','attributes_quoted','column_type','value_for_date_column','observable_state',
711 'observable_state','observers','errors','base_errors','errors_on','full_error_messages','array_from_ak_string',
712 'attribute_condition','association_handler','associated','associated_finder_sql_options','association_option',
713 'association_option','association_id','associated_ids','associated_handler_name','associated_type','association_type',
714 'collection_handler_name','model_name','model_name','parent_model_name','parent_model_name');
717 function execute($sql)
719 return $this->db->execute($sql);
722 function debug($toggle = null)
724 $this->db->connection->debug = $toggle === null ? !$this->db->connection->debug : $toggle;
727 function usage()
729 echo Ak::t("Description:
730 Database migrations is a sort of SCM like subversion, but for database settings.
732 The migration command takes the name of an installer located on your
733 /app/installers folder and runs one of the following commands:
735 - \"install\" + (options version number): Will update to the provided version
736 number or to the latest one in no version is given.
738 - \"uninstall\" + (options version number): Will downgrade to the provided
739 version number or to the lowest one in no version is given.
741 Current version number will be sorted at app/installers/installer_name_version.txt.
743 Example:
744 >> migrate framework install
746 Will run the default database schema for the framework.
747 This generates the tables for handling database driven sessions and cache.