Section 11: ออกแบบ Schema ด้วย Prisma Schema Language
- โครงสร้าง schema.prisma แบบ Multi-file, Scalar Type และ Attribute ที่ใช้บ่อย (@id, @unique, @default, @@index)
- ฟังก์ชันค่าเริ่มต้น autoincrement(), uuid(7), cuid(2), ulid() พร้อมข้อควรรู้ว่า uuid()/cuid() ทำงานฝั่ง Client เท่านั้น
- Native Type ของ PostgreSQL (@db.Uuid, @db.JsonB, @db.Timestamptz) และการออกแบบ Index ให้เหมาะกับการ Query
Section 12: ความสัมพันธ์ระหว่างตาราง (Relations)
- One-to-One, One-to-Many, Many-to-Many (Implicit และ Explicit Join Table) และ Self-relation
- onDelete และ onUpdate (Cascade, Restrict, SetNull), Composite Key และ relationMode (foreignKeys กับ prisma)
- Workshop: ออกแบบ Schema ระบบงานตัวอย่าง (User, Role, Product, Category, Order, OrderItem, Payment) แบบครบวงจร
Section 13: Prisma Migrate ตลอดวงจรการพัฒนา
- ความแตกต่างระหว่าง migrate dev, migrate deploy, db push และ Shadow Database
- การจัดการ Drift (migrate status, resolve, diff), การทำ Baselining และ Seed Data ด้วย prisma db seed
- Error Code ที่พบบ่อย (P3005, P3006, P3009, P3014, P3018) และแนวทาง Migration บน Production อย่างปลอดภัย
Section 14: Prisma Client Query เชิงลึก
- CRUD ครบชุดและ Batch Operations, Filtering ขั้นสูง (AND, OR, NOT, in, contains, mode: insensitive)
- การโหลดข้อมูลสัมพันธ์ (include, select, Nested Write), Pagination (Offset กับ Cursor) และ Aggregation (count, groupBy, _sum)
- JSON Field, Full-Text Search, Raw Query ($queryRaw, $executeRaw) การป้องกัน SQL Injection และ TypedSQL (Preview)
Section 15: Transaction, Performance และ Connection Pool
- Sequential กับ Interactive Transaction, ตัวเลือก maxWait, timeout, Isolation Level และการจัดการ Write Conflict (P2034)
- ปัญหา N+1 บน Prisma และวิธีตรวจจับ, relationLoadStrategy (Preview) และการเปิด Query Logging ดู SQL จริง
- Connection Pool ใน Prisma 7 (ตั้งที่ Driver Adapter), PgBouncer/Supavisor และ Prisma Client Extensions แทน $use
Section 16: MariaDB กับ Prisma - การใช้งานจริงและข้อควรระวัง
- MariaDB ใช้ Provider mysql เดียวกับ MySQL การติดตั้ง @prisma/adapter-mariadb และตารางเปรียบเทียบ Type Mapping กับ PostgreSQL
- ฟีเจอร์ที่ใช้ไม่ได้บน MariaDB (Scalar List, multiSchema, mode: insensitive, createManyAndReturn) และที่ได้เปรียบ (Full-Text Index)
- ข้อควรระวังสำคัญ: ปัญหาเปิดค้างของ Prisma 7 กับ MariaDB เรื่อง JSON, Migration Drift, Timezone และ Collation พร้อม Workshop ย้าย Schema มารันบน MariaDB