fixed some bugs 2
This commit is contained in:
@@ -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}");
|
||||
}
|
||||
};
|
||||
@@ -100,7 +100,9 @@ mysql ... < database/sql/deploy_settings_const.sql
|
||||
| `Loading stored database schema` | کد قدیمی — `git pull` (دیگر رخ نمیدهد). اگر شد: restore بکاپ |
|
||||
| `2019`/`2021` No بعد از baseline | baseline قدیمی → `fake_package_migrations.sql` |
|
||||
| `Unknown host HOST` | از `.env` بخوان نه placeholder |
|
||||
| `Unknown column 'is_exist'` | `git pull` + دوباره `deploy_settings_const.sql` (نسخه جدید ستون را اضافه میکند) |
|
||||
| `Unknown column 'total_referrals'` | `git pull` + `php artisan migrate` (ensure_total_referrals) |
|
||||
| `Unknown column 'order_limit_enabled'` / محدودیت سفارش ذخیره نمیشود | `git pull` + `php artisan migrate` (ensure_products_baseline_columns) |
|
||||
| `Nothing to migrate` ولی ستون نیست | baseline فقط در جدول migrations ثبت کرده — migrationهای `ensure_*` را deploy و `migrate` بزنید |
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
-- baseline_migrations.sql — قبل از php artisan migrate روی DB موجود
|
||||
-- USE `نام_دیتابیس`;
|
||||
--
|
||||
-- توجه: این فایل migrationها را «اجرا شده» علامت میزند. اگر ALTER واقعی قبلاً نخورده،
|
||||
-- migrate میگوید Nothing to migrate. برای پر کردن شکاف schema از migrationهای ensure_* استفاده کنید
|
||||
-- (مثلاً 2026_06_25_000001_ensure_total_referrals_* و 2026_07_08_000001_ensure_products_baseline_columns).
|
||||
|
||||
TRUNCATE TABLE `migrations`;
|
||||
|
||||
|
||||
@@ -6,11 +6,13 @@
|
||||
-- علت: baseline_migrations.sql این migration را در جدول migrations ثبت کرده
|
||||
-- بدون اینکه ALTER TABLE واقعاً اجرا شود.
|
||||
--
|
||||
-- راهحل: این فایل را مستقیم روی MySQL اجرا کنید (migrate کافی نیست).
|
||||
-- راهحل ترجیحی (بدون SQL دستی):
|
||||
-- git pull
|
||||
-- php artisan migrate
|
||||
-- (migration: 2026_06_25_000001_ensure_total_referrals_column_on_customers_table.php)
|
||||
--
|
||||
-- فقط اگر migrate در دسترس نیست، این فایل را مستقیم روی MySQL اجرا کنید:
|
||||
-- mysql -u USER -p DATABASE_NAME < database/sql/fix_missing_total_referrals_column.sql
|
||||
--
|
||||
-- یا از phpMyAdmin / Adminer همین کوئریها را بزنید.
|
||||
|
||||
START TRANSACTION;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user