#Migration with Macros

1 messages · Page 1 of 1 (latest)

silent tartan
#

From my point of view, migrations a great candidate to generate them with a Macro.

With evergrowing models and project scope, keeping track and writing this is a pain, and macros, autogenerated from the Model would make a lot of sense.

Are there any advances in this direction?

plain hemlock
#

From a Fluent point of view? No, currently macros are not usable in a library. For yourself, no reason why not

#

One thing to be wary of - we used to do automatic conformance of models to migrations which was great right up until you tried to rename or remove a column and then all hell broke loose. It's part of the reason why they're so explicit on Fluent 4. The automatic stuff doesn't scale well (unless we start tracking changes which is definitely a possibility)

silent tartan
#

Maybe i didn't explain myself correctly, but i was referring to these Migrations that we write user-level

#

they really seem like could be that ideally could be handled like this

tropic stone
silent tartan
#

that is exactly what i had in mind!

#

why wouldn't it be re-run automatically? Macros aren't expanded on Command+B?

tropic stone
#

I meant if you changed a model, the migration would indeed be updated but with it having the same name, it wouldn’t get re-run on the database and therefore wouldn’t actually change anything in the db

#

We’d have to find some way to version out the generated migration and update the version if it’s already been run but that’s not easy (or even possible I’m afraid)

#

Or you’d have to revert the migration first. This obviously doesn’t roll for production environment

silent tartan
#

mmm i understand now

#

remember coredata versioning now... there's a reason for that...

#

perhaps SwiftData should serve as inspiration?