feat: add CategoryImporter service and SeedCategoriesCommand for seeding category data
- Implemented CategoryImporter service to handle bulk export/import logic for categories. - Created SeedCategoriesCommand to seed category tables from JSON files in data/seed/. - Added validation and normalization for category data during import. - Ensured proper error handling and user feedback during the seeding process.
This commit is contained in:
@@ -111,3 +111,29 @@ A non-empty array of records, or `{ "items": [ … ] }`. Max **5000** rows.
|
||||
| `ERR_IMPORT_TOO_LARGE` | 422 | More than 5000 rows |
|
||||
| (field errors) | 422 | One entry per failed row/field; no rows written |
|
||||
| `ERR_IMPORT_FAILED` | 500 | DB error during replace (transaction rolled back) |
|
||||
|
||||
---
|
||||
|
||||
## Seeding a from-scratch database
|
||||
|
||||
Canonical category data ships in the repo at `data/seed/*.json`
|
||||
(`provinces.json`, `cities.json`, `specialties.json`, `doctor_services.json`).
|
||||
After creating an empty schema, populate it with:
|
||||
|
||||
```bash
|
||||
ddev exec php bin/console app:seed-categories
|
||||
```
|
||||
|
||||
The command (`App\Category\Command\SeedCategoriesCommand`) reads those files and
|
||||
runs the same strict validation + wipe-and-replace as the HTTP import, in
|
||||
dependency order (provinces → cities, specialties → doctor_services). The shared
|
||||
logic lives in `App\Category\Service\CategoryImporter`.
|
||||
|
||||
Full rebuild:
|
||||
```bash
|
||||
ddev exec php bin/console doctrine:database:drop --force
|
||||
ddev exec php bin/console doctrine:database:create
|
||||
ddev exec php bin/console doctrine:migrations:migrate --no-interaction
|
||||
ddev exec php bin/console app:seed-categories
|
||||
ddev exec php bin/console app:create-admin 09100000001 'Test@1234'
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user