Skip to content

Add paginator support from convex-helpers for component migrations#27

Draft
ianmacartney wants to merge 1 commit intomainfrom
ian/paginator-migration
Draft

Add paginator support from convex-helpers for component migrations#27
ianmacartney wants to merge 1 commit intomainfrom
ian/paginator-migration

Conversation

@ianmacartney
Copy link
Member

  • 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

- 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>
@coderabbitai
Copy link

coderabbitai bot commented Jan 30, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • 🔍 Trigger a full review
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ian/paginator-migration

Tip

🧪 Unit Test Generation v2 is now available!

We have significantly improved our unit test generation capabilities.

To enable: Add this to your .coderabbit.yaml configuration:

reviews:
  finishing_touches:
    unit_tests:
      enabled: true

Try it out by using the @coderabbitai generate unit tests command on your code files or under ✨ Finishing Touches on the walkthrough!

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 30, 2026

Open in StackBlitz

npm i https://pkg.pr.new/get-convex/migrations/@convex-dev/migrations@27

commit: f514088

Copy link
Member Author

@ianmacartney ianmacartney left a comment

Choose a reason for hiding this comment

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

needs some work

export const migrations = new Migrations<DataModel>(components.migrations, {
internalMutation,
// Required for component migrations - enables convex-helpers paginator
schema: schema as SchemaForDataModel<DataModel>,
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
schema: schema as SchemaForDataModel<DataModel>,
schema: schema,

"extends": "../tsconfig.json",
"include": ["."],
"exclude": ["_generated"]
"exclude": ["_generated", "localComponent"]
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
"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",
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
"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",
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
"convex": "^1.31.0",
"convex": "^1.35.0",

},
"peerDependencies": {
"convex": "^1.24.8"
"convex": "^1.31.0",
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
"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";
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
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";
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
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 {
Copy link
Member Author

Choose a reason for hiding this comment

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

let's put this elsewhere so it's not exposed in the public client

Comment on lines +68 to +73
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;
};
Copy link
Member Author

Choose a reason for hiding this comment

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

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>>)
Copy link
Member Author

Choose a reason for hiding this comment

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

this cast shouldn't be necessary

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.

1 participant