Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make embed_migrations() work from within a separate package #193

Open
kraig-mcfadden opened this issue Dec 2, 2021 · 2 comments
Open

Make embed_migrations() work from within a separate package #193

kraig-mcfadden opened this issue Dec 2, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@kraig-mcfadden
Copy link

I'm trying to write a package that bundles together a few database features, including connections (with tokio-postgres), connection pooling (with deadpool), and migrations (with refinery), but I'm running into some trouble: embed_migrations() does not search for the migrations directory from the project root. Rather, it searches from its own root, which in this case is the root of the package it's in, rather than the root of the project that is pulling in the package. (To be clear, I am writing a separate package that is being pulled in from GitHub).

There isn't really a workaround from what I can tell. I can't hardcode the path to the project migrations folder inside this package, since the package can be used by multiple projects. I can't pass in a string, since the macro runs at compile time. I've been forced to just pull refinery into each of my projects, on top of this other package I've been putting together.

An ideal solution would allow me to stick embed_migrations() (or something similar) in this package, but pass in the location of the migrations directory from the project using the package. This allows my project to manage its own migrations, but it doesn't need to know anything about refinery. Also, I could use the classes refinery provides and just roll my own migration logic, but I'd love to not do that, since that defeats the whole purpose of using refinery in the first place 😂

Is there a way to do this already and I've just overlooked it? Or does this sound like functionality that needs to be added?

@kraig-mcfadden
Copy link
Author

Also, if it's helpful, I'd be happy to take a stab at adding any needed functionality. I'd probably just need some direction on where to start / what a possible preferred solution might look like. Thanks!

@jxs
Copy link
Member

jxs commented Dec 5, 2021

Hi, and thanks for your interest!

There isn't really a workaround from what I can tell. I can't hardcode the path to the project migrations folder inside this package, since the package can be used by multiple projects. I can't pass in a string, since the macro runs at compile time. I've been forced to just pull refinery into each of my projects, on top of this other package I've been putting together.

the macro is expanded in compile time, but it's expanded code runs at runtime, so we can probably update the macro and switch LitStr to a type that accepts any type, that then in runtime it's going to be checked if it impl's AsPath needed for the crate_root().join.
We should then also change the location to no longer be relating to the crate root but rather absolute, one can get the crate root dynamically.

@jxs jxs added the enhancement New feature or request label Dec 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants