refinery
refinery copied to clipboard
compilation: Error when using `refinery` with `barrel`
Hey, this is a follow-up on the current issue mentioned in #233. Here is a minimal, reproducible example of the issue that I am having.
barrel = "*"
postgres = "*"
refinery = { version = "*", features = ["postgres"] }
What I have also tried doing, is I have replaced the standalone barrel
package with the updated one, which, from what I understand, is hosted at https://git.irde.st/spacekookie/barrel, so, my dependency would look something like the following
barrel = { git = "https://git.irde.st/spacekookie/barrel", rev = "800cdb2e2e114462d21b47bd44af9d1525bf88bc" }
In my V0__create_table_users.rs
migration file, I have the code from the official website of barrel. Contents remain unchanged.
use barrel::{types, Migration, Pg};
use barrel::backend::Pg;
fn main() {
let mut m = Migration::new();
m.create_table("actors", |t| {
t.add_column("name", types::varchar(255));
t.add_column("age", types::integer());
t.add_column("owns_plushy_sharks", types::boolean());
});
println!("{}", m.make::<Pg>());
}
The main file setup is fairly simple.
mod embedded {
use refinery::embed_migrations;
embed_migrations!();
// ^------------ Compilation error occurs here
}
fn main() {
let mut conn = postgres::Client::connect("", postgres::NoTls).unwrap();
embedded::migrations::runner().run(&mut conn).unwrap();
}
And the error I am getting whenever I try to run cargo check
is the following:
error[E0432]: unresolved import `barrel`
--> src\main.rs:6:5
|
6 | embed_migrations!();
| ^^^^^^^^^^^^^^^^^^^ no `Pg` in the root
|
= note: this error originates in the macro `embed_migrations` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0425]: cannot find function `migration` in module `V0__create_table_actors`
--> src\main.rs:6:5
|
6 | embed_migrations!();
| ^^^^^^^^^^^^^^^^^^^ not found in `V0__create_table_actors`
|
= note: this error originates in the macro `embed_migrations` (in Nightly builds, run with -Z macro-backtrace for more info)
Some errors have detailed explanations: E0425, E0432.
For more information about an error, try `rustc --explain E0425`.
error: could not compile `repr` due to 2 previous errors
One thing I have tried doing is to rename the fn main()
in my migration file to pub fn migration()
, however, when I run cargo check
again I get the following output:
error[E0432]: unresolved import `barrel`
--> src\main.rs:6:5
|
6 | embed_migrations!();
| ^^^^^^^^^^^^^^^^^^^ no `Pg` in the root
|
= note: this error originates in the macro `embed_migrations` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0308]: mismatched types
--> src\main.rs:6:5
|
6 | embed_migrations!();
| ^^^^^^^^^^^^^^^^^^^ expected struct `String`, found `()`
|
= note: this error originates in the macro `embed_migrations` (in Nightly builds, run with -Z macro-backtrace for more info)
Some errors have detailed explanations: E0308, E0432.
For more information about an error, try `rustc --explain E0308`.
error: could not compile `repr` due to 2 previous errors
I surely think that I'm missing out on something here. Either the crate is broken, or the documentation is outdated.
Thanks!
Hi,
have you looked into the example here in the repo and uses barrel
?
You can see there how to define a migration file in rust and then import it in main
. The migration file should contain a migration
function that returns a String
which is what barrel
make
function generates, The README.md
should probably mention that on the Usage part though.
Btw a MRE is an example that can be reproducible, therefore in this case a repository that can just be compiled/checked with cargo
for example.
Hi, have you looked into the example here in the repo and uses barrel?
No, I have not. I have only used the documentation at https://docs.rs/barrel, thought that it would be up-to-date, which it was not. The documentation will probably need to be updated in this case.
Btw a MRE is an example that can be reproducible, therefore in this case a repository that can just be compiled/checked with cargo for example.
Yes, I know. Creating a separate repository for this issue though would have been overkill since it uses the examples from the website, and the main example is a very tiny file.
@michaelgrigoryan25 Getting the Pg references in barrel is apparently a feature.
[dependencies.barrel]
version = "0.7.0"
features = ["pg"]
Hey @Sessional, thanks for your input. I have actually fixed the issue myself, and you are right about the pg
feature part in Cargo.toml
, it made everything work for me. Thank you for bringing this up! I will close this issue now.