File: /var/www/admin.javaapp.co.uk/database/migrations/2023_03_14_143955_create_orders_table.php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('orders', function (Blueprint $table) {
$table->id();
$table->string('order_number')->default('');
$table->foreignId('user_id')->nullable()->constrained('users');
$table->foreignId('cafe_id')->nullable()->constrained('cafes');
$table->foreignId('group_id')->nullable()->constrained('groups');
$table->foreignId('group_coffee_run_id')->nullable()->constrained('group_coffee_runs');
$table->tinyInteger('is_main_order')->default(0)->comment('0 = sub order, 1 = main order');
$table->json('order_item_array')->nullable();
$table->text('additional_note')->nullable();
$table->double('total_amount', 8, 2)->default(0);
$table->double('tax', 8, 2)->default(0);
$table->double('discount_amount', 8, 2)->default(0);
$table->string('request_unique_id')->default('');
$table->unsignedInteger('order_placed_at')->default(0);
$table->unsignedInteger('order_collected_at')->default(0);
$table->tinyInteger('status')->default(0)->comment("1 = placed, 2 = collected");
$table->unsignedInteger('created_at')->default(0);
$table->unsignedInteger('updated_at')->default(0);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('orders', function (Blueprint $table) {
$table->dropConstrainedForeignId('user_id');
$table->dropConstrainedForeignId('cafe_id');
$table->dropConstrainedForeignId('group_id');
});
Schema::dropIfExists('orders');
}
};