php - Doctrine 自定义 MariaDB 平台
问题描述
我已经基于现有的自定义方法创建了CustomDbPlatform
扩展。我不能扩展,因为它是最后一堂课。MySqlPlatform
MariaDb1027Platform
getDefaultValueDeclarationSQL
MariaDbPlatform
class CustomDbPlatform extends MySqlPlatform
{
public function getJsonTypeDeclarationSQL(array $column): string
{
return 'LONGTEXT';
}
protected function getReservedKeywordsClass(): string
{
return MariaDb102Keywords::class;
}
protected function initializeDoctrineTypeMappings(): void
{
parent::initializeDoctrineTypeMappings();
$this->doctrineTypeMapping['json'] = Types::JSON;
}
public function getDefaultValueDeclarationSQL($column): string
{
if (isset($column['default'], $column['type'])) {
$default = $column['default'];
$type = $column['type'];
if ($type instanceof DateTimePrecisionType && stripos($default, $this->getCurrentTimestampSQL()) !== false) {
if (isset($column['length']) && $column['length'] > 0 && $column['length'] < 255) {
return ' DEFAULT ' . sprintf('%s(%d)', $this->getCurrentTimestampSQL(), $column['length']);
}
return ' DEFAULT ' . $this->getCurrentTimestampSQL();
}
}
return parent::getDefaultValueDeclarationSQL($column);
}
}
不幸的是,在模式更新期间,Doctrine 强制使用新的表列定义基本上更新整个模式。此问题是由MySqlSchemaManager
专门针对MariaDb1027Platform
.
if ($this->_platform instanceof MariaDb1027Platform) {
$columnDefault = $this->getMariaDb1027ColumnDefault($this->_platform, $tableColumn['default']);
} else {
$columnDefault = $tableColumn['default'];
}
我怎样才能让 Doctrine 承认我CustomDbPlatform
的身份MariaDb1027Platform
?制作自定义 SchemaManager 似乎有点过头了。
使用
- Symfony 4.4
- 教义 2
- 玛丽亚数据库 10.3
解决方案
如果要扩展MariaDb1027Platform
,唯一的方法是:
- 从https://github.com/doctrine/dbal/blob/3.1.x/src/Platforms/MariaDb1027Platform.php复制平台类文件,
- 地方在你的项目中
- 删除
final
千瓦 - 在从 DBAL lib 自动加载类之前加载此文件 - 您可以使用 composer autoload
files
部分
另外,我创建了 PR https://github.com/doctrine/dbal/pull/4909,看看维护者是否想正式支持这个。
推荐阅读
- clickhouse - 在 clickhouse 中保存十进制列中的值的意外行为
- java - 如何模拟鼠标指针?
- javascript - Firebase functions.httpsCallable(...).then 不是函数
- powerbi - PowerBi 计算的度量不受类别的影响
- c++ - 如何从组合框发出信号
- c++ - 为什么我的 Qt 程序在断言失败后继续运行?
- java - 在 android studio 中更改 build sdk 时出错
- ruby - watir 是否被阻止登录 Facebook?如果是这样,是否有另一种宝石可以做到这一点?
- c++ - 无法从 cso 文件创建顶点着色器(从 fx 文件创建)
- email - 有没有办法实现匿名电子邮件?