Electron100 / butane

An ORM for Rust with a focus on simplicity and on writing Rust, not SQL
Apache License 2.0
91 stars 13 forks source link

chrono::DateTime doesnt work with migrations #53

Closed jayvdb closed 1 year ago

jayvdb commented 1 year ago

https://github.com/Electron100/butane/issues/19 added support for chrono::DateTime.

Encountered unexpected error: Cannot resolve type CustomType(chrono :: DateTime < chrono :: offset :: Utc >). Are you missing a #[butane_type] attribute?

It looks like chrono::naive::NaiveDateTime has some implementation in butane_core/src/db which does not yet exist for chrono::DateTime, so I will see if I can add it.

We also need to work out how to ensure the tests catch this in future.

Electron100 commented 1 year ago

The real issue here is that the migration type resolution is relying on the proc macro, which sees only the AST and not the type system. So when it sees a type identifier, it sees the path segments that are in the AST, not the actual type, meaning that chrono::DateTime and DateTime (after use chrono::DateTime) are not the same! The latter was getting accepted and the former is not. I'm putting out a change to make this slightly more flexible, but this type of issue is the biggest reason I want to move migration generation from proc-macro time to something triggered by the butane cli command. I've started working on that in the branch migration_v2 (but as I mentioned on the other PR, my progress has been slow)