Add paginator support from convex-helpers for component migrations#27
Add paginator support from convex-helpers for component migrations#27ianmacartney wants to merge 1 commit intomainfrom
Conversation
- Add convex-helpers as peer dependency for improved pagination - Add optional `schema` parameter to Migrations constructor - Use paginator from convex-helpers when schema is provided - Detect cursor format for backwards compatibility with old migrations - Add isNewFormatCursor() helper with tests - Add SchemaForDataModel type helper - Create local component example demonstrating component migrations - Update README with component migration documentation - Add AGENTS.md with development tips Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the
✨ Finishing touches🧪 Generate unit tests (beta)
Tip 🧪 Unit Test Generation v2 is now available!We have significantly improved our unit test generation capabilities. To enable: Add this to your reviews:
finishing_touches:
unit_tests:
enabled: trueTry it out by using the Have feedback? Share your thoughts on our Discord thread! Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
commit: |
| export const migrations = new Migrations<DataModel>(components.migrations, { | ||
| internalMutation, | ||
| // Required for component migrations - enables convex-helpers paginator | ||
| schema: schema as SchemaForDataModel<DataModel>, |
There was a problem hiding this comment.
| schema: schema as SchemaForDataModel<DataModel>, | |
| schema: schema, |
| "extends": "../tsconfig.json", | ||
| "include": ["."], | ||
| "exclude": ["_generated"] | ||
| "exclude": ["_generated", "localComponent"] |
There was a problem hiding this comment.
| "exclude": ["_generated", "localComponent"] | |
| "exclude": ["_generated"] |
| @@ -17,7 +17,8 @@ | |||
| "@types/react-dom": "18.3.7", | |||
| "@vitejs/plugin-react": "5.0.4", | |||
| "chokidar-cli": "3.0.0", | |||
| "convex": "1.30.0", | |||
| "convex": "1.31.7", | |||
There was a problem hiding this comment.
| "convex": "1.31.7", | |
| "convex": "1.35.0", |
| @@ -37,7 +38,8 @@ | |||
| "vitest": "3.2.4" | |||
| }, | |||
| "peerDependencies": { | |||
| "convex": "^1.24.8" | |||
| "convex": "^1.31.0", | |||
There was a problem hiding this comment.
| "convex": "^1.31.0", | |
| "convex": "^1.35.0", |
| }, | ||
| "peerDependencies": { | ||
| "convex": "^1.24.8" | ||
| "convex": "^1.31.0", |
There was a problem hiding this comment.
| "convex": "^1.31.0", | |
| "convex": "^1.35.0", |
| // Inside your component's convex folder (e.g., myComponent/example.ts) | ||
| import { Migrations, type SchemaForDataModel } from "@convex-dev/migrations"; | ||
| import { components } from "./_generated/api.js"; | ||
| import type { DataModel } from "./_generated/dataModel.js"; |
There was a problem hiding this comment.
| import type { DataModel } from "./_generated/dataModel.js"; |
snip
|
|
||
| ```ts | ||
| // Inside your component's convex folder (e.g., myComponent/example.ts) | ||
| import { Migrations, type SchemaForDataModel } from "@convex-dev/migrations"; |
There was a problem hiding this comment.
| import { Migrations, type SchemaForDataModel } from "@convex-dev/migrations"; | |
| import { Migrations } from "@convex-dev/migrations"; |
| * | ||
| * @returns true if this is a new-format cursor (or null for starting fresh) | ||
| */ | ||
| export function isNewFormatCursor(cursor: string | null): boolean { |
There was a problem hiding this comment.
let's put this elsewhere so it's not exposed in the public client
| export type SchemaForDataModel<DM extends GenericDataModel> = | ||
| SchemaDefinition<any, boolean> & { | ||
| // Branded type to document that this schema should produce a compatible DataModel. | ||
| // The actual type checking happens when paginator is called. | ||
| __dataModel?: DM; | ||
| }; |
There was a problem hiding this comment.
this should be something like DM extends DataModelFromSchema<infer Schema> ? Schema : never
| const q = useNewPaginator | ||
| ? (paginator(ctx.db as any, this.options!.schema as any).query( | ||
| table, | ||
| ) as unknown as QueryInitializer<NamedTableInfo<DataModel, TableName>>) |
There was a problem hiding this comment.
this cast shouldn't be necessary

schemaparameter to Migrations constructorCo-Authored-By: Claude Opus 4.5 noreply@anthropic.com