Skip to content

refactor(records): add RecordsStore interface#6263

Merged
TBonnin merged 1 commit into
masterfrom
tbonnin/nan-5692/records-refactor-interface
May 28, 2026
Merged

refactor(records): add RecordsStore interface#6263
TBonnin merged 1 commit into
masterfrom
tbonnin/nan-5692/records-refactor-interface

Conversation

@TBonnin

@TBonnin TBonnin commented May 27, 2026

Copy link
Copy Markdown
Collaborator

Add RecordsStore interface and refactor records.ts into a postgres implementation of RecordsStore.
PR looks big but it is only moving code around. No changes of behavior, only a refactor to be able to have multiple instance of records store

Next step: not expose the PostgresStore directly but a RecordsRouter that will dispatch operations to the appropriate store instance

@TBonnin TBonnin requested a review from a team May 27, 2026 22:21
@linear

linear Bot commented May 27, 2026

Copy link
Copy Markdown

NAN-5692

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

/db folder has been renamed /stores/postgres. That's why all the migrations files are shown in the diff

cubic-dev-ai[bot]

This comment was marked as resolved.

@NangoHQ NangoHQ deleted a comment from cubic-dev-ai Bot May 28, 2026
Add RecordsStore interface and refactor records.ts into a postgres
implementation of RecordsStore.
No changes of behavior, only a refactor to be able to have multiple
instance of records store.
@TBonnin TBonnin force-pushed the tbonnin/nan-5692/records-refactor-interface branch from acbac3c to cecfb83 Compare May 28, 2026 13:09
}
}

export async function incrCount(

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.

Nit: does the function really need to be exported from the module?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

it is indeed only used for testing. This was already the case before the refactoring and I didn't want to change it. It is not exported outside of the records package though

Comment on lines +35 to +38
records.startDaemon({
tickIntervalMs: envs.PERSIST_SEEN_PARTITION_INTERVAL_MS,
maxAgeMs: envs.PERSIST_SEEN_PARTITION_MAX_AGE_MS
});

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.

Will we want to think of records (main export from @nangohq/records) as a polymorphic reference at some point (ie. anything that implements RecordsStore), or will it remain a PostgresStore? If so, startDaemon might be leaking out of the abstraction, as it is currently defined as a PostgresStore-specific method.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The idea is to have the exported records to be the router (which implements the same interface, take care of assigning/routing logic and dispatch to the actual stores which are fully abstracted from the point of view of the callers of the records package.
You are right that the postgres daemon is currently leaking out of the abstraction but I didn't want to change too much in this PR. Eventually hiding the implementation details of the store(s) is the objective though.

@TBonnin TBonnin added this pull request to the merge queue May 28, 2026
Merged via the queue into master with commit 801eb1d May 28, 2026
26 of 27 checks passed
@TBonnin TBonnin deleted the tbonnin/nan-5692/records-refactor-interface branch May 28, 2026 14:54
agusayerza added a commit that referenced this pull request May 28, 2026
.dockerignore strips files under **/tests/ from the docker build context.
Reverting #6263's move of the clearDb helper into stores/postgres/tests/
so it is not stripped from the image.
agusayerza added a commit that referenced this pull request May 28, 2026
.dockerignore strips **/tests/ from the docker build context, so #6263's
re-export of clearDb from a tests/ file crashed the server on startup.
Import the helper directly in the one test that uses it.
TBonnin pushed a commit that referenced this pull request May 28, 2026
.dockerignore strips **/tests/ from the docker build context, so #6263's
re-export of clearDb from a tests/ file crashed the server on startup.
Import the helper directly in the one test that uses it.
pfreixes added a commit that referenced this pull request Jun 1, 2026
…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.)
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.

3 participants