Skip to content

feat(db): describe the project's database schema at runtime - #738

Open
m4tx wants to merge 1 commit into
migration-generator-rework-1from
migration-generator-rework-2
Open

m4tx wants to merge 1 commit into
migration-generator-rework-1from
migration-generator-rework-2

Conversation

@m4tx

@m4tx m4tx commented Nov 13, 2026

Copy link
Copy Markdown
Member

Description

Models now carry their migration schema, with all properties resolved by the compiler. Application models are registered in a linkme distributed slice, and ProjectSchema combines them with the schema obtained by replaying the project's migrations in order.

The hidden cot-internal-schema subcommand prints this as JSON, so that the Cot CLI can generate migrations from it.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Refactor / cleanup
  • Performance improvement
  • Other (describe above)

@m4tx
m4tx requested review from a team and a balanced review from Copilot November 13, 2026 17:20
@m4tx
m4tx added this pull request to stack #739 November 13, 2026 17:20

Copilot AI 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.

🟡 Changes recommended

Schema replay ignores schema-changing custom operations while reporting success, risking incorrect migration baselines that can generate duplicate table creations or destructive differences.

5 open issues
What changed in this PR

This PR adds runtime database schema descriptions so the Cot CLI can compare application models with replayed migrations when generating new migrations.

Changes:

  • Generate compiler-resolved schema metadata and register application models automatically.
  • Add serializable project schema types, migration replay, and a hidden JSON-dump command.
  • Support model app-name overrides and document the DatabaseField requirement.
File Description
docs/​databases/​overview.md Document field schema requirements and update the custom-type example.
cot/​src/​private.rs Re-export linkme for generated code.
cot/​src/​db/​relations.rs Enable serialization of foreign-key policies.
cot/​src/​db/​migrations/​schema.rs Add schema types, model registry, migration replay, and tests.
cot/​src/​db/​migrations.rs Expose the hidden schema module.
cot/​src/​db.rs Add model migration metadata and serializable column types.
cot/​src/​cli.rs Add the hidden schema JSON command.
cot/​Cargo.toml Enable linkme with database support.
cot-macros/​src/​model.rs Generate schema metadata, registrations, and app-name overrides.
cot-codegen/​src/​model.rs Parse the model app-name override.
Cargo.toml Declare the workspace linkme dependency.
Cargo.lock Lock linkme and its implementation dependency.

Review effort: Balanced

Comment thread cot/src/db/migrations/schema.rs Resolved
Comment thread cot-codegen/src/model.rs Resolved
Comment thread cot/src/cli.rs Resolved
Comment thread cot/src/db/migrations/schema.rs Resolved
Comment thread cot/src/db/migrations/schema.rs Resolved
@github-actions github-actions Bot added A-docs Area: Documentation A-deps Area: Dependencies C-lib Crate: cot (main library crate) C-macros Crate: cot-macros C-codegen Crate: cot-codegen labels Nov 13, 2026
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

🐰 Bencher Report

Projectcot
Branchmigration-generator-rework-2
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
6,751.50 µs
(-42.53%)Baseline: 11,748.10 µs
18,919.13 µs
(35.69%)
json_api/json_api📈 view plot
🚷 view threshold
665.31 µs
(-29.96%)Baseline: 949.95 µs
1,372.05 µs
(48.49%)
nested_routers/nested_routers📈 view plot
🚷 view threshold
643.03 µs
(-28.98%)Baseline: 905.45 µs
1,285.54 µs
(50.02%)
single_root_route/single_root_route📈 view plot
🚷 view threshold
583.90 µs
(-32.17%)Baseline: 860.89 µs
1,233.50 µs
(47.34%)
single_root_route_burst/single_root_route_burst📈 view plot
🚷 view threshold
10,290.00 µs
(-36.51%)Baseline: 16,207.01 µs
22,818.17 µs
(45.10%)
🐰 View full continuous benchmarking report in Bencher

🔗 Link this project to GitHub

@codecov

codecov Bot commented Nov 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.54217% with 24 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cot/src/db/migrations/schema.rs 82.50% 19 Missing and 2 partials ⚠️
cot/src/cli.rs 57.14% 3 Missing ⚠️
Flag Coverage Δ
rust 91.13% <85.54%> (-0.03%) ⬇️

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

Files with missing lines Coverage Δ
cot-codegen/src/model.rs 95.92% <ø> (+0.22%) ⬆️
cot-macros/src/model.rs 98.03% <100.00%> (+0.58%) ⬆️
cot/src/db.rs 83.20% <ø> (ø)
cot/src/db/migrations.rs 82.56% <ø> (ø)
cot/src/db/relations.rs 91.56% <ø> (ø)
cot/src/cli.rs 85.81% <57.14%> (-0.50%) ⬇️
cot/src/db/migrations/schema.rs 82.50% <82.50%> (ø)

... and 1 file with indirect coverage changes

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

@m4tx
m4tx force-pushed the migration-generator-rework-2 branch from bdf6c41 to 3b8e00b Compare November 16, 2026 13:45
Models now carry their migration schema, with all properties resolved by
the compiler. Application models are registered in a linkme distributed
slice, and `ProjectSchema` combines them with the schema obtained
by replaying the project's migrations in order.

Passing the hidden `--cot-internal-schema` flag to the project binary
prints this as JSON without reading the project config, so that the Cot
CLI can generate migrations from it.
@m4tx
m4tx force-pushed the migration-generator-rework-2 branch from 3b8e00b to 92c88ff Compare November 16, 2026 14:01

This branch has not been deployed

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

Labels

A-deps Area: Dependencies A-docs Area: Documentation C-codegen Crate: cot-codegen 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.

2 participants