feat(records): add records router#6285
Conversation
| } | ||
|
|
||
| private resolve(): RecordsStore { | ||
| return this.store; |
There was a problem hiding this comment.
for now router.resolve is very simple, only putting the scaffolding in place to implement on demand assignment and dispatching
There was a problem hiding this comment.
💡 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".
| environmentIds?: number[]; | ||
| batchSize?: number; | ||
| }) => AsyncGenerator<Result<RecordCount[]>>; | ||
| paginateCounts: (params?: { connectionIds?: number[]; environmentIds?: number[]; batchSize?: number }) => AsyncGenerator<Result<RecordCount[]>>; |
There was a problem hiding this comment.
fix: params was actually optional
| export type * from './types.js'; | ||
|
|
||
| export const records = new PostgresStore(); | ||
| export { records } from './catalog/router.js'; |
There was a problem hiding this comment.
records used by all the apps is now the router one.
There was a problem hiding this comment.
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 todistcan breakstore.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
| 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}`); |
There was a problem hiding this comment.
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>
| await this.db.raw(`CREATE SCHEMA IF NOT EXISTS ${schema}`); | |
| await this.db.raw('CREATE SCHEMA IF NOT EXISTS ??', [schema]); |
| .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 |
There was a problem hiding this comment.
safe to rename. They are not overwritten at the infra level
There was a problem hiding this comment.
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
bb304f6 to
e953943
Compare
There was a problem hiding this comment.
💡 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".
for now it always statically resolves to the current PostgresStore called default
e953943 to
de795c1
Compare
de795c1 to
3f6cda5
Compare
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)