Commit 73f38e72 authored by AlterTable's avatar AlterTable

Add column charset for MySql

parent df4071e1
......@@ -953,6 +953,14 @@ SQL
return $this->getUnsignedDeclaration($columnDef) . $autoinc;
}
/**
* {@inheritDoc}
*/
public function getColumnCharsetDeclarationSQL($charset)
{
return 'CHARACTER SET ' . $charset;
}
/**
* {@inheritDoc}
*/
......
......@@ -192,6 +192,9 @@ class MySqlSchemaManager extends AbstractSchemaManager
$column = new Column($tableColumn['field'], Type::getType($type), $options);
if (isset($tableColumn['characterset'])) {
$column->setPlatformOption('charset', $tableColumn['characterset']);
}
if (isset($tableColumn['collation'])) {
$column->setPlatformOption('collation', $tableColumn['collation']);
}
......
......@@ -201,6 +201,59 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
self::assertFalse($onlineTable->getColumn('def_blob_null')->getNotnull());
}
public function testColumnCharset()
{
$table = new Table('test_column_charset');
$table->addColumn('id', 'integer');
$table->addColumn('no_charset', 'text');
$table->addColumn('foo', 'text')->setPlatformOption('charset', 'ascii');
$table->addColumn('bar', 'text')->setPlatformOption('charset', 'latin1');
$this->schemaManager->dropAndCreateTable($table);
$columns = $this->schemaManager->listTableColumns('test_column_charset');
self::assertFalse($columns['id']->hasPlatformOption('charset'));
self::assertEquals('utf8', $columns['no_charset']->getPlatformOption('charset'));
self::assertEquals('ascii', $columns['foo']->getPlatformOption('charset'));
self::assertEquals('latin1', $columns['bar']->getPlatformOption('charset'));
}
public function testAlterColumnCharset()
{
$tableName = 'test_alter_column_charset';
$table = new Table($tableName);
$table->addColumn('col_text', 'text')->setPlatformOption('charset', 'utf8');
$this->schemaManager->dropAndCreateTable($table);
$diffTable = clone $table;
$diffTable->getColumn('col_text')->setPlatformOption('charset', 'ascii');
$comparator = new Comparator();
$this->schemaManager->alterTable($comparator->diffTable($table, $diffTable));
$table = $this->schemaManager->listTableDetails($tableName);
self::assertEquals('ascii', $table->getColumn('col_text')->getPlatformOption('charset'));
}
public function testColumnCharsetChange()
{
$table = new Table('test_column_charset_change');
$table->addColumn('col_string', 'string')->setLength(100)->setNotnull(true)->setPlatformOption('charset', 'utf8');
$diffTable = clone $table;
$diffTable->getColumn('col_string')->setPlatformOption('charset', 'ascii');
$fromSchema = new Schema([$table]);
$toSchema = new Schema([$diffTable]);
$diff = $fromSchema->getMigrateToSql($toSchema, $this->connection->getDatabasePlatform());
self::assertContains('ALTER TABLE test_column_charset_change CHANGE col_string col_string VARCHAR(100) CHARACTER SET ascii NOT NULL', $diff);
}
public function testColumnCollation()
{
$table = new Table('test_collation');
......
......@@ -905,6 +905,14 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
self::assertNotContains('DATABASE()', $sql);
}
public function testColumnCharsetDeclarationSQL() : void
{
self::assertSame(
'CHARACTER SET ascii',
$this->platform->getColumnCharsetDeclarationSQL('ascii')
);
}
public function testSupportsColumnCollation() : void
{
self::assertTrue($this->platform->supportsColumnCollation());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment