feat: infer organization country from location (CM-1366) - #4451
Merged
Conversation
Contributor
There was a problem hiding this comment.
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
systemcountry has been inferred, this guard finds it inexistingAttributesand permanently skips inference. If the default location later changes (for example, France to Germany), both the default country attribute andorganizations.countryremain 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.datasourcehas nocountryfield, andorganizations_geo_distribution.pipe:27-34still derives countries fromlocation. 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.
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
skwowet
force-pushed
the
feat/CM-1366-infer-org-country-from-location
branch
from
August 7, 2026 14:36
0660588 to
449d2e5
Compare
Contributor
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
getCountryhelperorgAttributes(source=system) andorganizations.country, same pattern as locationChanges
organizations.countrycolumn migrationcountryas an org attribute withdefaultColumn: 'country'systemattribute source (priority aftercustom/lfx-serve)prepareOrganizationDataafter attributes are resolved