146 lines
4.9 KiB
Markdown
146 lines
4.9 KiB
Markdown
# چکلیست Deploy — برنچ ماژولار
|
||
|
||
> **ایمنی:** `php artisan migrate` دیگر `mysql-schema.sql` را auto-load نمیکند (DROP TABLE نمیزند).
|
||
> فایل schema فقط دستی: `database/schema/mysql-schema.sql.reference`
|
||
|
||
## قبل از شروع
|
||
|
||
- [ ] بکاپ DB
|
||
- [ ] کد + SQLهای جدید روی سرور (`baseline_migrations.sql` حتماً نسخه جدید — **۱۱ ردیف**)
|
||
- [ ] `database/migrations/` فقط ۸ فایل `2026_*`
|
||
- [ ] `php artisan config:clear`
|
||
|
||
---
|
||
|
||
## DB موجود — ترتیب
|
||
|
||
```bash
|
||
cd /opt/PROJECT/server
|
||
|
||
DB_HOST=$(grep ^DB_HOST= .env | cut -d= -f2- | tr -d '\r"')
|
||
DB_PORT=$(grep ^DB_PORT= .env | cut -d= -f2- | tr -d '\r"')
|
||
DB_DATABASE=$(grep ^DB_DATABASE= .env | cut -d= -f2- | tr -d '\r"')
|
||
DB_USERNAME=$(grep ^DB_USERNAME= .env | cut -d= -f2- | tr -d '\r"')
|
||
DB_PASSWORD=$(grep ^DB_PASSWORD= .env | cut -d= -f2- | tr -d '\r"')
|
||
|
||
# ۱ baseline
|
||
mysql -h "$DB_HOST" -P "$DB_PORT" -u "$DB_USERNAME" -p"$DB_PASSWORD" "$DB_DATABASE" \
|
||
< database/sql/baseline_migrations.sql
|
||
|
||
# باید ۱۱ ردیف چاپ شود (شامل 2019 و 2021)
|
||
|
||
# ۲ چک DB — اگر کمتر از ۲ بود baseline قدیمی است
|
||
mysql -h "$DB_HOST" -P "$DB_PORT" -u "$DB_USERNAME" -p"$DB_PASSWORD" "$DB_DATABASE" -N -e \
|
||
"SELECT COUNT(*) FROM migrations WHERE migration LIKE '2019%' OR migration LIKE '2021%';"
|
||
|
||
# باید: 2
|
||
|
||
# ۳ status — ۱۰ تا همه Yes
|
||
php artisan migrate:status
|
||
|
||
# ۴ migrate
|
||
php artisan migrate
|
||
|
||
# ۵ settings
|
||
mysql -h "$DB_HOST" -P "$DB_PORT" -u "$DB_USERNAME" -p"$DB_PASSWORD" "$DB_DATABASE" \
|
||
< database/sql/deploy_settings_const.sql
|
||
```
|
||
|
||
**یا:** `bash database/sql/run_deploy_existing_db.sh`
|
||
|
||
### چک بعد از مرحله ۲
|
||
|
||
| خروجی `migrate:status` | کار |
|
||
|------------------------|-----|
|
||
| ۱۰ تا همه **Yes** | ادامه مرحله ۴ |
|
||
| `2019`/`2021` هنوز **No** | `fake_package_migrations.sql` بزن → دوباره status |
|
||
|
||
```bash
|
||
mysql -h "$DB_HOST" -P "$DB_PORT" -u "$DB_USERNAME" -p"$DB_PASSWORD" "$DB_DATABASE" \
|
||
< database/sql/fake_package_migrations.sql
|
||
php artisan migrate:status
|
||
php artisan migrate
|
||
```
|
||
|
||
---
|
||
|
||
## soroushgold — الان (بعد از خطا)
|
||
|
||
```bash
|
||
cd /opt/soroushgold/server
|
||
|
||
mysql -h 127.0.0.1 -P 3030 -u root -p soroushgold \
|
||
< database/sql/fake_package_migrations.sql
|
||
|
||
php artisan migrate:status
|
||
php artisan migrate
|
||
|
||
mysql -h 127.0.0.1 -P 3030 -u root -p soroushgold \
|
||
< database/sql/deploy_settings_const.sql
|
||
```
|
||
|
||
---
|
||
|
||
## DB خالی
|
||
|
||
```bash
|
||
mysql ... < database/schema/mysql-schema.sql.reference
|
||
mysql ... < database/sql/baseline_migrations.sql
|
||
php artisan migrate
|
||
mysql ... < database/sql/deploy_settings_const.sql
|
||
```
|
||
|
||
---
|
||
|
||
## خطاها
|
||
|
||
| خطا | فیکس |
|
||
|-----|------|
|
||
| `Table already exists` | `fake_package_migrations.sql` → `migrate` |
|
||
| `Loading stored database schema` | کد قدیمی — `git pull` (دیگر رخ نمیدهد). اگر شد: restore بکاپ |
|
||
| `2019`/`2021` No بعد از baseline | baseline قدیمی → `fake_package_migrations.sql` |
|
||
| `Unknown host HOST` | از `.env` بخوان نه placeholder |
|
||
| `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) |
|
||
| `Unknown column 'product_id'` روی `wallets` / `/customer/me` | `mysql ... < database/sql/gholaktala_upgrade.sql` سپس merge settings |
|
||
| upgrade کامل قلک طلا | `bash database/sql/run_gholaktala_upgrade.sh` |
|
||
| `Nothing to migrate` ولی ستون نیست | baseline فقط در جدول migrations ثبت کرده — migrationهای `ensure_*` را deploy و `migrate` بزنید |
|
||
|
||
---
|
||
|
||
## فایلها
|
||
|
||
| فایل | کار |
|
||
|------|-----|
|
||
| `baseline_migrations.sql` | ۱۱ migration یکجا |
|
||
| `fake_package_migrations.sql` | فقط 2019 + 2021 |
|
||
| `deploy_settings_const.sql` | settings + const |
|
||
| `ensure_wallet_module_columns.sql` | `wallets.product_id` + ستونهای transactions برای DB قدیمی |
|
||
| `deploy_safe_schema.sql` | ALTERهای idempotent (شامل wallets.product_id) |
|
||
| `fix_migrations_after_failed_migrate.sql` | reset کامل migrations |
|
||
| `run_deploy_existing_db.sh` | اجرای خودکار + چک |
|
||
|
||
---
|
||
|
||
## فوری — gholaktala /customer/me شکسته
|
||
|
||
```bash
|
||
cd /opt/gholak/server # یا مسیر واقعی پروژه
|
||
|
||
# بکاپ
|
||
mysqldump -h ... -u ... -p DB_NAME > /tmp/gholak_before_wallet_cols.sql
|
||
|
||
# فقط ستونهای گمشده (داده موجود دست نخورده؛ product_id=NULL = کیف اصلی قدیم)
|
||
mysql -h ... -u ... -p DB_NAME < database/sql/ensure_wallet_module_columns.sql
|
||
|
||
php artisan migrate # ثبت مایگریشن ensure_wallet_module_columns
|
||
php artisan config:clear
|
||
```
|
||
|
||
چک:
|
||
|
||
```sql
|
||
SHOW COLUMNS FROM wallets LIKE 'product_id';
|
||
-- باید یک ردیف برگردد
|
||
```
|