11<?php
22
33use think \migration \Migrator ;
4+ use Phinx \Config \Config ;
45use Phinx \Db \Adapter \AdapterFactory ;
56
67class CreateRulesTable extends Migrator
@@ -10,17 +11,19 @@ class CreateRulesTable extends Migrator
1011 *
1112 * @return void
1213 */
13- protected function init ()
14+ public function init ()
1415 {
1516 $ options = $ this ->getDbConfig ();
16-
17+
1718 $ adapter = AdapterFactory::instance ()->getAdapter ($ options ['adapter ' ], $ options );
18-
19+
1920 if ($ adapter ->hasOption ('table_prefix ' ) || $ adapter ->hasOption ('table_suffix ' )) {
2021 $ adapter = AdapterFactory::instance ()->getWrapper ('prefix ' , $ adapter );
2122 }
2223
23- $ this ->setAdapter ( $ adapter );
24+ $ adapter ->connect ();
25+
26+ $ this ->setAdapter ($ adapter );
2427 }
2528
2629 /**
@@ -43,6 +46,7 @@ protected function getDbConfig(): array
4346 'pass ' => $ config ['password ' ],
4447 'port ' => $ config ['hostport ' ],
4548 'charset ' => $ config ['charset ' ],
49+ 'suffix ' => $ config ['suffix ' ] ?? '' ,
4650 'table_prefix ' => $ config ['prefix ' ],
4751 ];
4852 } else {
@@ -54,13 +58,15 @@ protected function getDbConfig(): array
5458 'pass ' => explode (', ' , $ config ['password ' ])[0 ],
5559 'port ' => explode (', ' , $ config ['hostport ' ])[0 ],
5660 'charset ' => explode (', ' , $ config ['charset ' ])[0 ],
61+ 'suffix ' => explode (', ' , $ config ['suffix ' ] ?? '' )[0 ],
5762 'table_prefix ' => explode (', ' , $ config ['prefix ' ])[0 ],
5863 ];
5964 }
6065
6166 $ table = config ('database.migration_table ' , 'migrations ' );
6267
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 ;
6470
6571 return $ dbConfig ;
6672 }
@@ -104,6 +110,6 @@ public function down()
104110 {
105111 $ default = config ('tauthz.default ' );
106112 $ table = $ this ->table (config ('tauthz.enforcers. ' .$ default .'.database.rules_name ' ));
107- $ table ->drop ();
113+ $ table ->drop ()-> save () ;
108114 }
109115}
0 commit comments