| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- declare(strict_types=1);
- use Illuminate\Database\Migrations\Migration;
- use Illuminate\Database\Schema\Blueprint;
- use Illuminate\Support\Facades\Schema;
- return new class extends Migration
- {
- public function up(): void
- {
- Schema::create('stock_orders', function (Blueprint $table): void {
- $table->id();
- $table->foreignId('common_catalog_item_id')->constrained('common_catalog_items')->restrictOnDelete();
- $table->string('order_number');
- $table->string('status', 32)->default('ordered');
- $table->unsignedInteger('ordered_quantity');
- $table->unsignedInteger('available_quantity');
- $table->text('note')->nullable();
- $table->foreignId('user_id')->nullable()->constrained('users')->nullOnDelete();
- $table->timestamps();
- $table->softDeletes();
- $table->unique(['order_number', 'common_catalog_item_id']);
- $table->index(['common_catalog_item_id', 'status', 'available_quantity'], 'stock_order_item_status_available_index');
- });
- Schema::create('stock_reservations', function (Blueprint $table): void {
- $table->id();
- $table->foreignId('common_catalog_item_id')->constrained('common_catalog_items')->restrictOnDelete();
- $table->foreignId('stock_order_id')->constrained('stock_orders')->restrictOnDelete();
- $table->foreignId('manager_id')->nullable()->constrained('users')->nullOnDelete();
- $table->unsignedInteger('quantity');
- $table->string('status', 32)->default('active');
- $table->text('note')->nullable();
- $table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
- $table->timestamp('issued_at')->nullable();
- $table->timestamp('cancelled_at')->nullable();
- $table->timestamps();
- $table->index(['common_catalog_item_id', 'status']);
- $table->index(['stock_order_id', 'status']);
- });
- Schema::create('stock_movements', function (Blueprint $table): void {
- $table->id();
- $table->foreignId('common_catalog_item_id')->constrained('common_catalog_items')->restrictOnDelete();
- $table->foreignId('stock_order_id')->nullable()->constrained('stock_orders')->nullOnDelete();
- $table->foreignId('stock_reservation_id')->nullable()->constrained('stock_reservations')->nullOnDelete();
- $table->string('movement_type', 32);
- $table->unsignedInteger('quantity');
- $table->foreignId('user_id')->nullable()->constrained('users')->nullOnDelete();
- $table->text('note')->nullable();
- $table->timestamps();
- $table->index(['common_catalog_item_id', 'movement_type']);
- $table->index(['stock_order_id', 'movement_type']);
- });
- }
- public function down(): void
- {
- Schema::dropIfExists('stock_movements');
- Schema::dropIfExists('stock_reservations');
- Schema::dropIfExists('stock_orders');
- }
- };
|