13
13
use Dms \Core \Persistence \Db \Schema \Table ;
14
14
use Dms \Core \Persistence \Db \Schema \Type ;
15
15
use Doctrine \DBAL \Schema \Schema ;
16
+ use Doctrine \DBAL \Platforms \AbstractPlatform ;
17
+ use Doctrine \DBAL \Platforms \MySqlPlatform ;
16
18
use Doctrine \DBAL \Schema \Table as DoctrineTable ;
17
19
use Doctrine \DBAL \Types \Type as DoctrineType ;
18
20
@@ -28,26 +30,27 @@ class DoctrineSchemaConverter
28
30
* Converts the database to the equivalent doctrine schema.
29
31
*
30
32
* @param Database $database
33
+ * @param AbstractPlatform $platform
31
34
*
32
35
* @return Schema
33
36
*/
34
- public function convertToDoctrineSchema (Database $ database ) : \Doctrine \DBAL \Schema \Schema
37
+ public function convertToDoctrineSchema (Database $ database, AbstractPlatform $ platform ) : \Doctrine \DBAL \Schema \Schema
35
38
{
36
39
$ schema = new Schema ();
37
40
38
41
foreach ($ database ->getTables () as $ table ) {
39
- $ this ->mapTable ($ schema , $ table );
42
+ $ this ->mapTable ($ schema , $ table, $ platform );
40
43
}
41
44
42
45
return $ schema ;
43
46
}
44
47
45
- private function mapTable (Schema $ schema , Table $ table )
48
+ private function mapTable (Schema $ schema , Table $ table, AbstractPlatform $ platform )
46
49
{
47
50
$ doctrineTable = $ schema ->createTable ($ table ->getName ());
48
51
49
52
foreach ($ table ->getColumns () as $ column ) {
50
- $ this ->mapColumn ($ doctrineTable , $ column );
53
+ $ this ->mapColumn ($ doctrineTable , $ column, $ platform );
51
54
}
52
55
53
56
if ($ table ->hasPrimaryKeyColumn ()) {
@@ -102,9 +105,9 @@ private function mapForeignKeyMode($mode)
102
105
ForeignKeyMode::validate ($ mode );
103
106
}
104
107
105
- private function mapColumn (DoctrineTable $ doctrineTable , Column $ column )
108
+ private function mapColumn (DoctrineTable $ doctrineTable , Column $ column, AbstractPlatform $ platform )
106
109
{
107
- list ($ typeName , $ options ) = $ this ->mapColumnType ($ column ->getType ());
110
+ list ($ typeName , $ options ) = $ this ->mapColumnType ($ column ->getType (), $ platform );
108
111
109
112
$ doctrineTable ->addColumn (
110
113
$ column ->getName (),
@@ -113,7 +116,7 @@ private function mapColumn(DoctrineTable $doctrineTable, Column $column)
113
116
);
114
117
}
115
118
116
- private function mapColumnType (Type \Type $ type )
119
+ private function mapColumnType (Type \Type $ type, AbstractPlatform $ platform )
117
120
{
118
121
$ options = [];
119
122
@@ -142,9 +145,14 @@ private function mapColumnType(Type\Type $type)
142
145
143
146
return [DoctrineType::DECIMAL , $ options ];
144
147
145
- case $ type instanceof Type \Enum:
148
+ case $ type instanceof Type \Enum && $ platform instanceof MySqlPlatform :
146
149
return [CustomEnumTypeGenerator::generate ($ type ->getOptions ()), $ options ];
147
150
151
+ case $ type instanceof Type \Enum:
152
+ $ options ['length ' ] = 255 ;
153
+
154
+ return [DoctrineType::STRING , $ options ];
155
+
148
156
case $ type instanceof Type \Integer:
149
157
$ options ['autoincrement ' ] = $ type ->isAutoIncrement ();
150
158
$ options ['unsigned ' ] = $ type ->isUnsigned ();
0 commit comments