Skip to content

Commit 2b90e7d

Browse files
committed
Add table options to MySQL.
This allows innodb tables to be specified which is required for enabling foreign keys.
1 parent 7ee220e commit 2b90e7d

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/Cake/Database/Schema/MysqlSchema.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,18 @@ public function dropTableSql(Table $table) {
199199
*/
200200
public function createTableSql(Table $table, $columns, $constraints, $indexes) {
201201
$content = implode(",\n", array_merge($columns, $constraints, $indexes));
202-
return [sprintf("CREATE TABLE `%s` (\n%s\n)", $table->name(), $content)];
202+
$content = sprintf("CREATE TABLE `%s` (\n%s\n)", $table->name(), $content);
203+
$options = $table->options();
204+
if (isset($options['engine'])) {
205+
$content .= sprintf(" ENGINE=%s", $options['engine']);
206+
}
207+
if (isset($options['charset'])) {
208+
$content .= sprintf(" DEFAULT CHARSET=%s", $options['charset']);
209+
}
210+
if (isset($options['collate'])) {
211+
$content .= sprintf(" COLLATE=%s", $options['collate']);
212+
}
213+
return [$content];
203214
}
204215

205216
/**

lib/Cake/Test/TestCase/Database/Schema/MysqlSchemaTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,11 @@ public function testCreateSql() {
543543
->addConstraint('primary', [
544544
'type' => 'primary',
545545
'columns' => ['id']
546+
])
547+
->options([
548+
'engine' => 'InnoDB',
549+
'charset' => 'utf8',
550+
'collate' => 'utf8_general_ci',
546551
]);
547552

548553
$expected = <<<SQL
@@ -552,7 +557,7 @@ public function testCreateSql() {
552557
`body` TEXT,
553558
`created` DATETIME,
554559
PRIMARY KEY (`id`)
555-
)
560+
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci
556561
SQL;
557562
$result = $table->createSql($connection);
558563
$this->assertCount(1, $result);

0 commit comments

Comments
 (0)