# papayapos-seeding > Seed test data into PapayaPOS database for different testing scenarios. Use when user needs chart test data, wants to reset the database, or setup test users with proper mappings. - Author: martinjancipapayapos - Repository: papayapos/claude-marketplace - Version: 20260126112425 - Stars: 0 - Forks: 0 - Last Updated: 2026-02-06 - Source: https://github.com/papayapos/claude-marketplace - Web: https://mule.run/skillshub/@@papayapos/claude-marketplace~papayapos-seeding:20260126112425 --- --- name: papayapos-seeding description: Seed test data into PapayaPOS database for different testing scenarios. Use when user needs chart test data, wants to reset the database, or setup test users with proper mappings. --- # PapayaPOS Database Seeding A skill for seeding test data into PapayaPOS database for different testing scenarios. ## Overview This skill helps with: - Seeding chart test data for Sales Report testing (HOURLY, DAILY, MONTHLY granularity) - Setting up test users with proper Keycloak and DB mappings - Resetting the database for fresh test environments - Quick scenario-based seeding without full backend restarts ## Architecture ``` ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │ seed-db.sh │────▶│ PostgreSQL │ │ Keycloak │ │ (Script) │ │ Test Data │ │ User Setup │ └────────┬────────┘ └─────────────────┘ └─────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────────────┐ │ InitDbChartTestData.java │ │ (Runs automatically on backend startup when schema is created) │ └─────────────────────────────────────────────────────────────────┘ ``` ## Quick Reference ### Seed Script Location ``` papayapos-backend/scripts/seed-db.sh ``` ### Common Commands ```bash # Full reset + user setup + start backend (most common) ./scripts/seed-db.sh --reset --setup-user --start-backend # Just add chart data to existing DB (no reset) ./scripts/seed-db.sh --chart-data-only # Reset DB and setup user only (manual backend start) ./scripts/seed-db.sh --reset --setup-user # Just setup user (for existing DB) ./scripts/seed-db.sh --setup-user ``` ## Seeding Scenarios ### 1. Full Database Reset Drops the tenant schema and lets backend recreate it with fresh seed data: ```bash ./scripts/seed-db.sh --reset --setup-user --start-backend ``` This triggers: 1. Schema drop: `DROP SCHEMA "68cd0406-6670-496f-ab05-b5da25f282e6" CASCADE` 2. Backend startup detects missing schema 3. `PostgresqlDatabaseInitializer.createNewPgDb()` creates schema 4. `FactoryResetService.initDb()` runs all InitDbUnits including `InitDbChartTestData` 5. Keycloak user "testuser" is configured with all permissions ### 2. Chart Test Data Only Adds chart test data to existing database without reset: ```bash ./scripts/seed-db.sh --chart-data-only ``` Generates: - **HOURLY**: 48 transactions (last 48 hours), amounts 5-50 EUR - **DAILY**: ~260 transactions (days 3-99), amounts 20-200 EUR, ~20% days skipped - **MONTHLY**: ~320 transactions (days 100-400), amounts 100-500 EUR ### 3. User Setup Only Just configure Keycloak user without touching database: ```bash ./scripts/seed-db.sh --setup-user ``` Creates/updates: - Keycloak user: `testuser` / `test123` - All required roles (ACCESS_WEB_ADMIN, PRINT_REPORT, etc.) - Database mapping in `user_keycloak_mapping` ## Chart Granularity Testing The Sales Report (`/reports/sales`) uses different chart granularities based on date range: | Date Range | Chart Type | Data to Test | |------------|------------|--------------| | < 3 days | HOURLY | Last 48 hours of transactions | | 3-100 days | DAILY | Days 3-99 transactions | | > 100 days | MONTHLY | Days 100-400 transactions | ### API Testing ```bash # Test HOURLY chart (last 24 hours) NOW=$(($(date +%s) * 1000)) FROM=$((NOW - 86400000)) curl -H "Authorization: Bearer $TOKEN" \ "http://localhost:8080/api/v1/reports/sales-chart?f=$FROM&t=$NOW" # Test DAILY chart (last 30 days) FROM=$((NOW - 2592000000)) curl -H "Authorization: Bearer $TOKEN" \ "http://localhost:8080/api/v1/reports/sales-chart?f=$FROM&t=$NOW" # Test MONTHLY chart (last 6 months) FROM=$((NOW - 15552000000)) curl -H "Authorization: Bearer $TOKEN" \ "http://localhost:8080/api/v1/reports/sales-chart?f=$FROM&t=$NOW" ``` ## Files Reference ### Core Files | File | Description | |------|-------------| | `papayapos-backend/scripts/seed-db.sh` | Main seeding script | | `papayapos-common/psa.tools/src/main/java/psa/tools/db/initunits/InitDbChartTestData.java` | Chart test data generator | | `papayapos-common/psa.tools/src/main/java/psa/tools/db/ToolsContext.java` | InitDbUnit registry | ### Related Entities | Entity | Table | Key Fields | |--------|-------|------------| | AccountingTransaction | accountingtransactionentity | CLOSED_TIME, ACCOUNTING_TRANSACTION_STATE='CLOSED', ACCOUNTING_TRANSACTION_TYPE='RECEIPT' | | AccountingTransactionPayment | accountingtransactionpaymententity | PAYMENT_TYPE, PAYMENT_STATE='CREATED', AMOUNT | | SalePlace | saleplaceentity | IS_ENABLED=true (required for reports) | ## Troubleshooting ### No Data in Reports 1. **Check sale place is enabled:** ```bash docker exec papayapos-backend-postgres-1 psql -U postgres -c \ "SELECT \"ID\", \"IS_ENABLED\" FROM \"68cd0406-6670-496f-ab05-b5da25f282e6\".saleplaceentity;" ``` 2. **Check payment state is CREATED:** ```bash docker exec papayapos-backend-postgres-1 psql -U postgres -c \ "SELECT \"PAYMENT_STATE\", COUNT(*) FROM \"68cd0406-6670-496f-ab05-b5da25f282e6\".accountingtransactionpaymententity GROUP BY \"PAYMENT_STATE\";" ``` 3. **Check transaction type is RECEIPT:** ```bash docker exec papayapos-backend-postgres-1 psql -U postgres -c \ "SELECT \"ACCOUNTING_TRANSACTION_TYPE\", COUNT(*) FROM \"68cd0406-6670-496f-ab05-b5da25f282e6\".accountingtransactionentity GROUP BY \"ACCOUNTING_TRANSACTION_TYPE\";" ``` ### User Not Authorized Run user setup: ```bash ./scripts/seed-db.sh --setup-user ``` Or manually check: 1. Keycloak user has roles assigned 2. DB mapping exists in `user_keycloak_mapping` ### Script Errors **"bc: command not found"**: Install bc for arithmetic ```bash brew install bc # macOS ``` **"uuidgen: command not found"**: Install uuid-runtime ```bash brew install ossp-uuid # macOS ``` ## Adding New Seeding Scenarios ### 1. Via InitDbUnit (Java) Create new class in `psa.tools/src/main/java/psa/tools/db/initunits/`: ```java @Slf4j public class InitDbNewScenario extends InitDbUnit { @Override protected String getUnitFileName() { return null; // No CSV - generates programmatically } @Override public void init(String base, String lngCode, String countryCode, ModelDataEnum venueType) throws Exception { // Generate data } } ``` Register in `ToolsContext.java` constructor and `getAllDbUnits()`. ### 2. Via Script (SQL) Add new function to `seed-db.sh`: ```bash seed_my_scenario() { log_info "Seeding my scenario..." docker exec "$POSTGRES_CONTAINER" psql -U postgres -c \ "INSERT INTO \"$TENANT_ID\".mytable ..." } ``` Add corresponding flag and call in main execution. ## Instructions for Claude When user asks about seeding test data: 1. **For quick seeding:** ```bash ./scripts/seed-db.sh --chart-data-only --setup-user ``` 2. **For full reset:** ```bash ./scripts/seed-db.sh --reset --setup-user --start-backend ``` 3. **For chart testing:** - Ensure sale place is enabled - Verify data exists for the time range being tested - Use correct API parameters: `f` (from), `t` (to) in milliseconds 4. **For user issues:** - Check Keycloak user exists and has roles - Check `user_keycloak_mapping` table has entry - Token must not be expired (5 min default)