mirror of https://github.com/zer0bin-dev/zer0bin
refactor: 🚧 Use built in migrator (WIP)
This commit is contained in:
parent
be7617476f
commit
ead9d9108e
|
@ -276,12 +276,10 @@ dependencies = [
|
|||
"actix-web",
|
||||
"badge-maker",
|
||||
"chrono",
|
||||
"include_dir",
|
||||
"nanoid",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sqlx",
|
||||
"sqlx-pg-migrate",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -751,12 +749,6 @@ dependencies = [
|
|||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "glob"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
|
||||
|
||||
[[package]]
|
||||
name = "governor"
|
||||
version = "0.4.2"
|
||||
|
@ -879,26 +871,6 @@ dependencies = [
|
|||
"unicode-normalization",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "include_dir"
|
||||
version = "0.7.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "482a2e29200b7eed25d7fdbd14423326760b7f6658d21a4cf12d55a50713c69f"
|
||||
dependencies = [
|
||||
"glob",
|
||||
"include_dir_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "include_dir_macros"
|
||||
version = "0.7.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5e074c19deab2501407c91ba1860fa3d6820bfde307db6d8cb851b55a10be89b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.8.0"
|
||||
|
@ -1644,17 +1616,6 @@ dependencies = [
|
|||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sqlx-pg-migrate"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c953f3c114842c806461afc90a68da2fad7072d302cfcf69bdc31c893f6c899b"
|
||||
dependencies = [
|
||||
"include_dir",
|
||||
"sqlx",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sqlx-rt"
|
||||
version = "0.5.11"
|
||||
|
|
|
@ -16,9 +16,7 @@ actix-governor = "0.3.0"
|
|||
|
||||
badge-maker = "0.2.1"
|
||||
|
||||
sqlx = { version = "0.5", features = ["runtime-tokio-rustls", "postgres", "chrono"] }
|
||||
include_dir = "0.7.2"
|
||||
sqlx-pg-migrate = "1.0"
|
||||
sqlx = { version = "0.5.11", features = ["runtime-tokio-rustls", "postgres", "chrono"] }
|
||||
|
||||
chrono = { version = "0.4.19", features = ["serde"] }
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ mod config;
|
|||
mod models;
|
||||
mod routes;
|
||||
|
||||
use std::{io, path::PathBuf};
|
||||
use std::{io, path::Path, path::PathBuf};
|
||||
|
||||
use actix_cors::Cors;
|
||||
use actix_governor::{Governor, GovernorConfigBuilder};
|
||||
|
@ -12,9 +12,7 @@ use actix_web::{
|
|||
};
|
||||
use config::Config;
|
||||
|
||||
use include_dir::include_dir;
|
||||
use sqlx::{postgres::PgPoolOptions, PgPool};
|
||||
use sqlx_pg_migrate::migrate;
|
||||
use sqlx::{migrate::Migrator, postgres::PgPoolOptions, PgPool};
|
||||
|
||||
use crate::routes::{
|
||||
get_paste, get_raw_paste, get_stats, get_total_pastes_badge, get_version_badge, new_paste,
|
||||
|
@ -26,6 +24,15 @@ pub struct AppState {
|
|||
pub pool: PgPool,
|
||||
}
|
||||
|
||||
pub async fn migrations(pool: sqlx::Pool) -> Result<(), sqlx::Error> {
|
||||
Migrator::new(Path::new("./migrations"))
|
||||
.await?
|
||||
.run(pool)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[actix_rt::main]
|
||||
async fn main() -> io::Result<()> {
|
||||
let config = config::load(PathBuf::from("config.json"));
|
||||
|
@ -35,6 +42,7 @@ async fn main() -> io::Result<()> {
|
|||
.connect(db_uri)
|
||||
.await
|
||||
.expect("Failed to connect to database");
|
||||
migrations(pool).await;
|
||||
let address = format!(
|
||||
"{}:{}",
|
||||
config.server.backend_host, config.server.backend_port
|
||||
|
@ -45,9 +53,9 @@ async fn main() -> io::Result<()> {
|
|||
.finish()
|
||||
.unwrap();
|
||||
let state = AppState { config, pool };
|
||||
migrate(db_uri, &include_dir!("migrations"))
|
||||
.await
|
||||
.expect("Error in migrations!");
|
||||
// migrate(db_uri, &include_dir!("migrations"))
|
||||
// .await
|
||||
// .expect("Error in migrations!");
|
||||
println!("🚀 zer0bin is running on {address}");
|
||||
|
||||
HttpServer::new(move || {
|
||||
|
|
Loading…
Reference in New Issue