sea-orm icon indicating copy to clipboard operation
sea-orm copied to clipboard

Have `MigratorTrait` use `self`

Open ctron opened this issue 1 month ago • 3 comments

Motivation

Defining migrations, it is sometimes handy to have additional information, coming through configuration or other means of passing runtime information.

However, as MigratorTrait's migrations function doesn't have a self, that is rather tricky.

Proposed Solutions

Add &self to MigratorTrait functions. So this can be used, if required.

Additional Information

ctron avatar Nov 10 '25 14:11 ctron

right, I see what you mean. however this is a backwards-incompatible change. I'll see if I can think of some way to remain backwards compatible. for now, you can read environment variables from within the migrations function, or use lazy_static

tyt2y3 avatar Nov 10 '25 23:11 tyt2y3

for now, you can read environment variables from within the migrations function, or use lazy_static

Yes, and that's what I'm doing. But this makes it very hard for tests. Because basically all of this is global. So you can go with tokio's local stuff, but that's all far from optimal.

And yes, I do understand it's a breaking change. Maybe there is a way. But maybe it's a topic for SeaORM 3.0.

ctron avatar Nov 11 '25 09:11 ctron

we don't have to wait until 3.0 to fix this

tyt2y3 avatar Nov 11 '25 09:11 tyt2y3