Skip to content

feat(db): add AUTO and FOREIGN_KEY to DatabaseField - #737

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

m4tx wants to merge 1 commit into
masterfrom
migration-generator-rework-1

Conversation

@m4tx

@m4tx m4tx commented Nov 13, 2026

Copy link
Copy Markdown
Member

Description

This adds AUTO and FOREIGN_KEY associated constants to the DatabaseField trait. Before this change, the code didn't have a reliable way to tell whether a specific model field has a default value or is a foreign key, and we need that to generate migrations.

This is part of the initiative to rework the migration generator to use the compiler rather than rely on dumb source code parsing.

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:19
@m4tx
m4tx added this pull request to stack #739 November 13, 2026 17:20
@github-actions github-actions Bot added the C-lib Crate: cot (main library crate) label Nov 13, 2026

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

Auto<T> fails to forward T::FOREIGN_KEY, causing wrapped foreign-key fields to lose their metadata and migration generation to omit the corresponding constraint.

1 open issue
What changed in this PR

Adds database-field metadata to support compiler-based migration generation, reducing reliance on source-code parsing.

Changes:

  • Introduces documented AUTO and FOREIGN_KEY constants on DatabaseField.
  • Adds metadata implementations for Auto, ForeignKey, and Option.
  • Tests metadata values for basic fields and wrapped types.
File Description
cot/​src/​db/​fields.rs Implements field metadata and forwarding through Option.
cot/​src/​db.rs Defines and documents the constants and adds metadata tests.

Review effort: Balanced

Comment thread cot/src/db/fields.rs
impl<T: DatabaseField> DatabaseField for Auto<T> {
const NULLABLE: bool = T::NULLABLE;
const TYPE: ColumnType = T::TYPE;
const AUTO: bool = true;
@github-actions

Copy link
Copy Markdown

🐰 Bencher Report

Projectcot
Branchmigration-generator-rework-1
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
8,959.80 µs
(-23.73%)Baseline: 11,748.10 µs
18,919.13 µs
(47.36%)
json_api/json_api📈 view plot
🚷 view threshold
967.37 µs
(+1.83%)Baseline: 949.95 µs
1,372.05 µs
(70.51%)
nested_routers/nested_routers📈 view plot
🚷 view threshold
934.19 µs
(+3.17%)Baseline: 905.45 µs
1,285.54 µs
(72.67%)
single_root_route/single_root_route📈 view plot
🚷 view threshold
875.44 µs
(+1.69%)Baseline: 860.89 µs
1,233.50 µs
(70.97%)
single_root_route_burst/single_root_route_burst📈 view plot
🚷 view threshold
16,124.00 µs
(-0.51%)Baseline: 16,207.01 µs
22,818.17 µs
(70.66%)
🐰 View full continuous benchmarking report in Bencher

@codecov

codecov Bot commented Nov 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
rust 91.16% <100.00%> (-0.01%) ⬇️

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

Files with missing lines Coverage Δ
cot/src/db.rs 83.20% <100.00%> (+0.13%) ⬆️
cot/src/db/fields.rs 87.42% <ø> (ø)

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

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

C-lib Crate: cot (main library crate)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants