Data Seeding
Strategi seeding data untuk initial setup merchant, branch, roles, users, dan master data di MStore Backend.📊 Seed Data Categories
1. Lookup Tables (Static Reference Data)
Data statis yang jarang berubah, biasanya enum values. Examples:business_level: L0, L1, L2, L3, L4transaction_status: draft, completed, cancelled, refundedbranch_type: outlet, warehouse, distribution, hquser_role: owner, manager, cashier, auditor, etc.
third_party/migrations/seeder/
2. Master Data (Initial Setup)
Data yang dibuat saat merchant/branch baru didaftarkan. Examples:- Roles & Permissions (multi-level RBAC)
- Users (admin, owner-manager, cashier, etc.)
- Chart of Accounts (COA) untuk accounting
- Tax Configurations
- Default Settings per merchant/branch
internal/domains/excel_import/excel_import_data_seeder.go
3. Configuration Data
Sistem configuration yang bisa di-override per merchant. Examples:- Log level, timezone, currency
- Merchant defaults (payment method, tax rate)
- Branch defaults (warehouse, POS terminal)
🔄 Seed Data Flow
💻 Seeder Implementation (Go)
User Seeder
Role Seeder (Multi-Level RBAC)
Permission Seeder
Role-Permission Mapping
🚀 Running Seeders
Method 1: Via CLI Command
Method 2: Via API Endpoint
Method 3: Via Database Migration
✅ Seeding Checklist
- Backup database before seeding
- Verify lookup tables exist
- Check role & permission definitions
- Validate user credentials
- Test seeding on staging first
- Verify seeded data integrity
- Check for duplicate entries
- Validate foreign key constraints
- Monitor application logs
🚀 Best Practices
DO ✅
- Seed lookup tables first
- Use transactions for atomic seeding
- Validate data before inserting
- Document seed data changes
- Version control seed scripts
- Test seeding on staging
- Use idempotent seeders (safe to run multiple times)
DON’T ❌
- Seed production data directly
- Skip validation
- Use hardcoded IDs (use natural keys)
- Seed without backup
- Mix seed & migration scripts
- Seed sensitive data (passwords, tokens)
- Ignore foreign key constraints
📚 Related Documentation
MySQL Migrations
Migration strategy
MySQL Schema
Complete schema reference
Backup & Restore
Backup procedures
Multi-Level RBAC
RBAC architecture