# Generate schema.rs with cargo build

**URL:** <https://discourse.diesel.rs/t/generate-schema-rs-with-cargo-build/113>\
**Category:** Uncategorized\
**Created:** [September 1, 2019, 10:35pm UTC](https://discourse.diesel.rs/t/generate-schema-rs-with-cargo-build/113 "2019-09-01T22:35:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![NilsIrl](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.diesel.rs/nilsirl/32/57_2.png) [@NilsIrl](https://discourse.diesel.rs/u/NilsIrl)\
**Post date:** [September 1, 2019, 10:35pm UTC](https://discourse.diesel.rs/t/generate-schema-rs-with-cargo-build/113/1 "2019-09-01T22:35:54Z")

</div>

Would it be a good idea to generate `schema.rs` when running `cargo build` and not keep track of `schema.rs` inside of a VCS?

If so what would be the best way? What would the `build.rs` look like (if it is used)?

---

<div class="post-metadata">

**Author:** ![weiznich](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.diesel.rs/weiznich/32/64_2.png) [@weiznich](https://discourse.diesel.rs/u/weiznich)\
**Post date:** [September 2, 2019, 8:53pm UTC](https://discourse.diesel.rs/t/generate-schema-rs-with-cargo-build/113/2 "2019-09-02T20:53:05Z")

</div>

Normally `schema.rs` is meant to be included in your VCS, because it represents something at the current code status that does not change randomly.

If you really want to generate it at build time running `diesel print-schema` via [shell command](https://doc.rust-lang.org/std/process/struct.Command.html) is probably the easiest way.

---

<div class="post-metadata">

**Author:** ![NilsIrl](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.diesel.rs/nilsirl/32/57_2.png) [@NilsIrl](https://discourse.diesel.rs/u/NilsIrl)\
**Post date:** [September 2, 2019, 10:00pm UTC](https://discourse.diesel.rs/t/generate-schema-rs-with-cargo-build/113/3 "2019-09-02T22:00:31Z")

</div>

Isn’t that the whole point of migrations though? Doesn’t that make it redundant?

---

<div class="post-metadata">

**Author:** ![weiznich](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.diesel.rs/weiznich/32/64_2.png) [@weiznich](https://discourse.diesel.rs/u/weiznich)\
**Post date:** [September 3, 2019, 8:15am UTC](https://discourse.diesel.rs/t/generate-schema-rs-with-cargo-build/113/4 "2019-09-03T08:15:31Z")

</div>

At least in my opinion having a `schema.rs` in your VCS is not redundant, because migrations are not required. (For example you could develop against a existing database).  
Anyway we’ve currently no plan to split out the `print-schema` related code from diesel-cli, which would be required to support generating the schema from a `build.rs` without calling a shell command. If anyone want’s to do that as a third party crate, go for it.

---

<div class="post-metadata">

**Author:** ![NilsIrl](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.diesel.rs/nilsirl/32/57_2.png) [@NilsIrl](https://discourse.diesel.rs/u/NilsIrl)\
**Post date:** [September 3, 2019, 5:23pm UTC](https://discourse.diesel.rs/t/generate-schema-rs-with-cargo-build/113/5 "2019-09-03T17:23:38Z")

</div>

Ok.

I never thought of this though and I don’t think it would be useful regardless of whether schema.rs is redundant or not.
