Files
citrus-cms/database/migrations/2025_06_30_121107_add_controls_handovers.php
T
2026-04-28 21:15:09 +03:00

79 lines
2.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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::table('handovers', function (Blueprint $table) {
$afterColumn = 'responsible';
for ($i = 1; $i <= 10; $i++) {
// Sadece eksik olan sütunları ekle
if (!Schema::hasColumn('handovers', "control{$i}_controller")) {
$table->string("control{$i}_controller", 50)->nullable()->after($afterColumn);
}
if (!Schema::hasColumn('handovers', "control{$i}_date1")) {
$table->date("control{$i}_date1")->nullable()->after("control{$i}_controller");
}
if (!Schema::hasColumn('handovers', "control{$i}_date2")) {
$table->date("control{$i}_date2")->nullable()->after("control{$i}_date1");
}
if (!Schema::hasColumn('handovers', "control{$i}_date3")) {
$table->date("control{$i}_date3")->nullable()->after("control{$i}_date2");
}
if (!Schema::hasColumn('handovers', "control{$i}_id_status")) {
$table->string("control{$i}_id_status", 50)->nullable()->after("control{$i}_date3");
}
if (!Schema::hasColumn('handovers', "control{$i}_comments")) {
$table->string("control{$i}_comments", 100)->nullable()->after("control{$i}_id_status");
}
if (!Schema::hasColumn('handovers', "control{$i}_responsible")) {
$table->string("control{$i}_responsible", 50)->nullable()->after("control{$i}_comments");
}
$afterColumn = "control{$i}_responsible";
}
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('handovers', function (Blueprint $table) {
for ($i = 1; $i <= 10; $i++) {
$columnsToCheck = [
"control{$i}_controller",
"control{$i}_date1",
"control{$i}_date2",
"control{$i}_date3",
"control{$i}_id_status",
"control{$i}_responsible",
"control{$i}_comments"
];
$existingColumns = [];
foreach ($columnsToCheck as $column) {
if (Schema::hasColumn('handovers', $column)) {
$existingColumns[] = $column;
}
}
if (!empty($existingColumns)) {
$table->dropColumn($existingColumns);
}
}
});
}
};