Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR implements a database seeding functionality to populate initial user and vault data for development/testing purposes. The implementation includes new repository methods, type definitions, seed data, and infrastructure to create users with associated vaults.
Key changes:
- Added database seeding infrastructure with user creation and vault management
- Implemented
createOrUpdatemethod in users repository for upsert operations - Created bulk vault creation functionality with duplicate prevention
Reviewed Changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/modules/api/infra/repositories/vaults.repository.ts |
Adds createMany method for bulk vault creation |
src/modules/api/infra/repositories/users.repository.ts |
Implements createOrUpdate upsert method |
src/modules/api/infra/records/vaults/create-many-vaults.record.ts |
Defines type for bulk vault creation |
src/modules/api/infra/prisma/seed/types/vault.type.seed.ts |
Type definition for vault seed data |
src/modules/api/infra/prisma/seed/types/user.type.seed.ts |
Type definition for user seed data |
src/modules/api/infra/prisma/seed/seed.ts |
Main seeding script with error handling |
src/modules/api/infra/prisma/seed/data/users.data.seed.ts |
Predefined user and vault seed data |
src/modules/api/domain/usecases/seed/upsert-user-with-vaults.usecase.ts |
Business logic for creating users with vaults |
package.json |
Adds seeding scripts and tsx dependency |
Makefile |
Updates make targets for seeding workflow |
| { | ||
| name: 'Administrator', | ||
| email: 'admin@example.com', | ||
| passwordPlain: 'admin', |
There was a problem hiding this comment.
Using weak passwords like 'admin' and 'user' in seed data poses a security risk, especially if this data is used in non-development environments. Consider using stronger default passwords or environment-specific password generation.
| passwordPlain: 'admin', | |
| import { randomBytes } from 'crypto'; | |
| // Use strong random passwords for seed users to avoid security risks. | |
| export const usersToSeed: ReadonlyArray<UserTypeSeed> = [ | |
| { | |
| name: 'Administrator', | |
| email: 'admin@example.com', | |
| passwordPlain: randomBytes(16).toString('hex'), |
| { | ||
| name: 'Standard User', | ||
| email: 'user@example.com', | ||
| passwordPlain: 'user', |
There was a problem hiding this comment.
Using weak passwords like 'admin' and 'user' in seed data poses a security risk, especially if this data is used in non-development environments. Consider using stronger default passwords or environment-specific password generation.
| passwordPlain: 'user', | |
| passwordPlain: generateStrongPassword(), |
| return await this._usersRepository.createOrUpdate({ | ||
| email: input.email, | ||
| // eslint-disable-next-line no-undefined | ||
| name: input.name || undefined, |
There was a problem hiding this comment.
[nitpick] The eslint disable comment suggests there might be a better way to handle this. Consider using input.name ?? undefined or checking the project's style guide for the preferred way to handle nullable values.
| name: input.name || undefined, | |
| name: input.name ?? undefined, |
| if (existingVaults.length === 0) { | ||
| await this._vaultsRepository.createMany({ | ||
| userId: user.id, | ||
| vaults: vaults, |
There was a problem hiding this comment.
This object property assignment uses redundant syntax. It can be simplified to just vaults since the parameter name matches the property name.
| vaults: vaults, | |
| vaults, |
No description provided.