From 36e81a6c4fe7671078972a36523c27e6f70d2540 Mon Sep 17 00:00:00 2001 From: Dominic Harris Date: Mon, 4 Apr 2022 13:37:35 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20Fix=20migrator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/migrations/000_single_view.sql | 2 +- backend/src/main.rs | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/backend/migrations/000_single_view.sql b/backend/migrations/000_single_view.sql index f8ca4b9..7b28894 100644 --- a/backend/migrations/000_single_view.sql +++ b/backend/migrations/000_single_view.sql @@ -1 +1 @@ -alter table pastes add column single_view boolean default false; +ALTER TABLE pastes ADD column single_view BOOLEAN DEFAULT false; diff --git a/backend/src/main.rs b/backend/src/main.rs index 4de93bb..ec55836 100755 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -24,7 +24,7 @@ pub struct AppState { pub pool: PgPool, } -pub async fn migrations(pool: sqlx::Pool) -> Result<(), sqlx::Error> { +pub async fn migrations(pool: &PgPool) -> Result<(), sqlx::Error> { Migrator::new(Path::new("./migrations")) .await? .run(pool) @@ -36,26 +36,33 @@ pub async fn migrations(pool: sqlx::Pool) -> Result<(), sqlx::Error> { #[actix_rt::main] async fn main() -> io::Result<()> { let config = config::load(PathBuf::from("config.json")); + let db_uri = &config.databases.postgres_uri.to_string(); + let pool = PgPoolOptions::new() .max_connections(100) .connect(db_uri) .await .expect("Failed to connect to database"); - migrations(pool).await; + + migrations(&pool).await.expect("Failed to run migrations"); + let address = format!( "{}:{}", config.server.backend_host, config.server.backend_port ); + let paste_governor = GovernorConfigBuilder::default() .per_second(config.ratelimits.seconds_in_between_pastes) .burst_size(config.ratelimits.allowed_pastes_before_ratelimit) .finish() .unwrap(); + let state = AppState { config, pool }; // migrate(db_uri, &include_dir!("migrations")) // .await // .expect("Error in migrations!"); + println!("🚀 zer0bin is running on {address}"); HttpServer::new(move || {