Skip to content
Permalink
Browse files

Add table options to MySQL.

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 2b90e7dbc75cccae5f7b1fc76eba57bf6fcbe049
@@ -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];
}
/**
@@ -543,6 +543,11 @@ public function testCreateSql() {
->addConstraint('primary', [
'type' => 'primary',
'columns' => ['id']
])
->options([
'engine' => 'InnoDB',
'charset' => 'utf8',
'collate' => 'utf8_general_ci',
]);
$expected = <<<SQL
@@ -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);

0 comments on commit 2b90e7d

Please sign in to comment.
You can’t perform that action at this time.