Skip to content

feat(records): add records router#6285

Merged
TBonnin merged 3 commits into
masterfrom
tbonnin/nan-5692/records-router
May 29, 2026
Merged

feat(records): add records router#6285
TBonnin merged 3 commits into
masterfrom
tbonnin/nan-5692/records-router

Conversation

@TBonnin

@TBonnin TBonnin commented May 28, 2026

Copy link
Copy Markdown
Collaborator

Adding a RecordsRouter that implements the RecordsStore interface.
For now it always statically resolves to the current PostgresStore called default.
Next: assign to store and retrieve dynamically (still single pg store though)

@TBonnin TBonnin requested a review from a team May 28, 2026 21:20
@linear

linear Bot commented May 28, 2026

Copy link
Copy Markdown

NAN-5692

Comment thread packages/records/lib/catalog/default.ts Outdated
@superagent-security superagent-security Bot added the pr:flagged PR flagged for review by security analysis. label May 28, 2026

@superagent-security superagent-security Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Superagent found 1 security concern(s).

Comment thread packages/records/lib/catalog/default.ts Outdated
}

private resolve(): RecordsStore {
return this.store;

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.

for now router.resolve is very simple, only putting the scaffolding in place to implement on demand assignment and dispatching

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 29f8be8305

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/records/lib/catalog/router.ts Outdated
environmentIds?: number[];
batchSize?: number;
}) => AsyncGenerator<Result<RecordCount[]>>;
paginateCounts: (params?: { connectionIds?: number[]; environmentIds?: number[]; batchSize?: number }) => AsyncGenerator<Result<RecordCount[]>>;

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.

fix: params was actually optional

export type * from './types.js';

export const records = new PostgresStore();
export { records } from './catalog/router.js';

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.

records used by all the apps is now the router one.

@superagent-security superagent-security Bot removed the pr:flagged PR flagged for review by security analysis. label May 28, 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.

5 issues found across 10 files

Confidence score: 2/5

  • There is clear regression risk in packages/records/lib/stores/postgres/postgres.ts: hard-coding migrations to dist can break store.migrate() in source-tree/test/dev workflows, which is directly user-impacting.
  • Several high-confidence lifecycle issues (packages/records/lib/catalog/router.ts, packages/records/lib/catalog/default.ts, packages/records/lib/index.ts) indicate imports now eagerly open the Postgres store and start a daemon, creating unexpected DB side effects and potentially hanging short-lived processes/tests.
  • Given the multiple 6–8/10 severity findings with 8–9/10 confidence, this looks high risk until import-time side effects and migration-path behavior are corrected.
  • Pay close attention to packages/records/lib/stores/postgres/postgres.ts, packages/records/lib/catalog/router.ts, packages/records/lib/catalog/default.ts, packages/records/lib/index.ts - migration resolution, daemon startup timing, and import-time DB side effects need validation.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/records/lib/catalog/router.ts">

<violation number="1" location="packages/records/lib/catalog/router.ts:30">
P1: Avoid instantiating the default store at module load; importing `RecordsRouter` now opens the Postgres store and starts its daemon as a side effect.</violation>
</file>

<file name="packages/records/lib/index.ts">

<violation number="1" location="packages/records/lib/index.ts:5">
P2: This re-export now starts the records background daemon on package import. That makes `@nangohq/records` imports perform unexpected DB work and can keep short-lived processes/tests alive unless they remember to call `records.close()`.</violation>
</file>

<file name="packages/records/lib/stores/postgres/postgres.ts">

<violation number="1" location="packages/records/lib/stores/postgres/postgres.ts:66">
P1: Hard-coding the migrations directory to `dist` breaks `store.migrate()` when this package runs from the source tree (tests/dev `migrate:latest`).</violation>

<violation number="2" location="packages/records/lib/stores/postgres/postgres.ts:70">
P2: Quote the schema identifier instead of interpolating it into raw SQL.</violation>
</file>

<file name="packages/records/lib/catalog/default.ts">

<violation number="1" location="packages/records/lib/catalog/default.ts:51">
P1: Avoid starting the daemon in `getDefaultStore()`: package-root imports now eagerly open DB resources and start background work at module load.</violation>
</file>

Tip: instead of fixing issues one by one fix them all with cubic

Re-trigger cubic

Comment thread packages/records/lib/catalog/router.ts Outdated
Comment thread packages/records/lib/catalog/default.ts Outdated
Comment thread packages/records/lib/index.ts
const dir = path.join(packagesDir, 'dist/stores/postgres/migrations');
const schema = this.migrationsConfig.schemaName;
if (schema) {
await this.db.raw(`CREATE SCHEMA IF NOT EXISTS ${schema}`);

@cubic-dev-ai cubic-dev-ai Bot May 28, 2026

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.

P2: Quote the schema identifier instead of interpolating it into raw SQL.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/records/lib/stores/postgres/postgres.ts, line 70:

<comment>Quote the schema identifier instead of interpolating it into raw SQL.</comment>

<file context>
@@ -49,19 +50,37 @@ interface UpsertedMetadata {
+        const dir = path.join(packagesDir, 'dist/stores/postgres/migrations');
+        const schema = this.migrationsConfig.schemaName;
+        if (schema) {
+            await this.db.raw(`CREATE SCHEMA IF NOT EXISTS ${schema}`);
+        }
+        const [, pendingMigrations] = (await this.db.migrate.list({ ...this.migrationsConfig, directory: dir })) as [unknown, string[]];
</file context>
Suggested change
await this.db.raw(`CREATE SCHEMA IF NOT EXISTS ${schema}`);
await this.db.raw('CREATE SCHEMA IF NOT EXISTS ??', [schema]);
Fix with Cubic

@NangoHQ NangoHQ deleted a comment from cubic-dev-ai Bot May 28, 2026
.max(6 * 3600 * 1000) // max 6 hours to ensure the records_seen daily partition for next day is always created ahead of time
.default(1 * 3600 * 1000),
PERSIST_SEEN_PARTITION_MAX_AGE_MS: z.coerce
RECORDS_POSTGRES_SEEN_PARTITION_MAX_AGE_MS: z.coerce

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.

safe to rename. They are not overwritten at the infra level

@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.

1 issue found across 3 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/records/lib/stores/postgres/postgres.ts">

<violation number="1" location="packages/records/lib/stores/postgres/postgres.ts:66">
P1: Hard-coding the migrations directory to `dist` breaks `store.migrate()` when this package runs from the source tree (tests/dev `migrate:latest`).</violation>

<violation number="2" location="packages/records/lib/stores/postgres/postgres.ts:70">
P2: Quote the schema identifier instead of interpolating it into raw SQL.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread packages/utils/lib/environment/parse.ts
@TBonnin TBonnin force-pushed the tbonnin/nan-5692/records-router branch from bb304f6 to e953943 Compare May 29, 2026 14:18

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e953943e96

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/utils/lib/environment/parse.ts
TBonnin added 2 commits May 29, 2026 11:28
for now it always statically resolves to the current PostgresStore called default
@TBonnin TBonnin force-pushed the tbonnin/nan-5692/records-router branch from e953943 to de795c1 Compare May 29, 2026 15:28
@TBonnin TBonnin enabled auto-merge May 29, 2026 15:31
@TBonnin TBonnin force-pushed the tbonnin/nan-5692/records-router branch from de795c1 to 3f6cda5 Compare May 29, 2026 15:31
@TBonnin TBonnin added this pull request to the merge queue May 29, 2026
Merged via the queue into master with commit 0ee07fe May 29, 2026
27 checks passed
@TBonnin TBonnin deleted the tbonnin/nan-5692/records-router branch May 29, 2026 15:45
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