56 lines
1.7 KiB
PHP
56 lines
1.7 KiB
PHP
<?php
|
|
|
|
use Illuminate\Database\Migrations\Migration;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
class CreateOrdersTable extends Migration
|
|
{
|
|
/**
|
|
* Run the migrations.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function up()
|
|
{
|
|
Schema::create('addresses', function (Blueprint $table) {
|
|
$table->id('id');
|
|
$table->foreignUuid("userId")->references("uuid")->on("users");
|
|
|
|
// Address validation for international users is basically impossible so just use a string
|
|
$table->string("addres");
|
|
$table->timestamps();
|
|
});
|
|
|
|
Schema::create('orders', function (Blueprint $table) {
|
|
$table->uuid("uuid")->unique()->primary();
|
|
$table->boolean("fulfilled")->default(false);
|
|
|
|
$table->foreignUuid("userId")->references("uuid")->on("users");
|
|
$table->foreignId("addressId")->nullable()->references("id")->on("addresses");
|
|
|
|
$table->decimal("cost");
|
|
$table->boolean("paid")->default(false);
|
|
|
|
$table->timestamps();
|
|
});
|
|
|
|
Schema::create("orderProduct", function (Blueprint $table) {
|
|
$table->foreignUuid("productId")->references("uuid")->on("products")->cascadeOnUpdate()->cascadeOnDelete();
|
|
$table->foreignUuid("orderId")->references("uuid")->on("orders")->cascadeOnUpdate()->cascadeOnDelete();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Reverse the migrations.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function down()
|
|
{
|
|
Schema::dropIfExists('orderProduct');
|
|
Schema::dropIfExists('orders');
|
|
Schema::dropIfExists('addresses');
|
|
}
|
|
}
|