diff --git a/src/Illuminate/Database/Schema/Grammars/ChangeColumn.php b/src/Illuminate/Database/Schema/Grammars/ChangeColumn.php index 70ec66652eb9..9579222991b7 100644 --- a/src/Illuminate/Database/Schema/Grammars/ChangeColumn.php +++ b/src/Illuminate/Database/Schema/Grammars/ChangeColumn.php @@ -121,7 +121,7 @@ protected static function getDoctrineColumnChangeOptions(Fluent $fluent) { $options = ['type' => static::getDoctrineColumnType($fluent['type'])]; - if (in_array($fluent['type'], ['text', 'mediumText', 'longText'])) { + if (in_array($fluent['type'], ['tinyText', 'text', 'mediumText', 'longText'])) { $options['length'] = static::calculateDoctrineTextLength($fluent['type']); } @@ -152,10 +152,11 @@ protected static function getDoctrineColumnType($type) return Type::getType(match ($type) { 'biginteger' => 'bigint', 'smallinteger' => 'smallint', - 'mediumtext', 'longtext' => 'text', + 'tinytext', 'mediumtext', 'longtext' => 'text', 'binary' => 'blob', 'uuid' => 'guid', 'char' => 'string', + 'double' => 'float', default => $type, }); } @@ -169,6 +170,7 @@ protected static function getDoctrineColumnType($type) protected static function calculateDoctrineTextLength($type) { return match ($type) { + 'tinyText' => 1, 'mediumText' => 65535 + 1, 'longText' => 16777215 + 1, default => 255 + 1, @@ -197,6 +199,7 @@ protected static function doesntNeedCharacterOptions($type) 'mediumInteger', 'smallInteger', 'time', + 'timestamp', 'tinyInteger', ]); } diff --git a/tests/Database/DatabaseSchemaBlueprintIntegrationTest.php b/tests/Database/DatabaseSchemaBlueprintIntegrationTest.php index 0e990ecd848f..247b6c1d1516 100644 --- a/tests/Database/DatabaseSchemaBlueprintIntegrationTest.php +++ b/tests/Database/DatabaseSchemaBlueprintIntegrationTest.php @@ -149,6 +149,29 @@ public function testChangingCharColumnsWork() $this->assertEquals($expected, $queries); } + public function testChangingDoubleColumnsWork() + { + $this->db->connection()->getSchemaBuilder()->create('products', function ($table) { + $table->integer('price'); + }); + + $blueprint = new Blueprint('products', function ($table) { + $table->double('price')->change(); + }); + + $queries = $blueprint->toSql($this->db->connection(), new SQLiteGrammar); + + $expected = [ + 'CREATE TEMPORARY TABLE __temp__products AS SELECT price FROM products', + 'DROP TABLE products', + 'CREATE TABLE products (price DOUBLE PRECISION NOT NULL)', + 'INSERT INTO products (price) SELECT price FROM __temp__products', + 'DROP TABLE __temp__products', + ]; + + $this->assertEquals($expected, $queries); + } + public function testRenameIndexWorks() { $this->db->connection()->getSchemaBuilder()->create('users', function ($table) { diff --git a/tests/Integration/Database/DBAL/TimestampTypeTest.php b/tests/Integration/Database/DBAL/TimestampTypeTest.php index b3c9fc3e2875..d7cec38c53b0 100644 --- a/tests/Integration/Database/DBAL/TimestampTypeTest.php +++ b/tests/Integration/Database/DBAL/TimestampTypeTest.php @@ -59,4 +59,25 @@ public function testChangeTimestampColumnToDatetimeColumn() ? $this->assertSame('timestamp', Schema::getColumnType('test', 'timestamp_to_datetime')) : $this->assertSame('datetime', Schema::getColumnType('test', 'timestamp_to_datetime')); } + + public function testChangeStringColumnToTimestampColumn() + { + if ($this->driver !== 'mysql') { + $this->markTestSkipped('Test requires a MySQL connection.'); + } + + Schema::create('test', function (Blueprint $table) { + $table->string('string_to_timestamp'); + }); + + $blueprint = new Blueprint('test', function ($table) { + $table->timestamp('string_to_timestamp')->nullable(true)->change(); + }); + + $queries = $blueprint->toSql($this->getConnection(), $this->getConnection()->getSchemaGrammar()); + + $expected = ['ALTER TABLE test CHANGE string_to_timestamp string_to_timestamp TIMESTAMP NULL DEFAULT NULL']; + + $this->assertEquals($expected, $queries); + } } diff --git a/tests/Integration/Database/SchemaBuilderTest.php b/tests/Integration/Database/SchemaBuilderTest.php index 1b5a5401c2e2..a39f2166a85c 100644 --- a/tests/Integration/Database/SchemaBuilderTest.php +++ b/tests/Integration/Database/SchemaBuilderTest.php @@ -87,4 +87,29 @@ public function testRegisterCustomDoctrineTypeASecondTime() $this->assertArrayHasKey(TinyInteger::NAME, Type::getTypesMap()); $this->assertSame('tinyinteger', Schema::getColumnType('test', 'test_column')); } + + public function testChangeToTextColumn() + { + if ($this->driver !== 'mysql') { + $this->markTestSkipped('Test requires a MySQL connection.'); + } + + Schema::create('test', function (Blueprint $table) { + $table->integer('test_column'); + }); + + foreach (['tinyText', 'text', 'mediumText', 'longText'] as $type) { + $blueprint = new Blueprint('test', function ($table) use ($type) { + $table->$type('test_column')->change(); + }); + + $queries = $blueprint->toSql($this->getConnection(), $this->getConnection()->getSchemaGrammar()); + + $uppercase = strtoupper($type); + + $expected = ["ALTER TABLE test CHANGE test_column test_column $uppercase NOT NULL"]; + + $this->assertEquals($expected, $queries); + } + } }