Closed marcoow closed 9 months ago
I'm not really happy with the structure yet. While I think db
and web
makes sense, the fact that we also have app
, cli
, and config
bothers me because:
config
being its own package I think is necessary since all of the other packages (potentially) depend on it – yet, the config files are a bit hidden that way (ideally config
would be a top-level directory with only TOML files and wouldn't be its own package)app
isn't great as it's not supposed to be changed at all – I'm not sure whether I didn't actually like the special root package better…cli
as it's own package is also not great, in particular also since that's not even supposed to be touched by the developer; I had initially tried to combine that with app
but the problem is that because app
needs to depend on web
, when running any of the binaries, web
will be compiled and sqlx will perform the DB checks at compile time but the DB doesn't actually exist yet (in the case where you're running cargo db create
…)So the problem is there's 5 packages but you're not supposed to touch 2 of them (app
and cli
) and one only exists so we're able to share 1 struct (config
) and hides the actual config files 😞
Thinking out loud:
config
is needed everywhere. You need it in cli
to know which database you need to connect to, you need it in web
to read values from it`, you need it in your integration tests to read configuration, etc. Having it separate it's fine imo.cli
is a weird one: at the moment it only provides database-related commands. It only needs configuration and the path to the migrations folder: nothing else. You could make it a binary target in the db
crate itself, as long as you plan to keep that purely representational (i.e. no queries there). If you choose to keep it separate, I'd probably rename it to db-cli
.app
is another weird one: does it need to be its own crate? It could very well be, there's nothing wrong with that, but what prevents it from being merged with web
?cli
also contains the generate
binary which for the moment only generates migrations but could in the long term also generate other kinds of files, a.g. a controller, etc.
I think the idea between splitting app
and web
was to separate the binary/main
from the implementations of the web endpoints etc. but I agree there's no real value there – will merge the 2 👍
This converts the project to a workspace – loosely based on https://github.com/SeaQL/sea-orm/tree/master/examples/axum_example