|
| 1 | +# Test Database Workflows |
| 2 | + |
| 3 | +## Centralized Test Schema |
| 4 | + |
| 5 | +The database integration tests use a centralized schema to ensure consistency across all supported databases. |
| 6 | + |
| 7 | +### Schema File |
| 8 | + |
| 9 | +**`test-schema.json`** - Contains the complete test schema with: |
| 10 | +- **84 columns** covering all generator types |
| 11 | +- **83 generator fields** (excluding auto-increment ID) |
| 12 | +- All categories: Personal, Location, Network, Financial, Time, Localization, Product, Files, Media, Animals, Food, Vehicles, Identifiers, Text, and App data |
| 13 | + |
| 14 | +### How It Works |
| 15 | + |
| 16 | +Each database test job: |
| 17 | +1. Merges the centralized schema with database-specific configuration using `jq` |
| 18 | +2. Validates that exactly 83 generator fields are present |
| 19 | +3. Creates and populates the test table |
| 20 | +4. Verifies the row count |
| 21 | + |
| 22 | +### Benefits |
| 23 | + |
| 24 | +✅ **Single Source of Truth** - All generator fields defined once |
| 25 | +✅ **Consistency** - Same tests across all 6 databases |
| 26 | +✅ **Easy Updates** - Add new generators in one place |
| 27 | +✅ **Validation** - Automatic field count verification |
| 28 | +✅ **Reduced Duplication** - 71 lines vs 569 lines per database |
| 29 | + |
| 30 | +### Supported Databases |
| 31 | + |
| 32 | +1. **MySQL** 8.0 |
| 33 | +2. **MariaDB** 10.11 |
| 34 | +3. **PostgreSQL** 14 |
| 35 | +4. **SQLite** 3.x |
| 36 | +5. **MS SQL Server** 2022 |
| 37 | +6. **CockroachDB** Latest |
| 38 | + |
| 39 | +### Adding New Generators |
| 40 | + |
| 41 | +To add a new generator to all database tests: |
| 42 | + |
| 43 | +1. Add the column to `test-schema.json` in the `tables[0].columns` array |
| 44 | +2. Add the generator field to `test-schema.json` in the `populate[0].fields` array |
| 45 | +3. Update the field count validation in `test-databases.yml` (increment the `83` in all 6 tests) |
| 46 | + |
| 47 | +Example: |
| 48 | +```json |
| 49 | +// In tables[0].columns: |
| 50 | +{"name": "new_field", "type": {"name": "string", "args": {"length": 50}}} |
| 51 | + |
| 52 | +// In populate[0].fields: |
| 53 | +{"name": "new_field", "generator": "new_generator"} |
| 54 | +``` |
| 55 | + |
| 56 | +### Schema Validation |
| 57 | + |
| 58 | +Each test automatically validates: |
| 59 | +```bash |
| 60 | +FIELD_COUNT=$(jq '.populate[0].fields | length' test-schema.json) |
| 61 | +[ "$FIELD_COUNT" -eq 83 ] || (echo "❌ Expected 83 fields, got $FIELD_COUNT" && exit 1) |
| 62 | +``` |
| 63 | + |
| 64 | +This ensures no fields are accidentally omitted during schema merging. |
0 commit comments