å¾æ¥æåã§Alter管çãã¦ããDBã«CakePHPã®Migrationãå°å ¥ãããã¨ããæãmediumtext/longtextãæ±ãã®ã«ããã£ãã®ã§ã¡ã¢ã
MySQLã®textåã¯æé·65,535byteã®å¯å¤é·æåååã§ãããUTF8æç®ã§ç´2ä¸æåã¨ãªããå°ã容éã足ããmediumtext(æé·16MB)ã使ããããªãå ´é¢ãããã¾ãããããCakePHPã®Migration Pluginã使ã£ã¦ã¿ãã¨ãã©ããtextåã®ã¿ã®ãµãã¼ãã®ããã§ããã
以ä¸ã®æ§ãªãã¼ãã«ãã¾ãã¯ä½æãã¾ãã
mysql> CREATE TABLE testtable (id int, message text, medium_message mediumtext, long_message longtext);
ãããå ã«Migrationãã¡ã¤ã«ãä½æãã¾ãã
$ Console/cake Migrations.migration generate -f
çµæä½æãããMigrationãã¡ã¤ã«ã¯
'id' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false, 'key' => 'primary'), 'message' => array('type' => 'text', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'medium_message' => array('type' => 'text', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'long_message' => array('type' => 'text', 'null' => true, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
ã¨ãªããtext/mediumtext/longtextãåºå¥ããããã¹ã¦textåã¨ãã¦èªèããã¦ãã¾ãã¾ããã
ããã§ã¯å°ãã®ã§CakePHPã®ã³ã¢é¨åã«æãå
¥ãã¦å¯¾å¿ãããã¨ã«ãã¾ããã
ã¨ã¯ããã³ã¢ãã¡ã¤ã«ãç´æ¥ç·¨éããããã§ã¯ãªããCakePHPã®ã¯ã©ã¹ãªã¼ãã¼ã©ã¤ãã®ä»çµã¿ãå©ç¨ãã¾ããããã¯app/Libã«ã³ã¢ãã¡ã¤ã«ã¨ååã®ã¯ã©ã¹ãã¡ã¤ã«ãç½®ãã¨ã該å½ã¯ã©ã¹ããã¼ãããæã«ã³ã¢ã®ã¯ã©ã¹ã§ã¯ãªããapp/Libå´ã®ã¯ã©ã¹ã«ç½®ãæãã¦èªã¿è¾¼ãæ©è½ã§ããããã§CakePHPã®ã³ã¢èªä½ãã¢ããªã®ã¬ãã¸ããªã«å
¥ããªãã¦ãæ¸ã¿ã¾ãã
詳ããã¯ä»¥ä¸ãã覧ãã ããã
CakePHP ã®ã¯ã©ã¹ããªã¼ãã¼ã©ã¤ããã
å®éã«æ¸ãæããé¨åã¯ä»¥ä¸ã§ãã
å
ã¨ãªãMySQLã¯ã©ã¹ã¯CakePHP 2.5.8ã®ãã®ã§ãã
## project_path/app/Lib/Model/Datasource/Mysql.php // 116è¡ä»è¿ public $columns = array( 'primary_key' => array('name' => 'NOT NULL AUTO_INCREMENT'), 'string' => array('name' => 'varchar', 'limit' => '255'), 'mediumtext' => array('name' => 'mediumtext'), 'longtext' => array('name' => 'longtext'), 'text' => array('name' => 'text'), // 777è¡ä»è¿ if (strpos($col, 'mediumtext') !== false) { return 'mediumtext'; } if (strpos($col, 'longtext') !== false) { return 'longtext'; } if (strpos($col, 'text') !== false) { return 'text'; }
å
¨å
容ã¯ãã¡ãã
Gist : Mysql.php
ããã§mediumtext/longtextãå©ç¨ãããã¨ãã§ããããã«ãªãã¾ããã
ã¡ãªã¿ã«mediumtext/longtextãå
¬å¼ãµãã¼ãããªãçç±ã¨ãã¦ã¯ãCakePHPã¨ãã¦ã¯MySQLãPostgreSQLçãDBMSãå¤ãã£ã¦ãåãã¢ããªã±ã¼ã·ã§ã³ã³ã¼ãã§åããã¨ãç®æãã¦ãããããDBMSã«ãã£ã¦ããåããå¿
è¦ããªãããã«ããã®ãå°é£ãªãããã¨ããæã ã¨ç解ãã¾ããã
åè : LONGTEXT fields on schema generate
ä»åä¿®æ£ããã³ã¼ããMySQLã使ããã¨ã ããèæ ®ãããã®ã§ãã®ã§ããã®ããããç解ã®ä¸åèã«ãã¦ããã ããã°ã¨æãã¾ãã