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

Setting up the schema file according to diesel.toml when running `embed_migrations!` macro #1805

Closed
vityafx opened this Issue Aug 1, 2018 · 6 comments

Comments

Projects
None yet
2 participants
@vityafx

vityafx commented Aug 1, 2018

Could the embed_migrations! macro also initialize the schema file as diesel migration run does?

Rust 1.27.2
Diesel 1.3 (both in Cargo.toml of my binary crate and diesel-cli itself).

In the changelog file it is said:

Fixed

diesel print-schema and infer_schema! now properly handle unsigned types in MySQL

Deprecated

diesel_infer_schema has been deprecated. diesel print-schema is now the only way to generate database schema. Diesel CLI can be configured to automatically regenerate your schema file when migrations are run. See diesel.rs/guides/configuring-diesel-cli for details.

But I still want to perform migrations automatically and to generate my schema file automatically also. If diesel migration run setup the schema, why embed_migrations! does not?

@sgrif

This comment has been minimized.

Member

sgrif commented Aug 1, 2018

embed_migrations! is something that generates code at compile time, not an external tool that is run separately. Having that macro modify a file in your project as a side effect of being compiled would be extremely confusing. Not to mention that there's no guarantee that embed_migrations! will get compiled before src/schema.rs -- which would lead to a compiler error about code that doesn't exist.

@sgrif sgrif closed this Aug 1, 2018

@vityafx

This comment has been minimized.

vityafx commented Aug 1, 2018

@sgrif I am doing embed_migrations! in my build.rs so there is no problem at all to do that. And in the build.rs we can do everything we want at compilation, even calling diesel migration run actually. Why not to add a function to the embed_migrations! that will create the schema file?

@sgrif

This comment has been minimized.

Member

sgrif commented Aug 1, 2018

embed_migrations! is something that generates code at compile time, not an external tool that is run separately. Having that macro modify a file in your project as a side effect of being compiled would be extremely confusing.

This still applies to build.rs

@sgrif

This comment has been minimized.

Member

sgrif commented Aug 1, 2018

@vityafx

This comment has been minimized.

vityafx commented Aug 2, 2018

Wow, that's sad news. Thank you for this link :( So the only way now is invoking a command it seems.

@vityafx

This comment has been minimized.

vityafx commented Aug 2, 2018

Can I still have a file in src directory which includes contents from generated file in the target directory? According the link you posted, this will not violate any rules because the directory will remain unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment