parent
e00dd15e29
commit
7712f27714
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
if (!Schema::hasTable('schedule_overview_systems')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::table('schedule_overview_systems', function (Blueprint $table) {
|
||||
if (!Schema::hasColumn('schedule_overview_systems', 'year')) {
|
||||
$table->string('year', 4)->default(date('Y'))->after('id')->comment('年份');
|
||||
$table->index('year');
|
||||
}
|
||||
});
|
||||
|
||||
DB::table('schedule_overview_systems')
|
||||
->whereNull('year')
|
||||
->orWhere('year', '')
|
||||
->update(['year' => date('Y')]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
if (!Schema::hasTable('schedule_overview_systems') || !Schema::hasColumn('schedule_overview_systems', 'year')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::table('schedule_overview_systems', function (Blueprint $table) {
|
||||
$table->dropIndex(['year']);
|
||||
$table->dropColumn('year');
|
||||
});
|
||||
}
|
||||
};
|
||||
Loading…
Reference in new issue