added chat
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if (! Schema::hasTable('customers')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->addCustomerColumnIfMissing('chat_room_id', 'VARCHAR(255) NULL DEFAULT NULL', 'conditional_order_limit');
|
||||
$this->addCustomerColumnIfMissing('chat_user_id', 'VARCHAR(255) NULL DEFAULT NULL', 'chat_room_id');
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
// عمداً خالی — rollback ستون را حذف نمیکند
|
||||
}
|
||||
|
||||
private function customersTable(): string
|
||||
{
|
||||
return DB::getTablePrefix().'customers';
|
||||
}
|
||||
|
||||
private function customerColumnExists(string $column): bool
|
||||
{
|
||||
$result = DB::selectOne(
|
||||
'SELECT COUNT(*) AS cnt FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? AND COLUMN_NAME = ?',
|
||||
[DB::connection()->getDatabaseName(), $this->customersTable(), $column]
|
||||
);
|
||||
|
||||
return (int) $result->cnt > 0;
|
||||
}
|
||||
|
||||
private function addCustomerColumnIfMissing(string $column, string $definition, ?string $after = null): void
|
||||
{
|
||||
if ($this->customerColumnExists($column)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$table = $this->customersTable();
|
||||
$afterClause = ($after !== null && $this->customerColumnExists($after))
|
||||
? " AFTER `{$after}`"
|
||||
: '';
|
||||
|
||||
DB::statement("ALTER TABLE `{$table}` ADD COLUMN `{$column}` {$definition}{$afterClause}");
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user