นิยาม Attribute และตัวแปรระบบ
ภาพรวม
ระบบเก็บข้อมูลลูกค้าแบบยืดหยุ่นไว้ในคอลัมน์ line_user.custom_attribute ซึ่งเป็น JSONB แต่การมีคอลัมน์อิสระเพียงอย่างเดียวยังไม่พอ ต้องมี "พจนานุกรม" คอยบอกว่าคีย์ใดมีอยู่จริง เป็นชนิดข้อมูลอะไร และควรแสดงผลอย่างไร ตารางที่ทำหน้าที่นั้นคือ attribute_master
คู่กันคือ system_attribute ซึ่งเป็น ตัวแปรระดับ channel ไม่ผูกกับผู้ใช้คนใดคนหนึ่ง ใช้เก็บค่าที่ใช้ร่วมกัน เช่น ข้อความมาตรฐาน โควตาโปรโมชัน หรือค่าที่ workflow ต้องอ่าน
โครงสร้างข้อมูลหลัก
attribute_master (model AttributeMaster)
ผูกกับ channel ผ่าน line_oa_id (FK ไปยัง line_oa.id แบบ ON DELETE CASCADE) และ organization_id พร้อมข้อมูลบรรยาย name และ description
หัวใจของตารางคือคอลัมน์ schema JSONB ที่มีค่า default เป็น {"version":"1.0","attributes":[]} จุดที่ควรเข้าใจคือ รายการ attribute ทั้งหมดถูกเก็บรวมไว้ในแถวเดียว ไม่ได้แยกเป็นแถวละหนึ่ง attribute
มี unique constraint บน (line_oa_id, organization_id, name) และใช้ soft delete ผ่าน deleted_date
system_attribute (model SystemAttribute)
เก็บค่าแบบ key/value ในระดับ channel ประกอบด้วย key, value (TEXT), data_type (default string), description และ expires_at ที่ทำให้ค่าหมดอายุได้
มี unique constraint uq_system_attribute_oa_org_key บน (line_oa_id, organization_id, key)
คีย์ใน attribute_master.schema ถูกอ้างที่ไหนบ้าง
| จุดที่อ้างถึง | บทบาท |
|---|---|
line_user.custom_attribute | ค่าจริงรายบุคคล |
form_builder.field_attribute_mappings | ฟอร์มที่กรอกแล้วเขียนลง attribute ใด |
import_mapping_job.mappings | คอลัมน์ CSV ที่ map ไปยัง custom.<key> |
audience.filter_info | เงื่อนไขกรองกลุ่มเป้าหมาย |
friend_track_campaign.attribute_config | attribute ที่เก็บจากลิงก์ tracking |
| merge tag ใน rich message / campaign | ตัวแปรที่ถูกแทนค่าตอนส่งข้อความ |
ไฟล์ที่เกี่ยวข้อง
prisma/schema.prisma:990— modelAttributeMasterprisma/schema.prisma:1586— modelSystemAttributemanual-sql/3.bank.sqlและmanual-sql/5.sql— trigger ที่ตรวจจับการเปลี่ยนแปลงคีย์custom.<key>schema-dumps/2026-07-24/schema.sql:943และ:2790
จุดเชื่อมต่อกับ Service อื่น
- cms-api-go — ให้บริการโมดูล
attribute-masterและsystem-attributeโดยจำนวน attribute ที่สร้างได้ถูกจำกัดด้วยplan_limits.maxAttributes - worker-go — อ่านนิยามเหล่านี้ตอนประเมิน trigger rule และ workflow รวมถึงตอนรีเฟรช audience
- client-api-go — เขียนค่าลง
custom_attributeเมื่อผู้ใช้ส่งฟอร์มหรือทำกิจกรรมใน LIFF - เชื่อมกับ เพื่อน LINE, กลุ่มเป้าหมาย, ฟอร์ม และ Workflow