8
8
namespace KitLoong \MigrationsGenerator \Repositories ;
9
9
10
10
use KitLoong \MigrationsGenerator \MigrationsGeneratorSetting ;
11
+ use KitLoong \MigrationsGenerator \Schema \MySQL \ShowColumn ;
11
12
12
13
class MySQLRepository extends Repository
13
14
{
@@ -21,18 +22,21 @@ public function getDatabaseCollation(): array
21
22
{
22
23
$ setting = app (MigrationsGeneratorSetting::class);
23
24
$ columns = $ setting ->getConnection ()->select ("SELECT @@character_set_database, @@collation_database " );
24
- return ['charset ' => $ columns [0 ]->{'@@character_set_database ' }, 'collation ' => $ columns [0 ]->{'@@collation_database ' }];
25
+ return [
26
+ 'charset ' => $ columns [0 ]->{'@@character_set_database ' }, 'collation ' => $ columns [0 ]->{'@@collation_database ' }
27
+ ];
25
28
}
26
29
27
30
public function getEnumPresetValues (string $ table , string $ columnName ): ?string
28
31
{
29
32
/** @var MigrationsGeneratorSetting $setting */
30
33
$ setting = app (MigrationsGeneratorSetting::class);
31
34
32
- $ column = $ setting ->getConnection ()->select ("SHOW COLUMNS FROM ` $ {table}` where Field = ' $ {columnName}' AND Type LIKE 'enum(%' " );
33
- if (count ($ column ) > 0 ) {
35
+ $ columns = $ setting ->getConnection ()->select ("SHOW COLUMNS FROM ` $ {table}` where Field = ' $ {columnName}' AND Type LIKE 'enum(%' " );
36
+ if (count ($ columns ) > 0 ) {
37
+ $ showColumn = new ShowColumn ($ columns [0 ]);
34
38
return substr (
35
- str_replace ('enum( ' , '[ ' , $ this ->spaceAfterComma ($ column [ 0 ]-> Type )),
39
+ str_replace ('enum( ' , '[ ' , $ this ->spaceAfterComma ($ showColumn -> getType () )),
36
40
0 ,
37
41
-1
38
42
).'] ' ;
@@ -45,10 +49,11 @@ public function getSetPresetValues(string $table, string $columnName): ?string
45
49
/** @var MigrationsGeneratorSetting $setting */
46
50
$ setting = app (MigrationsGeneratorSetting::class);
47
51
48
- $ column = $ setting ->getConnection ()->select ("SHOW COLUMNS FROM ` $ {table}` where Field = ' $ {columnName}' AND Type LIKE 'set(%' " );
49
- if (count ($ column ) > 0 ) {
52
+ $ columns = $ setting ->getConnection ()->select ("SHOW COLUMNS FROM ` $ {table}` where Field = ' $ {columnName}' AND Type LIKE 'set(%' " );
53
+ if (count ($ columns ) > 0 ) {
54
+ $ showColumn = new ShowColumn ($ columns [0 ]);
50
55
return substr (
51
- str_replace ('set( ' , '[ ' , $ this ->spaceAfterComma ($ column [ 0 ]-> Type )),
56
+ str_replace ('set( ' , '[ ' , $ this ->spaceAfterComma ($ showColumn -> getType () )),
52
57
0 ,
53
58
-1
54
59
).'] ' ;
0 commit comments