From ba34a6cf3d924786c5b7fd55370352b03208f2ed Mon Sep 17 00:00:00 2001 From: EETagent Date: Sat, 29 Oct 2022 12:25:55 +0200 Subject: [PATCH 1/2] refactor: remove warnings --- api/src/pool.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/src/pool.rs b/api/src/pool.rs index 4b123bc..b031c6c 100644 --- a/api/src/pool.rs +++ b/api/src/pool.rs @@ -2,7 +2,7 @@ use portfolio_core::sea_orm; use async_trait::async_trait; use sea_orm::ConnectOptions; -use sea_orm_rocket::{rocket::figment::Figment, Config, Database}; +use sea_orm_rocket::{rocket::figment::Figment, Database}; use std::time::Duration; #[derive(Database, Debug)] @@ -20,7 +20,7 @@ impl sea_orm_rocket::Pool for SeaOrmPool { type Connection = sea_orm::DatabaseConnection; - async fn init(figment: &Figment) -> Result { + async fn init(_figment: &Figment) -> Result { dotenv::dotenv().ok(); let database_url = std::env::var("DATABASE_URL").unwrap(); let mut options: ConnectOptions = database_url.into(); From 515d4d1298b3fce172315d6a32a270241e96140e Mon Sep 17 00:00:00 2001 From: EETagent Date: Sat, 29 Oct 2022 12:34:10 +0200 Subject: [PATCH 2/2] chore: refactor dependencies --- Cargo.toml | 2 +- api/Cargo.toml | 17 +++---- core/Cargo.toml | 47 ++++++++++++------- entity/Cargo.toml | 8 ++-- entity/src/admin.rs | 2 - entity/src/candidate.rs | 5 +- entity/src/mod.rs | 2 - entity/src/parent.rs | 2 - entity/src/prelude.rs | 2 - entity/src/session.rs | 2 - migration/Cargo.toml | 7 ++- migration/README.md | 37 --------------- .../src/m20221024_111310_create_admin.rs | 1 - .../src/m20221024_121621_create_candidate.rs | 1 - .../src/m20221024_124701_create_parent.rs | 1 - migration/src/m20221024_134454_fill_admin.rs | 2 - .../src/m20221025_154422_create_session.rs | 1 - migration/src/main.rs | 17 ------- 18 files changed, 46 insertions(+), 110 deletions(-) delete mode 100644 migration/README.md delete mode 100644 migration/src/main.rs diff --git a/Cargo.toml b/Cargo.toml index 0da4e67..d159131 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "sea-orm-rocket-example" +name = "portfolio" version = "0.1.0" authors = ["Vojtěch Jungmann", "Sebastian Pravda"] edition = "2021" diff --git a/api/Cargo.toml b/api/Cargo.toml index 80dfd3c..d102cb2 100644 --- a/api/Cargo.toml +++ b/api/Cargo.toml @@ -5,22 +5,23 @@ edition = "2021" publish = false [dependencies] +rocket = { version = "^0.5.0-rc.2", features = [ + "json", +] } + async-stream = { version = "^0.3" } async-trait = { version = "0.1" } futures = { version = "^0.3" } futures-util = { version = "^0.3" } -rocket = { version = "0.5.0-rc.2", features = [ - "json", -] } -dotenv = "0.15.0" +tokio = "^1.21" -serde_json = { version = "^1" } +dotenv = "^0.15" + +serde_json = { version = "^1.0" } portfolio-entity = { path = "../entity" } portfolio-migration = { path = "../migration" } portfolio-core = { path = "../core" } -tokio = "1.21.2" - [dependencies.sea-orm-rocket] -version = "0.5.1" +version = "^0.5" diff --git a/core/Cargo.toml b/core/Cargo.toml index 884ea90..be620cd 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -2,29 +2,40 @@ name = "portfolio-core" version = "0.1.0" edition = "2021" +publish = false [dependencies] -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" -portfolio-entity = { path = "../entity" } -rand = "0.8.5" -chrono = "0.4.22" -jsonwebtoken = "8.1.1" -dotenv = "0.15.0" -tokio = "1.21.2" -futures = "0.3.25" -async-compat = "0.2.1" +chrono = "^0.4" -infer = "0.9" +# serialization & deserialization +serde = { version = "^1.0", features = ["derive"] } +serde_json = "^1.0" + +portfolio-entity = { path = "../entity" } + +# tokens +jsonwebtoken = "^8.1" + +# env +dotenv = "^0.15" + +# async +tokio = "^1.21" +futures = "^0.3" +async-compat = "^0.2" + +# file identifier +infer = "^0.9" # crypto -argon2 = { version = "0.4", features = ["std"] } -age = { version = "0.9", features = ["async"] } -secrecy = { version = "0.8.0" } -base64 = "0.13" +rand = "^0.8" +argon2 = { version = "^0.4", features = ["std"] } +age = { version = "^0.9", features = ["async"] } +secrecy = { version = "^0.8" } +base64 = "^0.13" [dependencies.sea-orm] -version = "^0.10.0" +version = "^0.10" features = [ "runtime-tokio-native-tls", "sqlx-postgres", @@ -32,5 +43,5 @@ features = [ ] [dev-dependencies] -tokio = "1.21" -async-tempfile = "0.2.0" \ No newline at end of file +tokio = "^1.21" +async-tempfile = "^0.2" \ No newline at end of file diff --git a/entity/Cargo.toml b/entity/Cargo.toml index c35f802..1b3a166 100644 --- a/entity/Cargo.toml +++ b/entity/Cargo.toml @@ -9,10 +9,8 @@ name = "entity" path = "src/lib.rs" [dependencies] -rocket = { version = "0.5.0-rc.2", features = [ - "json", -] } -chrono = "0.4.22" +serde = { version = "^1.0", features = ["derive"] } +chrono = "^0.4" [dependencies.sea-orm] -version = "^0.10.0" +version = "^0.10" diff --git a/entity/src/admin.rs b/entity/src/admin.rs index ccfab5a..5d48632 100644 --- a/entity/src/admin.rs +++ b/entity/src/admin.rs @@ -1,5 +1,3 @@ -//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3 - use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel)] diff --git a/entity/src/candidate.rs b/entity/src/candidate.rs index d9199ce..b7d23ac 100644 --- a/entity/src/candidate.rs +++ b/entity/src/candidate.rs @@ -1,11 +1,8 @@ -//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3 - use sea_orm::entity::prelude::*; -use rocket::serde::{Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)] -#[serde(crate = "rocket::serde")] #[sea_orm(table_name = "candidate")] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] diff --git a/entity/src/mod.rs b/entity/src/mod.rs index 63cf621..ef5f522 100644 --- a/entity/src/mod.rs +++ b/entity/src/mod.rs @@ -1,5 +1,3 @@ -//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3 - pub mod prelude; pub mod admin; diff --git a/entity/src/parent.rs b/entity/src/parent.rs index 4cf47cc..7e1b00c 100644 --- a/entity/src/parent.rs +++ b/entity/src/parent.rs @@ -1,5 +1,3 @@ -//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3 - use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel)] diff --git a/entity/src/prelude.rs b/entity/src/prelude.rs index 73b608f..af8586b 100644 --- a/entity/src/prelude.rs +++ b/entity/src/prelude.rs @@ -1,5 +1,3 @@ -//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3 - pub use super::admin::Entity as Admin; pub use super::candidate::Entity as Candidate; pub use super::parent::Entity as Parent; diff --git a/entity/src/session.rs b/entity/src/session.rs index 2df872b..79e71d2 100644 --- a/entity/src/session.rs +++ b/entity/src/session.rs @@ -1,5 +1,3 @@ -//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3 - use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel)] diff --git a/migration/Cargo.toml b/migration/Cargo.toml index 5bc4b91..794151d 100644 --- a/migration/Cargo.toml +++ b/migration/Cargo.toml @@ -9,11 +9,10 @@ name = "migration" path = "src/lib.rs" [dependencies] -rocket = { version = "0.5.0-rc.2" } -async-std = { version = "^1", features = ["attributes", "tokio1"] } -chrono = "0.4.22" +serde = { version = "^1.0", features = ["derive"] } +chrono = "^0.4" portfolio-entity = { path = "../entity" } [dependencies.sea-orm-migration] -version = "^0.10.0" +version = "^0.10" features = [ "runtime-tokio-native-tls", "sqlx-postgres", "sqlx-sqlite"] diff --git a/migration/README.md b/migration/README.md deleted file mode 100644 index 963caae..0000000 --- a/migration/README.md +++ /dev/null @@ -1,37 +0,0 @@ -# Running Migrator CLI - -- Apply all pending migrations - ```sh - cargo run - ``` - ```sh - cargo run -- up - ``` -- Apply first 10 pending migrations - ```sh - cargo run -- up -n 10 - ``` -- Rollback last applied migrations - ```sh - cargo run -- down - ``` -- Rollback last 10 applied migrations - ```sh - cargo run -- down -n 10 - ``` -- Drop all tables from the database, then reapply all migrations - ```sh - cargo run -- fresh - ``` -- Rollback all applied migrations, then reapply all migrations - ```sh - cargo run -- refresh - ``` -- Rollback all applied migrations - ```sh - cargo run -- reset - ``` -- Check the status of all migrations - ```sh - cargo run -- status - ``` diff --git a/migration/src/m20221024_111310_create_admin.rs b/migration/src/m20221024_111310_create_admin.rs index efe72fb..50809d5 100644 --- a/migration/src/m20221024_111310_create_admin.rs +++ b/migration/src/m20221024_111310_create_admin.rs @@ -36,7 +36,6 @@ impl MigrationTrait for Migration { } } -/// Learn more at https://docs.rs/sea-query#iden #[derive(Iden)] enum Admin { Table, diff --git a/migration/src/m20221024_121621_create_candidate.rs b/migration/src/m20221024_121621_create_candidate.rs index 974a93f..9d06911 100644 --- a/migration/src/m20221024_121621_create_candidate.rs +++ b/migration/src/m20221024_121621_create_candidate.rs @@ -48,7 +48,6 @@ impl MigrationTrait for Migration { } } -/// Learn more at https://docs.rs/sea-query#iden #[derive(Iden)] enum Candidate { Table, diff --git a/migration/src/m20221024_124701_create_parent.rs b/migration/src/m20221024_124701_create_parent.rs index 7573a9f..b53148e 100644 --- a/migration/src/m20221024_124701_create_parent.rs +++ b/migration/src/m20221024_124701_create_parent.rs @@ -36,7 +36,6 @@ impl MigrationTrait for Migration { } } -/// Learn more at https://docs.rs/sea-query#iden #[derive(Iden)] enum Parent { Table, diff --git a/migration/src/m20221024_134454_fill_admin.rs b/migration/src/m20221024_134454_fill_admin.rs index 0ec81b1..9250fd2 100644 --- a/migration/src/m20221024_134454_fill_admin.rs +++ b/migration/src/m20221024_134454_fill_admin.rs @@ -40,8 +40,6 @@ impl MigrationTrait for Migration { async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { let db = manager.get_connection(); - print!("{:?}", self.admin.clone().id); - self.admin.to_owned().delete(db).await?; Ok(()) diff --git a/migration/src/m20221025_154422_create_session.rs b/migration/src/m20221025_154422_create_session.rs index d7931f0..843ea61 100644 --- a/migration/src/m20221025_154422_create_session.rs +++ b/migration/src/m20221025_154422_create_session.rs @@ -34,7 +34,6 @@ impl MigrationTrait for Migration { } } -/// Learn more at https://docs.rs/sea-query#iden #[derive(Iden)] enum Session { Table, diff --git a/migration/src/main.rs b/migration/src/main.rs deleted file mode 100644 index 4626e82..0000000 --- a/migration/src/main.rs +++ /dev/null @@ -1,17 +0,0 @@ -use sea_orm_migration::prelude::*; - -#[async_std::main] -async fn main() { - // Setting `DATABASE_URL` environment variable - let key = "DATABASE_URL"; - if std::env::var(key).is_err() { - // Getting the database URL from Rocket.toml if it's not set - let figment = rocket::Config::figment(); - let database_url: String = figment - .extract_inner("databases.sea_orm.url") - .expect("Cannot find Database URL in Rocket.toml"); - std::env::set_var(key, database_url); - } - - cli::run_cli(migration::Migrator).await; -}