รวมคำสั่ง Frappe Bench Commands ที่ใช้บ่อย
รวมคำสั่ง Frappe Bench Commands ที่นักพัฒนาใช้บ่อยในการจัดการ Site, App, Database และ Scheduler สำหรับการพัฒนา ERPNext และ Frappe Framework

เมื่อเราพัฒนาแอปพลิเคชันบน Frappe Framework หรือ ERPNext สิ่งที่เราต้องใช้บ่อยที่สุดคือ Bench CLI ซึ่งเป็นเครื่องมือหลักในการจัดการ Site, App, Database และอื่นๆ บทความนี้รวบรวมคำสั่งที่ใช้บ่อยเพื่อให้เป็น Reference ในการทำงาน
Site Management
คำสั่งสำหรับจัดการ Site ใน Frappe Bench
# สร้าง Site ใหม่
bench new-site your-site.local --admin-password your-password
# ติดตั้ง App เข้า Site
bench --site your-site.local install-app your_app
# ถอนการติดตั้ง App จาก Site
bench --site your-site.local uninstall-app your_app
# กำหนด Site เป็น Default
bench use your-site.local
# ดูรายการ Apps ทั้งหมดใน Site
bench --site all list-apps
Development Commands
คำสั่งสำหรับการพัฒนา
# เริ่ม Development Server
bench start
# ล้าง Cache
bench clear-cache
# Build Assets สำหรับ App เฉพาะ
bench build --app your_app
# รัน Database Migrations
bench --site your-site.local migrate
# เข้า Console (Python REPL)
bench --site your-site.local console
# เข้า MariaDB Console
bench --site your-site.local mariadb
App Management
คำสั่งสำหรับจัดการ Apps
# ดาวน์โหลด App จาก GitHub
bench get-app https://github.com/username/your_app
# ดาวน์โหลด App เวอร์ชันเฉพาะ
bench get-app your_app --branch version-16
# สร้าง App ใหม่
bench new-app your_app
# ลบ App ออกจาก Bench
bench remove-app your_app
Database Commands
คำสั่งสำหรับจัดการฐานข้อมูล
# Backup Site
bench --site your-site.local backup
# Backup พร้อมไฟล์ที่อัพโหลด
bench --site your-site.local backup --with-files
# Restore จาก Backup
bench --site your-site.local restore path/to/backup.sql.gz
# Restore พร้อมไฟล์
bench --site your-site.local --force restore path/to/backup.sql.gz \
--with-private-files path/to/private.tar \
--with-public-files path/to/public.tar
# รัน Python Function โดยตรง
bench --site your-site.local execute module.function
Translation Commands
คำสั่งสำหรับจัดการ Translation
# Rebuild Translation Files ทั้งหมด
bench --site your-site.local execute frappe.translate.rebuild_all_translation_files
# ล้าง Translation Cache
bench --site your-site.local clear-cache
Scheduler Commands
คำสั่งสำหรับจัดการ Scheduler (Background Jobs)
# เปิดใช้งาน Scheduler
bench --site your-site.local enable-scheduler
# ปิดใช้งาน Scheduler
bench --site your-site.local disable-scheduler
# รัน Scheduled Job เฉพาะ
bench --site your-site.local execute your_app.tasks.daily_task
# ตรวจสอบสถานะ Scheduler
bench --site your-site.local scheduler status
Production Commands
คำสั่งสำหรับ Production Server
# Setup Production (Nginx + Supervisor)
sudo bench setup production frappe
# Reload Supervisor
sudo supervisorctl reload
# Restart ทุก Process
sudo supervisorctl restart all
# ดูสถานะ Process
sudo supervisorctl status
# Setup SSL Certificate (Let's Encrypt)
sudo -H bench setup lets-encrypt your-domain.com
# Renew SSL Certificate
sudo bench renew-lets-encrypt
Configuration Commands
คำสั่งสำหรับ Configuration
# เปิด Developer Mode
bench set-config -g developer_mode 1
# ปิด Developer Mode
bench set-config -g developer_mode 0
# เปิด DNS Multitenant
bench config dns_multitenant on
# ตั้งค่า Maintenance Mode
bench --site your-site.local set-maintenance-mode on
bench --site your-site.local set-maintenance-mode off
Multitenancy Commands
คำสั่งสำหรับ Multitenancy (หลาย Site บน Server เดียว)
# เปิด DNS Multitenant
bench config dns_multitenant on
# สร้าง Site ใหม่
bench new-site new-site.local
# Setup Nginx ใหม่
bench setup nginx
# Reload Nginx
sudo service nginx reload
Troubleshooting Commands
คำสั่งสำหรับแก้ไขปัญหา
# ติดตั้ง Requirements ใหม่
bench setup requirements
# Rebuild Assets
bench build --force
# ล้าง Cache ทั้งหมด
bench clear-cache
bench clear-website-cache
# ตรวจสอบ Error Logs
bench --site your-site.local show-pending-jobs
Update Commands
คำสั่งสำหรับ Update Frappe และ Apps
# Update ทุก Apps
bench update
# Update และ Reset Local Changes
bench update --reset
# Update Apps เฉพาะ (ไม่ Migrate)
bench update --pull
# Migrate หลัง Update
bench --site your-site.local migrate
สรุป
คำสั่ง Frappe Bench เหล่านี้เป็นพื้นฐานที่นักพัฒนา ERPNext และ Frappe Framework ควรรู้ การใช้งานคำสั่งเหล่านี้อย่างถูกต้องจะช่วยให้การพัฒนาและจัดการ Production Server เป็นไปอย่างราบรื่น