Skip to content

Commit

Permalink
Add table options to MySQL.
Browse files Browse the repository at this point in the history
This allows innodb tables to be specified which is required
for enabling foreign keys.
  • Loading branch information
markstory committed May 29, 2013
1 parent 7ee220e commit 2b90e7d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
13 changes: 12 additions & 1 deletion lib/Cake/Database/Schema/MysqlSchema.php
Expand Up @@ -199,7 +199,18 @@ public function dropTableSql(Table $table) {
*/
public function createTableSql(Table $table, $columns, $constraints, $indexes) {
$content = implode(",\n", array_merge($columns, $constraints, $indexes));
return [sprintf("CREATE TABLE `%s` (\n%s\n)", $table->name(), $content)];
$content = sprintf("CREATE TABLE `%s` (\n%s\n)", $table->name(), $content);
$options = $table->options();
if (isset($options['engine'])) {
$content .= sprintf(" ENGINE=%s", $options['engine']);
}
if (isset($options['charset'])) {
$content .= sprintf(" DEFAULT CHARSET=%s", $options['charset']);
}
if (isset($options['collate'])) {
$content .= sprintf(" COLLATE=%s", $options['collate']);
}
return [$content];
}

/**
Expand Down
7 changes: 6 additions & 1 deletion lib/Cake/Test/TestCase/Database/Schema/MysqlSchemaTest.php
Expand Up @@ -543,6 +543,11 @@ public function testCreateSql() {
->addConstraint('primary', [
'type' => 'primary',
'columns' => ['id']
])
->options([
'engine' => 'InnoDB',
'charset' => 'utf8',
'collate' => 'utf8_general_ci',
]);

$expected = <<<SQL
Expand All @@ -552,7 +557,7 @@ public function testCreateSql() {
`body` TEXT,
`created` DATETIME,
PRIMARY KEY (`id`)
)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci
SQL;
$result = $table->createSql($connection);
$this->assertCount(1, $result);
Expand Down

0 comments on commit 2b90e7d

Please sign in to comment.