fix some bugs

This commit is contained in:
2026-09-02 11:38:57 +03:30
parent b54f9f0527
commit e9674d6571
3 changed files with 58 additions and 2 deletions
@@ -0,0 +1,41 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
/**
* تولد قبل از ۱۹۷۰ روی TIMESTAMP مای‌اسکیوال ذخیره نمی‌شود (مثلاً ۱۹۶۷-۱۰-۲۳ → ۱۲۹۲).
*/
return new class extends Migration
{
public function up(): void
{
if (! Schema::hasTable('customers') || ! Schema::hasColumn('customers', 'birth_date')) {
return;
}
$row = DB::selectOne(
'SELECT DATA_TYPE AS data_type FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? AND COLUMN_NAME = ?',
[DB::connection()->getDatabaseName(), $this->customersTable(), 'birth_date']
);
$type = strtolower((string) ($row->data_type ?? ''));
if ($type === 'date') {
return;
}
DB::statement('ALTER TABLE `'.$this->customersTable().'` MODIFY `birth_date` DATE NULL DEFAULT NULL');
}
public function down(): void
{
// به TIMESTAMP برنمی‌گردانیم — تاریخ‌های قبل از ۱۹۷۰ قطع می‌شوند
}
private function customersTable(): string
{
return DB::getTablePrefix().'customers';
}
};