指定 schema 和 去掉多余东西
This commit is contained in:
parent
beeeb7b0d4
commit
3db80f5a78
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
/target
|
||||
config.toml
|
||||
|
60
Cargo.lock
generated
60
Cargo.lock
generated
@ -1202,6 +1202,16 @@ dependencies = [
|
||||
"minimal-lexical",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nu-ansi-term"
|
||||
version = "0.46.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
|
||||
dependencies = [
|
||||
"overload",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-bigint"
|
||||
version = "0.4.6"
|
||||
@ -1367,6 +1377,12 @@ dependencies = [
|
||||
"syn 2.0.71",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "overload"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
|
||||
|
||||
[[package]]
|
||||
name = "parking_lot"
|
||||
version = "0.12.3"
|
||||
@ -2481,6 +2497,7 @@ dependencies = [
|
||||
"tokio",
|
||||
"toml",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2850,6 +2867,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"valuable",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-log"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3"
|
||||
dependencies = [
|
||||
"log",
|
||||
"once_cell",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2859,12 +2888,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b"
|
||||
dependencies = [
|
||||
"matchers",
|
||||
"nu-ansi-term",
|
||||
"once_cell",
|
||||
"regex",
|
||||
"sharded-slab",
|
||||
"smallvec",
|
||||
"thread_local",
|
||||
"tracing",
|
||||
"tracing-core",
|
||||
"tracing-log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2956,6 +2988,12 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "valuable"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
|
||||
|
||||
[[package]]
|
||||
name = "vcpkg"
|
||||
version = "0.2.15"
|
||||
@ -3081,6 +3119,28 @@ dependencies = [
|
||||
"wasite",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||
dependencies = [
|
||||
"winapi-i686-pc-windows-gnu",
|
||||
"winapi-x86_64-pc-windows-gnu",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-i686-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.52.0"
|
||||
|
@ -1,3 +1,4 @@
|
||||
[workspace]
|
||||
resolver = "2"
|
||||
members = ["sr_download", "migration"]
|
||||
default-members = ["sr_download"]
|
||||
|
@ -6,9 +6,8 @@ edition = "2021"
|
||||
[dependencies]
|
||||
reqwest = "0.12.5"
|
||||
tokio = { version = "1.38.1", features = ["full"] }
|
||||
toml = "0.8.15"
|
||||
tracing = "0.1.40"
|
||||
serde = { version = "1.0.204", features = ["serde_derive"] }
|
||||
tracing-subscriber = "0.3.18"
|
||||
anyhow = { version = "1.0.86", features = ["backtrace"] }
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
@ -17,3 +16,6 @@ sea-orm = { version = "0.12.15", features = [
|
||||
"runtime-tokio-rustls",
|
||||
] }
|
||||
migration = { path = "../migration" }
|
||||
|
||||
serde = { version = "1.0.204", features = ["serde_derive"] }
|
||||
toml = "0.8.15"
|
||||
|
@ -13,9 +13,8 @@ pub struct ConfigFile {
|
||||
impl Default for ConfigFile {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
db_url: "postgres://srdown:srdown@192.168.3.22:10001/srdown?currentSchema=srdown"
|
||||
.to_string(),
|
||||
db_schema: "srdown".to_string(),
|
||||
db_url: "postgres://srdown:srdown@192.168.3.22:10001/srdown".to_string(),
|
||||
db_schema: "public".to_string(),
|
||||
max_connections: 10,
|
||||
sqlx_logging: true,
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
use sea_orm::{ConnectOptions, Database, DatabaseConnection};
|
||||
|
||||
use crate::config::ConfigFile;
|
||||
use migration::{Migrator, MigratorTrait};
|
||||
|
||||
pub async fn connect(conf: &ConfigFile) -> anyhow::Result<DatabaseConnection> {
|
||||
let mut opt = ConnectOptions::new(conf.db_url.clone());
|
||||
opt.max_connections(conf.max_connections)
|
||||
.set_schema_search_path(conf.db_schema.clone())
|
||||
.sqlx_logging(conf.sqlx_logging);
|
||||
|
||||
let db: DatabaseConnection = Database::connect(opt).await?;
|
||||
db.ping().await?;
|
||||
|
||||
Migrator::up(&db, None).await?;
|
||||
|
||||
Ok(db)
|
||||
}
|
@ -1,3 +1,6 @@
|
||||
use std::path::Path;
|
||||
use tracing::{event, Level};
|
||||
|
||||
mod config;
|
||||
mod db;
|
||||
mod model;
|
||||
@ -6,4 +9,19 @@ mod net;
|
||||
pub type SaveId = u32;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {}
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
tracing_subscriber::fmt().with_max_level(Level::INFO).init();
|
||||
event!(Level::INFO, "Starting srdownload");
|
||||
|
||||
let conf = match config::ConfigFile::read_from_file(Path::new("config.toml")) {
|
||||
Ok(conf) => conf,
|
||||
Err(_) => {
|
||||
config::ConfigFile::write_default_to_file(Path::new("config.toml"))?;
|
||||
config::ConfigFile::default()
|
||||
}
|
||||
};
|
||||
|
||||
let db_connect = db::connect(&conf).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user