vapor-community / mysql-provider

MySQL provider for the Vapor web framework.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fluent.EntityError.noDatabase if my Models are not Preparations

MoridinBG opened this issue · comments

I have moved all my model preparations to structs in a Migrations folder. This includes the initial database.create.
The reason is because usually during development I need to add additional fields or remove them and I do this in other migrations via database.modify. It makes little sense to have some initial preparation inside the model, that usually becomes very out of date, as development progresses.

But if I attempt to interact with models that have their db setup externally, I receive Fluent.EntityError.noDatabase errors.
If I add an empty conformance to Preparation on my models and add them to Config.preparations, everything works without issue.

What is more, if my initial migrations have not yet been run, the tables are not created and my models do not conform to Preparation or are not added to Config.preparations - on the first app run, when it runs this preparations, I can save, etc my models without issue. On following app runs, now that the preparations have been run, I again get Fluent.EntityError.noDatabase.

So it seems to me that during startup, Vapor looks for models/entities in Config.preparations and adds them to Database.map If it only finds dumb preparation structs, it never adds the Model mapping to the Database.

This is a very subtle, not obvious way to setup the mappings, that should be more explicit.

I posted this here by mistake, should be a Fluent issue.
Recreated as vapor/fluent#238