@@ -16,17 +16,15 @@ class CreateAuthTables extends Migration
16
16
private array $ tables ;
17
17
18
18
private array $ attributes ;
19
- private bool $ ifNotExists ;
20
19
21
20
public function __construct (?Forge $ forge = null )
22
21
{
23
22
parent ::__construct ($ forge );
24
23
25
24
/** @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 ' ] : [];
30
28
}
31
29
32
30
public function up (): void
@@ -45,7 +43,7 @@ public function up(): void
45
43
]);
46
44
$ this ->forge ->addPrimaryKey ('id ' );
47
45
$ this ->forge ->addUniqueKey ('username ' );
48
- $ this ->forge -> createTable ($ this ->tables ['users ' ], $ this -> ifNotExists , $ this -> attributes );
46
+ $ this ->createTable ($ this ->tables ['users ' ]);
49
47
50
48
/*
51
49
* Auth Identities Table
@@ -69,7 +67,7 @@ public function up(): void
69
67
$ this ->forge ->addUniqueKey (['type ' , 'secret ' ]);
70
68
$ this ->forge ->addKey ('user_id ' );
71
69
$ 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 ' ]);
73
71
74
72
/**
75
73
* Auth Login Attempts Table
@@ -90,7 +88,7 @@ public function up(): void
90
88
$ this ->forge ->addKey (['id_type ' , 'identifier ' ]);
91
89
$ this ->forge ->addKey ('user_id ' );
92
90
// 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 ' ]);
94
92
95
93
/*
96
94
* Auth Token Login Attempts Table
@@ -110,7 +108,7 @@ public function up(): void
110
108
$ this ->forge ->addKey (['id_type ' , 'identifier ' ]);
111
109
$ this ->forge ->addKey ('user_id ' );
112
110
// 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 ' ]);
114
112
115
113
/*
116
114
* Auth Remember Tokens (remember-me) Table
@@ -128,7 +126,7 @@ public function up(): void
128
126
$ this ->forge ->addPrimaryKey ('id ' );
129
127
$ this ->forge ->addUniqueKey ('selector ' );
130
128
$ 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 ' ]);
132
130
133
131
// Groups Users Table
134
132
$ this ->forge ->addField ([
@@ -139,7 +137,7 @@ public function up(): void
139
137
]);
140
138
$ this ->forge ->addPrimaryKey ('id ' );
141
139
$ 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 ' ]);
143
141
144
142
// Users Permissions Table
145
143
$ this ->forge ->addField ([
@@ -150,7 +148,7 @@ public function up(): void
150
148
]);
151
149
$ this ->forge ->addPrimaryKey ('id ' );
152
150
$ 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 ' ]);
154
152
}
155
153
156
154
// --------------------------------------------------------------------
@@ -169,4 +167,9 @@ public function down(): void
169
167
170
168
$ this ->db ->enableForeignKeyChecks ();
171
169
}
170
+
171
+ private function createTable (string $ tableName ): void
172
+ {
173
+ $ this ->forge ->createTable ($ tableName , false , $ this ->attributes );
174
+ }
172
175
}
0 commit comments