File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -49,8 +49,15 @@ public function upgrade(): void
4949 $ table ->integer (column: 'private ' )->default (value: 0 )->index ();
5050 $ table ->integer (column: 'contact_user_id ' )->nullable ()->index ();
5151 $ table ->integer (column: 'support_user_id ' )->nullable ()->index ();
52- $ table ->foreign (columns: ['contact_user_id ' ])->references (['user_id ' ])->on ('user ' )->nullOnDelete ()->cascadeOnUpdate ();
53- $ table ->foreign (columns: ['support_user_id ' ])->references (['user_id ' ])->on ('user ' )->nullOnDelete ()->cascadeOnUpdate ();
52+
53+ if (DB ::driverName () === DB ::SQL_SERVER ) {
54+ // SQL-Server can't use CASCADE or SET NULL constraints here, as it can't handle multiple paths
55+ $ table ->foreign (columns: ['contact_user_id ' ])->references (['user_id ' ])->on ('user ' );
56+ $ table ->foreign (columns: ['support_user_id ' ])->references (['user_id ' ])->on ('user ' );
57+ } else {
58+ $ table ->foreign (columns: ['contact_user_id ' ])->references (['user_id ' ])->on ('user ' )->nullOnDelete ()->cascadeOnUpdate ();
59+ $ table ->foreign (columns: ['support_user_id ' ])->references (['user_id ' ])->on ('user ' )->nullOnDelete ()->cascadeOnUpdate ();
60+ }
5461 });
5562 }
5663
Original file line number Diff line number Diff line change @@ -310,6 +310,13 @@ public function delete(User $user): void
310310 DB ::table ('user_gedcom_setting ' )->where ('user_id ' , '= ' , $ user ->id ())->delete ();
311311 DB ::table ('user_setting ' )->where ('user_id ' , '= ' , $ user ->id ())->delete ();
312312 DB ::table ('message ' )->where ('user_id ' , '= ' , $ user ->id ())->delete ();
313+
314+ if (DB ::driverName () === DB ::SQL_SERVER ) {
315+ // SQL-Server cannot handle these foreign key constraints.
316+ DB ::table ('gedcom ' )->where ('contact_user_id ' , '= ' , $ user ->id ())->update (['contact_user_id ' => null ]);
317+ DB ::table ('gedcom ' )->where ('support_user_id ' , '= ' , $ user ->id ())->update (['support_user_id ' => null ]);
318+ }
319+
313320 DB ::table ('user ' )->where ('user_id ' , '= ' , $ user ->id ())->delete ();
314321 }
315322
You can’t perform that action at this time.
0 commit comments