DrizzleSchemaManager.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace Doctrine\DBAL\Schema;
  3. use Doctrine\DBAL\Types\Type;
  4. use function explode;
  5. use function strtolower;
  6. use function trim;
  7. /**
  8. * Schema manager for the Drizzle RDBMS.
  9. */
  10. class DrizzleSchemaManager extends AbstractSchemaManager
  11. {
  12. /**
  13. * {@inheritdoc}
  14. */
  15. protected function _getPortableTableColumnDefinition($tableColumn)
  16. {
  17. $dbType = strtolower($tableColumn['DATA_TYPE']);
  18. $type = $this->_platform->getDoctrineTypeMapping($dbType);
  19. $type = $this->extractDoctrineTypeFromComment($tableColumn['COLUMN_COMMENT'], $type);
  20. $tableColumn['COLUMN_COMMENT'] = $this->removeDoctrineTypeFromComment($tableColumn['COLUMN_COMMENT'], $type);
  21. $options = [
  22. 'notnull' => ! (bool) $tableColumn['IS_NULLABLE'],
  23. 'length' => (int) $tableColumn['CHARACTER_MAXIMUM_LENGTH'],
  24. 'default' => $tableColumn['COLUMN_DEFAULT'] ?? null,
  25. 'autoincrement' => (bool) $tableColumn['IS_AUTO_INCREMENT'],
  26. 'scale' => (int) $tableColumn['NUMERIC_SCALE'],
  27. 'precision' => (int) $tableColumn['NUMERIC_PRECISION'],
  28. 'comment' => isset($tableColumn['COLUMN_COMMENT']) && $tableColumn['COLUMN_COMMENT'] !== ''
  29. ? $tableColumn['COLUMN_COMMENT']
  30. : null,
  31. ];
  32. $column = new Column($tableColumn['COLUMN_NAME'], Type::getType($type), $options);
  33. if (! empty($tableColumn['COLLATION_NAME'])) {
  34. $column->setPlatformOption('collation', $tableColumn['COLLATION_NAME']);
  35. }
  36. return $column;
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. protected function _getPortableDatabaseDefinition($database)
  42. {
  43. return $database['SCHEMA_NAME'];
  44. }
  45. /**
  46. * {@inheritdoc}
  47. */
  48. protected function _getPortableTableDefinition($table)
  49. {
  50. return $table['TABLE_NAME'];
  51. }
  52. /**
  53. * {@inheritdoc}
  54. */
  55. public function _getPortableTableForeignKeyDefinition($tableForeignKey)
  56. {
  57. $columns = [];
  58. foreach (explode(',', $tableForeignKey['CONSTRAINT_COLUMNS']) as $value) {
  59. $columns[] = trim($value, ' `');
  60. }
  61. $refColumns = [];
  62. foreach (explode(',', $tableForeignKey['REFERENCED_TABLE_COLUMNS']) as $value) {
  63. $refColumns[] = trim($value, ' `');
  64. }
  65. return new ForeignKeyConstraint(
  66. $columns,
  67. $tableForeignKey['REFERENCED_TABLE_NAME'],
  68. $refColumns,
  69. $tableForeignKey['CONSTRAINT_NAME'],
  70. [
  71. 'onUpdate' => $tableForeignKey['UPDATE_RULE'],
  72. 'onDelete' => $tableForeignKey['DELETE_RULE'],
  73. ]
  74. );
  75. }
  76. /**
  77. * {@inheritdoc}
  78. */
  79. protected function _getPortableTableIndexesList($tableIndexes, $tableName = null)
  80. {
  81. $indexes = [];
  82. foreach ($tableIndexes as $k) {
  83. $k['primary'] = (bool) $k['primary'];
  84. $indexes[] = $k;
  85. }
  86. return parent::_getPortableTableIndexesList($indexes, $tableName);
  87. }
  88. }