Skip to content

Commit

Permalink
Fixed migrations for SQLite/foreign key/Laravel 11.15+ compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
fulopattila122 committed Dec 14, 2024
1 parent 3e23985 commit 9e616ad
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function up(): void
$table->unsignedBigInteger('billing_zone_id')->nullable();
$table->unsignedBigInteger('shipping_zone_id')->nullable();

if (Schema::hasTable('zones')) {
if (!$this->isSqlite() && Schema::hasTable('zones')) {
$table->foreign('billing_zone_id')->references('id')->on('zones');
$table->foreign('shipping_zone_id')->references('id')->on('zones');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ public function up()
Schema::table('orders', function (Blueprint $table) {
if (!Schema::hasColumn('orders', 'customer_id')) {
$table->intOrBigIntBasedOnRelated('customer_id', Schema::connection(null), 'customers.id')->unsigned()->nullable()->after('billpayer_id');
$table->foreign('customer_id')->references('id')->on('customers');
if (!$this->isSqlite()) {
$table->foreign('customer_id')->references('id')->on('customers');
}
}
$table->unsignedBigInteger('shipping_method_id')->nullable()->after('shipping_address_id');

$table->foreign('shipping_method_id')->references('id')->on('shipping_methods');
if (!$this->isSqlite()) {
$table->foreign('shipping_method_id')->references('id')->on('shipping_methods');
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public function up()
Schema::table('orders', function (Blueprint $table) {
if (!Schema::hasColumn('orders', 'payment_method_id')) {
$table->bigInteger('payment_method_id')->unsigned()->nullable();
$table->foreign('payment_method_id')->references('id')->on('payment_methods');
if (!$this->isSqlite()) {
$table->foreign('payment_method_id')->references('id')->on('payment_methods');
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function up(): void
Schema::table('payment_methods', function (Blueprint $table) {
$table->unsignedBigInteger('zone_id')->nullable()->after('name');

if (Schema::hasTable('zones')) {
if (!$this->isSqlite() && Schema::hasTable('zones')) {
$table->foreign('zone_id')->references('id')->on('zones');
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
public function up()
{
Schema::table('shipping_methods', function (Blueprint $table) {
$table->foreign('zone_id')->references('id')->on('zones');
if (!$this->isSqlite()) {
$table->foreign('zone_id')->references('id')->on('zones');
}
});
}

Expand Down

0 comments on commit 9e616ad

Please sign in to comment.