Skip to content

feat: infer organization country from location (CM-1366) - #4451

Merged
skwowet merged 2 commits into
mainfrom
feat/CM-1366-infer-org-country-from-location
Aug 7, 2026
Merged

feat: infer organization country from location (CM-1366)#4451
skwowet merged 2 commits into
mainfrom
feat/CM-1366-infer-org-country-from-location

Conversation

@skwowet

@skwowet skwowet commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Infer organization country from location on write when country is missing, using the shared getCountry helper
  • Dual-write to orgAttributes (source=system) and organizations.country, same pattern as location

Changes

  • Add organizations.country column migration
  • Register country as an org attribute with defaultColumn: 'country'
  • Add system attribute source (priority after custom / lfx-serve)
  • Infer country in prepareOrganizationData after attributes are resolved
  • Cover findOrCreate (integrations, public API, members enrichment org upsert) and org enrichment apply path

Copilot AI balanced review requested due to automatic review settings August 7, 2026 14:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds inferred organization countries across the shared DAL, enrichment workflow, and persistence layer.

Changes:

  • Adds country fields and database migration.
  • Infers country from location using a system attribute.
  • Extends organization enrichment and legacy persistence paths.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
services/libs/types/src/organizations.ts Adds organization country type.
services/libs/types/src/enums/organizations.ts Adds the system attribute source.
services/libs/types/src/db/organizations.ts Adds country to database rows.
services/libs/data-access-layer/src/organizations/utils.ts Implements country inference.
services/libs/data-access-layer/src/organizations/types.ts Extends DAL organization types.
services/libs/data-access-layer/src/organizations/base.ts Persists and selects country.
services/libs/data-access-layer/src/organizations/attributesConfig.ts Registers country and source priority.
services/apps/organizations_enrichment_worker/src/activities/enrichment.ts Loads country and location during enrichment.
backend/src/database/repositories/organizationRepository.ts Supports country in legacy updates.
backend/src/database/models/organization.ts Maps the country column in Sequelize.
backend/src/database/migrations/V1786109400__add_country_to_organizations.sql Adds the country column.
Suppressed comments (2)

services/libs/data-access-layer/src/organizations/utils.ts:223

  • Once a system country has been inferred, this guard finds it in existingAttributes and permanently skips inference. If the default location later changes (for example, France to Germany), both the default country attribute and organizations.country remain stale. Treat only non-system country sources as authoritative, and refresh or clear the system-derived value when the default location changes.
  if (
    !attributes.some(({ name }) => name === 'country') &&
    !(existingAttributes ?? []).some(({ name }) => name === 'country')
  ) {

backend/src/database/migrations/V1786109400__add_country_to_organizations.sql:5

  • Adding the PostgreSQL column does not make it available to Insights: services/libs/tinybird/datasources/organizations.datasource has no country field, and organizations_geo_distribution.pipe:27-34 still derives countries from location. As written, the stated Insights consumer cannot use this dual-write. Add the datasource field and update the relevant pipe to consume it (with any desired fallback).
  add column if not exists "country" text;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread services/libs/data-access-layer/src/organizations/utils.ts
Comment thread backend/src/database/migrations/V1786109400__add_country_to_organizations.sql Outdated
skwowet added 2 commits August 7, 2026 20:05
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 7, 2026 14:36
@skwowet
skwowet force-pushed the feat/CM-1366-infer-org-country-from-location branch from 0660588 to 449d2e5 Compare August 7, 2026 14:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Suppressed comments (1)

services/libs/data-access-layer/src/organizations/utils.ts:219

  • This comment only restates the following block and conflicts with the repository rule that code should be self-explanatory rather than annotated with what it does. Please remove it.
  // Infer country from location when missing

@skwowet
skwowet merged commit 2496c0a into main Aug 7, 2026
14 checks passed
@skwowet
skwowet deleted the feat/CM-1366-infer-org-country-from-location branch August 7, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants