Skip to content

Conversation

@m4tx
Copy link
Member

@m4tx m4tx commented Jan 27, 2026

This adds support for user-defined migrations that might contain arbitrary code in them. This is primarily useful for data migrations which do not modify the schema, but fill in the data in the database instead.

This extends the migration engine to support a new type of migrations, as well as cot-cli with a new command that creates a new custom migration.

Fixes #211.

@github-actions github-actions bot added C-cli Crate: cot-cli (issues and Pull Requests related to Cot CLI) C-lib Crate: cot (main library crate) labels Jan 27, 2026
@github-actions
Copy link

github-actions bot commented Jan 27, 2026

🐰 Bencher Report

Branchcustom-migrations
Testbedgithub-ubuntu-latest
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
microseconds (µs)
(Result Δ%)
Upper Boundary
microseconds (µs)
(Limit %)
empty_router/empty_router📈 view plot
🚷 view threshold
5,671.20 µs
(-5.11%)Baseline: 5,976.29 µs
7,016.82 µs
(80.82%)
json_api/json_api📈 view plot
🚷 view threshold
1,026.40 µs
(+0.56%)Baseline: 1,020.67 µs
1,152.78 µs
(89.04%)
nested_routers/nested_routers📈 view plot
🚷 view threshold
949.46 µs
(+0.93%)Baseline: 940.68 µs
1,055.23 µs
(89.98%)
single_root_route/single_root_route📈 view plot
🚷 view threshold
915.10 µs
(+1.47%)Baseline: 901.87 µs
1,012.96 µs
(90.34%)
single_root_route_burst/single_root_route_burst📈 view plot
🚷 view threshold
16,763.00 µs
(-4.83%)Baseline: 17,613.55 µs
20,900.45 µs
(80.20%)
🐰 View full continuous benchmarking report in Bencher

This adds support for user-defined migrations that might contain
arbitrary code in them. This is primarily useful for data migrations
which do not modify the schema, but fill in the data in the database
instead.

This extends the migration engine to support a new type of migrations,
as well as cot-cli with a new command that creates a new custom
migration.
@m4tx m4tx force-pushed the custom-migrations branch from ca9e1b8 to 2104d84 Compare January 27, 2026 19:37
@github-actions github-actions bot added the C-macros Crate: cot-macros label Jan 27, 2026
@m4tx m4tx force-pushed the custom-migrations branch from 11d8817 to 4475202 Compare January 27, 2026 21:08
@m4tx m4tx marked this pull request as ready for review January 27, 2026 21:22
@m4tx m4tx changed the title feat(orm): support custom migrations feat(orm)!: support custom migrations Jan 27, 2026
@m4tx m4tx changed the title feat(orm)!: support custom migrations feat(orm): support custom migrations Jan 27, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for custom migrations to the Cot ORM, allowing developers to define data migrations with arbitrary code that don't modify the database schema.

Changes:

  • Added MigrationContext, CustomOperationFn, and CustomBuilder to the migration engine for defining custom migration operations
  • Implemented migration_op attribute macro to transform async functions into migration operations
  • Added cot migration new CLI command to create custom migrations with a user-defined name

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
cot/src/db/migrations.rs Core implementation of custom migrations including the context type, operation builder, and execution logic
cot-macros/src/migration_op.rs Macro implementation that transforms async functions to return pinned boxed futures
cot-macros/src/lib.rs Export of the new migration_op macro
cot-macros/tests/ui/attr_migration_op.rs UI test for correct usage of the macro
cot-macros/tests/ui/attr_migration_op_not_async.stderr Expected error output for non-async functions
cot-macros/tests/ui/attr_migration_op_not_async.rs UI test for error case
cot-macros/tests/compile_tests.rs Test registration for macro compile tests
cot-cli/src/migration_generator.rs Generator for custom migration files and refactored naming logic
cot-cli/src/main.rs CLI command routing for the new migration command
cot-cli/src/handlers.rs Handler implementation for creating custom migrations
cot-cli/src/args.rs CLI argument definitions for the new command
cot-cli/tests/migration_generator.rs Tests for custom migration generation and compilation
cot-cli/tests/snapshot_testing/help/snapshots/*.snap Updated help text snapshots showing the new command
cot-cli/tests/snapshot_testing/cli/snapshots/*.snap Updated shell completion snapshots for the new command

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link

codecov bot commented Jan 27, 2026

Codecov Report

❌ Patch coverage is 88.39286% with 26 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cot-cli/src/migration_generator.rs 83.49% 7 Missing and 10 partials ⚠️
cot/src/db/migrations.rs 88.88% 4 Missing and 4 partials ⚠️
cot-macros/src/migration_op.rs 94.73% 1 Missing ⚠️
Flag Coverage Δ
rust 90.39% <88.39%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
cot-cli/src/handlers.rs 95.93% <100.00%> (+0.93%) ⬆️
cot-cli/src/main.rs 100.00% <100.00%> (ø)
cot-macros/src/lib.rs 94.84% <100.00%> (+0.33%) ⬆️
cot-macros/src/migration_op.rs 94.73% <94.73%> (ø)
cot/src/db/migrations.rs 84.39% <88.88%> (+0.51%) ⬆️
cot-cli/src/migration_generator.rs 87.68% <83.49%> (-0.34%) ⬇️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@seqre seqre left a comment

Choose a reason for hiding this comment

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

Overall it LGTM, please write more tests before merging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-cli Crate: cot-cli (issues and Pull Requests related to Cot CLI) C-lib Crate: cot (main library crate) C-macros Crate: cot-macros

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for custom operations in migration generator

3 participants