Skip to content

Commit

Permalink
clean up and extract database into crate
Browse files Browse the repository at this point in the history
  • Loading branch information
thebino committed Aug 28, 2023
1 parent eb5b041 commit 9e841e6
Show file tree
Hide file tree
Showing 18 changed files with 142 additions and 136 deletions.
38 changes: 16 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 36 additions & 20 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ include = ["src/**/*", "LICENSE.md", "README.md", "CHANGELOG.md"]
[workspace]
members = [
"crates/accounts",
"crates/oauth_authorization_server",
"crates/oauth_authentication",
"crates/activity_pub",
"crates/common",
"crates/database",
"crates/media",
"crates/activity_pub",
"crates/oauth_authentication",
"crates/oauth_authorization_server",
"crates/plugin_interface"
]

Expand All @@ -39,17 +40,18 @@ members = [
accounts = { path = "./crates/accounts" }
activity_pub = { path = "./crates/activity_pub" }
common = { path = "./crates/common" }
database = { path = "./crates/database" }
media = { path = "./crates/media" }
oauth_authorization_server = { path = "./crates/oauth_authorization_server" }
oauth_authentication = { path = "./crates/oauth_authentication" }
oauth_authorization_server = { path = "./crates/oauth_authorization_server" }

# 3rd party dependencies
abi_stable = { version = "0.11.1" }
abi_stable = "0.11.1"
activitypub_federation = "0.4.6"
async-trait = { version = "0.1.73" }
async-trait = "0.1.73"
axum = { version = "0.6.20", features = ["ws", "headers"] }
axum-test = { version = "12.1.0" }
anyhow = { version = "1.0.72" }
axum-test = "12.1.0"
anyhow = "1.0.72"

core_extensions = { version = "1.5.2", default_features = false, features = ["std"] }
chrono = { version = "0.4.26", features = ["serde"] }
Expand All @@ -58,21 +60,33 @@ futures = "0.3.25"
futures-channel = "0.3.25"
futures-util = "0.3.25"

http = { version = "0.2.9" }
hyper = { version = "0.14", features = ["full"] }
mime = { version = "0.3" }
mockall = { version = "0.11.4" }
http = "0.2.9"
hyper = { version = "0.14.27", features = ["full"] }

log = "0.4.19"
mime = "0.3"
mockall = "0.11.4"

rstest = { version = "0.18.1" }
rumqttc = { version = "0.22.0" }
openidconnect = { version = "3.2.0", features = ["accept-rfc3339-timestamps", "accept-string-booleans"] }

pretty_assertions = "1.3.0"

rand = "0.8.5"
rstest = "0.18.2"
rumqttc = "0.22.0"
rsa = "0.9.2"
reqwest = { version = "0.11", default-features = false, features = ["blocking", "json", "stream", "multipart"] }

sea-orm = { version = "0.12.2", features = [ "runtime-tokio-rustls", "debug-print", "mock" ] }
serde = { version = "1.0.183" }
serde = "1.0.183"
serde_json = { version = "1.0.104", features = ["raw_value"] }
serde_urlencoded = "0.7.1"
smallvec = "1.8.0"
sqlx = { version = "0.7.1" }
sqlx = "0.7.1"

time = { version = "0.3.27" }
testdir = "0.8.0"
thiserror = "1.0.40"
time = "0.3.27"
tokio = { version = "1.30.0", features = ["full"] }
tokio-stream = { version = "0.1.11", features = ["net"] }
tokio-util = { version = "0.7.4", features = ["rt"] }
Expand All @@ -82,6 +96,7 @@ tracing = "0.1.37"
tracing-subscriber = { version = "0.3.17", features = ["registry", "fmt", "std", "json"] }
tracing-appender = "0.2.2"

url = { version = "2.4.0", features = ["serde"] }
uuid = { version = "1.4.1", features = ["serde", "v4"] }

[dependencies.photos_network_plugin]
Expand All @@ -95,6 +110,7 @@ path = "./crates/plugin_interface"
accounts.workspace = true
activity_pub.workspace = true
common.workspace = true
database.workspace = true
media.workspace = true
oauth_authentication.workspace = true
oauth_authorization_server.workspace = true
Expand Down Expand Up @@ -129,6 +145,6 @@ sqlx.workspace = true


[dev-dependencies]
pretty_assertions = "1.3.0"
serde_urlencoded = "0.7.1"
reqwest = { version = "0.11", default-features = false, features = ["blocking", "json", "stream", "multipart"] }
pretty_assertions.workspace = true
serde_urlencoded.workspace = true
reqwest.workspace = true
31 changes: 15 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,22 @@ To run tests for all crates in this workspace, run:
$ cargo test --workspace --all-targets
```

### Visual Studio Code

### 📜 Roadmap (MvP)
The fastest start into development can be archived by using [Visual Studio Code](https://code.visualstudio.com/) and [Docker](https://www.docker.com/get-started).

1. Install [Docker](https://www.docker.com/get-started)
2. Install [Visual Studio Code](https://code.visualstudio.com/)
3. Install [Visual Studio Code Remote - Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)
4. Clone and Open this repository in Visual Studio Code
5. Click the "Reopen in Container" Dialog
6. Launch **Photos.network** from the `RUN` window.

![VS Code with devcontainers](vscode.gif)



## 📜 Roadmap (MvP)

- Authenticate via openID
- Create a new media item
Expand All @@ -83,21 +97,6 @@ $ cargo test --workspace --all-targets



### Visual Studio Code

The fastest start into development can be archived by using [Visual Studio Code](https://code.visualstudio.com/) and [Docker](https://www.docker.com/get-started).

1. Install [Docker](https://www.docker.com/get-started)
2. Install [Visual Studio Code](https://code.visualstudio.com/)
3. Install [Visual Studio Code Remote - Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)
4. Clone and Open this repository in Visual Studio Code
5. Click the "Reopen in Container" Dialog
6. Launch **Photos.network** from the `RUN` window.

![VS Code with devcontainers](vscode.gif)



## 🏛️ License

```
Expand Down
2 changes: 2 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ If possible, encrypt your message with our PGP key;
- **Public key**: https://keys.openpgp.org/[email protected]


It is also possible to report it via the [Github security page](https://github.com/photos-network/core/security)

Please do not make vulnerabilities public without notifying us and giving us at least 4 weeks to respond.

If you are going to write about Photos.network’s security, please get in touch, so we can make sure that all claims are correct.
1 change: 0 additions & 1 deletion crates/accounts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ tower-http.workspace = true

# persistency
sea-orm = { workspace = true }
log = "0.4.19"

# testing
mockall = { workspace = true }
Expand Down
20 changes: 20 additions & 0 deletions crates/database/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "database"
version.workspace = true
authors.workspace = true
description.workspace = true
homepage.workspace = true
documentation.workspace = true
repository.workspace = true
readme.workspace = true
license.workspace = true
edition.workspace = true

[lib]
name = "database"
path = "src/lib.rs"
doctest = false

[dependencies]
async-trait = { workspace = true }
sea-orm = { workspace = true, features = ["sqlx-postgres", "runtime-tokio-rustls", "mock"] }
15 changes: 15 additions & 0 deletions crates/database/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# database

This crate provides an database abstraction used within [Photos.network](https://photos.network).

## Framework choice

The decision for [sea-orm](https://www.sea-ql.org/SeaORM/) has 3 main reasons compared to [Diesel](https://diesel.rs/)

- supports async
- testable
- written in rust

A big downsite of sea-orm:

- performance
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

pub mod repository;
//! This crate offers a database abstraction for [Photos.network](https://photos.network) core application.
//!
3 changes: 0 additions & 3 deletions crates/media/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ mime = { workspace = true }

# persistency
sea-orm = { workspace = true }
log = "0.4.19"


uuid = { workspace = true, features = ["serde"] }


Expand Down
2 changes: 1 addition & 1 deletion crates/media/src/api/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::sync::Arc;
use axum::routing::{delete, get, patch, post};
use axum::Router;

use crate::repository::repository::{MediaRepository, MediaRepositoryState};
use crate::repository::{MediaRepository, MediaRepositoryState};

use super::routes::delete_media_id::delete_media_id;
use super::routes::get_albums::get_albums;
Expand Down
2 changes: 1 addition & 1 deletion crates/media/src/api/routes/get_media.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
use std::result::Result;
use tracing::error;

use crate::repository::repository::MediaRepositoryState;
use crate::repository::MediaRepositoryState;

#[derive(Serialize, Deserialize)]
pub(crate) struct MediaListQuery {
Expand Down
3 changes: 1 addition & 2 deletions crates/media/src/api/routes/post_media.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
//!
use axum::http::StatusCode;
use common::model::auth::user::User;
use log::debug;
use tracing::error;
use tracing::{debug, error};

pub(crate) async fn post_media(user: User) -> std::result::Result<String, StatusCode> {
error!("POST /media user={}", user);
Expand Down
22 changes: 0 additions & 22 deletions crates/media/src/data/mod.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
use std::time::Duration;

use log::LevelFilter;
use sea_orm::{ConnectOptions, Database, DatabaseConnection, DbErr};

pub mod error;
pub mod exif_info;
pub mod file;
pub mod location;
pub mod media_item;

pub async fn open_db_conn(db_url: String) -> std::result::Result<DatabaseConnection, DbErr> {
let mut opt = ConnectOptions::new(db_url);
opt.max_connections(100)
.min_connections(5)
.connect_timeout(Duration::from_secs(8))
.acquire_timeout(Duration::from_secs(8))
.idle_timeout(Duration::from_secs(8))
.max_lifetime(Duration::from_secs(8))
.sqlx_logging(true)
.sqlx_logging_level(LevelFilter::Info);
// .set_schema_search_path("my_schema".into()); // Setting default PostgreSQL schema

let db = Database::connect(opt).await?;

Ok(db)
}
Loading

0 comments on commit 9e841e6

Please sign in to comment.