Add machines with day-by-day work lists for job tasks
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Machines (spec 19.4–19.5): the machines in their service units, their
|
||||
* counters and readings, and the day-by-day work list of each machine,
|
||||
* whose rows are job tasks or steps of quick sale order lines (the
|
||||
* order lines get their foreign key with their table).
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('machines', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name', 150);
|
||||
$table->string('type', 20);
|
||||
$table->text('description')->nullable();
|
||||
$table->foreignId('responsible_user_id')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('machine_service_units', function (Blueprint $table) {
|
||||
$table->foreignId('machine_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('service_unit_id')->constrained()->restrictOnDelete();
|
||||
|
||||
$table->primary(['machine_id', 'service_unit_id']);
|
||||
});
|
||||
|
||||
Schema::create('machine_counters', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('machine_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('name', 100);
|
||||
$table->string('unit', 20);
|
||||
$table->unsignedInteger('sort_order');
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('machine_counter_readings', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('machine_counter_id')->constrained()->cascadeOnDelete();
|
||||
$table->bigInteger('reading_milli');
|
||||
$table->foreignId('user_id')->constrained()->restrictOnDelete();
|
||||
$table->timestamp('read_at');
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['machine_counter_id', 'read_at']);
|
||||
});
|
||||
|
||||
Schema::create('machine_queue_entries', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('machine_id')->constrained()->restrictOnDelete();
|
||||
$table->date('planned_on');
|
||||
$table->unsignedInteger('position');
|
||||
$table->foreignId('task_id')->nullable()->constrained()->cascadeOnDelete();
|
||||
$table->unsignedBigInteger('quick_sale_order_line_id')->nullable();
|
||||
$table->unsignedSmallInteger('production_step_position')->nullable();
|
||||
$table->timestamp('completed_at')->nullable();
|
||||
$table->foreignId('completed_by')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['machine_id', 'completed_at', 'planned_on']);
|
||||
$table->index(['task_id', 'completed_at']);
|
||||
});
|
||||
|
||||
Schema::table('stock_movements', function (Blueprint $table) {
|
||||
$table->foreign('machine_id', 'stock_movements_machine_foreign')->references('id')->on('machines')->restrictOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
// SQLite (tests) cannot drop a foreign key; there the table is dropped by the earlier migration's rollback.
|
||||
if (Schema::getConnection()->getDriverName() !== 'sqlite') {
|
||||
Schema::table('stock_movements', function (Blueprint $table) {
|
||||
$table->dropForeign('stock_movements_machine_foreign');
|
||||
});
|
||||
}
|
||||
|
||||
Schema::dropIfExists('machine_queue_entries');
|
||||
Schema::dropIfExists('machine_counter_readings');
|
||||
Schema::dropIfExists('machine_counters');
|
||||
Schema::dropIfExists('machine_service_units');
|
||||
Schema::dropIfExists('machines');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user