Use create_post_table instead of SQL

This commit is contained in:
Sam Samai 2021-08-27 22:36:56 +10:00
parent f191645467
commit 380f2a0c04

View File

@ -82,23 +82,10 @@ async fn destroy(conn: Connection<Db>) -> Result<()> {
} }
async fn run_migrations(rocket: Rocket<Build>) -> fairing::Result { async fn run_migrations(rocket: Rocket<Build>) -> fairing::Result {
let con = sea_orm::Database::connect("mysql://root:@localhost/rocket_example") let conn = sea_orm::Database::connect("mysql://root:@localhost/rocket_example")
.await .await
.unwrap(); .unwrap();
let create_post_table = con let create_post_table = setup::create_post_table(&conn);
.execute(Statement::from_string(
DatabaseBackend::MySql,
r#"
CREATE TABLE posts (
id int NOT NULL AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
text VARCHAR(255) NOT NULL,
PRIMARY KEY (id)
)"#
.to_owned(),
))
.await;
println!("create_post_table: {:#?}", create_post_table);
Ok(rocket) Ok(rocket)
} }