fixed some bugs 2

This commit is contained in:
2026-07-08 17:13:04 +03:30
parent 5cbcf2fd52
commit 239736aefd
5 changed files with 117 additions and 4 deletions
@@ -0,0 +1,95 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
/**
* baseline_migrations.sql بعضی migrationهای products را «اجرا شده» ثبت می‌کند
* بدون ALTER TABLE واقعی → migrate می‌گوید Nothing to migrate ولی ستون نیست.
*
* این فایل idempotent است؛ روی هر سرور با php artisan migrate اجرا شود.
*/
return new class extends Migration
{
public function up(): void
{
if (! Schema::hasTable('products')) {
return;
}
$this->addProductColumnIfMissing(
'price_offset_percent',
'DECIMAL(8,2) NOT NULL DEFAULT 0',
'price_profit'
);
$this->addProductColumnIfMissing(
'order_limit_enabled',
'TINYINT(1) NOT NULL DEFAULT 0',
'percent_fee_buy'
);
$this->addProductColumnIfMissing(
'min_order_cash',
'BIGINT UNSIGNED NULL DEFAULT NULL',
'order_limit_enabled'
);
$this->addProductColumnIfMissing(
'max_order_cash',
'BIGINT UNSIGNED NULL DEFAULT NULL',
'min_order_cash'
);
$this->addProductColumnIfMissing(
'show_in_assets',
'TINYINT(1) NOT NULL DEFAULT 0',
'show'
);
$this->addProductColumnIfMissing(
'use_last_price_if_zero',
'TINYINT(1) NOT NULL DEFAULT 0',
'show_in_assets'
);
DB::purge();
DB::reconnect();
}
public function down(): void
{
// عمداً خالی — rollback ستون‌های baseline را حذف نمی‌کند
}
private function productsTable(): string
{
return DB::getTablePrefix().'products';
}
private function productColumnExists(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->productsTable(), $column]
);
return (int) $result->cnt > 0;
}
private function addProductColumnIfMissing(string $column, string $definition, ?string $after = null): void
{
if ($this->productColumnExists($column)) {
return;
}
$table = $this->productsTable();
$afterClause = ($after !== null && $this->productColumnExists($after))
? " AFTER `{$after}`"
: '';
DB::statement("ALTER TABLE `{$table}` ADD COLUMN `{$column}` {$definition}{$afterClause}");
}
};