@@ -16,17 +16,15 @@ class CreateAuthTables extends Migration
1616 private array $ tables ;
1717
1818 private array $ attributes ;
19- private bool $ ifNotExists ;
2019
2120 public function __construct (?Forge $ forge = null )
2221 {
2322 parent ::__construct ($ forge );
2423
2524 /** @var Auth $authConfig */
26- $ authConfig = config ('Auth ' );
27- $ this ->tables = $ authConfig ->tables ;
28- $ this ->ifNotExists = false ;
29- $ this ->attributes = ($ this ->db ->getPlatform () === 'MySQLi ' ) ? ['ENGINE ' => 'InnoDB ' ] : [];
25+ $ authConfig = config ('Auth ' );
26+ $ this ->tables = $ authConfig ->tables ;
27+ $ this ->attributes = ($ this ->db ->getPlatform () === 'MySQLi ' ) ? ['ENGINE ' => 'InnoDB ' ] : [];
3028 }
3129
3230 public function up (): void
@@ -45,7 +43,7 @@ public function up(): void
4543 ]);
4644 $ this ->forge ->addPrimaryKey ('id ' );
4745 $ this ->forge ->addUniqueKey ('username ' );
48- $ this ->forge -> createTable ($ this ->tables ['users ' ], $ this -> ifNotExists , $ this -> attributes );
46+ $ this ->createTable ($ this ->tables ['users ' ]);
4947
5048 /*
5149 * Auth Identities Table
@@ -69,7 +67,7 @@ public function up(): void
6967 $ this ->forge ->addUniqueKey (['type ' , 'secret ' ]);
7068 $ this ->forge ->addKey ('user_id ' );
7169 $ this ->forge ->addForeignKey ('user_id ' , $ this ->tables ['users ' ], 'id ' , '' , 'CASCADE ' );
72- $ this ->forge -> createTable ($ this ->tables ['identities ' ], $ this -> ifNotExists , $ this -> attributes );
70+ $ this ->createTable ($ this ->tables ['identities ' ]);
7371
7472 /**
7573 * Auth Login Attempts Table
@@ -90,7 +88,7 @@ public function up(): void
9088 $ this ->forge ->addKey (['id_type ' , 'identifier ' ]);
9189 $ this ->forge ->addKey ('user_id ' );
9290 // NOTE: Do NOT delete the user_id or identifier when the user is deleted for security audits
93- $ this ->forge -> createTable ($ this ->tables ['logins ' ], $ this -> ifNotExists , $ this -> attributes );
91+ $ this ->createTable ($ this ->tables ['logins ' ]);
9492
9593 /*
9694 * Auth Token Login Attempts Table
@@ -110,7 +108,7 @@ public function up(): void
110108 $ this ->forge ->addKey (['id_type ' , 'identifier ' ]);
111109 $ this ->forge ->addKey ('user_id ' );
112110 // NOTE: Do NOT delete the user_id or identifier when the user is deleted for security audits
113- $ this ->forge -> createTable ($ this ->tables ['token_logins ' ], $ this -> ifNotExists , $ this -> attributes );
111+ $ this ->createTable ($ this ->tables ['token_logins ' ]);
114112
115113 /*
116114 * Auth Remember Tokens (remember-me) Table
@@ -128,7 +126,7 @@ public function up(): void
128126 $ this ->forge ->addPrimaryKey ('id ' );
129127 $ this ->forge ->addUniqueKey ('selector ' );
130128 $ this ->forge ->addForeignKey ('user_id ' , $ this ->tables ['users ' ], 'id ' , '' , 'CASCADE ' );
131- $ this ->forge -> createTable ($ this ->tables ['remember_tokens ' ], $ this -> ifNotExists , $ this -> attributes );
129+ $ this ->createTable ($ this ->tables ['remember_tokens ' ]);
132130
133131 // Groups Users Table
134132 $ this ->forge ->addField ([
@@ -139,7 +137,7 @@ public function up(): void
139137 ]);
140138 $ this ->forge ->addPrimaryKey ('id ' );
141139 $ this ->forge ->addForeignKey ('user_id ' , $ this ->tables ['users ' ], 'id ' , '' , 'CASCADE ' );
142- $ this ->forge -> createTable ($ this ->tables ['groups_users ' ], $ this -> ifNotExists , $ this -> attributes );
140+ $ this ->createTable ($ this ->tables ['groups_users ' ]);
143141
144142 // Users Permissions Table
145143 $ this ->forge ->addField ([
@@ -150,7 +148,7 @@ public function up(): void
150148 ]);
151149 $ this ->forge ->addPrimaryKey ('id ' );
152150 $ this ->forge ->addForeignKey ('user_id ' , $ this ->tables ['users ' ], 'id ' , '' , 'CASCADE ' );
153- $ this ->forge -> createTable ($ this ->tables ['permissions_users ' ], $ this -> ifNotExists , $ this -> attributes );
151+ $ this ->createTable ($ this ->tables ['permissions_users ' ]);
154152 }
155153
156154 // --------------------------------------------------------------------
@@ -169,4 +167,9 @@ public function down(): void
169167
170168 $ this ->db ->enableForeignKeyChecks ();
171169 }
170+
171+ private function createTable (string $ tableName ): void
172+ {
173+ $ this ->forge ->createTable ($ tableName , false , $ this ->attributes );
174+ }
172175}
0 commit comments