|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the API Platform project. |
| 5 | + * |
| 6 | + * (c) Kévin Dunglas <dunglas@gmail.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +declare(strict_types=1); |
| 13 | + |
| 14 | +use Illuminate\Database\Migrations\Migration; |
| 15 | +use Illuminate\Database\Schema\Blueprint; |
| 16 | +use Illuminate\Support\Facades\Schema; |
| 17 | + |
| 18 | +/* |
| 19 | + * Tables for testing custom primary key handling in ModelMetadata. |
| 20 | + * |
| 21 | + * Uses the common convention of <table>_id as primary key, where the |
| 22 | + * PK name on the parent table matches the FK name on the child table. |
| 23 | + */ |
| 24 | +return new class extends Migration { |
| 25 | + public function up(): void |
| 26 | + { |
| 27 | + Schema::create('devices', static function (Blueprint $table): void { |
| 28 | + $table->increments('device_id'); |
| 29 | + $table->string('hostname'); |
| 30 | + $table->timestamps(); |
| 31 | + }); |
| 32 | + |
| 33 | + Schema::create('ports', static function (Blueprint $table): void { |
| 34 | + $table->increments('port_id'); |
| 35 | + $table->unsignedInteger('device_id'); |
| 36 | + $table->string('name'); |
| 37 | + $table->foreign('device_id')->references('device_id')->on('devices'); |
| 38 | + $table->timestamps(); |
| 39 | + }); |
| 40 | + } |
| 41 | + |
| 42 | + public function down(): void |
| 43 | + { |
| 44 | + Schema::dropIfExists('ports'); |
| 45 | + Schema::dropIfExists('devices'); |
| 46 | + } |
| 47 | +}; |
0 commit comments