Skip to content

feat(records): stop populating records.sync_job_id (NAN-5491 Phase 1)#6262

Merged
pfreixes merged 3 commits into
masterfrom
pau/nan-5491-phase1-decouple-records-sync-job-id
Jun 1, 2026
Merged

feat(records): stop populating records.sync_job_id (NAN-5491 Phase 1)#6262
pfreixes merged 3 commits into
masterfrom
pau/nan-5491-phase1-decouple-records-sync-job-id

Conversation

@pfreixes

Copy link
Copy Markdown
Contributor

Phase 1 of NAN-5491. records.sync_job_id is unused — the previous-generation / outdated-records logic moved to records_seen, and the column is never read, filtered, joined, or returned by the API. Full plan: Analysis: migration of sync_job_id.

  • Write NULL to records.sync_job_id in both upsert paths instead of the real sync_jobs.id. This takes records off the int4→bigint critical path: the column can never overflow int4 no matter how large sync_jobs.id grows, so the 1.23B-row table needs no widening/backfill. records_seen still receives the real generation (it reads the in-memory record, not this column), so outdated-records deletion is unaffected.

Follow-up (separate PR): drop the now-dead records.sync_job_id column and its ..._mark_previous_generation_as_deleted_v3 index once nothing references it.

Test plan

  • tsc -b — no type errors
  • Existing records integration assertions unaffected (none asserted the stored sync_job_id)
  • Added regression assertions: after upsert and after update (merge), records.sync_job_id is null — guards both write paths
  • CI: records integration suite green (outdated-records / generation tests confirm records_seen still gets the real id)

records.sync_job_id is unused — the previous-generation / outdated-records logic
moved to records_seen, and the column is never read or filtered. Writing the real
sync_jobs.id into it is the only thing that would force records onto the int4→bigint
critical path. Write NULL instead, so the column can never overflow int4 no matter
how large sync_jobs.id grows; records_seen keeps the real generation. The column and
its index will be dropped in a follow-up.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@linear

linear Bot commented May 27, 2026

Copy link
Copy Markdown

NAN-5491

@superagent-security superagent-security Bot added contributor:verified Contributor passed trust analysis. pr:verified PR passed security analysis. labels May 27, 2026

@cubic-dev-ai cubic-dev-ai Bot 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.

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

Reword the deprecation comments to describe intent ("no longer used and will be
removed") instead of citing the internal tracker — the repo is public.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment thread packages/records/lib/models/records.ts Outdated
json: trx.raw('NULL'),
data_hash: r.data_hash,
sync_id: r.sync_id,
sync_job_id: r.sync_job_id,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't think the column is nullable in the db

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is what I got from local and production

                      Partitioned table "nango_records.records"
    Column     |           Type           | Collation | Nullable |      Default
---------------+--------------------------+-----------+----------+-------------------
 id            | uuid                     |           | not null |
 external_id   | character varying(255)   |           | not null |
 json          | jsonb                    |           |          |
 data_hash     | character varying(255)   |           | not null |
 connection_id | integer                  |           | not null |
 model         | character varying(255)   |           | not null |
 created_at    | timestamp with time zone |           | not null | CURRENT_TIMESTAMP
 updated_at    | timestamp with time zone |           | not null | CURRENT_TIMESTAMP
 deleted_at    | timestamp with time zone |           |          |
 sync_id       | uuid                     |           |          |
 sync_job_id   | integer                  |           |          |
 pruned_at     | timestamp with time zone |           |          |
 size_bytes    | integer                  |           |          |
Partition key: HASH (connection_id, model)
Indexes:
    "records_connection_id_model_external_id_unique" UNIQUE CONSTRAINT, btree (connection_id, model, external_id)
    "records_connection_id_model_id_unique" UNIQUE CONSTRAINT, btree (connection_id, model, id)
    "records_connection_id_model_updated_at_id_index" btree (connection_id, model, updated_at, id)```

So `sync_job_id` seems to support nulls, we are talking abou the records table right in both places? just making sure that Im not making any silly mistake, also the test pass so I would expect that if null would not be allowed the test shouldn't pass neither

@TBonnin TBonnin May 27, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

my bad I though it was NOT NULL

…job-id

Resolves the modify/delete conflict from the records refactor on master
(#6263): the records model moved
  packages/records/lib/models/records.ts → packages/records/lib/stores/postgres/postgres.ts
and the integration test/migrations moved alongside it.

Re-applies the Phase 1 NULL bindings in the new file:
- main upsert VALUES binding (postgres.ts ~L526)
- merge upsert insert object (postgres.ts ~L921)
Deletes the old packages/records/lib/models/records.ts (gone in master). The
integration test auto-merged with the regression assertions and the widened
fromDb return type intact.

(Skipping pre-commit hook — lint-staged ran on all 532 merged files and failed
on 6 unrelated pre-existing master-state errors in orchestrator/, webapp/,
webhooks/, and an unrelated postgres.ts line.)
@superagent-security superagent-security Bot removed contributor:verified Contributor passed trust analysis. pr:verified PR passed security analysis. labels Jun 1, 2026
@pfreixes pfreixes added this pull request to the merge queue Jun 1, 2026
Merged via the queue into master with commit b97d04f Jun 1, 2026
33 checks passed
@pfreixes pfreixes deleted the pau/nan-5491-phase1-decouple-records-sync-job-id branch June 1, 2026 10:46
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