feat: add schema-aligned db types and test factory primitives#4326
feat: add schema-aligned db types and test factory primitives#4326skwowet wants to merge 11 commits into
Conversation
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Introduces schema-aligned persistence types, DAL batch helpers, and reusable database test factories.
Changes:
- Adds canonical
*DbRowand*DbInserttypes. - Adds batch DAL inserts and migrates existing callers.
- Adds test-kit factories, fixtures, and supporting ADRs.
Review note: Blocking issues include removed DAL exports breaking existing workers, malformed empty segment inserts, and factory contracts that do not preserve required inputs. The PR title also lacks the required JIRA key.
Reviewed changes
Copilot reviewed 47 out of 49 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
services/libs/types/src/organizations.ts |
Removes superseded identity input type. |
services/libs/types/src/index.ts |
Exports database types. |
services/libs/types/src/db/segments.ts |
Defines segment row/insert types. |
services/libs/types/src/db/organizations.ts |
Defines organization row/insert types. |
services/libs/types/src/db/organization-identities.ts |
Defines organization identity types. |
services/libs/types/src/db/members.ts |
Defines member row/insert types. |
services/libs/types/src/db/member-segment-affiliations.ts |
Defines segment affiliation types. |
services/libs/types/src/db/member-organizations.ts |
Defines member-organization types. |
services/libs/types/src/db/member-organization-affiliation-overrides.ts |
Defines override types. |
services/libs/types/src/db/member-identities.ts |
Defines member identity types. |
services/libs/types/src/db/index.ts |
Exports DB type modules. |
services/libs/types/src/db/activity-relations.ts |
Defines activity relation types. |
services/libs/test-kit/src/types.ts |
Removes obsolete PostgreSQL type. |
services/libs/test-kit/src/faker.ts |
Exposes Faker. |
services/libs/test-kit/src/factories/segment.ts |
Adds hierarchical segment factory. |
services/libs/test-kit/src/factories/organization.ts |
Adds organization factory. |
services/libs/test-kit/src/factories/organization-identity.ts |
Adds organization identity factory. |
services/libs/test-kit/src/factories/member.ts |
Adds member factory. |
services/libs/test-kit/src/factories/member-segment-affiliation.ts |
Adds segment affiliation factory. |
services/libs/test-kit/src/factories/member-organization.ts |
Adds member-organization factory. |
services/libs/test-kit/src/factories/member-organization-affiliation-override.ts |
Adds override factory. |
services/libs/test-kit/src/factories/member-identity.ts |
Adds member identity factory. |
services/libs/test-kit/src/factories/index.ts |
Exports factories. |
services/libs/test-kit/src/factories/defaults.ts |
Adds default application utility. |
services/libs/test-kit/src/factories/activity-relation.ts |
Adds activity relation helpers. |
services/libs/test-kit/src/db/qx.ts |
Adds Vitest query-executor fixture. |
services/libs/test-kit/src/db/postgres.ts |
Localizes PostgreSQL configuration type. |
services/libs/test-kit/src/db/index.ts |
Exports database test utilities. |
services/libs/test-kit/package.json |
Adds exports and dependencies. |
services/libs/data-access-layer/src/segments/index.ts |
Adds segment batch insertion. |
services/libs/data-access-layer/src/organizations/identities.ts |
Adds organization identity batching. |
services/libs/data-access-layer/src/organizations/base.ts |
Adds organization batch insertion. |
services/libs/data-access-layer/src/old/apps/data_sink_worker/repo/settings.repo.ts |
Uses targeted integrations import. |
services/libs/data-access-layer/src/old/apps/data_sink_worker/repo/member.repo.ts |
Uses renamed identity helper. |
services/libs/data-access-layer/src/members/organizations.ts |
Adds member-organization batching. |
services/libs/data-access-layer/src/members/identities.ts |
Renames and aligns identity insertion. |
services/libs/data-access-layer/src/members/base.ts |
Aligns member creation with DB types. |
services/libs/data-access-layer/src/member-organization-affiliation/index.ts |
Supports returning override rows. |
services/libs/data-access-layer/src/member_segment_affiliations/index.ts |
Adds affiliation batch insertion. |
services/libs/data-access-layer/src/index.ts |
Updates DAL barrel exports. |
services/libs/data-access-layer/src/activities/sql.ts |
Uses targeted display-service import. |
services/libs/data-access-layer/package.json |
Adds test tooling dependencies. |
services/apps/members_enrichment_worker/src/activities/enrichment.ts |
Batches organization identities. |
pnpm-lock.yaml |
Updates dependency resolution. |
docs/adr/README.md |
Indexes the new ADRs. |
docs/adr/0007-test-factory-primitives-and-defaults.md |
Documents factory design. |
docs/adr/0006-database-schema-types-as-source-of-truth.md |
Documents schema-type policy. |
backend/src/database/repositories/organizationRepository.ts |
Uses batched identity insertion. |
backend/src/api/public/v1/members/createMember.ts |
Uses renamed identity insertion helper. |
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 47 out of 49 changed files in this pull request and generated 9 comments.
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
Comments suppressed due to low confidence (1)
services/libs/data-access-layer/src/index.ts:27
- These removals break existing root imports from this package. For example, packages_worker imports
BqStats/OsspckgsJobKindfromosspckgs/types,recordDownloadSnapshotfromosspckgs/downloads, and the RubyGems helpers fromosspckgs/rubygemsvia@crowd/data-access-layer; those exports disappear after this change and the affected workspaces will no longer type-check. Restore the public exports (or migrate every consumer in this PR).
export * from './osspckgs/stewardships'
export * from './osspckgs/types'
export * from './osspckgs/versions'
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
…liation inserts Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
|
|
||
| ## Decision | ||
|
|
||
| Treat test setup as **composition of sharp primitives**, not smart world-builders. Keep three layers separate. |
| TinybirdClient, | ||
| } from '@crowd/database' | ||
| import { ActivityDisplayService } from '@crowd/integrations' | ||
| import { ActivityDisplayService } from '@crowd/integrations/src/integrations/activityDisplayService' |
There was a problem hiding this comment.
just out of curiosity, is there any reason why we changed this import ?
Summary
Introduces schema-aligned DB types, DAL batch insert helpers, and test-kit factory primitives. Shared foundation for DB-backed tests and better type safety when reading/writing persisted data across backend, workers, DAL, and test utilities.
Why
Entity shapes are duplicated and drift across
@crowd/types, DAL inputs, merge helpers, and API models — often with wrong nullability and incomplete field sets.This PR starts fixing that by anchoring types to the database schema and routing inserts through consistent DAL helpers. Tests build on the same paths production code uses, instead of parallel ad-hoc shapes.
Changes
Types (
@crowd/types/src/db)*DbRow/*DbInserttypes for members, identities, organizations, segments, activity relations, member organizations, and related tablesPick,Partial,Omit) — no more hand-maintained duplicatesorganizations.tsTest kit (
@crowd/test-kit)db/(postgres,withQx) andfactories/create*— persist via DAL, no faker or hidden scaffoldingwith*Defaults— opt-in fill for harmless fields only; tests own scenario-defining dataDAL
*DbInsert:insertMemberIdentities,insertOrganizationIdentities,insertOrganizations,insertSegmentsinsertManyMemberIdentities→insertMemberIdentities,addOrgIdentity→insertOrganizationIdentitiessegments.typeon insert (generated column)changeMemberOrganizationAffiliationOverridessupportsreturnRowsactivityTypesto avoid pulling the integrations barrel in testsCall sites
createMember,organizationRepository,enrichment.ts,member.repo.tsto use new helpersDocs