Added Blueprint::charset() and Blueprint::collation(). (#7070)

Co-authored-by: 李铭昕 <715557344@qq.com>
This commit is contained in:
lyan 2024-10-11 17:48:06 +08:00 committed by GitHub
parent f2a5d3e90e
commit e42bc9676f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 32 additions and 0 deletions

View File

@ -3,6 +3,7 @@
## Added
- [#7063](https://github.com/hyperf/hyperf/pull/7063) Added methods `nullableUuidMorphs` `uuidMorphs` and `nullableNumericMorphs` to `Hyperf\Database\Schema\Blueprint`.
- [#7070](https://github.com/hyperf/hyperf/pull/7070) Added `Blueprint::charset()` and `Blueprint::collation()`.
- [#7071](https://github.com/hyperf/hyperf/pull/7071) Added `Hyperf\Database\Schema\Blueprint::tinyText()`.
# v3.1.43 - 2024-10-10

View File

@ -120,6 +120,22 @@ class Blueprint
}
}
/**
* Specify the character set that should be used for the table.
*/
public function charset(string $charset): void
{
$this->charset = $charset;
}
/**
* Specify the collation that should be used for the table.
*/
public function collation(string $collation): void
{
$this->collation = $collation;
}
/**
* Get the raw SQL statements for the blueprint.
*

View File

@ -216,6 +216,21 @@ class MySqlSchemaGrammarTest extends TestCase
$this->assertCount(1, $statements);
$this->assertSame("create table `users` (`id` int unsigned not null auto_increment primary key, `email` varchar(255) character set utf8mb4 collate 'utf8mb4_unicode_ci' not null) default character set utf8 collate 'utf8_unicode_ci'", $statements[0]);
$blueprint = new Blueprint('users');
$blueprint->create();
$blueprint->increments('id');
$blueprint->string('email');
$blueprint->charset('utf8mb4');
$blueprint->collation('utf8mb4_unicode_ci');
$conn = $this->getConnection();
$conn->shouldReceive('getConfig')->once()->with('engine')->andReturn(null);
$statements = $blueprint->toSql($conn, $this->getGrammar());
$this->assertCount(1, $statements);
$this->assertSame("create table `users` (`id` int unsigned not null auto_increment primary key, `email` varchar(255) not null) default character set utf8mb4 collate 'utf8mb4_unicode_ci'", $statements[0]);
}
public function testBasicCreateTableWithPrefix()