#Migration with Macros
1 messages · Page 1 of 1 (latest)
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)
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
So a while back I’ve written https://github.com/ptoffy/fluent-migration-macros
SwiftSyntax has probably changed in the meantime but you could take inspiration from it. Main issue is it won’t get rerun automatically if something changes
Simple showcase project to show how macros could be used to create Fluent migrations - ptoffy/fluent-migration-macros
that is exactly what i had in mind!
why wouldn't it be re-run automatically? Macros aren't expanded on Command+B?
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