@@ -15,13 +15,16 @@ class CreateAuthTables extends Migration
1515 */
1616 private array $ tables ;
1717
18+ private array $ attributes ;
19+
1820 public function __construct (?Forge $ forge = null )
1921 {
2022 parent ::__construct ($ forge );
2123
2224 /** @var Auth $authConfig */
23- $ authConfig = config ('Auth ' );
24- $ this ->tables = $ authConfig ->tables ;
25+ $ authConfig = config ('Auth ' );
26+ $ this ->tables = $ authConfig ->tables ;
27+ $ this ->attributes = ($ this ->db ->getPlatform () === 'MySQLi ' ) ? ['ENGINE ' => 'InnoDB ' ] : [];
2528 }
2629
2730 public function up (): void
@@ -40,7 +43,7 @@ public function up(): void
4043 ]);
4144 $ this ->forge ->addPrimaryKey ('id ' );
4245 $ this ->forge ->addUniqueKey ('username ' );
43- $ this ->forge -> createTable ($ this ->tables ['users ' ]);
46+ $ this ->createTable ($ this ->tables ['users ' ]);
4447
4548 /*
4649 * Auth Identities Table
@@ -64,7 +67,7 @@ public function up(): void
6467 $ this ->forge ->addUniqueKey (['type ' , 'secret ' ]);
6568 $ this ->forge ->addKey ('user_id ' );
6669 $ this ->forge ->addForeignKey ('user_id ' , $ this ->tables ['users ' ], 'id ' , '' , 'CASCADE ' );
67- $ this ->forge -> createTable ($ this ->tables ['identities ' ]);
70+ $ this ->createTable ($ this ->tables ['identities ' ]);
6871
6972 /**
7073 * Auth Login Attempts Table
@@ -85,7 +88,7 @@ public function up(): void
8588 $ this ->forge ->addKey (['id_type ' , 'identifier ' ]);
8689 $ this ->forge ->addKey ('user_id ' );
8790 // NOTE: Do NOT delete the user_id or identifier when the user is deleted for security audits
88- $ this ->forge -> createTable ($ this ->tables ['logins ' ]);
91+ $ this ->createTable ($ this ->tables ['logins ' ]);
8992
9093 /*
9194 * Auth Token Login Attempts Table
@@ -105,7 +108,7 @@ public function up(): void
105108 $ this ->forge ->addKey (['id_type ' , 'identifier ' ]);
106109 $ this ->forge ->addKey ('user_id ' );
107110 // NOTE: Do NOT delete the user_id or identifier when the user is deleted for security audits
108- $ this ->forge -> createTable ($ this ->tables ['token_logins ' ]);
111+ $ this ->createTable ($ this ->tables ['token_logins ' ]);
109112
110113 /*
111114 * Auth Remember Tokens (remember-me) Table
@@ -123,7 +126,7 @@ public function up(): void
123126 $ this ->forge ->addPrimaryKey ('id ' );
124127 $ this ->forge ->addUniqueKey ('selector ' );
125128 $ this ->forge ->addForeignKey ('user_id ' , $ this ->tables ['users ' ], 'id ' , '' , 'CASCADE ' );
126- $ this ->forge -> createTable ($ this ->tables ['remember_tokens ' ]);
129+ $ this ->createTable ($ this ->tables ['remember_tokens ' ]);
127130
128131 // Groups Users Table
129132 $ this ->forge ->addField ([
@@ -134,7 +137,7 @@ public function up(): void
134137 ]);
135138 $ this ->forge ->addPrimaryKey ('id ' );
136139 $ this ->forge ->addForeignKey ('user_id ' , $ this ->tables ['users ' ], 'id ' , '' , 'CASCADE ' );
137- $ this ->forge -> createTable ($ this ->tables ['groups_users ' ]);
140+ $ this ->createTable ($ this ->tables ['groups_users ' ]);
138141
139142 // Users Permissions Table
140143 $ this ->forge ->addField ([
@@ -145,7 +148,7 @@ public function up(): void
145148 ]);
146149 $ this ->forge ->addPrimaryKey ('id ' );
147150 $ this ->forge ->addForeignKey ('user_id ' , $ this ->tables ['users ' ], 'id ' , '' , 'CASCADE ' );
148- $ this ->forge -> createTable ($ this ->tables ['permissions_users ' ]);
151+ $ this ->createTable ($ this ->tables ['permissions_users ' ]);
149152 }
150153
151154 // --------------------------------------------------------------------
@@ -164,4 +167,9 @@ public function down(): void
164167
165168 $ this ->db ->enableForeignKeyChecks ();
166169 }
170+
171+ private function createTable (string $ tableName ): void
172+ {
173+ $ this ->forge ->createTable ($ tableName , false , $ this ->attributes );
174+ }
167175}
0 commit comments