@@ -17,10 +17,10 @@ public function up()
1717 Schema::create ('two_factor_auths ' , function (Blueprint $ table ) {
1818 $ table ->string ('id ' )->nullable ();
1919
20- if ($ this ->isUnsignedInteger ()) {
21- $ table ->unsignedInteger ('user_id ' );
22- } else {
20+ if ($ this ->useBigInt ()) {
2321 $ table ->unsignedBigInteger ('user_id ' );
22+ } else {
23+ $ table ->unsignedInteger ('user_id ' );
2424 }
2525
2626 $ table ->foreign ('user_id ' )->references ('id ' )->on ('users ' )->onDelete ('cascade ' );
@@ -39,33 +39,13 @@ public function down()
3939 }
4040
4141 /**
42- * Determine if the column type for "user_id" should be of type "unsignedInteger"
43- * using the type of "id" on "users" as a reference.
44- *
45- * Why do we do this?
46- *
47- * Laravel 5.8 changed the type of "id" on "users" from "increments"
48- * to "bigIncrements". Hence, we potentially could run into trouble if we
49- * don't support the following two potential scenarios
50- *
51- * 1. We update from 5.7 to 5.8, but decide to keep using "increments"
52- * 2. We start a fresh Laravel project which uses "bigIncrements" by default
53- *
54- * The only way to account for both scenarios in a reliable way is to check
55- * the type of "id" on "users" before we create our foreign key.
56- *
57- * Why is this not ideal?
58- *
59- * 1. There now is a dependency on doctrine/dbal
60- * 2. We now have to use conditional logic in our migration file
42+ * Determine if the type of the "user_id" column should be of type
43+ * "unsignedBigInteger".
6144 *
6245 * @return bool
6346 */
64- private function isUnsignedInteger ()
47+ private function useBigInt ()
6548 {
66- return DB ::getDoctrineSchemaManager ()
67- ->listTableDetails ('users ' )
68- ->getColumn ('id ' )
69- ->getType () instanceof \Doctrine \DBAL \Types \IntegerType;
49+ return config ('twofactor-auth.big_int ' );
7050 }
7151}
0 commit comments