@@ -15,13 +15,16 @@ class CreateAuthTables extends Migration
15
15
*/
16
16
private array $ tables ;
17
17
18
+ private array $ attributes ;
19
+
18
20
public function __construct (?Forge $ forge = null )
19
21
{
20
22
parent ::__construct ($ forge );
21
23
22
24
/** @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 ' ] : [];
25
28
}
26
29
27
30
public function up (): void
@@ -40,7 +43,7 @@ public function up(): void
40
43
]);
41
44
$ this ->forge ->addPrimaryKey ('id ' );
42
45
$ this ->forge ->addUniqueKey ('username ' );
43
- $ this ->forge -> createTable ($ this ->tables ['users ' ]);
46
+ $ this ->createTable ($ this ->tables ['users ' ]);
44
47
45
48
/*
46
49
* Auth Identities Table
@@ -64,7 +67,7 @@ public function up(): void
64
67
$ this ->forge ->addUniqueKey (['type ' , 'secret ' ]);
65
68
$ this ->forge ->addKey ('user_id ' );
66
69
$ this ->forge ->addForeignKey ('user_id ' , $ this ->tables ['users ' ], 'id ' , '' , 'CASCADE ' );
67
- $ this ->forge -> createTable ($ this ->tables ['identities ' ]);
70
+ $ this ->createTable ($ this ->tables ['identities ' ]);
68
71
69
72
/**
70
73
* Auth Login Attempts Table
@@ -85,7 +88,7 @@ public function up(): void
85
88
$ this ->forge ->addKey (['id_type ' , 'identifier ' ]);
86
89
$ this ->forge ->addKey ('user_id ' );
87
90
// 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 ' ]);
89
92
90
93
/*
91
94
* Auth Token Login Attempts Table
@@ -105,7 +108,7 @@ public function up(): void
105
108
$ this ->forge ->addKey (['id_type ' , 'identifier ' ]);
106
109
$ this ->forge ->addKey ('user_id ' );
107
110
// 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 ' ]);
109
112
110
113
/*
111
114
* Auth Remember Tokens (remember-me) Table
@@ -123,7 +126,7 @@ public function up(): void
123
126
$ this ->forge ->addPrimaryKey ('id ' );
124
127
$ this ->forge ->addUniqueKey ('selector ' );
125
128
$ 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 ' ]);
127
130
128
131
// Groups Users Table
129
132
$ this ->forge ->addField ([
@@ -134,7 +137,7 @@ public function up(): void
134
137
]);
135
138
$ this ->forge ->addPrimaryKey ('id ' );
136
139
$ 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 ' ]);
138
141
139
142
// Users Permissions Table
140
143
$ this ->forge ->addField ([
@@ -145,7 +148,7 @@ public function up(): void
145
148
]);
146
149
$ this ->forge ->addPrimaryKey ('id ' );
147
150
$ 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 ' ]);
149
152
}
150
153
151
154
// --------------------------------------------------------------------
@@ -164,4 +167,9 @@ public function down(): void
164
167
165
168
$ this ->db ->enableForeignKeyChecks ();
166
169
}
170
+
171
+ private function createTable (string $ tableName ): void
172
+ {
173
+ $ this ->forge ->createTable ($ tableName , false , $ this ->attributes );
174
+ }
167
175
}
0 commit comments