Merge pull request #18 from EETagent/small_dependencies_refactoring

Small dependencies refactoring
This commit is contained in:
Vojtěch Jungmann 2022-10-29 13:02:58 +02:00 committed by GitHub
commit dd7386882b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 48 additions and 112 deletions

View file

@ -1,5 +1,5 @@
[package] [package]
name = "sea-orm-rocket-example" name = "portfolio"
version = "0.1.0" version = "0.1.0"
authors = ["Vojtěch Jungmann", "Sebastian Pravda"] authors = ["Vojtěch Jungmann", "Sebastian Pravda"]
edition = "2021" edition = "2021"

View file

@ -5,22 +5,23 @@ edition = "2021"
publish = false publish = false
[dependencies] [dependencies]
rocket = { version = "^0.5.0-rc.2", features = [
"json",
] }
async-stream = { version = "^0.3" } async-stream = { version = "^0.3" }
async-trait = { version = "0.1" } async-trait = { version = "0.1" }
futures = { version = "^0.3" } futures = { version = "^0.3" }
futures-util = { version = "^0.3" } futures-util = { version = "^0.3" }
rocket = { version = "0.5.0-rc.2", features = [ tokio = "^1.21"
"json",
] }
dotenv = "0.15.0"
serde_json = { version = "^1" } dotenv = "^0.15"
serde_json = { version = "^1.0" }
portfolio-entity = { path = "../entity" } portfolio-entity = { path = "../entity" }
portfolio-migration = { path = "../migration" } portfolio-migration = { path = "../migration" }
portfolio-core = { path = "../core" } portfolio-core = { path = "../core" }
tokio = "1.21.2"
[dependencies.sea-orm-rocket] [dependencies.sea-orm-rocket]
version = "0.5.1" version = "^0.5"

View file

@ -2,7 +2,7 @@ use portfolio_core::sea_orm;
use async_trait::async_trait; use async_trait::async_trait;
use sea_orm::ConnectOptions; 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; use std::time::Duration;
#[derive(Database, Debug)] #[derive(Database, Debug)]
@ -20,7 +20,7 @@ impl sea_orm_rocket::Pool for SeaOrmPool {
type Connection = sea_orm::DatabaseConnection; type Connection = sea_orm::DatabaseConnection;
async fn init(figment: &Figment) -> Result<Self, Self::Error> { async fn init(_figment: &Figment) -> Result<Self, Self::Error> {
dotenv::dotenv().ok(); dotenv::dotenv().ok();
let database_url = std::env::var("DATABASE_URL").unwrap(); let database_url = std::env::var("DATABASE_URL").unwrap();
let mut options: ConnectOptions = database_url.into(); let mut options: ConnectOptions = database_url.into();

View file

@ -2,29 +2,40 @@
name = "portfolio-core" name = "portfolio-core"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
publish = false
[dependencies] [dependencies]
serde = { version = "1.0", features = ["derive"] } chrono = "^0.4"
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"
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 # crypto
argon2 = { version = "0.4", features = ["std"] } rand = "^0.8"
age = { version = "0.9", features = ["async"] } argon2 = { version = "^0.4", features = ["std"] }
secrecy = { version = "0.8.0" } age = { version = "^0.9", features = ["async"] }
base64 = "0.13" secrecy = { version = "^0.8" }
base64 = "^0.13"
[dependencies.sea-orm] [dependencies.sea-orm]
version = "^0.10.0" version = "^0.10"
features = [ features = [
"runtime-tokio-native-tls", "runtime-tokio-native-tls",
"sqlx-postgres", "sqlx-postgres",
@ -32,5 +43,5 @@ features = [
] ]
[dev-dependencies] [dev-dependencies]
tokio = "1.21" tokio = "^1.21"
async-tempfile = "0.2.0" async-tempfile = "^0.2"

View file

@ -9,10 +9,8 @@ name = "entity"
path = "src/lib.rs" path = "src/lib.rs"
[dependencies] [dependencies]
rocket = { version = "0.5.0-rc.2", features = [ serde = { version = "^1.0", features = ["derive"] }
"json", chrono = "^0.4"
] }
chrono = "0.4.22"
[dependencies.sea-orm] [dependencies.sea-orm]
version = "^0.10.0" version = "^0.10"

View file

@ -1,5 +1,3 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3
use sea_orm::entity::prelude::*; use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] #[derive(Clone, Debug, PartialEq, DeriveEntityModel)]

View file

@ -1,11 +1,8 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3
use sea_orm::entity::prelude::*; use sea_orm::entity::prelude::*;
use rocket::serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[serde(crate = "rocket::serde")]
#[sea_orm(table_name = "candidate")] #[sea_orm(table_name = "candidate")]
pub struct Model { pub struct Model {
#[sea_orm(primary_key, auto_increment = false)] #[sea_orm(primary_key, auto_increment = false)]

View file

@ -1,5 +1,3 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3
pub mod prelude; pub mod prelude;
pub mod admin; pub mod admin;

View file

@ -1,5 +1,3 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3
use sea_orm::entity::prelude::*; use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] #[derive(Clone, Debug, PartialEq, DeriveEntityModel)]

View file

@ -1,5 +1,3 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3
pub use super::admin::Entity as Admin; pub use super::admin::Entity as Admin;
pub use super::candidate::Entity as Candidate; pub use super::candidate::Entity as Candidate;
pub use super::parent::Entity as Parent; pub use super::parent::Entity as Parent;

View file

@ -1,5 +1,3 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3
use sea_orm::entity::prelude::*; use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] #[derive(Clone, Debug, PartialEq, DeriveEntityModel)]

View file

@ -9,11 +9,10 @@ name = "migration"
path = "src/lib.rs" path = "src/lib.rs"
[dependencies] [dependencies]
rocket = { version = "0.5.0-rc.2" } serde = { version = "^1.0", features = ["derive"] }
async-std = { version = "^1", features = ["attributes", "tokio1"] } chrono = "^0.4"
chrono = "0.4.22"
portfolio-entity = { path = "../entity" } portfolio-entity = { path = "../entity" }
[dependencies.sea-orm-migration] [dependencies.sea-orm-migration]
version = "^0.10.0" version = "^0.10"
features = [ "runtime-tokio-native-tls", "sqlx-postgres", "sqlx-sqlite"] features = [ "runtime-tokio-native-tls", "sqlx-postgres", "sqlx-sqlite"]

View file

@ -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
```

View file

@ -36,7 +36,6 @@ impl MigrationTrait for Migration {
} }
} }
/// Learn more at https://docs.rs/sea-query#iden
#[derive(Iden)] #[derive(Iden)]
enum Admin { enum Admin {
Table, Table,

View file

@ -48,7 +48,6 @@ impl MigrationTrait for Migration {
} }
} }
/// Learn more at https://docs.rs/sea-query#iden
#[derive(Iden)] #[derive(Iden)]
pub enum Candidate { pub enum Candidate {
Table, Table,

View file

@ -36,7 +36,6 @@ impl MigrationTrait for Migration {
} }
} }
/// Learn more at https://docs.rs/sea-query#iden
#[derive(Iden)] #[derive(Iden)]
enum Parent { enum Parent {
Table, Table,

View file

@ -40,8 +40,6 @@ impl MigrationTrait for Migration {
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let db = manager.get_connection(); let db = manager.get_connection();
print!("{:?}", self.admin.clone().id);
self.admin.to_owned().delete(db).await?; self.admin.to_owned().delete(db).await?;
Ok(()) Ok(())

View file

@ -34,7 +34,6 @@ impl MigrationTrait for Migration {
} }
} }
/// Learn more at https://docs.rs/sea-query#iden
#[derive(Iden)] #[derive(Iden)]
pub enum Session { pub enum Session {
Table, Table,

View file

@ -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;
}