-
Notifications
You must be signed in to change notification settings - Fork 0
Add generate-test-data CLI tool for comprehensive database population with service-based architecture #209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
@copilot the script should obviously also populate supporting tables: such as contest_registrations_requests, contest_participants, access_control etc. |
Updated the proposal to include all supporting tables:
Added CLI parameters to control:
The comprehensive proposal is now in the PR description, including all 16 tables to be populated. |
|
@copilot keep in mind that population should probably happen with running db and file storage. So you should verify at start that they are running. Because for example to upload task files you need file storage |
Updated the proposal to include pre-flight connectivity checks: Before generating data:
New CLI flags:
Execution flow now starts with verifying both PostgreSQL and file storage are running before attempting to upload task files or create any database records. The tool will exit early with helpful error messages if connectivity fails. |
|
@copilot approved. You can implement |
Co-authored-by: HermanPlay <78978614+HermanPlay@users.noreply.github.com>
Co-authored-by: HermanPlay <78978614+HermanPlay@users.noreply.github.com>
Implementation complete in commit fb4b045. CLI tool created at
Build status: Ready to use: go build -o generate-test-data ./cmd/generate-test-data
./generate-test-data --help |
Co-authored-by: HermanPlay <78978614+HermanPlay@users.noreply.github.com>
|
…se defaults to 50+ users Co-authored-by: HermanPlay <78978614+HermanPlay@users.noreply.github.com>
All three changes implemented in commit 66c87dd:
Test with: |
|
@copilot please use services to generate objects. This way we can for example handle file upload using consistent logic in generator and app. The same goes for users, generate users, using auth service to ensure that password generation is the same. Do not create direct models. |
…nsistent password hashing Co-authored-by: HermanPlay <78978614+HermanPlay@users.noreply.github.com>
Refactored to use services in commit d4e278d: User Generation now uses AuthService:
Service Layer Integration:
New Requirement:
The tool now uses the same authentication/user creation logic as the main application, ensuring password generation consistency. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Implements a comprehensive Go CLI tool for generating realistic test data in the Mini-Maxit database, addressing all requirements from the original issue. Uses service layer for data generation to ensure consistency with application business logic.
Implementation Complete
Successfully created a production-ready CLI tool at
/cmd/generate-test-data/that generates comprehensive test data for all database entities using the application's service layer.Service-Based Architecture
Key Design Decision: The tool uses the application's service layer instead of direct model creation to ensure consistency:
AuthService.Register()for password hashing, ensuring identical authentication logic as the main applicationAll Tables Populated (16 Total)
Core Entities:
Supporting Tables:
6. UserGroup - many-to-many user-group relationships
7. ContestTask - tasks assigned to contests with timing
8. ContestParticipant - individual user participation
9. ContestParticipantGroup - group participation in contests
10. ContestRegistrationRequests - pending/approved/rejected registration requests
11. AccessControl - permissions for tasks and contests (owner/manage/edit)
12. TestCase - test cases for tasks with input/output files
13. File - all file metadata (task descriptions, test cases, submissions, results)
14. LanguageConfig - programming languages (C, C++, etc.)
15. SubmissionResult - evaluation results
16. TestResult - individual test case results
Pre-flight Checks
The tool verifies required services before generating data:
sqlDB.Ping()Use
--skip-connectivity-checkto bypass these checks for offline testing.CLI Parameters (30+ Flags)
User Generation:
--users,--admin-count,--teacher-count,--student-count- Control user count and role distribution--user-password- Default password (hashed via AuthService, default: "password123")Group Generation:
--groups,--users-per-group- Control group count and membershipTask Generation:
--tasks,--visible-tasks,--tests-per-task- Control task count, visibility, and test cases--fixtures-dir- Path to task archive fixtures (default: "./fixtures")--create-fixtures- Create sample fixture files if they don't existContest Generation:
--contests,--tasks-per-contest,--participants-per-contest- Control contest configuration--group-participants-per-contest- Control group participationSubmission Generation:
--submissions-per-task,--submissions-per-contest- Control submission volumeSupporting Data:
--registration-requests-per-contest- Pending/approved/rejected registration requests--collaborators-per-task,--collaborators-per-contest- Users with edit/manage permissions via AccessControlDatabase & File Storage:
--db-*flags - Override env vars for DB connection--file-storage-host,--file-storage-port- Override file storage connection settingsUtilities:
--clear-existing- Truncate tables before generation--seed- Random seed for reproducible data (0 = time-based)--skip-connectivity-check- Skip pre-flight connectivity checks--dry-run- Show what would be created without creating--verbose- Detailed progress outputExample Usage
Implementation Details
/cmd/generate-test-data/main.go(1400+ lines)github.com/spf13/cobrav1.10.2 (CLI framework)github.com/brianvoe/gofakeit/v7v7.12.1 (realistic fake data generation)github.com/joho/godotenvv1.5.1 (automatic .env loading).envfrom project rootJWT_SECRET_KEYenvironment variable required for AuthServiceDefault Data Generation
The tool generates substantial test data by default:
password123(hashed via AuthService)Data Generation Flow
.envfrom project root--clear-existingVerification
✅ Builds successfully
✅ All existing tests pass
✅ go vet clean
✅ Code review feedback addressed
✅ CodeQL security scan: 0 alerts
✅ Service-based architecture ensures consistency with application
✅ Ready for production use
Files Created
/cmd/generate-test-data/main.go- Complete implementation with service layer integration/cmd/generate-test-data/README.md- Comprehensive documentation.gitignore- Excludes build artifactOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.