Skip to content

[LOCKLITE-145] Create a database seed#85

Merged
vbetsch merged 14 commits intodevelopfrom
api/test/145-prisma-seed
Aug 9, 2025
Merged

[LOCKLITE-145] Create a database seed#85
vbetsch merged 14 commits intodevelopfrom
api/test/145-prisma-seed

Conversation

@vbetsch
Copy link
Owner

@vbetsch vbetsch commented Aug 9, 2025

No description provided.

@vbetsch vbetsch requested a review from Copilot August 9, 2025 15:42
@vbetsch vbetsch self-assigned this Aug 9, 2025
@vbetsch vbetsch added database About database schema or models api About endpoints and services labels Aug 9, 2025
@notion-workspace
Copy link

Créer un seed Prisma

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 createOrUpdate method 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',
Copy link

Copilot AI Aug 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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'),

Copilot uses AI. Check for mistakes.
{
name: 'Standard User',
email: 'user@example.com',
passwordPlain: 'user',
Copy link

Copilot AI Aug 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
passwordPlain: 'user',
passwordPlain: generateStrongPassword(),

Copilot uses AI. Check for mistakes.
return await this._usersRepository.createOrUpdate({
email: input.email,
// eslint-disable-next-line no-undefined
name: input.name || undefined,
Copy link

Copilot AI Aug 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Suggested change
name: input.name || undefined,
name: input.name ?? undefined,

Copilot uses AI. Check for mistakes.
if (existingVaults.length === 0) {
await this._vaultsRepository.createMany({
userId: user.id,
vaults: vaults,
Copy link

Copilot AI Aug 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This object property assignment uses redundant syntax. It can be simplified to just vaults since the parameter name matches the property name.

Suggested change
vaults: vaults,
vaults,

Copilot uses AI. Check for mistakes.
@vbetsch vbetsch merged commit c3b8fe6 into develop Aug 9, 2025
4 checks passed
@vbetsch vbetsch deleted the api/test/145-prisma-seed branch August 9, 2025 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api About endpoints and services database About database schema or models

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants