1
1
<?php
2
2
3
3
use think \migration \Migrator ;
4
+ use Phinx \Config \Config ;
4
5
use Phinx \Db \Adapter \AdapterFactory ;
5
6
6
7
class CreateRulesTable extends Migrator
@@ -10,17 +11,19 @@ class CreateRulesTable extends Migrator
10
11
*
11
12
* @return void
12
13
*/
13
- protected function init ()
14
+ public function init ()
14
15
{
15
16
$ options = $ this ->getDbConfig ();
16
-
17
+
17
18
$ adapter = AdapterFactory::instance ()->getAdapter ($ options ['adapter ' ], $ options );
18
-
19
+
19
20
if ($ adapter ->hasOption ('table_prefix ' ) || $ adapter ->hasOption ('table_suffix ' )) {
20
21
$ adapter = AdapterFactory::instance ()->getWrapper ('prefix ' , $ adapter );
21
22
}
22
23
23
- $ this ->setAdapter ( $ adapter );
24
+ $ adapter ->connect ();
25
+
26
+ $ this ->setAdapter ($ adapter );
24
27
}
25
28
26
29
/**
@@ -43,6 +46,7 @@ protected function getDbConfig(): array
43
46
'pass ' => $ config ['password ' ],
44
47
'port ' => $ config ['hostport ' ],
45
48
'charset ' => $ config ['charset ' ],
49
+ 'suffix ' => $ config ['suffix ' ] ?? '' ,
46
50
'table_prefix ' => $ config ['prefix ' ],
47
51
];
48
52
} else {
@@ -54,13 +58,15 @@ protected function getDbConfig(): array
54
58
'pass ' => explode (', ' , $ config ['password ' ])[0 ],
55
59
'port ' => explode (', ' , $ config ['hostport ' ])[0 ],
56
60
'charset ' => explode (', ' , $ config ['charset ' ])[0 ],
61
+ 'suffix ' => explode (', ' , $ config ['suffix ' ] ?? '' )[0 ],
57
62
'table_prefix ' => explode (', ' , $ config ['prefix ' ])[0 ],
58
63
];
59
64
}
60
65
61
66
$ table = config ('database.migration_table ' , 'migrations ' );
62
67
63
- $ dbConfig ['default_migration_table ' ] = $ dbConfig ['table_prefix ' ] . $ table ;
68
+ $ dbConfig ['migration_table ' ] = $ dbConfig ['table_prefix ' ] . $ table ;
69
+ $ dbConfig ['version_order ' ] = Config::VERSION_ORDER_CREATION_TIME ;
64
70
65
71
return $ dbConfig ;
66
72
}
@@ -104,6 +110,6 @@ public function down()
104
110
{
105
111
$ default = config ('tauthz.default ' );
106
112
$ table = $ this ->table (config ('tauthz.enforcers. ' .$ default .'.database.rules_name ' ));
107
- $ table ->drop ();
113
+ $ table ->drop ()-> save () ;
108
114
}
109
115
}
0 commit comments