Your IP : 216.73.216.79


Current Path : /var/www/html/ains/docs/
Upload File :
Current File : /var/www/html/ains/docs/frontend-user-accounts-migration.md

# MEMORY / NOTES

## Migration: Create frontend_user accounts from school table (2026-08-17)

File created: `console/migrations/m260817_000000_create_frontend_user_accounts_from_school.php`

Status: NOT YET RUN (manually)

### Run manually
```
php yii migrate/up m260817_000000_create_frontend_user_accounts_from_school
```

### Account rules generated
| Role | Username | Password | frontend_user.role |
|------|----------|----------|-------------------|
| guru (per school) | `gpm@<school_code>` | `GPM@<school_code>123!` | `teacher` |
| ppd (per distinct PPD) | `ppd@<ppd>` | `PPD@<ppd>123!` | `ppd` |
| negeri (per distinct state) | `jpn@<state>` | `JPN@<state>123!` | `jpn` |

### Rules
- Username + password key: ALL lowercase, spaces removed (e.g. `Pulau Pinang` -> `pulaupinang`)
- Example: guru `gpm@abc1234` / `GPM@abc1234123!`; ppd `ppd@kualamuda` / `PPD@kualamuda123!`; jpn `jpn@pulaupinang` / `JPN@pulaupinang123!`
- Password hashed with `Yii::$app->security->generatePasswordHash()`
- `status = 1`, `auth_key` = random string
- Skips usernames that already exist (safe to re-run)
- Teacher links `user_school`, `user_ppd`, `user_state` from school row; ppd/jpn link their scope
- `safeDown` deletes accounts with username prefix `gpm@` / `ppd@` / `jpn@`

### Tables/roles context
- `school` (id, state, ppd, type, school_code, name, address, postcode, city, phone, fax, email, target)
- `frontend_user` (username, fullname, email, mobile_no, status, role, user_state, user_ppd, user_school, password_hash, auth_key, ...)
- Role map used by app: `teacher`, `ppd`, `jpn`, `kpm`, `murid` (controllers in `backend/modules/fruserdynav2`)