Re-added auto migrations

This commit is contained in:
Dennis Brentjes
2023-03-30 17:08:44 +02:00
parent 70ae15f655
commit 1296f363af
4 changed files with 126 additions and 20 deletions

View File

@@ -6,15 +6,22 @@ use actix_web::HttpServer;
use actix_web::App;
use actix_web::web;
use diesel::PgConnection;
use diesel::r2d2::{ConnectionManager, Pool};
use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness};
use request::{login, register, gamenights, gamenight_post, gamenight_get};
use diesel::r2d2::ConnectionManager;
use diesel::r2d2::Pool;
use util::GetConnection;
pub(crate) type DbPool = Pool<ConnectionManager<PgConnection>>;
pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!();
fn run_migration(conn: &mut PgConnection) {
conn.run_pending_migrations(MIGRATIONS).unwrap();
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let url = "postgres://root:root@localhost/gamenight";
let url = "postgres://root:root@127.0.0.1/gamenight";
let manager = ConnectionManager::<PgConnection>::new(url);
// Refer to the `r2d2` documentation for more methods to use
// when building a connection pool
@@ -23,6 +30,9 @@ async fn main() -> std::io::Result<()> {
.build(manager)
.expect("Could not build connection pool");
let mut conn = pool.get_conn();
run_migration(&mut conn);
HttpServer::new(move || {
App::new()
.app_data(web::Data::new(pool.clone()))

View File

@@ -26,8 +26,6 @@ fn get_claims(req: &HttpRequest) -> Result<Claims, ApiError> {
message: "JWT-token was not specified in the Authorization header as Bearer: token".to_string()
})?;
println!("{:?}", token);
let secret = "secret";
Ok(decode::<Claims>(token.as_str(), &DecodingKey::from_secret(secret.as_bytes()), &Validation::default())?.claims)
}
@@ -38,8 +36,6 @@ pub fn get_token(user: &User) -> Result<String, ApiError> {
uid: user.id,
};
println!("{:?}", claims);
let secret = "secret";
Ok(encode(
&Header::default(),