Run migrations on start, not on every connection

This commit is contained in:
Magnus Hoff 2017-08-22 09:37:40 +02:00
parent d93501cb00
commit df63c25646

View file

@ -46,11 +46,14 @@ fn core_main() -> Result<(), Box<std::error::Error>> {
.map(|p| p.parse().expect("Guaranteed by validator")) .map(|p| p.parse().expect("Guaranteed by validator"))
.unwrap_or(8080); .unwrap_or(8080);
// Connect to the database and run migrations up front:
db::connect_database(&db_file, true);
let server = let server =
hyper::server::Http::new() hyper::server::Http::new()
.bind( .bind(
&SocketAddr::new(bind_host, bind_port), &SocketAddr::new(bind_host, bind_port),
move || Ok(site::Site::new(state::State::new(db::connect_database(&db_file, true)))) move || Ok(site::Site::new(state::State::new(db::connect_database(&db_file, false))))
)?; )?;
server.run()?; server.run()?;