diesel: embed migrations in binary
Signed-off-by: supercmmetry <vishaals2000@gmail.com>
This commit is contained in:
parent
22cb897088
commit
c41b036e07
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -601,6 +601,7 @@ dependencies = [
|
||||
name = "katbin"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"diesel",
|
||||
"diesel_migrations",
|
||||
"dotenv",
|
||||
|
@ -19,3 +19,4 @@ jsonwebtoken = "7.1.2"
|
||||
slog = "2.5.2"
|
||||
slog-term = "2.6.0"
|
||||
slog-async = "2.5.0"
|
||||
chrono = "0.4.11"
|
||||
|
@ -45,12 +45,9 @@ mod date_serializer {
|
||||
}
|
||||
|
||||
impl Claims {
|
||||
pub fn new(username: String, access_level: AccessLevel) -> Claims {
|
||||
pub fn new(username: String) -> Claims {
|
||||
let iat = Utc::now();
|
||||
let exp = match access_level {
|
||||
AccessLevel::Admin => iat + chrono::Duration::minutes(30),
|
||||
_ => iat + chrono::Duration::days(1)
|
||||
};
|
||||
let exp = iat + chrono::Duration::days(1);
|
||||
|
||||
Claims {
|
||||
username,
|
||||
|
18
src/main.rs
18
src/main.rs
@ -7,6 +7,8 @@ extern crate rocket_contrib;
|
||||
#[macro_use]
|
||||
extern crate diesel;
|
||||
#[macro_use]
|
||||
extern crate diesel_migrations;
|
||||
#[macro_use]
|
||||
extern crate serde;
|
||||
#[macro_use]
|
||||
extern crate slog;
|
||||
@ -17,16 +19,28 @@ pub mod utils;
|
||||
|
||||
use slog_term;
|
||||
use slog_async;
|
||||
use slog::Drain;
|
||||
use slog::{Drain, Logger};
|
||||
|
||||
embed_migrations!("migrations");
|
||||
|
||||
fn run_migrations(logger: &Logger) {
|
||||
let result = embedded_migrations::run(&utils::db::pg_connection());
|
||||
if let Err(e) = result {
|
||||
error!(logger, "migration error: {}", e.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
dotenv::dotenv().ok();
|
||||
|
||||
let decorator = slog_term::TermDecorator::new().build();
|
||||
let drain = slog_term::FullFormat::new(decorator).build().fuse();
|
||||
let drain = slog_async::Async::new(drain).build().fuse();
|
||||
|
||||
let logger = slog::Logger::root(drain, o!());
|
||||
|
||||
run_migrations(&logger);
|
||||
|
||||
let mut rocket = rocket::ignite();
|
||||
|
||||
rocket = api::routes::fuel(rocket);
|
||||
|
Loading…
Reference in New Issue
Block a user