Add SQLx operation tracing (#5223)
* wip: vendor sqlx-tracing * (compiles) standardize pg types used * more standardization * general log message improvements * wip: improve sqlx-tracing architecture * unify sqlx::Executor type * wip: try fix sqlx tracing * wip: sqlx-tracing compiles * so close * it compiles * fix ci
This commit is contained in:
593
Cargo.lock
generated
593
Cargo.lock
generated
@@ -521,6 +521,22 @@ dependencies = [
|
|||||||
"zbus",
|
"zbus",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "astral-tokio-tar"
|
||||||
|
version = "0.5.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ec179a06c1769b1e42e1e2cbe74c7dcdb3d6383c838454d063eaac5bbb7ebbe5"
|
||||||
|
dependencies = [
|
||||||
|
"filetime",
|
||||||
|
"futures-core",
|
||||||
|
"libc",
|
||||||
|
"portable-atomic",
|
||||||
|
"rustc-hash",
|
||||||
|
"tokio",
|
||||||
|
"tokio-stream",
|
||||||
|
"xattr",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "async-broadcast"
|
name = "async-broadcast"
|
||||||
version = "0.7.2"
|
version = "0.7.2"
|
||||||
@@ -671,6 +687,28 @@ dependencies = [
|
|||||||
"windows-sys 0.61.2",
|
"windows-sys 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "async-stream"
|
||||||
|
version = "0.3.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0b5a71a6f37880a80d1d7f19efd781e4b5de42c88f0722cc13bcb6cc2cfe8476"
|
||||||
|
dependencies = [
|
||||||
|
"async-stream-impl",
|
||||||
|
"futures-core",
|
||||||
|
"pin-project-lite",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "async-stream-impl"
|
||||||
|
version = "0.3.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.106",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "async-stripe"
|
name = "async-stripe"
|
||||||
version = "0.41.0"
|
version = "0.41.0"
|
||||||
@@ -892,6 +930,49 @@ dependencies = [
|
|||||||
"thiserror 2.0.17",
|
"thiserror 2.0.17",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "axum"
|
||||||
|
version = "0.8.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8b52af3cb4058c895d37317bb27508dccc8e5f2d39454016b297bf4a400597b8"
|
||||||
|
dependencies = [
|
||||||
|
"axum-core",
|
||||||
|
"bytes",
|
||||||
|
"futures-util",
|
||||||
|
"http 1.3.1",
|
||||||
|
"http-body 1.0.1",
|
||||||
|
"http-body-util",
|
||||||
|
"itoa",
|
||||||
|
"matchit",
|
||||||
|
"memchr",
|
||||||
|
"mime",
|
||||||
|
"percent-encoding",
|
||||||
|
"pin-project-lite",
|
||||||
|
"serde_core",
|
||||||
|
"sync_wrapper",
|
||||||
|
"tower",
|
||||||
|
"tower-layer",
|
||||||
|
"tower-service",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "axum-core"
|
||||||
|
version = "0.5.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "08c78f31d7b1291f7ee735c1c6780ccde7785daae9a9206026862dab7d8792d1"
|
||||||
|
dependencies = [
|
||||||
|
"bytes",
|
||||||
|
"futures-core",
|
||||||
|
"http 1.3.1",
|
||||||
|
"http-body 1.0.1",
|
||||||
|
"http-body-util",
|
||||||
|
"mime",
|
||||||
|
"pin-project-lite",
|
||||||
|
"sync_wrapper",
|
||||||
|
"tower-layer",
|
||||||
|
"tower-service",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "backtrace"
|
name = "backtrace"
|
||||||
version = "0.3.76"
|
version = "0.3.76"
|
||||||
@@ -1066,6 +1147,83 @@ dependencies = [
|
|||||||
"piper",
|
"piper",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bollard"
|
||||||
|
version = "0.19.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "87a52479c9237eb04047ddb94788c41ca0d26eaff8b697ecfbb4c32f7fdc3b1b"
|
||||||
|
dependencies = [
|
||||||
|
"async-stream",
|
||||||
|
"base64 0.22.1",
|
||||||
|
"bitflags 2.9.4",
|
||||||
|
"bollard-buildkit-proto",
|
||||||
|
"bollard-stubs",
|
||||||
|
"bytes",
|
||||||
|
"chrono",
|
||||||
|
"futures-core",
|
||||||
|
"futures-util",
|
||||||
|
"hex",
|
||||||
|
"home",
|
||||||
|
"http 1.3.1",
|
||||||
|
"http-body-util",
|
||||||
|
"hyper 1.7.0",
|
||||||
|
"hyper-named-pipe",
|
||||||
|
"hyper-rustls 0.27.7",
|
||||||
|
"hyper-util",
|
||||||
|
"hyperlocal",
|
||||||
|
"log",
|
||||||
|
"num",
|
||||||
|
"pin-project-lite",
|
||||||
|
"rand 0.9.2",
|
||||||
|
"rustls 0.23.32",
|
||||||
|
"rustls-native-certs 0.8.1",
|
||||||
|
"rustls-pemfile 2.2.0",
|
||||||
|
"rustls-pki-types",
|
||||||
|
"serde",
|
||||||
|
"serde_derive",
|
||||||
|
"serde_json",
|
||||||
|
"serde_repr",
|
||||||
|
"serde_urlencoded",
|
||||||
|
"thiserror 2.0.17",
|
||||||
|
"tokio",
|
||||||
|
"tokio-stream",
|
||||||
|
"tokio-util",
|
||||||
|
"tonic 0.14.2",
|
||||||
|
"tower-service",
|
||||||
|
"url",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bollard-buildkit-proto"
|
||||||
|
version = "0.7.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "85a885520bf6249ab931a764ffdb87b0ceef48e6e7d807cfdb21b751e086e1ad"
|
||||||
|
dependencies = [
|
||||||
|
"prost 0.14.3",
|
||||||
|
"prost-types",
|
||||||
|
"tonic 0.14.2",
|
||||||
|
"tonic-prost",
|
||||||
|
"ureq",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bollard-stubs"
|
||||||
|
version = "1.49.1-rc.28.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5731fe885755e92beff1950774068e0cae67ea6ec7587381536fca84f1779623"
|
||||||
|
dependencies = [
|
||||||
|
"base64 0.22.1",
|
||||||
|
"bollard-buildkit-proto",
|
||||||
|
"bytes",
|
||||||
|
"chrono",
|
||||||
|
"prost 0.14.3",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"serde_repr",
|
||||||
|
"serde_with",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "borsh"
|
name = "borsh"
|
||||||
version = "1.5.7"
|
version = "1.5.7"
|
||||||
@@ -2378,6 +2536,17 @@ dependencies = [
|
|||||||
"const-random",
|
"const-random",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "docker_credential"
|
||||||
|
version = "1.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1d89dfcba45b4afad7450a99b39e751590463e45c04728cf555d36bb66940de8"
|
||||||
|
dependencies = [
|
||||||
|
"base64 0.21.7",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "document-features"
|
name = "document-features"
|
||||||
version = "0.2.11"
|
version = "0.2.11"
|
||||||
@@ -2679,6 +2848,17 @@ dependencies = [
|
|||||||
"windows-sys 0.48.0",
|
"windows-sys 0.48.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "etcetera"
|
||||||
|
version = "0.10.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "26c7b13d0780cb82722fd59f6f57f925e143427e4a75313a6c77243bf5326ae6"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"home",
|
||||||
|
"windows-sys 0.59.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "event-listener"
|
name = "event-listener"
|
||||||
version = "2.5.3"
|
version = "2.5.3"
|
||||||
@@ -3801,6 +3981,21 @@ dependencies = [
|
|||||||
"want",
|
"want",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hyper-named-pipe"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "73b7d8abf35697b81a825e386fc151e0d503e8cb5fcb93cc8669c376dfd6f278"
|
||||||
|
dependencies = [
|
||||||
|
"hex",
|
||||||
|
"hyper 1.7.0",
|
||||||
|
"hyper-util",
|
||||||
|
"pin-project-lite",
|
||||||
|
"tokio",
|
||||||
|
"tower-service",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hyper-rustls"
|
name = "hyper-rustls"
|
||||||
version = "0.24.2"
|
version = "0.24.2"
|
||||||
@@ -3835,6 +4030,19 @@ dependencies = [
|
|||||||
"webpki-roots 1.0.3",
|
"webpki-roots 1.0.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hyper-timeout"
|
||||||
|
version = "0.5.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2b90d566bffbce6a75bd8b09a05aa8c2cb1fabb6cb348f8840c9e4c90a0d83b0"
|
||||||
|
dependencies = [
|
||||||
|
"hyper 1.7.0",
|
||||||
|
"hyper-util",
|
||||||
|
"pin-project-lite",
|
||||||
|
"tokio",
|
||||||
|
"tower-service",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hyper-tls"
|
name = "hyper-tls"
|
||||||
version = "0.6.0"
|
version = "0.6.0"
|
||||||
@@ -3877,6 +4085,21 @@ dependencies = [
|
|||||||
"windows-registry",
|
"windows-registry",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hyperlocal"
|
||||||
|
version = "0.9.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "986c5ce3b994526b3cd75578e62554abd09f0899d6206de48b3e96ab34ccc8c7"
|
||||||
|
dependencies = [
|
||||||
|
"hex",
|
||||||
|
"http-body-util",
|
||||||
|
"hyper 1.7.0",
|
||||||
|
"hyper-util",
|
||||||
|
"pin-project-lite",
|
||||||
|
"tokio",
|
||||||
|
"tower-service",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iana-time-zone"
|
name = "iana-time-zone"
|
||||||
version = "0.1.64"
|
version = "0.1.64"
|
||||||
@@ -4566,6 +4789,7 @@ dependencies = [
|
|||||||
"sha2",
|
"sha2",
|
||||||
"spdx",
|
"spdx",
|
||||||
"sqlx",
|
"sqlx",
|
||||||
|
"sqlx-tracing",
|
||||||
"strum",
|
"strum",
|
||||||
"thiserror 2.0.17",
|
"thiserror 2.0.17",
|
||||||
"tikv-jemalloc-ctl",
|
"tikv-jemalloc-ctl",
|
||||||
@@ -4888,6 +5112,12 @@ version = "0.1.10"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5"
|
checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "matchit"
|
||||||
|
version = "0.8.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "maxminddb"
|
name = "maxminddb"
|
||||||
version = "0.26.0"
|
version = "0.26.0"
|
||||||
@@ -5873,6 +6103,124 @@ dependencies = [
|
|||||||
"vcpkg",
|
"vcpkg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "opentelemetry"
|
||||||
|
version = "0.30.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "aaf416e4cb72756655126f7dd7bb0af49c674f4c1b9903e80c009e0c37e552e6"
|
||||||
|
dependencies = [
|
||||||
|
"futures-core",
|
||||||
|
"futures-sink",
|
||||||
|
"js-sys",
|
||||||
|
"pin-project-lite",
|
||||||
|
"thiserror 2.0.17",
|
||||||
|
"tracing",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "opentelemetry-appender-tracing"
|
||||||
|
version = "0.30.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e68f63eca5fad47e570e00e893094fc17be959c80c79a7d6ec1abdd5ae6ffc16"
|
||||||
|
dependencies = [
|
||||||
|
"opentelemetry",
|
||||||
|
"tracing",
|
||||||
|
"tracing-core",
|
||||||
|
"tracing-log",
|
||||||
|
"tracing-opentelemetry",
|
||||||
|
"tracing-subscriber",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "opentelemetry-http"
|
||||||
|
version = "0.30.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "50f6639e842a97dbea8886e3439710ae463120091e2e064518ba8e716e6ac36d"
|
||||||
|
dependencies = [
|
||||||
|
"async-trait",
|
||||||
|
"bytes",
|
||||||
|
"http 1.3.1",
|
||||||
|
"opentelemetry",
|
||||||
|
"reqwest",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "opentelemetry-otlp"
|
||||||
|
version = "0.30.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dbee664a43e07615731afc539ca60c6d9f1a9425e25ca09c57bc36c87c55852b"
|
||||||
|
dependencies = [
|
||||||
|
"http 1.3.1",
|
||||||
|
"opentelemetry",
|
||||||
|
"opentelemetry-http",
|
||||||
|
"opentelemetry-proto",
|
||||||
|
"opentelemetry_sdk",
|
||||||
|
"prost 0.13.5",
|
||||||
|
"reqwest",
|
||||||
|
"thiserror 2.0.17",
|
||||||
|
"tokio",
|
||||||
|
"tonic 0.13.1",
|
||||||
|
"tracing",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "opentelemetry-proto"
|
||||||
|
version = "0.30.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2e046fd7660710fe5a05e8748e70d9058dc15c94ba914e7c4faa7c728f0e8ddc"
|
||||||
|
dependencies = [
|
||||||
|
"opentelemetry",
|
||||||
|
"opentelemetry_sdk",
|
||||||
|
"prost 0.13.5",
|
||||||
|
"tonic 0.13.1",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "opentelemetry-semantic-conventions"
|
||||||
|
version = "0.30.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "83d059a296a47436748557a353c5e6c5705b9470ef6c95cfc52c21a8814ddac2"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "opentelemetry-testing"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "562407eb254fea88076c8a410a733a8ee2075fd9c7fbde3da2a03d29e2cef104"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"opentelemetry",
|
||||||
|
"opentelemetry-appender-tracing",
|
||||||
|
"opentelemetry-otlp",
|
||||||
|
"opentelemetry-semantic-conventions",
|
||||||
|
"opentelemetry_sdk",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"serial_test",
|
||||||
|
"tempfile",
|
||||||
|
"testcontainers",
|
||||||
|
"tokio",
|
||||||
|
"tracing-opentelemetry",
|
||||||
|
"tracing-subscriber",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "opentelemetry_sdk"
|
||||||
|
version = "0.30.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "11f644aa9e5e31d11896e024305d7e3c98a88884d9f8919dbf37a9991bc47a4b"
|
||||||
|
dependencies = [
|
||||||
|
"futures-channel",
|
||||||
|
"futures-executor",
|
||||||
|
"futures-util",
|
||||||
|
"opentelemetry",
|
||||||
|
"percent-encoding",
|
||||||
|
"rand 0.9.2",
|
||||||
|
"serde_json",
|
||||||
|
"thiserror 2.0.17",
|
||||||
|
"tokio",
|
||||||
|
"tokio-stream",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "option-ext"
|
name = "option-ext"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
@@ -5997,6 +6345,31 @@ dependencies = [
|
|||||||
"windows-link 0.2.1",
|
"windows-link 0.2.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "parse-display"
|
||||||
|
version = "0.9.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "914a1c2265c98e2446911282c6ac86d8524f495792c38c5bd884f80499c7538a"
|
||||||
|
dependencies = [
|
||||||
|
"parse-display-derive",
|
||||||
|
"regex",
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "parse-display-derive"
|
||||||
|
version = "0.9.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2ae7800a4c974efd12df917266338e79a7a74415173caf7e70aa0a0707345281"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"regex",
|
||||||
|
"regex-syntax",
|
||||||
|
"structmeta",
|
||||||
|
"syn 2.0.106",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parse-size"
|
name = "parse-size"
|
||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
@@ -6384,7 +6757,7 @@ dependencies = [
|
|||||||
"inferno",
|
"inferno",
|
||||||
"num",
|
"num",
|
||||||
"paste",
|
"paste",
|
||||||
"prost",
|
"prost 0.13.5",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -6590,7 +6963,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "2796faa41db3ec313a31f7624d9286acf277b52de526150b7e69f3debf891ee5"
|
checksum = "2796faa41db3ec313a31f7624d9286acf277b52de526150b7e69f3debf891ee5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"prost-derive",
|
"prost-derive 0.13.5",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "prost"
|
||||||
|
version = "0.14.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d2ea70524a2f82d518bce41317d0fae74151505651af45faf1ffbd6fd33f0568"
|
||||||
|
dependencies = [
|
||||||
|
"bytes",
|
||||||
|
"prost-derive 0.14.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -6606,6 +6989,28 @@ dependencies = [
|
|||||||
"syn 2.0.106",
|
"syn 2.0.106",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "prost-derive"
|
||||||
|
version = "0.14.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "27c6023962132f4b30eb4c172c91ce92d933da334c59c23cddee82358ddafb0b"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"itertools 0.14.0",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.106",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "prost-types"
|
||||||
|
version = "0.14.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8991c4cbdb8bc5b11f0b074ffe286c30e523de90fee5ba8132f1399f23cb3dd7"
|
||||||
|
dependencies = [
|
||||||
|
"prost 0.14.3",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "protobuf"
|
name = "protobuf"
|
||||||
version = "3.7.2"
|
version = "3.7.2"
|
||||||
@@ -7633,6 +8038,15 @@ dependencies = [
|
|||||||
"winapi-util",
|
"winapi-util",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "scc"
|
||||||
|
version = "2.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "46e6f046b7fef48e2660c57ed794263155d713de679057f2d0c169bfc6e756cc"
|
||||||
|
dependencies = [
|
||||||
|
"sdd",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "schannel"
|
name = "schannel"
|
||||||
version = "0.1.28"
|
version = "0.1.28"
|
||||||
@@ -7724,6 +8138,12 @@ dependencies = [
|
|||||||
"untrusted",
|
"untrusted",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sdd"
|
||||||
|
version = "3.0.10"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "490dcfcbfef26be6800d11870ff2df8774fa6e86d047e3e8c8a76b25655e41ca"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "seahash"
|
name = "seahash"
|
||||||
version = "4.1.0"
|
version = "4.1.0"
|
||||||
@@ -8170,6 +8590,32 @@ dependencies = [
|
|||||||
"syn 2.0.106",
|
"syn 2.0.106",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serial_test"
|
||||||
|
version = "3.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0d0b343e184fc3b7bb44dff0705fffcf4b3756ba6aff420dddd8b24ca145e555"
|
||||||
|
dependencies = [
|
||||||
|
"futures-executor",
|
||||||
|
"futures-util",
|
||||||
|
"log",
|
||||||
|
"once_cell",
|
||||||
|
"parking_lot",
|
||||||
|
"scc",
|
||||||
|
"serial_test_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serial_test_derive"
|
||||||
|
version = "3.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6f50427f258fb77356e4cd4aa0e87e2bd2c66dbcee41dc405282cae2bfc26c83"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.106",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serialize-to-javascript"
|
name = "serialize-to-javascript"
|
||||||
version = "0.1.2"
|
version = "0.1.2"
|
||||||
@@ -8576,7 +9022,7 @@ dependencies = [
|
|||||||
"chrono",
|
"chrono",
|
||||||
"crc",
|
"crc",
|
||||||
"dotenvy",
|
"dotenvy",
|
||||||
"etcetera",
|
"etcetera 0.8.0",
|
||||||
"futures-channel",
|
"futures-channel",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
@@ -8629,6 +9075,20 @@ dependencies = [
|
|||||||
"uuid 1.18.1",
|
"uuid 1.18.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sqlx-tracing"
|
||||||
|
version = "0.2.0"
|
||||||
|
dependencies = [
|
||||||
|
"derive_more 2.0.1",
|
||||||
|
"futures",
|
||||||
|
"opentelemetry",
|
||||||
|
"opentelemetry-testing",
|
||||||
|
"sqlx",
|
||||||
|
"testcontainers",
|
||||||
|
"tokio",
|
||||||
|
"tracing",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "stable_deref_trait"
|
name = "stable_deref_trait"
|
||||||
version = "1.2.1"
|
version = "1.2.1"
|
||||||
@@ -9405,6 +9865,35 @@ dependencies = [
|
|||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "testcontainers"
|
||||||
|
version = "0.25.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3f3ac71069f20ecfa60c396316c283fbf35e6833a53dff551a31b5458da05edc"
|
||||||
|
dependencies = [
|
||||||
|
"astral-tokio-tar",
|
||||||
|
"async-trait",
|
||||||
|
"bollard",
|
||||||
|
"bytes",
|
||||||
|
"docker_credential",
|
||||||
|
"either",
|
||||||
|
"etcetera 0.10.0",
|
||||||
|
"futures",
|
||||||
|
"log",
|
||||||
|
"memchr",
|
||||||
|
"parse-display",
|
||||||
|
"pin-project-lite",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"serde_with",
|
||||||
|
"thiserror 2.0.17",
|
||||||
|
"tokio",
|
||||||
|
"tokio-stream",
|
||||||
|
"tokio-util",
|
||||||
|
"ulid",
|
||||||
|
"url",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "theseus"
|
name = "theseus"
|
||||||
version = "1.0.0-local"
|
version = "1.0.0-local"
|
||||||
@@ -9871,6 +10360,72 @@ version = "1.0.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "df8b2b54733674ad286d16267dcfc7a71ed5c776e4ac7aa3c3e2561f7c637bf2"
|
checksum = "df8b2b54733674ad286d16267dcfc7a71ed5c776e4ac7aa3c3e2561f7c637bf2"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tonic"
|
||||||
|
version = "0.13.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7e581ba15a835f4d9ea06c55ab1bd4dce26fc53752c69a04aac00703bfb49ba9"
|
||||||
|
dependencies = [
|
||||||
|
"async-trait",
|
||||||
|
"base64 0.22.1",
|
||||||
|
"bytes",
|
||||||
|
"http 1.3.1",
|
||||||
|
"http-body 1.0.1",
|
||||||
|
"http-body-util",
|
||||||
|
"hyper 1.7.0",
|
||||||
|
"hyper-timeout",
|
||||||
|
"hyper-util",
|
||||||
|
"percent-encoding",
|
||||||
|
"pin-project",
|
||||||
|
"prost 0.13.5",
|
||||||
|
"tokio",
|
||||||
|
"tokio-stream",
|
||||||
|
"tower",
|
||||||
|
"tower-layer",
|
||||||
|
"tower-service",
|
||||||
|
"tracing",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tonic"
|
||||||
|
version = "0.14.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "eb7613188ce9f7df5bfe185db26c5814347d110db17920415cf2fbcad85e7203"
|
||||||
|
dependencies = [
|
||||||
|
"async-trait",
|
||||||
|
"axum",
|
||||||
|
"base64 0.22.1",
|
||||||
|
"bytes",
|
||||||
|
"h2 0.4.12",
|
||||||
|
"http 1.3.1",
|
||||||
|
"http-body 1.0.1",
|
||||||
|
"http-body-util",
|
||||||
|
"hyper 1.7.0",
|
||||||
|
"hyper-timeout",
|
||||||
|
"hyper-util",
|
||||||
|
"percent-encoding",
|
||||||
|
"pin-project",
|
||||||
|
"socket2 0.6.1",
|
||||||
|
"sync_wrapper",
|
||||||
|
"tokio",
|
||||||
|
"tokio-stream",
|
||||||
|
"tower",
|
||||||
|
"tower-layer",
|
||||||
|
"tower-service",
|
||||||
|
"tracing",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tonic-prost"
|
||||||
|
version = "0.14.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "66bd50ad6ce1252d87ef024b3d64fe4c3cf54a86fb9ef4c631fdd0ded7aeaa67"
|
||||||
|
dependencies = [
|
||||||
|
"bytes",
|
||||||
|
"prost 0.14.3",
|
||||||
|
"tonic 0.14.2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "totp-rs"
|
name = "totp-rs"
|
||||||
version = "5.7.0"
|
version = "5.7.0"
|
||||||
@@ -9893,11 +10448,15 @@ checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
|
"indexmap 2.11.4",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
|
"slab",
|
||||||
"sync_wrapper",
|
"sync_wrapper",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"tokio-util",
|
||||||
"tower-layer",
|
"tower-layer",
|
||||||
"tower-service",
|
"tower-service",
|
||||||
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -10013,6 +10572,24 @@ dependencies = [
|
|||||||
"tracing-core",
|
"tracing-core",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tracing-opentelemetry"
|
||||||
|
version = "0.31.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ddcf5959f39507d0d04d6413119c04f33b623f4f951ebcbdddddfad2d0623a9c"
|
||||||
|
dependencies = [
|
||||||
|
"js-sys",
|
||||||
|
"once_cell",
|
||||||
|
"opentelemetry",
|
||||||
|
"opentelemetry_sdk",
|
||||||
|
"smallvec",
|
||||||
|
"tracing",
|
||||||
|
"tracing-core",
|
||||||
|
"tracing-log",
|
||||||
|
"tracing-subscriber",
|
||||||
|
"web-time",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tracing-subscriber"
|
name = "tracing-subscriber"
|
||||||
version = "0.3.20"
|
version = "0.3.20"
|
||||||
@@ -10108,6 +10685,16 @@ dependencies = [
|
|||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ulid"
|
||||||
|
version = "1.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "470dbf6591da1b39d43c14523b2b469c86879a53e8b758c8e090a470fe7b1fbe"
|
||||||
|
dependencies = [
|
||||||
|
"rand 0.9.2",
|
||||||
|
"web-time",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uname"
|
name = "uname"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
|
|||||||
@@ -164,6 +164,7 @@ sha2 = "0.10.9"
|
|||||||
shlex = "1.3.0"
|
shlex = "1.3.0"
|
||||||
spdx = "0.12.0"
|
spdx = "0.12.0"
|
||||||
sqlx = { version = "0.8.6", default-features = false }
|
sqlx = { version = "0.8.6", default-features = false }
|
||||||
|
sqlx-tracing = { path = "packages/sqlx-tracing" }
|
||||||
strum = "0.27.2"
|
strum = "0.27.2"
|
||||||
sysinfo = { version = "0.37.2", default-features = false }
|
sysinfo = { version = "0.37.2", default-features = false }
|
||||||
tar = "0.4.44"
|
tar = "0.4.44"
|
||||||
@@ -269,4 +270,5 @@ codegen-units = 1 # Compile crates one after another so the compiler can optimi
|
|||||||
# Specific profile for labrinth production builds
|
# Specific profile for labrinth production builds
|
||||||
[profile.release-labrinth]
|
[profile.release-labrinth]
|
||||||
inherits = "release"
|
inherits = "release"
|
||||||
|
strip = false # Keep debug symbols for Sentry
|
||||||
panic = "unwind" # Don't exit the whole app on panic in production
|
panic = "unwind" # Don't exit the whole app on panic in production
|
||||||
|
|||||||
26
apps/labrinth/.sqlx/query-1adbd24d815107e13bc1440c7a8f4eeff66ab4165a9f4980032e114db4dc1286.json
generated
Normal file
26
apps/labrinth/.sqlx/query-1adbd24d815107e13bc1440c7a8f4eeff66ab4165a9f4980032e114db4dc1286.json
generated
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"db_name": "PostgreSQL",
|
||||||
|
"query": "\n SELECT\n id,\n status AS \"status: PayoutStatus\"\n FROM payouts\n ORDER BY id\n ",
|
||||||
|
"describe": {
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"ordinal": 0,
|
||||||
|
"name": "id",
|
||||||
|
"type_info": "Int8"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ordinal": 1,
|
||||||
|
"name": "status: PayoutStatus",
|
||||||
|
"type_info": "Varchar"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"parameters": {
|
||||||
|
"Left": []
|
||||||
|
},
|
||||||
|
"nullable": [
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"hash": "1adbd24d815107e13bc1440c7a8f4eeff66ab4165a9f4980032e114db4dc1286"
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"db_name": "PostgreSQL",
|
"db_name": "PostgreSQL",
|
||||||
"query": "\n INSERT INTO loader_field_enum_values (enum_id, value, created, metadata)\n VALUES ($1, $2, COALESCE($3, timezone('utc', now())), $4)\n ON CONFLICT (enum_id, value) DO UPDATE\n SET metadata = jsonb_set(\n COALESCE(loader_field_enum_values.metadata, $4),\n '{type}', \n COALESCE($4->'type', loader_field_enum_values.metadata->'type')\n ),\n created = COALESCE($3, loader_field_enum_values.created)\n RETURNING id\n ",
|
"query": "\n INSERT INTO loader_field_enum_values (enum_id, value, created, metadata)\n VALUES ($1, $2, COALESCE($3, timezone('utc', now())), $4)\n ON CONFLICT (enum_id, value) DO UPDATE\n SET metadata = jsonb_set(\n COALESCE(loader_field_enum_values.metadata, $4),\n '{type}',\n COALESCE($4->'type', loader_field_enum_values.metadata->'type')\n ),\n created = COALESCE($3, loader_field_enum_values.created)\n RETURNING id\n ",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [
|
"columns": [
|
||||||
{
|
{
|
||||||
@@ -21,5 +21,5 @@
|
|||||||
false
|
false
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"hash": "79c73369365ed7a09f4f48a87605d22db4a49ab5fd9943b54865448d0e9a8d67"
|
"hash": "ad48051c9ac8f233ebfeeebec834ff96df8525a6ed872be7a64b8f349b36b276"
|
||||||
}
|
}
|
||||||
20
apps/labrinth/.sqlx/query-b92b5bb7d179c4fcdbc45600ccfd2402f52fea71e27b08e7926fcc2a9e62c0f3.json
generated
Normal file
20
apps/labrinth/.sqlx/query-b92b5bb7d179c4fcdbc45600ccfd2402f52fea71e27b08e7926fcc2a9e62c0f3.json
generated
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"db_name": "PostgreSQL",
|
||||||
|
"query": "SELECT status AS \"status: PayoutStatus\" FROM payouts WHERE id = 1",
|
||||||
|
"describe": {
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"ordinal": 0,
|
||||||
|
"name": "status: PayoutStatus",
|
||||||
|
"type_info": "Varchar"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"parameters": {
|
||||||
|
"Left": []
|
||||||
|
},
|
||||||
|
"nullable": [
|
||||||
|
false
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"hash": "b92b5bb7d179c4fcdbc45600ccfd2402f52fea71e27b08e7926fcc2a9e62c0f3"
|
||||||
|
}
|
||||||
18
apps/labrinth/.sqlx/query-cd5ccd618fb3cc41646a6de86f9afedb074492b4ec7f2457c14113f5fd13aa02.json
generated
Normal file
18
apps/labrinth/.sqlx/query-cd5ccd618fb3cc41646a6de86f9afedb074492b4ec7f2457c14113f5fd13aa02.json
generated
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"db_name": "PostgreSQL",
|
||||||
|
"query": "\n INSERT INTO payouts (id, method, platform_id, status, user_id, amount, created)\n VALUES ($1, $2, $3, $4, $5, 10.0, NOW())\n ",
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"parameters": {
|
||||||
|
"Left": [
|
||||||
|
"Int8",
|
||||||
|
"Text",
|
||||||
|
"Text",
|
||||||
|
"Varchar",
|
||||||
|
"Int8"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"nullable": []
|
||||||
|
},
|
||||||
|
"hash": "cd5ccd618fb3cc41646a6de86f9afedb074492b4ec7f2457c14113f5fd13aa02"
|
||||||
|
}
|
||||||
17
apps/labrinth/.sqlx/query-cec4240c7c848988b3dfd13e3f8e5c93783c7641b019fdb698a1ec0be1393606.json
generated
Normal file
17
apps/labrinth/.sqlx/query-cec4240c7c848988b3dfd13e3f8e5c93783c7641b019fdb698a1ec0be1393606.json
generated
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"db_name": "PostgreSQL",
|
||||||
|
"query": "\n INSERT INTO payouts (id, method, platform_id, status, user_id, amount, created)\n VALUES ($1, $2, NULL, $3, $4, 10.00, NOW())\n ",
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"parameters": {
|
||||||
|
"Left": [
|
||||||
|
"Int8",
|
||||||
|
"Text",
|
||||||
|
"Varchar",
|
||||||
|
"Int8"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"nullable": []
|
||||||
|
},
|
||||||
|
"hash": "cec4240c7c848988b3dfd13e3f8e5c93783c7641b019fdb698a1ec0be1393606"
|
||||||
|
}
|
||||||
@@ -27,7 +27,6 @@ async-stripe = { workspace = true, features = [
|
|||||||
"connect",
|
"connect",
|
||||||
"webhook-events",
|
"webhook-events",
|
||||||
] }
|
] }
|
||||||
derive_more = { workspace = true, features = ["deref", "deref_mut"]}
|
|
||||||
async-trait = { workspace = true }
|
async-trait = { workspace = true }
|
||||||
base64 = { workspace = true }
|
base64 = { workspace = true }
|
||||||
bitflags = { workspace = true }
|
bitflags = { workspace = true }
|
||||||
@@ -41,6 +40,7 @@ color-thief = { workspace = true }
|
|||||||
const_format = { workspace = true }
|
const_format = { workspace = true }
|
||||||
dashmap = { workspace = true }
|
dashmap = { workspace = true }
|
||||||
deadpool-redis.workspace = true
|
deadpool-redis.workspace = true
|
||||||
|
derive_more = { workspace = true, features = ["deref", "deref_mut"] }
|
||||||
dotenvy = { workspace = true }
|
dotenvy = { workspace = true }
|
||||||
either = { workspace = true }
|
either = { workspace = true }
|
||||||
eyre = { workspace = true }
|
eyre = { workspace = true }
|
||||||
@@ -112,6 +112,7 @@ sqlx = { workspace = true, features = [
|
|||||||
"rust_decimal",
|
"rust_decimal",
|
||||||
"tls-rustls-aws-lc-rs",
|
"tls-rustls-aws-lc-rs",
|
||||||
] }
|
] }
|
||||||
|
sqlx-tracing = { workspace = true, features = ["postgres"] }
|
||||||
strum = { workspace = true }
|
strum = { workspace = true }
|
||||||
thiserror = { workspace = true }
|
thiserror = { workspace = true }
|
||||||
tokio = { workspace = true, features = ["rt-multi-thread", "sync"] }
|
tokio = { workspace = true, features = ["rt-multi-thread", "sync"] }
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use crate::database;
|
use crate::database;
|
||||||
|
use crate::database::PgPool;
|
||||||
use crate::database::models::project_item::ProjectQueryResult;
|
use crate::database::models::project_item::ProjectQueryResult;
|
||||||
use crate::database::models::version_item::VersionQueryResult;
|
use crate::database::models::version_item::VersionQueryResult;
|
||||||
use crate::database::models::{DBCollection, DBOrganization, DBTeamMember};
|
use crate::database::models::{DBCollection, DBOrganization, DBTeamMember};
|
||||||
@@ -8,7 +9,6 @@ use crate::models::users::User;
|
|||||||
use crate::routes::ApiError;
|
use crate::routes::ApiError;
|
||||||
use futures::TryStreamExt;
|
use futures::TryStreamExt;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use sqlx::PgPool;
|
|
||||||
|
|
||||||
pub trait ValidateAuthorized {
|
pub trait ValidateAuthorized {
|
||||||
fn validate_authorized(
|
fn validate_authorized(
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use std::fmt::Write;
|
|||||||
use crate::auth::get_user_from_headers;
|
use crate::auth::get_user_from_headers;
|
||||||
use crate::auth::oauth::uris::{OAuthRedirectUris, ValidatedRedirectUri};
|
use crate::auth::oauth::uris::{OAuthRedirectUris, ValidatedRedirectUri};
|
||||||
use crate::auth::validate::extract_authorization_header;
|
use crate::auth::validate::extract_authorization_header;
|
||||||
|
use crate::database::PgPool;
|
||||||
use crate::database::models::flow_item::DBFlow;
|
use crate::database::models::flow_item::DBFlow;
|
||||||
use crate::database::models::oauth_client_authorization_item::DBOAuthClientAuthorization;
|
use crate::database::models::oauth_client_authorization_item::DBOAuthClientAuthorization;
|
||||||
use crate::database::models::oauth_client_item::DBOAuthClient;
|
use crate::database::models::oauth_client_item::DBOAuthClient;
|
||||||
@@ -24,7 +25,6 @@ use rand::distributions::Alphanumeric;
|
|||||||
use rand::{Rng, SeedableRng};
|
use rand::{Rng, SeedableRng};
|
||||||
use rand_chacha::ChaCha20Rng;
|
use rand_chacha::ChaCha20Rng;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::postgres::PgPool;
|
|
||||||
|
|
||||||
use self::errors::{OAuthError, OAuthErrorType};
|
use self::errors::{OAuthError, OAuthErrorType};
|
||||||
|
|
||||||
@@ -288,7 +288,7 @@ pub async fn request_token(
|
|||||||
client_id,
|
client_id,
|
||||||
user_id,
|
user_id,
|
||||||
}
|
}
|
||||||
.insert(&mut *transaction)
|
.insert(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
transaction.commit().await?;
|
transaction.commit().await?;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ pub async fn get_maybe_user_from_headers<'a, E>(
|
|||||||
required_scopes: Scopes,
|
required_scopes: Scopes,
|
||||||
) -> Result<Option<(Scopes, User)>, AuthenticationError>
|
) -> Result<Option<(Scopes, User)>, AuthenticationError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres> + Copy,
|
||||||
{
|
{
|
||||||
if !req.headers().contains_key(AUTHORIZATION) {
|
if !req.headers().contains_key(AUTHORIZATION) {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
@@ -52,7 +52,7 @@ pub async fn get_full_user_from_headers<'a, E>(
|
|||||||
required_scopes: Scopes,
|
required_scopes: Scopes,
|
||||||
) -> Result<(Scopes, DBUser), AuthenticationError>
|
) -> Result<(Scopes, DBUser), AuthenticationError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres> + Copy,
|
||||||
{
|
{
|
||||||
let (scopes, db_user) = get_user_record_from_bearer_token(
|
let (scopes, db_user) = get_user_record_from_bearer_token(
|
||||||
req,
|
req,
|
||||||
@@ -80,7 +80,7 @@ pub async fn get_user_from_headers<'a, E>(
|
|||||||
required_scopes: Scopes,
|
required_scopes: Scopes,
|
||||||
) -> Result<(Scopes, User), AuthenticationError>
|
) -> Result<(Scopes, User), AuthenticationError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres> + Copy,
|
||||||
{
|
{
|
||||||
let (scopes, db_user) = get_full_user_from_headers(
|
let (scopes, db_user) = get_full_user_from_headers(
|
||||||
req,
|
req,
|
||||||
@@ -102,7 +102,7 @@ pub async fn get_user_record_from_bearer_token<'a, 'b, E>(
|
|||||||
session_queue: &AuthQueue,
|
session_queue: &AuthQueue,
|
||||||
) -> Result<Option<(Scopes, user_item::DBUser)>, AuthenticationError>
|
) -> Result<Option<(Scopes, user_item::DBUser)>, AuthenticationError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres> + Copy,
|
||||||
{
|
{
|
||||||
let token = if let Some(token) = token {
|
let token = if let Some(token) = token {
|
||||||
token
|
token
|
||||||
@@ -227,7 +227,7 @@ pub async fn check_is_moderator_from_headers<'a, 'b, E>(
|
|||||||
required_scopes: Scopes,
|
required_scopes: Scopes,
|
||||||
) -> Result<User, AuthenticationError>
|
) -> Result<User, AuthenticationError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres> + Copy,
|
||||||
{
|
{
|
||||||
let user = get_user_from_headers(
|
let user = get_user_from_headers(
|
||||||
req,
|
req,
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::database::PgPool;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use crate::queue::billing::{index_billing, index_subscriptions};
|
use crate::queue::billing::{index_billing, index_subscriptions};
|
||||||
use crate::queue::email::EmailQueue;
|
use crate::queue::email::EmailQueue;
|
||||||
@@ -10,7 +11,6 @@ use crate::search::indexing::index_projects;
|
|||||||
use crate::util::anrok;
|
use crate::util::anrok;
|
||||||
use crate::{database, search};
|
use crate::{database, search};
|
||||||
use clap::ValueEnum;
|
use clap::ValueEnum;
|
||||||
use sqlx::Postgres;
|
|
||||||
use tracing::{error, info, warn};
|
use tracing::{error, info, warn};
|
||||||
|
|
||||||
#[derive(ValueEnum, Debug, Copy, Clone, PartialEq, Eq)]
|
#[derive(ValueEnum, Debug, Copy, Clone, PartialEq, Eq)]
|
||||||
@@ -31,8 +31,8 @@ impl BackgroundTask {
|
|||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub async fn run(
|
pub async fn run(
|
||||||
self,
|
self,
|
||||||
pool: sqlx::PgPool,
|
pool: PgPool,
|
||||||
ro_pool: sqlx::PgPool,
|
ro_pool: PgPool,
|
||||||
redis_pool: RedisPool,
|
redis_pool: RedisPool,
|
||||||
search_config: search::SearchConfig,
|
search_config: search::SearchConfig,
|
||||||
clickhouse: clickhouse::Client,
|
clickhouse: clickhouse::Client,
|
||||||
@@ -104,7 +104,7 @@ pub async fn run_email(email_queue: EmailQueue) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_bank_balances(pool: sqlx::Pool<Postgres>) {
|
pub async fn update_bank_balances(pool: PgPool) {
|
||||||
let payouts_queue = PayoutsQueue::new();
|
let payouts_queue = PayoutsQueue::new();
|
||||||
|
|
||||||
match insert_bank_balances_and_webhook(&payouts_queue, &pool).await {
|
match insert_bank_balances_and_webhook(&payouts_queue, &pool).await {
|
||||||
@@ -120,7 +120,7 @@ pub async fn run_migrations() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn index_search(
|
pub async fn index_search(
|
||||||
ro_pool: sqlx::PgPool,
|
ro_pool: PgPool,
|
||||||
redis_pool: RedisPool,
|
redis_pool: RedisPool,
|
||||||
search_config: search::SearchConfig,
|
search_config: search::SearchConfig,
|
||||||
) {
|
) {
|
||||||
@@ -132,7 +132,7 @@ pub async fn index_search(
|
|||||||
info!("Done indexing local database");
|
info!("Done indexing local database");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn release_scheduled(pool: sqlx::Pool<Postgres>) {
|
pub async fn release_scheduled(pool: PgPool) {
|
||||||
info!("Releasing scheduled versions/projects!");
|
info!("Releasing scheduled versions/projects!");
|
||||||
|
|
||||||
let projects_results = sqlx::query!(
|
let projects_results = sqlx::query!(
|
||||||
@@ -168,10 +168,7 @@ pub async fn release_scheduled(pool: sqlx::Pool<Postgres>) {
|
|||||||
info!("Finished releasing scheduled versions/projects");
|
info!("Finished releasing scheduled versions/projects");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_versions(
|
pub async fn update_versions(pool: PgPool, redis_pool: RedisPool) {
|
||||||
pool: sqlx::Pool<Postgres>,
|
|
||||||
redis_pool: RedisPool,
|
|
||||||
) {
|
|
||||||
info!("Indexing game versions list from Mojang");
|
info!("Indexing game versions list from Mojang");
|
||||||
let result = version_updater::update_versions(&pool, &redis_pool).await;
|
let result = version_updater::update_versions(&pool, &redis_pool).await;
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
@@ -181,7 +178,7 @@ pub async fn update_versions(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn payouts(
|
pub async fn payouts(
|
||||||
pool: sqlx::Pool<Postgres>,
|
pool: PgPool,
|
||||||
clickhouse: clickhouse::Client,
|
clickhouse: clickhouse::Client,
|
||||||
redis_pool: RedisPool,
|
redis_pool: RedisPool,
|
||||||
) {
|
) {
|
||||||
@@ -209,10 +206,7 @@ pub async fn payouts(
|
|||||||
info!("Done running payouts");
|
info!("Done running payouts");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn sync_payout_statuses(
|
pub async fn sync_payout_statuses(pool: PgPool, mural: muralpay::Client) {
|
||||||
pool: sqlx::Pool<Postgres>,
|
|
||||||
mural: muralpay::Client,
|
|
||||||
) {
|
|
||||||
// Mural sets a max limit of 100 for search payouts endpoint
|
// Mural sets a max limit of 100 for search payouts endpoint
|
||||||
const LIMIT: u32 = 100;
|
const LIMIT: u32 = 100;
|
||||||
|
|
||||||
@@ -241,11 +235,11 @@ pub async fn sync_payout_statuses(
|
|||||||
mod version_updater {
|
mod version_updater {
|
||||||
use std::sync::LazyLock;
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
|
use crate::database::PgPool;
|
||||||
use crate::database::models::legacy_loader_fields::MinecraftGameVersion;
|
use crate::database::models::legacy_loader_fields::MinecraftGameVersion;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use sqlx::Postgres;
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
|
|
||||||
@@ -273,7 +267,7 @@ mod version_updater {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_versions(
|
pub async fn update_versions(
|
||||||
pool: &sqlx::Pool<Postgres>,
|
pool: &PgPool,
|
||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<(), VersionIndexingError> {
|
) -> Result<(), VersionIndexingError> {
|
||||||
let input = reqwest::get(
|
let input = reqwest::get(
|
||||||
|
|||||||
@@ -5,6 +5,6 @@ pub use models::DBImage;
|
|||||||
pub use models::DBProject;
|
pub use models::DBProject;
|
||||||
pub use models::DBVersion;
|
pub use models::DBVersion;
|
||||||
pub use postgres_database::{
|
pub use postgres_database::{
|
||||||
MIGRATOR, ReadOnlyPgPool, check_for_migrations, connect_all,
|
Acquire, Executor, MIGRATOR, PgPool, PgTransaction, ReadOnlyPgPool,
|
||||||
register_and_set_metrics,
|
check_for_migrations, connect_all, register_and_set_metrics,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ pub struct DBAffiliateCode {
|
|||||||
impl DBAffiliateCode {
|
impl DBAffiliateCode {
|
||||||
pub async fn get_by_id(
|
pub async fn get_by_id(
|
||||||
id: DBAffiliateCodeId,
|
id: DBAffiliateCodeId,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Option<DBAffiliateCode>, DatabaseError> {
|
) -> Result<Option<DBAffiliateCode>, DatabaseError> {
|
||||||
let record = sqlx::query!(
|
let record = sqlx::query!(
|
||||||
"SELECT id, created_at, created_by, affiliate, source_name
|
"SELECT id, created_at, created_by, affiliate, source_name
|
||||||
@@ -36,7 +36,7 @@ impl DBAffiliateCode {
|
|||||||
|
|
||||||
pub async fn get_by_affiliate(
|
pub async fn get_by_affiliate(
|
||||||
affiliate: DBUserId,
|
affiliate: DBUserId,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Vec<DBAffiliateCode>, DatabaseError> {
|
) -> Result<Vec<DBAffiliateCode>, DatabaseError> {
|
||||||
let records = sqlx::query!(
|
let records = sqlx::query!(
|
||||||
"SELECT id, created_at, created_by, affiliate, source_name
|
"SELECT id, created_at, created_by, affiliate, source_name
|
||||||
@@ -62,7 +62,7 @@ impl DBAffiliateCode {
|
|||||||
|
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
&self,
|
&self,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<(), DatabaseError> {
|
) -> Result<(), DatabaseError> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"INSERT INTO affiliate_codes (id, created_at, created_by, affiliate, source_name)
|
"INSERT INTO affiliate_codes (id, created_at, created_by, affiliate, source_name)
|
||||||
@@ -80,7 +80,7 @@ impl DBAffiliateCode {
|
|||||||
|
|
||||||
pub async fn remove(
|
pub async fn remove(
|
||||||
id: DBAffiliateCodeId,
|
id: DBAffiliateCodeId,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Option<()>, DatabaseError> {
|
) -> Result<Option<()>, DatabaseError> {
|
||||||
let result = sqlx::query!(
|
let result = sqlx::query!(
|
||||||
"DELETE FROM affiliate_codes WHERE id = $1",
|
"DELETE FROM affiliate_codes WHERE id = $1",
|
||||||
@@ -99,7 +99,7 @@ impl DBAffiliateCode {
|
|||||||
pub async fn update_source_name(
|
pub async fn update_source_name(
|
||||||
id: DBAffiliateCodeId,
|
id: DBAffiliateCodeId,
|
||||||
source_name: &str,
|
source_name: &str,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<bool, DatabaseError> {
|
) -> Result<bool, DatabaseError> {
|
||||||
let result = sqlx::query!(
|
let result = sqlx::query!(
|
||||||
"UPDATE affiliate_codes SET source_name = $1 WHERE id = $2",
|
"UPDATE affiliate_codes SET source_name = $1 WHERE id = $2",
|
||||||
@@ -113,7 +113,7 @@ impl DBAffiliateCode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_all(
|
pub async fn get_all(
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Vec<DBAffiliateCode>, DatabaseError> {
|
) -> Result<Vec<DBAffiliateCode>, DatabaseError> {
|
||||||
let records = sqlx::query!(
|
let records = sqlx::query!(
|
||||||
"SELECT id, created_at, created_by, affiliate, source_name
|
"SELECT id, created_at, created_by, affiliate, source_name
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ impl Category {
|
|||||||
exec: E,
|
exec: E,
|
||||||
) -> Result<HashMap<ProjectTypeId, CategoryId>, DatabaseError>
|
) -> Result<HashMap<ProjectTypeId, CategoryId>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let result = sqlx::query!(
|
let result = sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -70,7 +70,7 @@ impl Category {
|
|||||||
exec: E,
|
exec: E,
|
||||||
) -> Result<Option<CategoryId>, DatabaseError>
|
) -> Result<Option<CategoryId>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let result = sqlx::query!(
|
let result = sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -91,7 +91,7 @@ impl Category {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<Category>, DatabaseError>
|
) -> Result<Vec<Category>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
let mut redis = redis.connect().await?;
|
let mut redis = redis.connect().await?;
|
||||||
@@ -140,7 +140,7 @@ impl LinkPlatform {
|
|||||||
exec: E,
|
exec: E,
|
||||||
) -> Result<Option<LinkPlatformId>, DatabaseError>
|
) -> Result<Option<LinkPlatformId>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let result = sqlx::query!(
|
let result = sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -160,7 +160,7 @@ impl LinkPlatform {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<LinkPlatform>, DatabaseError>
|
) -> Result<Vec<LinkPlatform>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
let mut redis = redis.connect().await?;
|
let mut redis = redis.connect().await?;
|
||||||
@@ -209,7 +209,7 @@ impl ReportType {
|
|||||||
exec: E,
|
exec: E,
|
||||||
) -> Result<Option<ReportTypeId>, DatabaseError>
|
) -> Result<Option<ReportTypeId>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let result = sqlx::query!(
|
let result = sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -229,7 +229,7 @@ impl ReportType {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<String>, DatabaseError>
|
) -> Result<Vec<String>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
let mut redis = redis.connect().await?;
|
let mut redis = redis.connect().await?;
|
||||||
@@ -274,7 +274,7 @@ impl ProjectType {
|
|||||||
exec: E,
|
exec: E,
|
||||||
) -> Result<Option<ProjectTypeId>, DatabaseError>
|
) -> Result<Option<ProjectTypeId>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let result = sqlx::query!(
|
let result = sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -294,7 +294,7 @@ impl ProjectType {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<String>, DatabaseError>
|
) -> Result<Vec<String>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
let mut redis = redis.connect().await?;
|
let mut redis = redis.connect().await?;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::database::PgTransaction;
|
||||||
use crate::database::models::{
|
use crate::database::models::{
|
||||||
DBChargeId, DBProductPriceId, DBUserId, DBUserSubscriptionId, DatabaseError,
|
DBChargeId, DBProductPriceId, DBUserId, DBUserSubscriptionId, DatabaseError,
|
||||||
};
|
};
|
||||||
@@ -123,7 +124,7 @@ macro_rules! select_charges_with_predicate {
|
|||||||
impl DBCharge {
|
impl DBCharge {
|
||||||
pub async fn upsert(
|
pub async fn upsert(
|
||||||
&self,
|
&self,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<DBChargeId, DatabaseError> {
|
) -> Result<DBChargeId, DatabaseError> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
r#"
|
r#"
|
||||||
@@ -173,7 +174,7 @@ impl DBCharge {
|
|||||||
self.tax_transaction_version,
|
self.tax_transaction_version,
|
||||||
self.tax_platform_accounting_time,
|
self.tax_platform_accounting_time,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(self.id)
|
Ok(self.id)
|
||||||
@@ -181,7 +182,7 @@ impl DBCharge {
|
|||||||
|
|
||||||
pub async fn get(
|
pub async fn get(
|
||||||
id: DBChargeId,
|
id: DBChargeId,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Option<DBCharge>, DatabaseError> {
|
) -> Result<Option<DBCharge>, DatabaseError> {
|
||||||
let id = id.0;
|
let id = id.0;
|
||||||
let res = select_charges_with_predicate!("WHERE id = $1", id)
|
let res = select_charges_with_predicate!("WHERE id = $1", id)
|
||||||
@@ -193,7 +194,7 @@ impl DBCharge {
|
|||||||
|
|
||||||
pub async fn get_from_user(
|
pub async fn get_from_user(
|
||||||
user_id: DBUserId,
|
user_id: DBUserId,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Vec<DBCharge>, DatabaseError> {
|
) -> Result<Vec<DBCharge>, DatabaseError> {
|
||||||
let user_id = user_id.0;
|
let user_id = user_id.0;
|
||||||
let res = select_charges_with_predicate!(
|
let res = select_charges_with_predicate!(
|
||||||
@@ -211,7 +212,7 @@ impl DBCharge {
|
|||||||
|
|
||||||
pub async fn get_children(
|
pub async fn get_children(
|
||||||
charge_id: DBChargeId,
|
charge_id: DBChargeId,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Vec<DBCharge>, DatabaseError> {
|
) -> Result<Vec<DBCharge>, DatabaseError> {
|
||||||
let charge_id = charge_id.0;
|
let charge_id = charge_id.0;
|
||||||
let res = select_charges_with_predicate!(
|
let res = select_charges_with_predicate!(
|
||||||
@@ -229,7 +230,7 @@ impl DBCharge {
|
|||||||
|
|
||||||
pub async fn get_open_subscription(
|
pub async fn get_open_subscription(
|
||||||
user_subscription_id: DBUserSubscriptionId,
|
user_subscription_id: DBUserSubscriptionId,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Option<DBCharge>, DatabaseError> {
|
) -> Result<Option<DBCharge>, DatabaseError> {
|
||||||
let user_subscription_id = user_subscription_id.0;
|
let user_subscription_id = user_subscription_id.0;
|
||||||
let res = select_charges_with_predicate!(
|
let res = select_charges_with_predicate!(
|
||||||
@@ -246,7 +247,7 @@ impl DBCharge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_chargeable(
|
pub async fn get_chargeable(
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Vec<DBCharge>, DatabaseError> {
|
) -> Result<Vec<DBCharge>, DatabaseError> {
|
||||||
let charge_type = ChargeType::Subscription.as_str();
|
let charge_type = ChargeType::Subscription.as_str();
|
||||||
let res = select_charges_with_predicate!(
|
let res = select_charges_with_predicate!(
|
||||||
@@ -270,7 +271,7 @@ impl DBCharge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_unprovision(
|
pub async fn get_unprovision(
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Vec<DBCharge>, DatabaseError> {
|
) -> Result<Vec<DBCharge>, DatabaseError> {
|
||||||
let charge_type = ChargeType::Subscription.as_str();
|
let charge_type = ChargeType::Subscription.as_str();
|
||||||
let res = select_charges_with_predicate!(
|
let res = select_charges_with_predicate!(
|
||||||
@@ -297,7 +298,7 @@ impl DBCharge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_cancellable(
|
pub async fn get_cancellable(
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Vec<DBCharge>, DatabaseError> {
|
) -> Result<Vec<DBCharge>, DatabaseError> {
|
||||||
let charge_type = ChargeType::Subscription.as_str();
|
let charge_type = ChargeType::Subscription.as_str();
|
||||||
let res = select_charges_with_predicate!(
|
let res = select_charges_with_predicate!(
|
||||||
@@ -327,7 +328,7 @@ impl DBCharge {
|
|||||||
///
|
///
|
||||||
/// This also locks the charges.
|
/// This also locks the charges.
|
||||||
pub async fn get_updateable_lock(
|
pub async fn get_updateable_lock(
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
limit: i64,
|
limit: i64,
|
||||||
) -> Result<Vec<DBCharge>, DatabaseError> {
|
) -> Result<Vec<DBCharge>, DatabaseError> {
|
||||||
let res = select_charges_with_predicate!(
|
let res = select_charges_with_predicate!(
|
||||||
@@ -358,7 +359,7 @@ impl DBCharge {
|
|||||||
///
|
///
|
||||||
/// Charges are locked.
|
/// Charges are locked.
|
||||||
pub async fn get_missing_tax_identifier_lock(
|
pub async fn get_missing_tax_identifier_lock(
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
offset: i64,
|
offset: i64,
|
||||||
limit: i64,
|
limit: i64,
|
||||||
) -> Result<Vec<DBCharge>, DatabaseError> {
|
) -> Result<Vec<DBCharge>, DatabaseError> {
|
||||||
@@ -387,7 +388,7 @@ impl DBCharge {
|
|||||||
|
|
||||||
pub async fn remove(
|
pub async fn remove(
|
||||||
id: DBChargeId,
|
id: DBChargeId,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<(), DatabaseError> {
|
) -> Result<(), DatabaseError> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -396,7 +397,7 @@ impl DBCharge {
|
|||||||
",
|
",
|
||||||
id.0 as i64
|
id.0 as i64
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use super::ids::*;
|
use super::ids::*;
|
||||||
use crate::database::models;
|
|
||||||
use crate::database::models::DatabaseError;
|
use crate::database::models::DatabaseError;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
|
use crate::database::{PgTransaction, models};
|
||||||
use crate::models::collections::CollectionStatus;
|
use crate::models::collections::CollectionStatus;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
@@ -23,7 +23,7 @@ pub struct CollectionBuilder {
|
|||||||
impl CollectionBuilder {
|
impl CollectionBuilder {
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
self,
|
self,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<DBCollectionId, DatabaseError> {
|
) -> Result<DBCollectionId, DatabaseError> {
|
||||||
let collection_struct = DBCollection {
|
let collection_struct = DBCollection {
|
||||||
id: self.collection_id,
|
id: self.collection_id,
|
||||||
@@ -61,7 +61,7 @@ pub struct DBCollection {
|
|||||||
impl DBCollection {
|
impl DBCollection {
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
&self,
|
&self,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<(), DatabaseError> {
|
) -> Result<(), DatabaseError> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -83,7 +83,7 @@ impl DBCollection {
|
|||||||
self.raw_icon_url.as_ref(),
|
self.raw_icon_url.as_ref(),
|
||||||
self.status.to_string(),
|
self.status.to_string(),
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let (collection_ids, project_ids): (Vec<_>, Vec<_>) =
|
let (collection_ids, project_ids): (Vec<_>, Vec<_>) =
|
||||||
@@ -97,7 +97,7 @@ impl DBCollection {
|
|||||||
&collection_ids[..],
|
&collection_ids[..],
|
||||||
&project_ids[..],
|
&project_ids[..],
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -105,10 +105,10 @@ impl DBCollection {
|
|||||||
|
|
||||||
pub async fn remove(
|
pub async fn remove(
|
||||||
id: DBCollectionId,
|
id: DBCollectionId,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Option<()>, DatabaseError> {
|
) -> Result<Option<()>, DatabaseError> {
|
||||||
let collection = Self::get(id, &mut **transaction, redis).await?;
|
let collection = Self::get(id, &mut *transaction, redis).await?;
|
||||||
|
|
||||||
if let Some(collection) = collection {
|
if let Some(collection) = collection {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -118,7 +118,7 @@ impl DBCollection {
|
|||||||
",
|
",
|
||||||
id as DBCollectionId,
|
id as DBCollectionId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -128,7 +128,7 @@ impl DBCollection {
|
|||||||
",
|
",
|
||||||
id as DBCollectionId,
|
id as DBCollectionId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
models::DBCollection::clear_cache(collection.id, redis).await?;
|
models::DBCollection::clear_cache(collection.id, redis).await?;
|
||||||
@@ -145,7 +145,7 @@ impl DBCollection {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Option<DBCollection>, DatabaseError>
|
) -> Result<Option<DBCollection>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
DBCollection::get_many(&[id], executor, redis)
|
DBCollection::get_many(&[id], executor, redis)
|
||||||
.await
|
.await
|
||||||
@@ -158,7 +158,7 @@ impl DBCollection {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<DBCollection>, DatabaseError>
|
) -> Result<Vec<DBCollection>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let val = redis
|
let val = redis
|
||||||
.get_cached_keys(
|
.get_cached_keys(
|
||||||
|
|||||||
@@ -7,9 +7,12 @@ use chrono::{DateTime, Utc};
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::types::Json;
|
use sqlx::types::Json;
|
||||||
|
|
||||||
use crate::database::models::{
|
use crate::database::{
|
||||||
DBFileId, DBProjectId, DatabaseError, DelphiReportId,
|
PgTransaction,
|
||||||
DelphiReportIssueDetailsId, DelphiReportIssueId,
|
models::{
|
||||||
|
DBFileId, DBProjectId, DatabaseError, DelphiReportId,
|
||||||
|
DelphiReportIssueDetailsId, DelphiReportIssueId,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A Delphi malware analysis report for a project version file.
|
/// A Delphi malware analysis report for a project version file.
|
||||||
@@ -32,7 +35,7 @@ pub struct DBDelphiReport {
|
|||||||
impl DBDelphiReport {
|
impl DBDelphiReport {
|
||||||
pub async fn upsert(
|
pub async fn upsert(
|
||||||
&self,
|
&self,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<DelphiReportId, DatabaseError> {
|
) -> Result<DelphiReportId, DatabaseError> {
|
||||||
Ok(DelphiReportId(sqlx::query_scalar!(
|
Ok(DelphiReportId(sqlx::query_scalar!(
|
||||||
"
|
"
|
||||||
@@ -47,7 +50,7 @@ impl DBDelphiReport {
|
|||||||
self.artifact_url,
|
self.artifact_url,
|
||||||
self.severity as DelphiSeverity,
|
self.severity as DelphiSeverity,
|
||||||
)
|
)
|
||||||
.fetch_one(&mut **transaction)
|
.fetch_one(&mut *transaction)
|
||||||
.await?))
|
.await?))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -181,7 +184,7 @@ pub struct DelphiReportIssueResult {
|
|||||||
impl DBDelphiReportIssue {
|
impl DBDelphiReportIssue {
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
&self,
|
&self,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<DelphiReportIssueId, DatabaseError> {
|
) -> Result<DelphiReportIssueId, DatabaseError> {
|
||||||
Ok(DelphiReportIssueId(
|
Ok(DelphiReportIssueId(
|
||||||
sqlx::query_scalar!(
|
sqlx::query_scalar!(
|
||||||
@@ -193,7 +196,7 @@ impl DBDelphiReportIssue {
|
|||||||
self.report_id as DelphiReportId,
|
self.report_id as DelphiReportId,
|
||||||
self.issue_type,
|
self.issue_type,
|
||||||
)
|
)
|
||||||
.fetch_one(&mut **transaction)
|
.fetch_one(&mut *transaction)
|
||||||
.await?,
|
.await?,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@@ -234,7 +237,7 @@ pub struct ReportIssueDetail {
|
|||||||
impl ReportIssueDetail {
|
impl ReportIssueDetail {
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
&self,
|
&self,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<DelphiReportIssueDetailsId, DatabaseError> {
|
) -> Result<DelphiReportIssueDetailsId, DatabaseError> {
|
||||||
Ok(DelphiReportIssueDetailsId(sqlx::query_scalar!(
|
Ok(DelphiReportIssueDetailsId(sqlx::query_scalar!(
|
||||||
"
|
"
|
||||||
@@ -249,19 +252,19 @@ impl ReportIssueDetail {
|
|||||||
sqlx::types::Json(&self.data) as Json<&HashMap<String, serde_json::Value>>,
|
sqlx::types::Json(&self.data) as Json<&HashMap<String, serde_json::Value>>,
|
||||||
self.severity as DelphiSeverity,
|
self.severity as DelphiSeverity,
|
||||||
)
|
)
|
||||||
.fetch_one(&mut **transaction)
|
.fetch_one(&mut *transaction)
|
||||||
.await?))
|
.await?))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn remove_all_by_issue_id(
|
pub async fn remove_all_by_issue_id(
|
||||||
issue_id: DelphiReportIssueId,
|
issue_id: DelphiReportIssueId,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<u64, DatabaseError> {
|
) -> Result<u64, DatabaseError> {
|
||||||
Ok(sqlx::query!(
|
Ok(sqlx::query!(
|
||||||
"DELETE FROM delphi_report_issue_details WHERE issue_id = $1",
|
"DELETE FROM delphi_report_issue_details WHERE issue_id = $1",
|
||||||
issue_id as DelphiReportIssueId,
|
issue_id as DelphiReportIssueId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?
|
.await?
|
||||||
.rows_affected())
|
.rows_affected())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::database::models::DBUserId;
|
use crate::database::{PgTransaction, models::DBUserId};
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
|
|
||||||
pub struct DBFriend {
|
pub struct DBFriend {
|
||||||
@@ -11,7 +11,7 @@ pub struct DBFriend {
|
|||||||
impl DBFriend {
|
impl DBFriend {
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
&self,
|
&self,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<(), sqlx::Error> {
|
) -> Result<(), sqlx::Error> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -23,7 +23,7 @@ impl DBFriend {
|
|||||||
self.created,
|
self.created,
|
||||||
self.accepted,
|
self.accepted,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -35,7 +35,7 @@ impl DBFriend {
|
|||||||
exec: E,
|
exec: E,
|
||||||
) -> Result<Option<DBFriend>, sqlx::Error>
|
) -> Result<Option<DBFriend>, sqlx::Error>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let friend = sqlx::query!(
|
let friend = sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -62,7 +62,7 @@ impl DBFriend {
|
|||||||
user_id: DBUserId,
|
user_id: DBUserId,
|
||||||
friend_id: DBUserId,
|
friend_id: DBUserId,
|
||||||
accepted: bool,
|
accepted: bool,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<(), sqlx::Error> {
|
) -> Result<(), sqlx::Error> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -74,7 +74,7 @@ impl DBFriend {
|
|||||||
friend_id.0,
|
friend_id.0,
|
||||||
accepted,
|
accepted,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -86,7 +86,7 @@ impl DBFriend {
|
|||||||
exec: E,
|
exec: E,
|
||||||
) -> Result<Vec<DBFriend>, sqlx::Error>
|
) -> Result<Vec<DBFriend>, sqlx::Error>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let friends = sqlx::query!(
|
let friends = sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -114,7 +114,7 @@ impl DBFriend {
|
|||||||
pub async fn remove(
|
pub async fn remove(
|
||||||
user_id: DBUserId,
|
user_id: DBUserId,
|
||||||
friend_id: DBUserId,
|
friend_id: DBUserId,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<(), sqlx::Error> {
|
) -> Result<(), sqlx::Error> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -124,7 +124,7 @@ impl DBFriend {
|
|||||||
user_id.0 as i64,
|
user_id.0 as i64,
|
||||||
friend_id.0 as i64,
|
friend_id.0 as i64,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use super::DatabaseError;
|
use super::DatabaseError;
|
||||||
|
use crate::database::PgTransaction;
|
||||||
use crate::models::ids::{
|
use crate::models::ids::{
|
||||||
AffiliateCodeId, ChargeId, CollectionId, FileId, ImageId, NotificationId,
|
AffiliateCodeId, ChargeId, CollectionId, FileId, ImageId, NotificationId,
|
||||||
OAuthAccessTokenId, OAuthClientAuthorizationId, OAuthClientId,
|
OAuthAccessTokenId, OAuthClientAuthorizationId, OAuthClientId,
|
||||||
@@ -21,7 +22,7 @@ const ID_RETRY_COUNT: usize = 20;
|
|||||||
macro_rules! generate_ids {
|
macro_rules! generate_ids {
|
||||||
($function_name:ident, $return_type:ident, $select_stmnt:expr) => {
|
($function_name:ident, $return_type:ident, $select_stmnt:expr) => {
|
||||||
pub async fn $function_name(
|
pub async fn $function_name(
|
||||||
con: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
con: &mut PgTransaction<'_>,
|
||||||
) -> Result<$return_type, DatabaseError> {
|
) -> Result<$return_type, DatabaseError> {
|
||||||
let mut rng = ChaCha20Rng::from_entropy();
|
let mut rng = ChaCha20Rng::from_entropy();
|
||||||
let length = 8;
|
let length = 8;
|
||||||
@@ -32,7 +33,7 @@ macro_rules! generate_ids {
|
|||||||
// Check if ID is unique
|
// Check if ID is unique
|
||||||
loop {
|
loop {
|
||||||
let results = sqlx::query!($select_stmnt, id as i64)
|
let results = sqlx::query!($select_stmnt, id as i64)
|
||||||
.fetch_one(&mut **con)
|
.fetch_one(&mut *con)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if results.exists.unwrap_or(true)
|
if results.exists.unwrap_or(true)
|
||||||
@@ -58,7 +59,7 @@ macro_rules! generate_bulk_ids {
|
|||||||
($function_name:ident, $return_type:ident, $select_stmnt:expr) => {
|
($function_name:ident, $return_type:ident, $select_stmnt:expr) => {
|
||||||
pub async fn $function_name(
|
pub async fn $function_name(
|
||||||
count: usize,
|
count: usize,
|
||||||
con: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
con: &mut PgTransaction<'_>,
|
||||||
) -> Result<Vec<$return_type>, DatabaseError> {
|
) -> Result<Vec<$return_type>, DatabaseError> {
|
||||||
let mut retry_count = 0;
|
let mut retry_count = 0;
|
||||||
|
|
||||||
@@ -73,7 +74,7 @@ macro_rules! generate_bulk_ids {
|
|||||||
(0..count).map(|x| base + x as i64).collect::<Vec<_>>();
|
(0..count).map(|x| base + x as i64).collect::<Vec<_>>();
|
||||||
|
|
||||||
let results = sqlx::query!($select_stmnt, &ids)
|
let results = sqlx::query!($select_stmnt, &ids)
|
||||||
.fetch_one(&mut **con)
|
.fetch_one(&mut *con)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if !results.exists.unwrap_or(true) {
|
if !results.exists.unwrap_or(true) {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use super::ids::*;
|
use super::ids::*;
|
||||||
|
use crate::database::PgTransaction;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use crate::{database::models::DatabaseError, models::images::ImageContext};
|
use crate::{database::models::DatabaseError, models::images::ImageContext};
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
@@ -28,7 +29,7 @@ pub struct DBImage {
|
|||||||
impl DBImage {
|
impl DBImage {
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
&self,
|
&self,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<(), DatabaseError> {
|
) -> Result<(), DatabaseError> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -51,7 +52,7 @@ impl DBImage {
|
|||||||
self.thread_message_id.map(|x| x.0),
|
self.thread_message_id.map(|x| x.0),
|
||||||
self.report_id.map(|x| x.0),
|
self.report_id.map(|x| x.0),
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -59,10 +60,10 @@ impl DBImage {
|
|||||||
|
|
||||||
pub async fn remove(
|
pub async fn remove(
|
||||||
id: DBImageId,
|
id: DBImageId,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Option<()>, DatabaseError> {
|
) -> Result<Option<()>, DatabaseError> {
|
||||||
let image = Self::get(id, &mut **transaction, redis).await?;
|
let image = Self::get(id, &mut *transaction, redis).await?;
|
||||||
|
|
||||||
if let Some(image) = image {
|
if let Some(image) = image {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -72,7 +73,7 @@ impl DBImage {
|
|||||||
",
|
",
|
||||||
id as DBImageId,
|
id as DBImageId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
DBImage::clear_cache(image.id, redis).await?;
|
DBImage::clear_cache(image.id, redis).await?;
|
||||||
@@ -85,7 +86,7 @@ impl DBImage {
|
|||||||
|
|
||||||
pub async fn get_many_contexted(
|
pub async fn get_many_contexted(
|
||||||
context: ImageContext,
|
context: ImageContext,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<Vec<DBImage>, sqlx::Error> {
|
) -> Result<Vec<DBImage>, sqlx::Error> {
|
||||||
// Set all of project_id, version_id, thread_message_id, report_id to None
|
// Set all of project_id, version_id, thread_message_id, report_id to None
|
||||||
// Then set the one that is relevant to Some
|
// Then set the one that is relevant to Some
|
||||||
@@ -137,7 +138,7 @@ impl DBImage {
|
|||||||
report_id.map(|x| x.0),
|
report_id.map(|x| x.0),
|
||||||
|
|
||||||
)
|
)
|
||||||
.fetch(&mut **transaction)
|
.fetch(&mut *transaction)
|
||||||
.map_ok(|row| {
|
.map_ok(|row| {
|
||||||
let id = DBImageId(row.id);
|
let id = DBImageId(row.id);
|
||||||
|
|
||||||
@@ -165,7 +166,7 @@ impl DBImage {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Option<DBImage>, DatabaseError>
|
) -> Result<Option<DBImage>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
DBImage::get_many(&[id], executor, redis)
|
DBImage::get_many(&[id], executor, redis)
|
||||||
.await
|
.await
|
||||||
@@ -178,7 +179,7 @@ impl DBImage {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<DBImage>, DatabaseError>
|
) -> Result<Vec<DBImage>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
use futures::TryStreamExt;
|
use futures::TryStreamExt;
|
||||||
|
|
||||||
|
|||||||
@@ -43,11 +43,11 @@ impl MinecraftGameVersion {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<MinecraftGameVersion>, DatabaseError>
|
) -> Result<Vec<MinecraftGameVersion>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Acquire<'a, Database = sqlx::Postgres>,
|
E: crate::database::Acquire<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let mut exec = exec.acquire().await?;
|
let mut exec = exec.acquire().await?;
|
||||||
let game_version_enum =
|
let game_version_enum =
|
||||||
LoaderFieldEnum::get(Self::FIELD_NAME, &mut *exec, redis)
|
LoaderFieldEnum::get(Self::FIELD_NAME, &mut exec, redis)
|
||||||
.await?
|
.await?
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
DatabaseError::SchemaError(
|
DatabaseError::SchemaError(
|
||||||
@@ -55,7 +55,7 @@ impl MinecraftGameVersion {
|
|||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
let game_version_enum_values =
|
let game_version_enum_values =
|
||||||
LoaderFieldEnumValue::list(game_version_enum.id, &mut *exec, redis)
|
LoaderFieldEnumValue::list(game_version_enum.id, &mut exec, redis)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let game_versions = game_version_enum_values
|
let game_versions = game_version_enum_values
|
||||||
@@ -180,7 +180,7 @@ impl<'a> MinecraftGameVersionBuilder<'a> {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<LoaderFieldEnumValueId, DatabaseError>
|
) -> Result<LoaderFieldEnumValueId, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'b, Database = sqlx::Postgres> + Copy,
|
E: crate::database::Executor<'b, Database = sqlx::Postgres> + Copy,
|
||||||
{
|
{
|
||||||
let game_versions_enum =
|
let game_versions_enum =
|
||||||
LoaderFieldEnum::get("game_versions", exec, redis)
|
LoaderFieldEnum::get("game_versions", exec, redis)
|
||||||
@@ -205,7 +205,7 @@ impl<'a> MinecraftGameVersionBuilder<'a> {
|
|||||||
ON CONFLICT (enum_id, value) DO UPDATE
|
ON CONFLICT (enum_id, value) DO UPDATE
|
||||||
SET metadata = jsonb_set(
|
SET metadata = jsonb_set(
|
||||||
COALESCE(loader_field_enum_values.metadata, $4),
|
COALESCE(loader_field_enum_values.metadata, $4),
|
||||||
'{type}',
|
'{type}',
|
||||||
COALESCE($4->'type', loader_field_enum_values.metadata->'type')
|
COALESCE($4->'type', loader_field_enum_values.metadata->'type')
|
||||||
),
|
),
|
||||||
created = COALESCE($3, loader_field_enum_values.created)
|
created = COALESCE($3, loader_field_enum_values.created)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use std::hash::Hasher;
|
|||||||
|
|
||||||
use super::DatabaseError;
|
use super::DatabaseError;
|
||||||
use super::ids::*;
|
use super::ids::*;
|
||||||
|
use crate::database::PgTransaction;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use chrono::DateTime;
|
use chrono::DateTime;
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
@@ -35,7 +36,7 @@ impl Game {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Option<Game>, DatabaseError>
|
) -> Result<Option<Game>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
Ok(Self::list(exec, redis)
|
Ok(Self::list(exec, redis)
|
||||||
.await?
|
.await?
|
||||||
@@ -48,7 +49,7 @@ impl Game {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<Game>, DatabaseError>
|
) -> Result<Vec<Game>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
let mut redis = redis.connect().await?;
|
let mut redis = redis.connect().await?;
|
||||||
@@ -108,7 +109,7 @@ impl Loader {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Option<LoaderId>, DatabaseError>
|
) -> Result<Option<LoaderId>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
let mut redis = redis.connect().await?;
|
let mut redis = redis.connect().await?;
|
||||||
@@ -145,7 +146,7 @@ impl Loader {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<Loader>, DatabaseError>
|
) -> Result<Vec<Loader>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
let mut redis = redis.connect().await?;
|
let mut redis = redis.connect().await?;
|
||||||
@@ -379,7 +380,7 @@ impl LoaderField {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Option<LoaderField>, DatabaseError>
|
) -> Result<Option<LoaderField>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let fields = Self::get_fields(loader_ids, exec, redis).await?;
|
let fields = Self::get_fields(loader_ids, exec, redis).await?;
|
||||||
Ok(fields.into_iter().find(|f| f.field == field))
|
Ok(fields.into_iter().find(|f| f.field == field))
|
||||||
@@ -393,7 +394,7 @@ impl LoaderField {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<LoaderField>, DatabaseError>
|
) -> Result<Vec<LoaderField>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let found_loader_fields =
|
let found_loader_fields =
|
||||||
Self::get_fields_per_loader(loader_ids, exec, redis).await?;
|
Self::get_fields_per_loader(loader_ids, exec, redis).await?;
|
||||||
@@ -411,7 +412,7 @@ impl LoaderField {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<HashMap<LoaderId, Vec<LoaderField>>, DatabaseError>
|
) -> Result<HashMap<LoaderId, Vec<LoaderField>>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let val = redis.get_cached_keys_raw(
|
let val = redis.get_cached_keys_raw(
|
||||||
LOADER_FIELDS_NAMESPACE,
|
LOADER_FIELDS_NAMESPACE,
|
||||||
@@ -464,7 +465,7 @@ impl LoaderField {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<LoaderField>, DatabaseError>
|
) -> Result<Vec<LoaderField>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
let mut redis = redis.connect().await?;
|
let mut redis = redis.connect().await?;
|
||||||
@@ -523,7 +524,7 @@ impl LoaderFieldEnum {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Option<LoaderFieldEnum>, DatabaseError>
|
) -> Result<Option<LoaderFieldEnum>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
let mut redis = redis.connect().await?;
|
let mut redis = redis.connect().await?;
|
||||||
@@ -579,7 +580,7 @@ impl LoaderFieldEnumValue {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<LoaderFieldEnumValue>, DatabaseError>
|
) -> Result<Vec<LoaderFieldEnumValue>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
Ok(Self::list_many(&[loader_field_enum_id], exec, redis)
|
Ok(Self::list_many(&[loader_field_enum_id], exec, redis)
|
||||||
.await?
|
.await?
|
||||||
@@ -595,7 +596,7 @@ impl LoaderFieldEnumValue {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<HashMap<LoaderFieldId, Vec<LoaderFieldEnumValue>>, DatabaseError>
|
) -> Result<HashMap<LoaderFieldId, Vec<LoaderFieldEnumValue>>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let get_enum_id = |x: &LoaderField| match x.field_type {
|
let get_enum_id = |x: &LoaderField| match x.field_type {
|
||||||
LoaderFieldType::Enum(id) | LoaderFieldType::ArrayEnum(id) => {
|
LoaderFieldType::Enum(id) | LoaderFieldType::ArrayEnum(id) => {
|
||||||
@@ -634,7 +635,7 @@ impl LoaderFieldEnumValue {
|
|||||||
DatabaseError,
|
DatabaseError,
|
||||||
>
|
>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let val = redis.get_cached_keys_raw(
|
let val = redis.get_cached_keys_raw(
|
||||||
LOADER_FIELD_ENUM_VALUES_NAMESPACE,
|
LOADER_FIELD_ENUM_VALUES_NAMESPACE,
|
||||||
@@ -687,7 +688,7 @@ impl LoaderFieldEnumValue {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<LoaderFieldEnumValue>, DatabaseError>
|
) -> Result<Vec<LoaderFieldEnumValue>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let result = Self::list(loader_field_enum_id, exec, redis)
|
let result = Self::list(loader_field_enum_id, exec, redis)
|
||||||
.await?
|
.await?
|
||||||
@@ -712,7 +713,7 @@ impl LoaderFieldEnumValue {
|
|||||||
impl VersionField {
|
impl VersionField {
|
||||||
pub async fn insert_many(
|
pub async fn insert_many(
|
||||||
items: Vec<Self>,
|
items: Vec<Self>,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<(), DatabaseError> {
|
) -> Result<(), DatabaseError> {
|
||||||
let mut query_version_fields = vec![];
|
let mut query_version_fields = vec![];
|
||||||
for item in items {
|
for item in items {
|
||||||
@@ -792,7 +793,7 @@ impl VersionField {
|
|||||||
&string_values[..] as &[Option<String>],
|
&string_values[..] as &[Option<String>],
|
||||||
&enum_values[..] as &[i32]
|
&enum_values[..] as &[i32]
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
use crate::database::PgPool;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::PgPool;
|
|
||||||
|
|
||||||
use crate::database::models::{DBProjectId, DBUserId};
|
use crate::database::models::{DBProjectId, DBUserId};
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use super::ids::*;
|
use super::ids::*;
|
||||||
|
use crate::database::PgTransaction;
|
||||||
use crate::database::{models::DatabaseError, redis::RedisPool};
|
use crate::database::{models::DatabaseError, redis::RedisPool};
|
||||||
use crate::models::notifications::{
|
use crate::models::notifications::{
|
||||||
NotificationBody, NotificationChannel, NotificationDeliveryStatus,
|
NotificationBody, NotificationChannel, NotificationDeliveryStatus,
|
||||||
@@ -36,7 +37,7 @@ impl NotificationBuilder {
|
|||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
&self,
|
&self,
|
||||||
user: DBUserId,
|
user: DBUserId,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<(), DatabaseError> {
|
) -> Result<(), DatabaseError> {
|
||||||
self.insert_many(vec![user], transaction, redis).await
|
self.insert_many(vec![user], transaction, redis).await
|
||||||
@@ -45,7 +46,7 @@ impl NotificationBuilder {
|
|||||||
pub async fn insert_many_payout_notifications(
|
pub async fn insert_many_payout_notifications(
|
||||||
users: Vec<DBUserId>,
|
users: Vec<DBUserId>,
|
||||||
dates_available: Vec<DateTime<Utc>>,
|
dates_available: Vec<DateTime<Utc>>,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<(), DatabaseError> {
|
) -> Result<(), DatabaseError> {
|
||||||
let notification_ids =
|
let notification_ids =
|
||||||
@@ -87,7 +88,7 @@ impl NotificationBuilder {
|
|||||||
&users_raw_ids[..],
|
&users_raw_ids[..],
|
||||||
&dates_available[..],
|
&dates_available[..],
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let notification_types = notification_ids
|
let notification_types = notification_ids
|
||||||
@@ -111,7 +112,7 @@ impl NotificationBuilder {
|
|||||||
pub async fn insert_many(
|
pub async fn insert_many(
|
||||||
&self,
|
&self,
|
||||||
users: Vec<DBUserId>,
|
users: Vec<DBUserId>,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<(), DatabaseError> {
|
) -> Result<(), DatabaseError> {
|
||||||
let notification_ids =
|
let notification_ids =
|
||||||
@@ -139,7 +140,7 @@ impl NotificationBuilder {
|
|||||||
&users_raw_ids[..],
|
&users_raw_ids[..],
|
||||||
&bodies[..],
|
&bodies[..],
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let notification_types = notification_ids
|
let notification_types = notification_ids
|
||||||
@@ -161,7 +162,7 @@ impl NotificationBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn insert_many_deliveries(
|
pub async fn insert_many_deliveries(
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
notification_ids: &[i64],
|
notification_ids: &[i64],
|
||||||
users_raw_ids: &[i64],
|
users_raw_ids: &[i64],
|
||||||
@@ -245,7 +246,7 @@ impl NotificationBuilder {
|
|||||||
NotificationDeliveryStatus::SkippedDefault.as_str(),
|
NotificationDeliveryStatus::SkippedDefault.as_str(),
|
||||||
);
|
);
|
||||||
|
|
||||||
query.execute(&mut **transaction).await?;
|
query.execute(&mut *transaction).await?;
|
||||||
|
|
||||||
DBNotification::clear_user_notifications_cache(users, redis).await?;
|
DBNotification::clear_user_notifications_cache(users, redis).await?;
|
||||||
|
|
||||||
@@ -259,7 +260,7 @@ impl DBNotification {
|
|||||||
executor: E,
|
executor: E,
|
||||||
) -> Result<Option<Self>, sqlx::error::Error>
|
) -> Result<Option<Self>, sqlx::error::Error>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres> + Copy,
|
||||||
{
|
{
|
||||||
Self::get_many(&[id], executor)
|
Self::get_many(&[id], executor)
|
||||||
.await
|
.await
|
||||||
@@ -271,7 +272,7 @@ impl DBNotification {
|
|||||||
exec: E,
|
exec: E,
|
||||||
) -> Result<Vec<DBNotification>, sqlx::Error>
|
) -> Result<Vec<DBNotification>, sqlx::Error>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let notification_ids_parsed: Vec<i64> =
|
let notification_ids_parsed: Vec<i64> =
|
||||||
notification_ids.iter().map(|x| x.0).collect();
|
notification_ids.iter().map(|x| x.0).collect();
|
||||||
@@ -324,7 +325,7 @@ impl DBNotification {
|
|||||||
exec: E,
|
exec: E,
|
||||||
) -> Result<Vec<DBNotification>, DatabaseError>
|
) -> Result<Vec<DBNotification>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres> + Copy,
|
||||||
{
|
{
|
||||||
let db_notifications = sqlx::query!(
|
let db_notifications = sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -378,7 +379,7 @@ impl DBNotification {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<DBNotification>, DatabaseError>
|
) -> Result<Vec<DBNotification>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres> + Copy,
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
let mut redis = redis.connect().await?;
|
let mut redis = redis.connect().await?;
|
||||||
@@ -455,7 +456,7 @@ impl DBNotification {
|
|||||||
|
|
||||||
pub async fn read(
|
pub async fn read(
|
||||||
id: DBNotificationId,
|
id: DBNotificationId,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Option<()>, DatabaseError> {
|
) -> Result<Option<()>, DatabaseError> {
|
||||||
Self::read_many(&[id], transaction, redis).await
|
Self::read_many(&[id], transaction, redis).await
|
||||||
@@ -463,7 +464,7 @@ impl DBNotification {
|
|||||||
|
|
||||||
pub async fn read_many(
|
pub async fn read_many(
|
||||||
notification_ids: &[DBNotificationId],
|
notification_ids: &[DBNotificationId],
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Option<()>, DatabaseError> {
|
) -> Result<Option<()>, DatabaseError> {
|
||||||
let notification_ids_parsed: Vec<i64> =
|
let notification_ids_parsed: Vec<i64> =
|
||||||
@@ -478,7 +479,7 @@ impl DBNotification {
|
|||||||
",
|
",
|
||||||
¬ification_ids_parsed
|
¬ification_ids_parsed
|
||||||
)
|
)
|
||||||
.fetch(&mut **transaction)
|
.fetch(&mut *transaction)
|
||||||
.map_ok(|x| DBUserId(x.user_id))
|
.map_ok(|x| DBUserId(x.user_id))
|
||||||
.try_collect::<Vec<_>>()
|
.try_collect::<Vec<_>>()
|
||||||
.await?;
|
.await?;
|
||||||
@@ -494,7 +495,7 @@ impl DBNotification {
|
|||||||
|
|
||||||
pub async fn remove(
|
pub async fn remove(
|
||||||
id: DBNotificationId,
|
id: DBNotificationId,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Option<()>, DatabaseError> {
|
) -> Result<Option<()>, DatabaseError> {
|
||||||
Self::remove_many(&[id], transaction, redis).await
|
Self::remove_many(&[id], transaction, redis).await
|
||||||
@@ -502,7 +503,7 @@ impl DBNotification {
|
|||||||
|
|
||||||
pub async fn remove_many(
|
pub async fn remove_many(
|
||||||
notification_ids: &[DBNotificationId],
|
notification_ids: &[DBNotificationId],
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Option<()>, DatabaseError> {
|
) -> Result<Option<()>, DatabaseError> {
|
||||||
let notification_ids_parsed: Vec<i64> =
|
let notification_ids_parsed: Vec<i64> =
|
||||||
@@ -515,7 +516,7 @@ impl DBNotification {
|
|||||||
",
|
",
|
||||||
¬ification_ids_parsed
|
¬ification_ids_parsed
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -525,7 +526,7 @@ impl DBNotification {
|
|||||||
",
|
",
|
||||||
¬ification_ids_parsed
|
¬ification_ids_parsed
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let affected_users = sqlx::query!(
|
let affected_users = sqlx::query!(
|
||||||
@@ -536,7 +537,7 @@ impl DBNotification {
|
|||||||
",
|
",
|
||||||
¬ification_ids_parsed
|
¬ification_ids_parsed
|
||||||
)
|
)
|
||||||
.fetch(&mut **transaction)
|
.fetch(&mut *transaction)
|
||||||
.map_ok(|x| DBUserId(x.user_id))
|
.map_ok(|x| DBUserId(x.user_id))
|
||||||
.try_collect::<Vec<_>>()
|
.try_collect::<Vec<_>>()
|
||||||
.await?;
|
.await?;
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ impl From<NotificationDeliveryQueryResult> for DBNotificationDelivery {
|
|||||||
impl DBNotificationDelivery {
|
impl DBNotificationDelivery {
|
||||||
pub async fn get_all_user(
|
pub async fn get_all_user(
|
||||||
user_id: DBUserId,
|
user_id: DBUserId,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Vec<DBNotificationDelivery>, DatabaseError> {
|
) -> Result<Vec<DBNotificationDelivery>, DatabaseError> {
|
||||||
let user_id = user_id.0;
|
let user_id = user_id.0;
|
||||||
let results = select_notification_deliveries_with_predicate!(
|
let results = select_notification_deliveries_with_predicate!(
|
||||||
@@ -78,7 +78,7 @@ impl DBNotificationDelivery {
|
|||||||
pub async fn lock_channel_processable(
|
pub async fn lock_channel_processable(
|
||||||
channel: NotificationChannel,
|
channel: NotificationChannel,
|
||||||
limit: i64,
|
limit: i64,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Vec<DBNotificationDelivery>, DatabaseError> {
|
) -> Result<Vec<DBNotificationDelivery>, DatabaseError> {
|
||||||
// This follows the `idx_notifications_deliveries_composite_queue` index.
|
// This follows the `idx_notifications_deliveries_composite_queue` index.
|
||||||
Ok(select_notification_deliveries_with_predicate!(
|
Ok(select_notification_deliveries_with_predicate!(
|
||||||
@@ -107,7 +107,7 @@ impl DBNotificationDelivery {
|
|||||||
/// Inserts the row into the table and updates its ID.
|
/// Inserts the row into the table and updates its ID.
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
&mut self,
|
&mut self,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<(), DatabaseError> {
|
) -> Result<(), DatabaseError> {
|
||||||
let id = sqlx::query_scalar!(
|
let id = sqlx::query_scalar!(
|
||||||
"
|
"
|
||||||
@@ -136,7 +136,7 @@ impl DBNotificationDelivery {
|
|||||||
/// Updates semantically mutable columns of the row.
|
/// Updates semantically mutable columns of the row.
|
||||||
pub async fn update(
|
pub async fn update(
|
||||||
&self,
|
&self,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<(), DatabaseError> {
|
) -> Result<(), DatabaseError> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ impl From<NotificationTemplateQueryResult> for NotificationTemplate {
|
|||||||
impl NotificationTemplate {
|
impl NotificationTemplate {
|
||||||
pub async fn list_channel(
|
pub async fn list_channel(
|
||||||
channel: NotificationChannel,
|
channel: NotificationChannel,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<NotificationTemplate>, DatabaseError> {
|
) -> Result<Vec<NotificationTemplate>, DatabaseError> {
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ impl NotificationTypeItem {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<NotificationTypeItem>, DatabaseError>
|
) -> Result<Vec<NotificationTypeItem>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
let mut redis = redis.connect().await?;
|
let mut redis = redis.connect().await?;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use chrono::{DateTime, Utc};
|
|||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::models::pats::Scopes;
|
use crate::{database::PgTransaction, models::pats::Scopes};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
DBOAuthClientAuthorizationId, DBOAuthClientId, DBUserId, DatabaseError,
|
DBOAuthClientAuthorizationId, DBOAuthClientId, DBUserId, DatabaseError,
|
||||||
@@ -41,7 +41,7 @@ impl DBOAuthClientAuthorization {
|
|||||||
pub async fn get(
|
pub async fn get(
|
||||||
client_id: DBOAuthClientId,
|
client_id: DBOAuthClientId,
|
||||||
user_id: DBUserId,
|
user_id: DBUserId,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Option<DBOAuthClientAuthorization>, DatabaseError> {
|
) -> Result<Option<DBOAuthClientAuthorization>, DatabaseError> {
|
||||||
let value = sqlx::query_as!(
|
let value = sqlx::query_as!(
|
||||||
DBAuthClientAuthorizationQueryResult,
|
DBAuthClientAuthorizationQueryResult,
|
||||||
@@ -61,7 +61,7 @@ impl DBOAuthClientAuthorization {
|
|||||||
|
|
||||||
pub async fn get_all_for_user(
|
pub async fn get_all_for_user(
|
||||||
user_id: DBUserId,
|
user_id: DBUserId,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Vec<DBOAuthClientAuthorization>, DatabaseError> {
|
) -> Result<Vec<DBOAuthClientAuthorization>, DatabaseError> {
|
||||||
let results = sqlx::query_as!(
|
let results = sqlx::query_as!(
|
||||||
DBAuthClientAuthorizationQueryResult,
|
DBAuthClientAuthorizationQueryResult,
|
||||||
@@ -83,7 +83,7 @@ impl DBOAuthClientAuthorization {
|
|||||||
client_id: DBOAuthClientId,
|
client_id: DBOAuthClientId,
|
||||||
user_id: DBUserId,
|
user_id: DBUserId,
|
||||||
scopes: Scopes,
|
scopes: Scopes,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<(), DatabaseError> {
|
) -> Result<(), DatabaseError> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -101,7 +101,7 @@ impl DBOAuthClientAuthorization {
|
|||||||
user_id.0,
|
user_id.0,
|
||||||
scopes.bits() as i64,
|
scopes.bits() as i64,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -110,7 +110,7 @@ impl DBOAuthClientAuthorization {
|
|||||||
pub async fn remove(
|
pub async fn remove(
|
||||||
client_id: DBOAuthClientId,
|
client_id: DBOAuthClientId,
|
||||||
user_id: DBUserId,
|
user_id: DBUserId,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<(), DatabaseError> {
|
) -> Result<(), DatabaseError> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
use sha2::Digest;
|
use sha2::Digest;
|
||||||
|
|
||||||
use super::{DBOAuthClientId, DBOAuthRedirectUriId, DBUserId, DatabaseError};
|
use super::{DBOAuthClientId, DBOAuthRedirectUriId, DBUserId, DatabaseError};
|
||||||
use crate::models::pats::Scopes;
|
use crate::{database::PgTransaction, models::pats::Scopes};
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Clone, Debug)]
|
#[derive(Deserialize, Serialize, Clone, Debug)]
|
||||||
pub struct DBOAuthRedirectUri {
|
pub struct DBOAuthRedirectUri {
|
||||||
@@ -80,14 +80,14 @@ macro_rules! select_clients_with_predicate {
|
|||||||
impl DBOAuthClient {
|
impl DBOAuthClient {
|
||||||
pub async fn get(
|
pub async fn get(
|
||||||
id: DBOAuthClientId,
|
id: DBOAuthClientId,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Option<DBOAuthClient>, DatabaseError> {
|
) -> Result<Option<DBOAuthClient>, DatabaseError> {
|
||||||
Ok(Self::get_many(&[id], exec).await?.into_iter().next())
|
Ok(Self::get_many(&[id], exec).await?.into_iter().next())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_many(
|
pub async fn get_many(
|
||||||
ids: &[DBOAuthClientId],
|
ids: &[DBOAuthClientId],
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Vec<DBOAuthClient>, DatabaseError> {
|
) -> Result<Vec<DBOAuthClient>, DatabaseError> {
|
||||||
let ids = ids.iter().map(|id| id.0).collect_vec();
|
let ids = ids.iter().map(|id| id.0).collect_vec();
|
||||||
let ids_ref: &[i64] = &ids;
|
let ids_ref: &[i64] = &ids;
|
||||||
@@ -103,7 +103,7 @@ impl DBOAuthClient {
|
|||||||
|
|
||||||
pub async fn get_all_user_clients(
|
pub async fn get_all_user_clients(
|
||||||
user_id: DBUserId,
|
user_id: DBUserId,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Vec<DBOAuthClient>, DatabaseError> {
|
) -> Result<Vec<DBOAuthClient>, DatabaseError> {
|
||||||
let user_id_param = user_id.0;
|
let user_id_param = user_id.0;
|
||||||
let clients = select_clients_with_predicate!(
|
let clients = select_clients_with_predicate!(
|
||||||
@@ -118,7 +118,7 @@ impl DBOAuthClient {
|
|||||||
|
|
||||||
pub async fn remove(
|
pub async fn remove(
|
||||||
id: DBOAuthClientId,
|
id: DBOAuthClientId,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<(), DatabaseError> {
|
) -> Result<(), DatabaseError> {
|
||||||
// Cascades to oauth_client_redirect_uris, oauth_client_authorizations
|
// Cascades to oauth_client_redirect_uris, oauth_client_authorizations
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -136,7 +136,7 @@ impl DBOAuthClient {
|
|||||||
|
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
&self,
|
&self,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<(), DatabaseError> {
|
) -> Result<(), DatabaseError> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -155,10 +155,10 @@ impl DBOAuthClient {
|
|||||||
self.secret_hash,
|
self.secret_hash,
|
||||||
self.created_by.0
|
self.created_by.0
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Self::insert_redirect_uris(&self.redirect_uris, &mut **transaction)
|
Self::insert_redirect_uris(&self.redirect_uris, &mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -166,7 +166,7 @@ impl DBOAuthClient {
|
|||||||
|
|
||||||
pub async fn update_editable_fields(
|
pub async fn update_editable_fields(
|
||||||
&self,
|
&self,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<(), DatabaseError> {
|
) -> Result<(), DatabaseError> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -190,7 +190,7 @@ impl DBOAuthClient {
|
|||||||
|
|
||||||
pub async fn remove_redirect_uris(
|
pub async fn remove_redirect_uris(
|
||||||
ids: impl IntoIterator<Item = DBOAuthRedirectUriId>,
|
ids: impl IntoIterator<Item = DBOAuthRedirectUriId>,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<(), DatabaseError> {
|
) -> Result<(), DatabaseError> {
|
||||||
let ids = ids.into_iter().map(|id| id.0).collect_vec();
|
let ids = ids.into_iter().map(|id| id.0).collect_vec();
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -209,7 +209,7 @@ impl DBOAuthClient {
|
|||||||
|
|
||||||
pub async fn insert_redirect_uris(
|
pub async fn insert_redirect_uris(
|
||||||
uris: &[DBOAuthRedirectUri],
|
uris: &[DBOAuthRedirectUri],
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<(), DatabaseError> {
|
) -> Result<(), DatabaseError> {
|
||||||
let (ids, client_ids, uris): (Vec<_>, Vec<_>, Vec<_>) = uris
|
let (ids, client_ids, uris): (Vec<_>, Vec<_>, Vec<_>) = uris
|
||||||
.iter()
|
.iter()
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ pub struct DBOAuthAccessToken {
|
|||||||
impl DBOAuthAccessToken {
|
impl DBOAuthAccessToken {
|
||||||
pub async fn get(
|
pub async fn get(
|
||||||
token_hash: String,
|
token_hash: String,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Option<DBOAuthAccessToken>, DatabaseError> {
|
) -> Result<Option<DBOAuthAccessToken>, DatabaseError> {
|
||||||
let value = sqlx::query!(
|
let value = sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -65,7 +65,7 @@ impl DBOAuthAccessToken {
|
|||||||
/// Inserts and returns the time until the token expires
|
/// Inserts and returns the time until the token expires
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
&self,
|
&self,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<chrono::Duration, DatabaseError> {
|
) -> Result<chrono::Duration, DatabaseError> {
|
||||||
let r = sqlx::query!(
|
let r = sqlx::query!(
|
||||||
"
|
"
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::database::PgTransaction;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use ariadne::ids::base62_impl::parse_base62;
|
use ariadne::ids::base62_impl::parse_base62;
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
@@ -38,7 +39,7 @@ pub struct DBOrganization {
|
|||||||
impl DBOrganization {
|
impl DBOrganization {
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
self,
|
self,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<(), super::DatabaseError> {
|
) -> Result<(), super::DatabaseError> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -54,7 +55,7 @@ impl DBOrganization {
|
|||||||
self.raw_icon_url,
|
self.raw_icon_url,
|
||||||
self.color.map(|x| x as i32),
|
self.color.map(|x| x as i32),
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -66,7 +67,7 @@ impl DBOrganization {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Option<Self>, super::DatabaseError>
|
) -> Result<Option<Self>, super::DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
Self::get_many(&[string], exec, redis)
|
Self::get_many(&[string], exec, redis)
|
||||||
.await
|
.await
|
||||||
@@ -79,7 +80,7 @@ impl DBOrganization {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Option<Self>, super::DatabaseError>
|
) -> Result<Option<Self>, super::DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
Self::get_many_ids(&[id], exec, redis)
|
Self::get_many_ids(&[id], exec, redis)
|
||||||
.await
|
.await
|
||||||
@@ -92,7 +93,7 @@ impl DBOrganization {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<Self>, super::DatabaseError>
|
) -> Result<Vec<Self>, super::DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let ids = organization_ids
|
let ids = organization_ids
|
||||||
.iter()
|
.iter()
|
||||||
@@ -111,7 +112,7 @@ impl DBOrganization {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<Self>, super::DatabaseError>
|
) -> Result<Vec<Self>, super::DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let val = redis
|
let val = redis
|
||||||
.get_cached_keys_with_slug(
|
.get_cached_keys_with_slug(
|
||||||
@@ -172,7 +173,7 @@ impl DBOrganization {
|
|||||||
exec: E,
|
exec: E,
|
||||||
) -> Result<Option<Self>, super::DatabaseError>
|
) -> Result<Option<Self>, super::DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let result = sqlx::query!(
|
let result = sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -205,10 +206,10 @@ impl DBOrganization {
|
|||||||
|
|
||||||
pub async fn remove(
|
pub async fn remove(
|
||||||
id: DBOrganizationId,
|
id: DBOrganizationId,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Option<()>, super::DatabaseError> {
|
) -> Result<Option<()>, super::DatabaseError> {
|
||||||
let organization = Self::get_id(id, &mut **transaction, redis).await?;
|
let organization = Self::get_id(id, &mut *transaction, redis).await?;
|
||||||
|
|
||||||
if let Some(organization) = organization {
|
if let Some(organization) = organization {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -218,7 +219,7 @@ impl DBOrganization {
|
|||||||
",
|
",
|
||||||
id as DBOrganizationId,
|
id as DBOrganizationId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
DBTeamMember::clear_cache(organization.team_id, redis).await?;
|
DBTeamMember::clear_cache(organization.team_id, redis).await?;
|
||||||
@@ -230,7 +231,7 @@ impl DBOrganization {
|
|||||||
",
|
",
|
||||||
organization.team_id as DBTeamId,
|
organization.team_id as DBTeamId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -240,7 +241,7 @@ impl DBOrganization {
|
|||||||
",
|
",
|
||||||
organization.team_id as DBTeamId,
|
organization.team_id as DBTeamId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(Some(()))
|
Ok(Some(()))
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use super::ids::*;
|
use super::ids::*;
|
||||||
|
use crate::database::PgTransaction;
|
||||||
use crate::database::models::DatabaseError;
|
use crate::database::models::DatabaseError;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use crate::models::pats::Scopes;
|
use crate::models::pats::Scopes;
|
||||||
@@ -29,7 +30,7 @@ pub struct DBPersonalAccessToken {
|
|||||||
impl DBPersonalAccessToken {
|
impl DBPersonalAccessToken {
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
&self,
|
&self,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<(), DatabaseError> {
|
) -> Result<(), DatabaseError> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -49,7 +50,7 @@ impl DBPersonalAccessToken {
|
|||||||
self.user_id as DBUserId,
|
self.user_id as DBUserId,
|
||||||
self.expires
|
self.expires
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -65,7 +66,7 @@ impl DBPersonalAccessToken {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Option<DBPersonalAccessToken>, DatabaseError>
|
) -> Result<Option<DBPersonalAccessToken>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
Self::get_many(&[id], exec, redis)
|
Self::get_many(&[id], exec, redis)
|
||||||
.await
|
.await
|
||||||
@@ -78,7 +79,7 @@ impl DBPersonalAccessToken {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<DBPersonalAccessToken>, DatabaseError>
|
) -> Result<Vec<DBPersonalAccessToken>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let ids = pat_ids
|
let ids = pat_ids
|
||||||
.iter()
|
.iter()
|
||||||
@@ -97,7 +98,7 @@ impl DBPersonalAccessToken {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<DBPersonalAccessToken>, DatabaseError>
|
) -> Result<Vec<DBPersonalAccessToken>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let val = redis
|
let val = redis
|
||||||
.get_cached_keys_with_slug(
|
.get_cached_keys_with_slug(
|
||||||
@@ -154,7 +155,7 @@ impl DBPersonalAccessToken {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<DBPatId>, DatabaseError>
|
) -> Result<Vec<DBPatId>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
let mut redis = redis.connect().await?;
|
let mut redis = redis.connect().await?;
|
||||||
@@ -228,7 +229,7 @@ impl DBPersonalAccessToken {
|
|||||||
|
|
||||||
pub async fn remove(
|
pub async fn remove(
|
||||||
id: DBPatId,
|
id: DBPatId,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<Option<()>, sqlx::error::Error> {
|
) -> Result<Option<()>, sqlx::error::Error> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -236,7 +237,7 @@ impl DBPersonalAccessToken {
|
|||||||
",
|
",
|
||||||
id as DBPatId,
|
id as DBPatId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(Some(()))
|
Ok(Some(()))
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
use crate::models::payouts::{PayoutMethodType, PayoutStatus};
|
use crate::{
|
||||||
|
database::PgTransaction,
|
||||||
|
models::payouts::{PayoutMethodType, PayoutStatus},
|
||||||
|
};
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use rust_decimal::Decimal;
|
use rust_decimal::Decimal;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@@ -26,7 +29,7 @@ pub struct DBPayout {
|
|||||||
impl DBPayout {
|
impl DBPayout {
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
&self,
|
&self,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<(), DatabaseError> {
|
) -> Result<(), DatabaseError> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -47,7 +50,7 @@ impl DBPayout {
|
|||||||
self.method_address,
|
self.method_address,
|
||||||
self.platform_id,
|
self.platform_id,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -58,7 +61,7 @@ impl DBPayout {
|
|||||||
executor: E,
|
executor: E,
|
||||||
) -> Result<Option<DBPayout>, DatabaseError>
|
) -> Result<Option<DBPayout>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
DBPayout::get_many(&[id], executor)
|
DBPayout::get_many(&[id], executor)
|
||||||
.await
|
.await
|
||||||
@@ -70,7 +73,7 @@ impl DBPayout {
|
|||||||
exec: E,
|
exec: E,
|
||||||
) -> Result<Vec<DBPayout>, DatabaseError>
|
) -> Result<Vec<DBPayout>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
use futures::TryStreamExt;
|
use futures::TryStreamExt;
|
||||||
|
|
||||||
@@ -103,7 +106,7 @@ impl DBPayout {
|
|||||||
|
|
||||||
pub async fn get_all_for_user(
|
pub async fn get_all_for_user(
|
||||||
user_id: DBUserId,
|
user_id: DBUserId,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Vec<DBPayoutId>, DatabaseError> {
|
) -> Result<Vec<DBPayoutId>, DatabaseError> {
|
||||||
let results = sqlx::query!(
|
let results = sqlx::query!(
|
||||||
"
|
"
|
||||||
|
|||||||
@@ -55,14 +55,14 @@ impl TryFrom<ProductQueryResult> for DBProduct {
|
|||||||
impl DBProduct {
|
impl DBProduct {
|
||||||
pub async fn get(
|
pub async fn get(
|
||||||
id: DBProductId,
|
id: DBProductId,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Option<DBProduct>, DatabaseError> {
|
) -> Result<Option<DBProduct>, DatabaseError> {
|
||||||
Ok(Self::get_many(&[id], exec).await?.into_iter().next())
|
Ok(Self::get_many(&[id], exec).await?.into_iter().next())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_price(
|
pub async fn get_price(
|
||||||
id: DBProductPriceId,
|
id: DBProductPriceId,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Option<DBProduct>, DatabaseError> {
|
) -> Result<Option<DBProduct>, DatabaseError> {
|
||||||
let maybe_row = select_products_with_predicate!(
|
let maybe_row = select_products_with_predicate!(
|
||||||
"INNER JOIN products_prices pp ON pp.id = $1
|
"INNER JOIN products_prices pp ON pp.id = $1
|
||||||
@@ -99,7 +99,7 @@ impl DBProduct {
|
|||||||
|
|
||||||
pub async fn get_many(
|
pub async fn get_many(
|
||||||
ids: &[DBProductId],
|
ids: &[DBProductId],
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Vec<DBProduct>, DatabaseError> {
|
) -> Result<Vec<DBProduct>, DatabaseError> {
|
||||||
let ids = ids.iter().map(|id| id.0).collect_vec();
|
let ids = ids.iter().map(|id| id.0).collect_vec();
|
||||||
let ids_ref: &[i64] = &ids;
|
let ids_ref: &[i64] = &ids;
|
||||||
@@ -117,7 +117,7 @@ impl DBProduct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_all(
|
pub async fn get_all(
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Vec<DBProduct>, DatabaseError> {
|
) -> Result<Vec<DBProduct>, DatabaseError> {
|
||||||
let one = 1;
|
let one = 1;
|
||||||
let results = select_products_with_predicate!("WHERE 1 = $1", one)
|
let results = select_products_with_predicate!("WHERE 1 = $1", one)
|
||||||
@@ -148,7 +148,7 @@ impl QueryProductWithPrices {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<Self>, DatabaseError>
|
) -> Result<Vec<Self>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres> + Copy,
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
let mut redis = redis.connect().await?;
|
let mut redis = redis.connect().await?;
|
||||||
@@ -292,14 +292,14 @@ impl TryFrom<ProductPriceQueryResult> for DBProductPrice {
|
|||||||
impl DBProductPrice {
|
impl DBProductPrice {
|
||||||
pub async fn get(
|
pub async fn get(
|
||||||
id: DBProductPriceId,
|
id: DBProductPriceId,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Option<DBProductPrice>, DatabaseError> {
|
) -> Result<Option<DBProductPrice>, DatabaseError> {
|
||||||
Ok(Self::get_many(&[id], exec).await?.into_iter().next())
|
Ok(Self::get_many(&[id], exec).await?.into_iter().next())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_many(
|
pub async fn get_many(
|
||||||
ids: &[DBProductPriceId],
|
ids: &[DBProductPriceId],
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Vec<DBProductPrice>, DatabaseError> {
|
) -> Result<Vec<DBProductPrice>, DatabaseError> {
|
||||||
let ids = ids.iter().map(|id| id.0).collect_vec();
|
let ids = ids.iter().map(|id| id.0).collect_vec();
|
||||||
let ids_ref: &[i64] = &ids;
|
let ids_ref: &[i64] = &ids;
|
||||||
@@ -318,7 +318,7 @@ impl DBProductPrice {
|
|||||||
|
|
||||||
pub async fn get_all_product_prices(
|
pub async fn get_all_product_prices(
|
||||||
product_id: DBProductId,
|
product_id: DBProductId,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Vec<DBProductPrice>, DatabaseError> {
|
) -> Result<Vec<DBProductPrice>, DatabaseError> {
|
||||||
let res = Self::get_all_products_prices(&[product_id], exec).await?;
|
let res = Self::get_all_products_prices(&[product_id], exec).await?;
|
||||||
|
|
||||||
@@ -327,7 +327,7 @@ impl DBProductPrice {
|
|||||||
|
|
||||||
pub async fn get_all_public_product_prices(
|
pub async fn get_all_public_product_prices(
|
||||||
product_id: DBProductId,
|
product_id: DBProductId,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Vec<DBProductPrice>, DatabaseError> {
|
) -> Result<Vec<DBProductPrice>, DatabaseError> {
|
||||||
let res =
|
let res =
|
||||||
Self::get_all_public_products_prices(&[product_id], exec).await?;
|
Self::get_all_public_products_prices(&[product_id], exec).await?;
|
||||||
@@ -339,7 +339,7 @@ impl DBProductPrice {
|
|||||||
/// it won't be included in the resulting map.
|
/// it won't be included in the resulting map.
|
||||||
pub async fn get_all_public_products_prices(
|
pub async fn get_all_public_products_prices(
|
||||||
product_ids: &[DBProductId],
|
product_ids: &[DBProductId],
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<DashMap<DBProductId, Vec<DBProductPrice>>, DatabaseError> {
|
) -> Result<DashMap<DBProductId, Vec<DBProductPrice>>, DatabaseError> {
|
||||||
Self::get_all_products_prices_with_visibility(
|
Self::get_all_products_prices_with_visibility(
|
||||||
product_ids,
|
product_ids,
|
||||||
@@ -351,7 +351,7 @@ impl DBProductPrice {
|
|||||||
|
|
||||||
pub async fn get_all_products_prices(
|
pub async fn get_all_products_prices(
|
||||||
product_ids: &[DBProductId],
|
product_ids: &[DBProductId],
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<DashMap<DBProductId, Vec<DBProductPrice>>, DatabaseError> {
|
) -> Result<DashMap<DBProductId, Vec<DBProductPrice>>, DatabaseError> {
|
||||||
Self::get_all_products_prices_with_visibility(product_ids, None, exec)
|
Self::get_all_products_prices_with_visibility(product_ids, None, exec)
|
||||||
.await
|
.await
|
||||||
@@ -360,7 +360,7 @@ impl DBProductPrice {
|
|||||||
async fn get_all_products_prices_with_visibility(
|
async fn get_all_products_prices_with_visibility(
|
||||||
product_ids: &[DBProductId],
|
product_ids: &[DBProductId],
|
||||||
public_filter: Option<bool>,
|
public_filter: Option<bool>,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<DashMap<DBProductId, Vec<DBProductPrice>>, DatabaseError> {
|
) -> Result<DashMap<DBProductId, Vec<DBProductPrice>>, DatabaseError> {
|
||||||
let ids = product_ids.iter().map(|id| id.0).collect_vec();
|
let ids = product_ids.iter().map(|id| id.0).collect_vec();
|
||||||
let ids_ref: &[i64] = &ids;
|
let ids_ref: &[i64] = &ids;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ pub struct DBProductsTaxIdentifier {
|
|||||||
impl DBProductsTaxIdentifier {
|
impl DBProductsTaxIdentifier {
|
||||||
pub async fn get_product(
|
pub async fn get_product(
|
||||||
product_id: DBProductId,
|
product_id: DBProductId,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Option<Self>, ApiError> {
|
) -> Result<Option<Self>, ApiError> {
|
||||||
let maybe_row = sqlx::query!(
|
let maybe_row = sqlx::query!(
|
||||||
"SELECT * FROM products_tax_identifiers WHERE product_id = $1",
|
"SELECT * FROM products_tax_identifiers WHERE product_id = $1",
|
||||||
@@ -29,7 +29,7 @@ impl DBProductsTaxIdentifier {
|
|||||||
|
|
||||||
pub async fn get_price(
|
pub async fn get_price(
|
||||||
price_id: DBProductPriceId,
|
price_id: DBProductPriceId,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Option<Self>, ApiError> {
|
) -> Result<Option<Self>, ApiError> {
|
||||||
let maybe_row = sqlx::query!(
|
let maybe_row = sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -58,7 +58,7 @@ pub struct ProductInfo {
|
|||||||
|
|
||||||
pub async fn product_info_by_product_price_id(
|
pub async fn product_info_by_product_price_id(
|
||||||
product_price_id: DBProductPriceId,
|
product_price_id: DBProductPriceId,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Option<ProductInfo>, ApiError> {
|
) -> Result<Option<ProductInfo>, ApiError> {
|
||||||
let maybe_row = sqlx::query!(
|
let maybe_row = sqlx::query!(
|
||||||
r#"
|
r#"
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ use super::loader_fields::{
|
|||||||
VersionField,
|
VersionField,
|
||||||
};
|
};
|
||||||
use super::{DBUser, ids::*};
|
use super::{DBUser, ids::*};
|
||||||
use crate::database::models;
|
|
||||||
use crate::database::models::DatabaseError;
|
use crate::database::models::DatabaseError;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
|
use crate::database::{PgTransaction, models};
|
||||||
use crate::models::projects::{
|
use crate::models::projects::{
|
||||||
MonetizationStatus, ProjectStatus, SideTypesMigrationReviewStatus,
|
MonetizationStatus, ProjectStatus, SideTypesMigrationReviewStatus,
|
||||||
};
|
};
|
||||||
@@ -34,7 +34,7 @@ impl LinkUrl {
|
|||||||
pub async fn insert_many_projects(
|
pub async fn insert_many_projects(
|
||||||
links: Vec<Self>,
|
links: Vec<Self>,
|
||||||
project_id: DBProjectId,
|
project_id: DBProjectId,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<(), sqlx::error::Error> {
|
) -> Result<(), sqlx::error::Error> {
|
||||||
let (project_ids, platform_ids, urls): (Vec<_>, Vec<_>, Vec<_>) = links
|
let (project_ids, platform_ids, urls): (Vec<_>, Vec<_>, Vec<_>) = links
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@@ -51,7 +51,7 @@ impl LinkUrl {
|
|||||||
&platform_ids[..],
|
&platform_ids[..],
|
||||||
&urls[..],
|
&urls[..],
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -73,7 +73,7 @@ impl DBGalleryItem {
|
|||||||
pub async fn insert_many(
|
pub async fn insert_many(
|
||||||
items: Vec<Self>,
|
items: Vec<Self>,
|
||||||
project_id: DBProjectId,
|
project_id: DBProjectId,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<(), sqlx::error::Error> {
|
) -> Result<(), sqlx::error::Error> {
|
||||||
let (
|
let (
|
||||||
project_ids,
|
project_ids,
|
||||||
@@ -112,7 +112,7 @@ impl DBGalleryItem {
|
|||||||
&descriptions[..] as &[Option<String>],
|
&descriptions[..] as &[Option<String>],
|
||||||
&orderings[..]
|
&orderings[..]
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -128,7 +128,7 @@ pub struct DBModCategory {
|
|||||||
impl DBModCategory {
|
impl DBModCategory {
|
||||||
pub async fn insert_many(
|
pub async fn insert_many(
|
||||||
items: Vec<Self>,
|
items: Vec<Self>,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<(), DatabaseError> {
|
) -> Result<(), DatabaseError> {
|
||||||
let (project_ids, category_ids, is_additionals): (
|
let (project_ids, category_ids, is_additionals): (
|
||||||
Vec<_>,
|
Vec<_>,
|
||||||
@@ -147,7 +147,7 @@ impl DBModCategory {
|
|||||||
&category_ids[..],
|
&category_ids[..],
|
||||||
&is_additionals[..]
|
&is_additionals[..]
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -181,7 +181,7 @@ pub struct ProjectBuilder {
|
|||||||
impl ProjectBuilder {
|
impl ProjectBuilder {
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
self,
|
self,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<DBProjectId, DatabaseError> {
|
) -> Result<DBProjectId, DatabaseError> {
|
||||||
let project_struct = DBProject {
|
let project_struct = DBProject {
|
||||||
id: self.project_id,
|
id: self.project_id,
|
||||||
@@ -299,7 +299,7 @@ pub struct DBProject {
|
|||||||
impl DBProject {
|
impl DBProject {
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
&self,
|
&self,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<(), DatabaseError> {
|
) -> Result<(), DatabaseError> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -337,7 +337,7 @@ impl DBProject {
|
|||||||
self.organization_id.map(|x| x.0 as i64),
|
self.organization_id.map(|x| x.0 as i64),
|
||||||
self.side_types_migration_review_status.as_str()
|
self.side_types_migration_review_status.as_str()
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -345,10 +345,10 @@ impl DBProject {
|
|||||||
|
|
||||||
pub async fn remove(
|
pub async fn remove(
|
||||||
id: DBProjectId,
|
id: DBProjectId,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Option<()>, DatabaseError> {
|
) -> Result<Option<()>, DatabaseError> {
|
||||||
let project = Self::get_id(id, &mut **transaction, redis).await?;
|
let project = Self::get_id(id, &mut *transaction, redis).await?;
|
||||||
|
|
||||||
if let Some(project) = project {
|
if let Some(project) = project {
|
||||||
DBProject::clear_cache(id, project.inner.slug, Some(true), redis)
|
DBProject::clear_cache(id, project.inner.slug, Some(true), redis)
|
||||||
@@ -361,7 +361,7 @@ impl DBProject {
|
|||||||
",
|
",
|
||||||
id as DBProjectId
|
id as DBProjectId
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -371,7 +371,7 @@ impl DBProject {
|
|||||||
",
|
",
|
||||||
id as DBProjectId
|
id as DBProjectId
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -381,7 +381,7 @@ impl DBProject {
|
|||||||
",
|
",
|
||||||
id as DBProjectId,
|
id as DBProjectId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -392,7 +392,7 @@ impl DBProject {
|
|||||||
",
|
",
|
||||||
id as DBProjectId,
|
id as DBProjectId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -402,7 +402,7 @@ impl DBProject {
|
|||||||
",
|
",
|
||||||
id as DBProjectId,
|
id as DBProjectId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -412,7 +412,7 @@ impl DBProject {
|
|||||||
",
|
",
|
||||||
id as DBProjectId,
|
id as DBProjectId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
for version in project.versions {
|
for version in project.versions {
|
||||||
@@ -426,7 +426,7 @@ impl DBProject {
|
|||||||
",
|
",
|
||||||
id as DBProjectId,
|
id as DBProjectId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -437,7 +437,7 @@ impl DBProject {
|
|||||||
",
|
",
|
||||||
id as DBProjectId,
|
id as DBProjectId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -447,7 +447,7 @@ impl DBProject {
|
|||||||
",
|
",
|
||||||
id as DBProjectId,
|
id as DBProjectId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
models::DBTeamMember::clear_cache(project.inner.team_id, redis)
|
models::DBTeamMember::clear_cache(project.inner.team_id, redis)
|
||||||
@@ -461,7 +461,7 @@ impl DBProject {
|
|||||||
",
|
",
|
||||||
project.inner.team_id as DBTeamId,
|
project.inner.team_id as DBTeamId,
|
||||||
)
|
)
|
||||||
.fetch(&mut **transaction)
|
.fetch(&mut *transaction)
|
||||||
.map_ok(|x| DBUserId(x.user_id))
|
.map_ok(|x| DBUserId(x.user_id))
|
||||||
.try_collect::<Vec<_>>()
|
.try_collect::<Vec<_>>()
|
||||||
.await?;
|
.await?;
|
||||||
@@ -475,7 +475,7 @@ impl DBProject {
|
|||||||
",
|
",
|
||||||
project.inner.team_id as DBTeamId,
|
project.inner.team_id as DBTeamId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(Some(()))
|
Ok(Some(()))
|
||||||
@@ -490,7 +490,7 @@ impl DBProject {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Option<ProjectQueryResult>, DatabaseError>
|
) -> Result<Option<ProjectQueryResult>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Acquire<'a, Database = sqlx::Postgres>,
|
E: crate::database::Acquire<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
DBProject::get_many(&[string], executor, redis)
|
DBProject::get_many(&[string], executor, redis)
|
||||||
.await
|
.await
|
||||||
@@ -503,7 +503,7 @@ impl DBProject {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Option<ProjectQueryResult>, DatabaseError>
|
) -> Result<Option<ProjectQueryResult>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Acquire<'a, Database = sqlx::Postgres>,
|
E: crate::database::Acquire<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
DBProject::get_many(
|
DBProject::get_many(
|
||||||
&[crate::models::ids::ProjectId::from(id)],
|
&[crate::models::ids::ProjectId::from(id)],
|
||||||
@@ -520,7 +520,7 @@ impl DBProject {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<ProjectQueryResult>, DatabaseError>
|
) -> Result<Vec<ProjectQueryResult>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Acquire<'a, Database = sqlx::Postgres>,
|
E: crate::database::Acquire<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let ids = project_ids
|
let ids = project_ids
|
||||||
.iter()
|
.iter()
|
||||||
@@ -539,7 +539,7 @@ impl DBProject {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<ProjectQueryResult>, DatabaseError>
|
) -> Result<Vec<ProjectQueryResult>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Acquire<'a, Database = sqlx::Postgres>,
|
E: crate::database::Acquire<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let val = redis.get_cached_keys_with_slug(
|
let val = redis.get_cached_keys_with_slug(
|
||||||
PROJECTS_NAMESPACE,
|
PROJECTS_NAMESPACE,
|
||||||
@@ -573,7 +573,7 @@ impl DBProject {
|
|||||||
.map(|x| x.to_string())
|
.map(|x| x.to_string())
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
)
|
)
|
||||||
.fetch(&mut *exec)
|
.fetch(&mut exec)
|
||||||
.try_fold(
|
.try_fold(
|
||||||
DashMap::new(),
|
DashMap::new(),
|
||||||
|acc: DashMap<DBProjectId, Vec<(DBVersionId, DateTime<Utc>)>>, m| {
|
|acc: DashMap<DBProjectId, Vec<(DBVersionId, DateTime<Utc>)>>, m| {
|
||||||
@@ -598,7 +598,7 @@ impl DBProject {
|
|||||||
",
|
",
|
||||||
&all_version_ids.iter().map(|x| x.0).collect::<Vec<_>>()
|
&all_version_ids.iter().map(|x| x.0).collect::<Vec<_>>()
|
||||||
)
|
)
|
||||||
.fetch(&mut *exec)
|
.fetch(&mut exec)
|
||||||
.try_fold(
|
.try_fold(
|
||||||
DashMap::new(),
|
DashMap::new(),
|
||||||
|acc: DashMap<DBProjectId, Vec<QueryVersionField>>, m| {
|
|acc: DashMap<DBProjectId, Vec<QueryVersionField>>, m| {
|
||||||
@@ -632,7 +632,7 @@ impl DBProject {
|
|||||||
.map(|x| x.0)
|
.map(|x| x.0)
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
)
|
)
|
||||||
.fetch(&mut *exec)
|
.fetch(&mut exec)
|
||||||
.map_ok(|m| QueryLoaderFieldEnumValue {
|
.map_ok(|m| QueryLoaderFieldEnumValue {
|
||||||
id: LoaderFieldEnumValueId(m.id),
|
id: LoaderFieldEnumValueId(m.id),
|
||||||
enum_id: LoaderFieldEnumId(m.enum_id),
|
enum_id: LoaderFieldEnumId(m.enum_id),
|
||||||
@@ -653,7 +653,7 @@ impl DBProject {
|
|||||||
",
|
",
|
||||||
&project_ids_parsed,
|
&project_ids_parsed,
|
||||||
&slugs
|
&slugs
|
||||||
).fetch(&mut *exec)
|
).fetch(&mut exec)
|
||||||
.try_fold(DashMap::new(), |acc : DashMap<DBProjectId, Vec<DBGalleryItem>>, m| {
|
.try_fold(DashMap::new(), |acc : DashMap<DBProjectId, Vec<DBGalleryItem>>, m| {
|
||||||
acc.entry(DBProjectId(m.mod_id))
|
acc.entry(DBProjectId(m.mod_id))
|
||||||
.or_default()
|
.or_default()
|
||||||
@@ -680,7 +680,7 @@ impl DBProject {
|
|||||||
",
|
",
|
||||||
&project_ids_parsed,
|
&project_ids_parsed,
|
||||||
&slugs
|
&slugs
|
||||||
).fetch(&mut *exec)
|
).fetch(&mut exec)
|
||||||
.try_fold(DashMap::new(), |acc : DashMap<DBProjectId, Vec<LinkUrl>>, m| {
|
.try_fold(DashMap::new(), |acc : DashMap<DBProjectId, Vec<LinkUrl>>, m| {
|
||||||
acc.entry(DBProjectId(m.mod_id))
|
acc.entry(DBProjectId(m.mod_id))
|
||||||
.or_default()
|
.or_default()
|
||||||
@@ -722,7 +722,7 @@ impl DBProject {
|
|||||||
GROUP BY mod_id
|
GROUP BY mod_id
|
||||||
",
|
",
|
||||||
&all_version_ids.iter().map(|x| x.0).collect::<Vec<_>>()
|
&all_version_ids.iter().map(|x| x.0).collect::<Vec<_>>()
|
||||||
).fetch(&mut *exec)
|
).fetch(&mut exec)
|
||||||
.map_ok(|m| {
|
.map_ok(|m| {
|
||||||
let project_id = DBProjectId(m.mod_id);
|
let project_id = DBProjectId(m.mod_id);
|
||||||
|
|
||||||
@@ -753,7 +753,7 @@ impl DBProject {
|
|||||||
",
|
",
|
||||||
&loader_field_ids.iter().map(|x| x.0).collect::<Vec<_>>()
|
&loader_field_ids.iter().map(|x| x.0).collect::<Vec<_>>()
|
||||||
)
|
)
|
||||||
.fetch(&mut *exec)
|
.fetch(&mut exec)
|
||||||
.map_ok(|m| QueryLoaderField {
|
.map_ok(|m| QueryLoaderField {
|
||||||
id: LoaderFieldId(m.id),
|
id: LoaderFieldId(m.id),
|
||||||
field: m.field,
|
field: m.field,
|
||||||
@@ -788,7 +788,7 @@ impl DBProject {
|
|||||||
&project_ids_parsed,
|
&project_ids_parsed,
|
||||||
&slugs,
|
&slugs,
|
||||||
)
|
)
|
||||||
.fetch(&mut *exec)
|
.fetch(&mut exec)
|
||||||
.try_fold(DashMap::new(), |acc, m| {
|
.try_fold(DashMap::new(), |acc, m| {
|
||||||
let id = m.id;
|
let id = m.id;
|
||||||
let project_id = DBProjectId(id);
|
let project_id = DBProjectId(id);
|
||||||
@@ -885,7 +885,7 @@ impl DBProject {
|
|||||||
DatabaseError,
|
DatabaseError,
|
||||||
>
|
>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
type Dependencies = Vec<(
|
type Dependencies = Vec<(
|
||||||
Option<DBVersionId>,
|
Option<DBVersionId>,
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use crate::database::PgTransaction;
|
||||||
|
|
||||||
use super::ids::*;
|
use super::ids::*;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
|
|
||||||
@@ -29,7 +31,7 @@ pub struct ReportQueryResult {
|
|||||||
impl DBReport {
|
impl DBReport {
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
&self,
|
&self,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<(), sqlx::error::Error> {
|
) -> Result<(), sqlx::error::Error> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -50,7 +52,7 @@ impl DBReport {
|
|||||||
self.body,
|
self.body,
|
||||||
self.reporter as DBUserId
|
self.reporter as DBUserId
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -61,7 +63,7 @@ impl DBReport {
|
|||||||
exec: E,
|
exec: E,
|
||||||
) -> Result<Option<ReportQueryResult>, sqlx::Error>
|
) -> Result<Option<ReportQueryResult>, sqlx::Error>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
Self::get_many(&[id], exec)
|
Self::get_many(&[id], exec)
|
||||||
.await
|
.await
|
||||||
@@ -73,7 +75,7 @@ impl DBReport {
|
|||||||
exec: E,
|
exec: E,
|
||||||
) -> Result<Vec<ReportQueryResult>, sqlx::Error>
|
) -> Result<Vec<ReportQueryResult>, sqlx::Error>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
use futures::stream::TryStreamExt;
|
use futures::stream::TryStreamExt;
|
||||||
|
|
||||||
@@ -111,7 +113,7 @@ impl DBReport {
|
|||||||
|
|
||||||
pub async fn remove_full(
|
pub async fn remove_full(
|
||||||
id: DBReportId,
|
id: DBReportId,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<Option<()>, sqlx::error::Error> {
|
) -> Result<Option<()>, sqlx::error::Error> {
|
||||||
let result = sqlx::query!(
|
let result = sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -119,7 +121,7 @@ impl DBReport {
|
|||||||
",
|
",
|
||||||
id as DBReportId
|
id as DBReportId
|
||||||
)
|
)
|
||||||
.fetch_one(&mut **transaction)
|
.fetch_one(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if !result.exists.unwrap_or(false) {
|
if !result.exists.unwrap_or(false) {
|
||||||
@@ -133,7 +135,7 @@ impl DBReport {
|
|||||||
",
|
",
|
||||||
id as DBReportId
|
id as DBReportId
|
||||||
)
|
)
|
||||||
.fetch_optional(&mut **transaction)
|
.fetch_optional(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if let Some(thread_id) = thread_id {
|
if let Some(thread_id) = thread_id {
|
||||||
@@ -150,7 +152,7 @@ impl DBReport {
|
|||||||
",
|
",
|
||||||
id as DBReportId,
|
id as DBReportId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(Some(()))
|
Ok(Some(()))
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use super::ids::*;
|
use super::ids::*;
|
||||||
|
use crate::database::PgTransaction;
|
||||||
use crate::database::models::DatabaseError;
|
use crate::database::models::DatabaseError;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use ariadne::ids::base62_impl::parse_base62;
|
use ariadne::ids::base62_impl::parse_base62;
|
||||||
@@ -29,7 +30,7 @@ pub struct SessionBuilder {
|
|||||||
impl SessionBuilder {
|
impl SessionBuilder {
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
&self,
|
&self,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<DBSessionId, DatabaseError> {
|
) -> Result<DBSessionId, DatabaseError> {
|
||||||
let id = generate_session_id(transaction).await?;
|
let id = generate_session_id(transaction).await?;
|
||||||
|
|
||||||
@@ -54,7 +55,7 @@ impl SessionBuilder {
|
|||||||
self.ip,
|
self.ip,
|
||||||
self.user_agent,
|
self.user_agent,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(id)
|
Ok(id)
|
||||||
@@ -92,7 +93,7 @@ impl DBSession {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Option<DBSession>, DatabaseError>
|
) -> Result<Option<DBSession>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
Self::get_many(&[id], exec, redis)
|
Self::get_many(&[id], exec, redis)
|
||||||
.await
|
.await
|
||||||
@@ -105,7 +106,7 @@ impl DBSession {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Option<DBSession>, DatabaseError>
|
) -> Result<Option<DBSession>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
DBSession::get_many(
|
DBSession::get_many(
|
||||||
&[crate::models::ids::SessionId::from(id)],
|
&[crate::models::ids::SessionId::from(id)],
|
||||||
@@ -122,7 +123,7 @@ impl DBSession {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<DBSession>, DatabaseError>
|
) -> Result<Vec<DBSession>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let ids = session_ids
|
let ids = session_ids
|
||||||
.iter()
|
.iter()
|
||||||
@@ -141,7 +142,7 @@ impl DBSession {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<DBSession>, DatabaseError>
|
) -> Result<Vec<DBSession>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
use futures::TryStreamExt;
|
use futures::TryStreamExt;
|
||||||
|
|
||||||
@@ -207,7 +208,7 @@ impl DBSession {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<DBSessionId>, DatabaseError>
|
) -> Result<Vec<DBSessionId>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
let mut redis = redis.connect().await?;
|
let mut redis = redis.connect().await?;
|
||||||
@@ -286,7 +287,7 @@ impl DBSession {
|
|||||||
|
|
||||||
pub async fn remove(
|
pub async fn remove(
|
||||||
id: DBSessionId,
|
id: DBSessionId,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<Option<()>, sqlx::error::Error> {
|
) -> Result<Option<()>, sqlx::error::Error> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -294,7 +295,7 @@ impl DBSession {
|
|||||||
",
|
",
|
||||||
id as DBSessionId,
|
id as DBSessionId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(Some(()))
|
Ok(Some(()))
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::database::PgTransaction;
|
||||||
use crate::database::models::{
|
use crate::database::models::{
|
||||||
DBSharedInstanceId, DBSharedInstanceVersionId, DBUserId,
|
DBSharedInstanceId, DBSharedInstanceVersionId, DBUserId,
|
||||||
};
|
};
|
||||||
@@ -42,7 +43,7 @@ impl From<SharedInstanceQueryResult> for DBSharedInstance {
|
|||||||
impl DBSharedInstance {
|
impl DBSharedInstance {
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
&self,
|
&self,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<(), sqlx::Error> {
|
) -> Result<(), sqlx::Error> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -54,7 +55,7 @@ impl DBSharedInstance {
|
|||||||
self.owner_id as DBUserId,
|
self.owner_id as DBUserId,
|
||||||
self.current_version_id.map(|x| x.0),
|
self.current_version_id.map(|x| x.0),
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -62,7 +63,7 @@ impl DBSharedInstance {
|
|||||||
|
|
||||||
pub async fn get(
|
pub async fn get(
|
||||||
id: DBSharedInstanceId,
|
id: DBSharedInstanceId,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Option<Self>, sqlx::Error> {
|
) -> Result<Option<Self>, sqlx::Error> {
|
||||||
let result = sqlx::query_as!(
|
let result = sqlx::query_as!(
|
||||||
SharedInstanceQueryResult,
|
SharedInstanceQueryResult,
|
||||||
@@ -81,7 +82,7 @@ impl DBSharedInstance {
|
|||||||
|
|
||||||
pub async fn list_for_user(
|
pub async fn list_for_user(
|
||||||
user: DBUserId,
|
user: DBUserId,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Vec<Self>, sqlx::Error> {
|
) -> Result<Vec<Self>, sqlx::Error> {
|
||||||
let results = sqlx::query_as!(
|
let results = sqlx::query_as!(
|
||||||
SharedInstanceQueryResult,
|
SharedInstanceQueryResult,
|
||||||
@@ -129,7 +130,7 @@ pub struct DBSharedInstanceUser {
|
|||||||
impl DBSharedInstanceUser {
|
impl DBSharedInstanceUser {
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
&self,
|
&self,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<(), sqlx::Error> {
|
) -> Result<(), sqlx::Error> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -140,7 +141,7 @@ impl DBSharedInstanceUser {
|
|||||||
self.shared_instance_id as DBSharedInstanceId,
|
self.shared_instance_id as DBSharedInstanceId,
|
||||||
self.permissions.bits() as i64,
|
self.permissions.bits() as i64,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -149,7 +150,7 @@ impl DBSharedInstanceUser {
|
|||||||
pub async fn get_user_permissions(
|
pub async fn get_user_permissions(
|
||||||
instance_id: DBSharedInstanceId,
|
instance_id: DBSharedInstanceId,
|
||||||
user_id: DBUserId,
|
user_id: DBUserId,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Option<SharedInstanceUserPermissions>, super::DatabaseError>
|
) -> Result<Option<SharedInstanceUserPermissions>, super::DatabaseError>
|
||||||
{
|
{
|
||||||
let permissions = sqlx::query!(
|
let permissions = sqlx::query!(
|
||||||
@@ -173,7 +174,7 @@ impl DBSharedInstanceUser {
|
|||||||
|
|
||||||
pub async fn get_from_instance(
|
pub async fn get_from_instance(
|
||||||
instance_id: DBSharedInstanceId,
|
instance_id: DBSharedInstanceId,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<DBSharedInstanceUser>, super::DatabaseError> {
|
) -> Result<Vec<DBSharedInstanceUser>, super::DatabaseError> {
|
||||||
Self::get_from_instance_many(&[instance_id], exec, redis).await
|
Self::get_from_instance_many(&[instance_id], exec, redis).await
|
||||||
@@ -181,7 +182,7 @@ impl DBSharedInstanceUser {
|
|||||||
|
|
||||||
pub async fn get_from_instance_many(
|
pub async fn get_from_instance_many(
|
||||||
instance_ids: &[DBSharedInstanceId],
|
instance_ids: &[DBSharedInstanceId],
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<DBSharedInstanceUser>, super::DatabaseError> {
|
) -> Result<Vec<DBSharedInstanceUser>, super::DatabaseError> {
|
||||||
if instance_ids.is_empty() {
|
if instance_ids.is_empty() {
|
||||||
@@ -274,7 +275,7 @@ impl From<SharedInstanceVersionQueryResult> for DBSharedInstanceVersion {
|
|||||||
impl DBSharedInstanceVersion {
|
impl DBSharedInstanceVersion {
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
&self,
|
&self,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<(), sqlx::Error> {
|
) -> Result<(), sqlx::Error> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -287,7 +288,7 @@ impl DBSharedInstanceVersion {
|
|||||||
self.sha512,
|
self.sha512,
|
||||||
self.created,
|
self.created,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -295,7 +296,7 @@ impl DBSharedInstanceVersion {
|
|||||||
|
|
||||||
pub async fn get(
|
pub async fn get(
|
||||||
id: DBSharedInstanceVersionId,
|
id: DBSharedInstanceVersionId,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Option<Self>, sqlx::Error> {
|
) -> Result<Option<Self>, sqlx::Error> {
|
||||||
let result = sqlx::query_as!(
|
let result = sqlx::query_as!(
|
||||||
SharedInstanceVersionQueryResult,
|
SharedInstanceVersionQueryResult,
|
||||||
@@ -314,7 +315,7 @@ impl DBSharedInstanceVersion {
|
|||||||
|
|
||||||
pub async fn get_for_instance(
|
pub async fn get_for_instance(
|
||||||
instance_id: DBSharedInstanceId,
|
instance_id: DBSharedInstanceId,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Vec<Self>, sqlx::Error> {
|
) -> Result<Vec<Self>, sqlx::Error> {
|
||||||
let results = sqlx::query_as!(
|
let results = sqlx::query_as!(
|
||||||
SharedInstanceVersionQueryResult,
|
SharedInstanceVersionQueryResult,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use super::{DBOrganization, DBProject, ids::*};
|
use super::{DBOrganization, DBProject, ids::*};
|
||||||
use crate::{
|
use crate::{
|
||||||
database::redis::RedisPool,
|
database::{PgTransaction, redis::RedisPool},
|
||||||
models::teams::{OrganizationPermissions, ProjectPermissions},
|
models::teams::{OrganizationPermissions, ProjectPermissions},
|
||||||
};
|
};
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
@@ -28,7 +28,7 @@ pub struct TeamMemberBuilder {
|
|||||||
impl TeamBuilder {
|
impl TeamBuilder {
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
self,
|
self,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<DBTeamId, super::DatabaseError> {
|
) -> Result<DBTeamId, super::DatabaseError> {
|
||||||
let team_id = generate_team_id(transaction).await?;
|
let team_id = generate_team_id(transaction).await?;
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ impl TeamBuilder {
|
|||||||
",
|
",
|
||||||
team.id as DBTeamId,
|
team.id as DBTeamId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let mut team_member_ids = Vec::new();
|
let mut team_member_ids = Vec::new();
|
||||||
@@ -101,7 +101,7 @@ impl TeamBuilder {
|
|||||||
&payouts_splits[..],
|
&payouts_splits[..],
|
||||||
&orderings[..],
|
&orderings[..],
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(team_id)
|
Ok(team_id)
|
||||||
@@ -126,7 +126,7 @@ impl DBTeam {
|
|||||||
executor: E,
|
executor: E,
|
||||||
) -> Result<Option<TeamAssociationId>, super::DatabaseError>
|
) -> Result<Option<TeamAssociationId>, super::DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let result = sqlx::query!(
|
let result = sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -195,7 +195,7 @@ impl DBTeamMember {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<DBTeamMember>, super::DatabaseError>
|
) -> Result<Vec<DBTeamMember>, super::DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres> + Copy,
|
||||||
{
|
{
|
||||||
Self::get_from_team_full_many(&[id], executor, redis).await
|
Self::get_from_team_full_many(&[id], executor, redis).await
|
||||||
}
|
}
|
||||||
@@ -206,7 +206,7 @@ impl DBTeamMember {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<DBTeamMember>, super::DatabaseError>
|
) -> Result<Vec<DBTeamMember>, super::DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres> + Copy,
|
||||||
{
|
{
|
||||||
if team_ids.is_empty() {
|
if team_ids.is_empty() {
|
||||||
return Ok(Vec::new());
|
return Ok(Vec::new());
|
||||||
@@ -276,7 +276,7 @@ impl DBTeamMember {
|
|||||||
executor: E,
|
executor: E,
|
||||||
) -> Result<Option<Self>, super::DatabaseError>
|
) -> Result<Option<Self>, super::DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
Self::get_from_user_id_many(&[id], user_id, executor)
|
Self::get_from_user_id_many(&[id], user_id, executor)
|
||||||
.await
|
.await
|
||||||
@@ -290,7 +290,7 @@ impl DBTeamMember {
|
|||||||
executor: E,
|
executor: E,
|
||||||
) -> Result<Vec<Self>, super::DatabaseError>
|
) -> Result<Vec<Self>, super::DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let team_ids_parsed: Vec<i64> = team_ids.iter().map(|x| x.0).collect();
|
let team_ids_parsed: Vec<i64> = team_ids.iter().map(|x| x.0).collect();
|
||||||
|
|
||||||
@@ -335,7 +335,7 @@ impl DBTeamMember {
|
|||||||
executor: E,
|
executor: E,
|
||||||
) -> Result<Option<Self>, super::DatabaseError>
|
) -> Result<Option<Self>, super::DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let result = sqlx::query!(
|
let result = sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -379,7 +379,7 @@ impl DBTeamMember {
|
|||||||
|
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
&self,
|
&self,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<(), sqlx::error::Error> {
|
) -> Result<(), sqlx::error::Error> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -400,7 +400,7 @@ impl DBTeamMember {
|
|||||||
self.accepted,
|
self.accepted,
|
||||||
self.payouts_split
|
self.payouts_split
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -409,7 +409,7 @@ impl DBTeamMember {
|
|||||||
pub async fn delete(
|
pub async fn delete(
|
||||||
id: DBTeamId,
|
id: DBTeamId,
|
||||||
user_id: DBUserId,
|
user_id: DBUserId,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<(), super::DatabaseError> {
|
) -> Result<(), super::DatabaseError> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -419,7 +419,7 @@ impl DBTeamMember {
|
|||||||
id as DBTeamId,
|
id as DBTeamId,
|
||||||
user_id as DBUserId,
|
user_id as DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -436,7 +436,7 @@ impl DBTeamMember {
|
|||||||
new_payouts_split: Option<Decimal>,
|
new_payouts_split: Option<Decimal>,
|
||||||
new_ordering: Option<i64>,
|
new_ordering: Option<i64>,
|
||||||
new_is_owner: Option<bool>,
|
new_is_owner: Option<bool>,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<(), super::DatabaseError> {
|
) -> Result<(), super::DatabaseError> {
|
||||||
if let Some(permissions) = new_permissions {
|
if let Some(permissions) = new_permissions {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -449,7 +449,7 @@ impl DBTeamMember {
|
|||||||
id as DBTeamId,
|
id as DBTeamId,
|
||||||
user_id as DBUserId,
|
user_id as DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -464,7 +464,7 @@ impl DBTeamMember {
|
|||||||
id as DBTeamId,
|
id as DBTeamId,
|
||||||
user_id as DBUserId,
|
user_id as DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -479,7 +479,7 @@ impl DBTeamMember {
|
|||||||
id as DBTeamId,
|
id as DBTeamId,
|
||||||
user_id as DBUserId,
|
user_id as DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -495,7 +495,7 @@ impl DBTeamMember {
|
|||||||
id as DBTeamId,
|
id as DBTeamId,
|
||||||
user_id as DBUserId,
|
user_id as DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -510,7 +510,7 @@ impl DBTeamMember {
|
|||||||
id as DBTeamId,
|
id as DBTeamId,
|
||||||
user_id as DBUserId,
|
user_id as DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -525,7 +525,7 @@ impl DBTeamMember {
|
|||||||
id as DBTeamId,
|
id as DBTeamId,
|
||||||
user_id as DBUserId,
|
user_id as DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -540,7 +540,7 @@ impl DBTeamMember {
|
|||||||
id as DBTeamId,
|
id as DBTeamId,
|
||||||
user_id as DBUserId,
|
user_id as DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -554,7 +554,7 @@ impl DBTeamMember {
|
|||||||
executor: E,
|
executor: E,
|
||||||
) -> Result<Option<Self>, super::DatabaseError>
|
) -> Result<Option<Self>, super::DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let accepted = if allow_pending {
|
let accepted = if allow_pending {
|
||||||
vec![true, false]
|
vec![true, false]
|
||||||
@@ -607,7 +607,7 @@ impl DBTeamMember {
|
|||||||
executor: E,
|
executor: E,
|
||||||
) -> Result<Option<Self>, super::DatabaseError>
|
) -> Result<Option<Self>, super::DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let accepted = if allow_pending {
|
let accepted = if allow_pending {
|
||||||
vec![true, false]
|
vec![true, false]
|
||||||
@@ -658,7 +658,7 @@ impl DBTeamMember {
|
|||||||
executor: E,
|
executor: E,
|
||||||
) -> Result<Option<Self>, super::DatabaseError>
|
) -> Result<Option<Self>, super::DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let result = sqlx::query!(
|
let result = sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -707,7 +707,7 @@ impl DBTeamMember {
|
|||||||
executor: E,
|
executor: E,
|
||||||
) -> Result<(Option<Self>, Option<Self>), super::DatabaseError>
|
) -> Result<(Option<Self>, Option<Self>), super::DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres> + Copy,
|
||||||
{
|
{
|
||||||
let project_team_member =
|
let project_team_member =
|
||||||
Self::get_from_user_id(project.team_id, user_id, executor).await?;
|
Self::get_from_user_id(project.team_id, user_id, executor).await?;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use super::ids::*;
|
use super::ids::*;
|
||||||
|
use crate::database::PgTransaction;
|
||||||
use crate::database::models::DatabaseError;
|
use crate::database::models::DatabaseError;
|
||||||
use crate::models::threads::{MessageBody, ThreadType};
|
use crate::models::threads::{MessageBody, ThreadType};
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
@@ -43,7 +44,7 @@ pub struct DBThreadMessage {
|
|||||||
impl ThreadMessageBuilder {
|
impl ThreadMessageBuilder {
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
&self,
|
&self,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<DBThreadMessageId, DatabaseError> {
|
) -> Result<DBThreadMessageId, DatabaseError> {
|
||||||
let thread_message_id = generate_thread_message_id(transaction).await?;
|
let thread_message_id = generate_thread_message_id(transaction).await?;
|
||||||
|
|
||||||
@@ -62,7 +63,7 @@ impl ThreadMessageBuilder {
|
|||||||
self.thread_id as DBThreadId,
|
self.thread_id as DBThreadId,
|
||||||
self.hide_identity
|
self.hide_identity
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(thread_message_id)
|
Ok(thread_message_id)
|
||||||
@@ -72,7 +73,7 @@ impl ThreadMessageBuilder {
|
|||||||
impl ThreadBuilder {
|
impl ThreadBuilder {
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
&self,
|
&self,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<DBThreadId, DatabaseError> {
|
) -> Result<DBThreadId, DatabaseError> {
|
||||||
let thread_id = generate_thread_id(&mut *transaction).await?;
|
let thread_id = generate_thread_id(&mut *transaction).await?;
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -89,7 +90,7 @@ impl ThreadBuilder {
|
|||||||
self.project_id.map(|x| x.0),
|
self.project_id.map(|x| x.0),
|
||||||
self.report_id.map(|x| x.0),
|
self.report_id.map(|x| x.0),
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let (thread_ids, members): (Vec<_>, Vec<_>) =
|
let (thread_ids, members): (Vec<_>, Vec<_>) =
|
||||||
@@ -104,7 +105,7 @@ impl ThreadBuilder {
|
|||||||
&thread_ids[..],
|
&thread_ids[..],
|
||||||
&members[..],
|
&members[..],
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(thread_id)
|
Ok(thread_id)
|
||||||
@@ -117,7 +118,7 @@ impl DBThread {
|
|||||||
exec: E,
|
exec: E,
|
||||||
) -> Result<Option<DBThread>, sqlx::Error>
|
) -> Result<Option<DBThread>, sqlx::Error>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres> + Copy,
|
||||||
{
|
{
|
||||||
Self::get_many(&[id], exec)
|
Self::get_many(&[id], exec)
|
||||||
.await
|
.await
|
||||||
@@ -129,7 +130,7 @@ impl DBThread {
|
|||||||
exec: E,
|
exec: E,
|
||||||
) -> Result<Vec<DBThread>, sqlx::Error>
|
) -> Result<Vec<DBThread>, sqlx::Error>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres> + Copy,
|
||||||
{
|
{
|
||||||
use futures::stream::TryStreamExt;
|
use futures::stream::TryStreamExt;
|
||||||
|
|
||||||
@@ -173,7 +174,7 @@ impl DBThread {
|
|||||||
|
|
||||||
pub async fn remove_full(
|
pub async fn remove_full(
|
||||||
id: DBThreadId,
|
id: DBThreadId,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<Option<()>, sqlx::error::Error> {
|
) -> Result<Option<()>, sqlx::error::Error> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -182,7 +183,7 @@ impl DBThread {
|
|||||||
",
|
",
|
||||||
id as DBThreadId,
|
id as DBThreadId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -191,7 +192,7 @@ impl DBThread {
|
|||||||
",
|
",
|
||||||
id as DBThreadId
|
id as DBThreadId
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -200,7 +201,7 @@ impl DBThread {
|
|||||||
",
|
",
|
||||||
id as DBThreadId,
|
id as DBThreadId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(Some(()))
|
Ok(Some(()))
|
||||||
@@ -213,7 +214,7 @@ impl DBThreadMessage {
|
|||||||
exec: E,
|
exec: E,
|
||||||
) -> Result<Option<DBThreadMessage>, sqlx::Error>
|
) -> Result<Option<DBThreadMessage>, sqlx::Error>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
Self::get_many(&[id], exec)
|
Self::get_many(&[id], exec)
|
||||||
.await
|
.await
|
||||||
@@ -225,7 +226,7 @@ impl DBThreadMessage {
|
|||||||
exec: E,
|
exec: E,
|
||||||
) -> Result<Vec<DBThreadMessage>, sqlx::Error>
|
) -> Result<Vec<DBThreadMessage>, sqlx::Error>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
use futures::stream::TryStreamExt;
|
use futures::stream::TryStreamExt;
|
||||||
|
|
||||||
@@ -257,7 +258,7 @@ impl DBThreadMessage {
|
|||||||
pub async fn remove_full(
|
pub async fn remove_full(
|
||||||
id: DBThreadMessageId,
|
id: DBThreadMessageId,
|
||||||
private: bool,
|
private: bool,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<Option<()>, sqlx::error::Error> {
|
) -> Result<Option<()>, sqlx::error::Error> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -269,7 +270,7 @@ impl DBThreadMessage {
|
|||||||
serde_json::to_value(MessageBody::Deleted { private })
|
serde_json::to_value(MessageBody::Deleted { private })
|
||||||
.unwrap_or(serde_json::json!({}))
|
.unwrap_or(serde_json::json!({}))
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(Some(()))
|
Ok(Some(()))
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use super::ids::{DBProjectId, DBUserId};
|
use super::ids::{DBProjectId, DBUserId};
|
||||||
use super::{DBCollectionId, DBReportId, DBThreadId};
|
use super::{DBCollectionId, DBReportId, DBThreadId};
|
||||||
use crate::database::models;
|
|
||||||
use crate::database::models::charge_item::DBCharge;
|
use crate::database::models::charge_item::DBCharge;
|
||||||
use crate::database::models::user_subscription_item::DBUserSubscription;
|
use crate::database::models::user_subscription_item::DBUserSubscription;
|
||||||
use crate::database::models::{DBOrganizationId, DatabaseError};
|
use crate::database::models::{DBOrganizationId, DatabaseError};
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
|
use crate::database::{PgTransaction, models};
|
||||||
use crate::models::billing::ChargeStatus;
|
use crate::models::billing::ChargeStatus;
|
||||||
use crate::models::users::Badges;
|
use crate::models::users::Badges;
|
||||||
use ariadne::ids::base62_impl::{parse_base62, to_base62};
|
use ariadne::ids::base62_impl::{parse_base62, to_base62};
|
||||||
@@ -56,7 +56,7 @@ pub struct DBUser {
|
|||||||
impl DBUser {
|
impl DBUser {
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
&self,
|
&self,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<(), sqlx::error::Error> {
|
) -> Result<(), sqlx::error::Error> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -97,7 +97,7 @@ impl DBUser {
|
|||||||
self.allow_friend_requests,
|
self.allow_friend_requests,
|
||||||
self.is_subscribed_to_newsletter,
|
self.is_subscribed_to_newsletter,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -109,7 +109,7 @@ impl DBUser {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Option<DBUser>, DatabaseError>
|
) -> Result<Option<DBUser>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
DBUser::get_many(&[string], executor, redis)
|
DBUser::get_many(&[string], executor, redis)
|
||||||
.await
|
.await
|
||||||
@@ -122,7 +122,7 @@ impl DBUser {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Option<DBUser>, DatabaseError>
|
) -> Result<Option<DBUser>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
DBUser::get_many(&[ariadne::ids::UserId::from(id)], executor, redis)
|
DBUser::get_many(&[ariadne::ids::UserId::from(id)], executor, redis)
|
||||||
.await
|
.await
|
||||||
@@ -135,7 +135,7 @@ impl DBUser {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<DBUser>, DatabaseError>
|
) -> Result<Vec<DBUser>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let ids = user_ids
|
let ids = user_ids
|
||||||
.iter()
|
.iter()
|
||||||
@@ -154,7 +154,7 @@ impl DBUser {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<DBUser>, DatabaseError>
|
) -> Result<Vec<DBUser>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
use futures::TryStreamExt;
|
use futures::TryStreamExt;
|
||||||
|
|
||||||
@@ -233,7 +233,7 @@ impl DBUser {
|
|||||||
exec: E,
|
exec: E,
|
||||||
) -> Result<Option<DBUserId>, sqlx::Error>
|
) -> Result<Option<DBUserId>, sqlx::Error>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let user = sqlx::query!(
|
let user = sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -254,7 +254,7 @@ impl DBUser {
|
|||||||
exec: E,
|
exec: E,
|
||||||
) -> Result<Vec<DBUserId>, sqlx::Error>
|
) -> Result<Vec<DBUserId>, sqlx::Error>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let users = sqlx::query!(
|
let users = sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -276,7 +276,7 @@ impl DBUser {
|
|||||||
exec: E,
|
exec: E,
|
||||||
) -> Result<bool, sqlx::Error>
|
) -> Result<bool, sqlx::Error>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let ids = user_ids.iter().map(|x| x.0).collect::<Vec<_>>();
|
let ids = user_ids.iter().map(|x| x.0).collect::<Vec<_>>();
|
||||||
let count = sqlx::query_scalar!(
|
let count = sqlx::query_scalar!(
|
||||||
@@ -295,7 +295,7 @@ impl DBUser {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<DBProjectId>, DatabaseError>
|
) -> Result<Vec<DBProjectId>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
use futures::stream::TryStreamExt;
|
use futures::stream::TryStreamExt;
|
||||||
|
|
||||||
@@ -347,7 +347,7 @@ impl DBUser {
|
|||||||
exec: E,
|
exec: E,
|
||||||
) -> Result<Vec<DBOrganizationId>, sqlx::Error>
|
) -> Result<Vec<DBOrganizationId>, sqlx::Error>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
use futures::stream::TryStreamExt;
|
use futures::stream::TryStreamExt;
|
||||||
|
|
||||||
@@ -372,7 +372,7 @@ impl DBUser {
|
|||||||
exec: E,
|
exec: E,
|
||||||
) -> Result<Vec<DBCollectionId>, sqlx::Error>
|
) -> Result<Vec<DBCollectionId>, sqlx::Error>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
use futures::stream::TryStreamExt;
|
use futures::stream::TryStreamExt;
|
||||||
|
|
||||||
@@ -396,7 +396,7 @@ impl DBUser {
|
|||||||
exec: E,
|
exec: E,
|
||||||
) -> Result<Vec<DBProjectId>, sqlx::Error>
|
) -> Result<Vec<DBProjectId>, sqlx::Error>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
use futures::stream::TryStreamExt;
|
use futures::stream::TryStreamExt;
|
||||||
|
|
||||||
@@ -420,7 +420,7 @@ impl DBUser {
|
|||||||
exec: E,
|
exec: E,
|
||||||
) -> Result<Vec<DBReportId>, sqlx::Error>
|
) -> Result<Vec<DBReportId>, sqlx::Error>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
use futures::stream::TryStreamExt;
|
use futures::stream::TryStreamExt;
|
||||||
|
|
||||||
@@ -444,7 +444,7 @@ impl DBUser {
|
|||||||
exec: E,
|
exec: E,
|
||||||
) -> Result<Vec<String>, sqlx::Error>
|
) -> Result<Vec<String>, sqlx::Error>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
use futures::stream::TryStreamExt;
|
use futures::stream::TryStreamExt;
|
||||||
|
|
||||||
@@ -502,10 +502,10 @@ impl DBUser {
|
|||||||
|
|
||||||
pub async fn remove(
|
pub async fn remove(
|
||||||
id: DBUserId,
|
id: DBUserId,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Option<()>, DatabaseError> {
|
) -> Result<Option<()>, DatabaseError> {
|
||||||
let user = Self::get_id(id, &mut **transaction, redis).await?;
|
let user = Self::get_id(id, &mut *transaction, redis).await?;
|
||||||
|
|
||||||
if let Some(delete_user) = user {
|
if let Some(delete_user) = user {
|
||||||
DBUser::clear_caches(&[(id, Some(delete_user.username))], redis)
|
DBUser::clear_caches(&[(id, Some(delete_user.username))], redis)
|
||||||
@@ -523,7 +523,7 @@ impl DBUser {
|
|||||||
deleted_user as DBUserId,
|
deleted_user as DBUserId,
|
||||||
id as DBUserId,
|
id as DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -535,7 +535,7 @@ impl DBUser {
|
|||||||
deleted_user as DBUserId,
|
deleted_user as DBUserId,
|
||||||
id as DBUserId,
|
id as DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -547,7 +547,7 @@ impl DBUser {
|
|||||||
deleted_user as DBUserId,
|
deleted_user as DBUserId,
|
||||||
id as DBUserId,
|
id as DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
use futures::TryStreamExt;
|
use futures::TryStreamExt;
|
||||||
@@ -558,7 +558,7 @@ impl DBUser {
|
|||||||
",
|
",
|
||||||
id as DBUserId,
|
id as DBUserId,
|
||||||
)
|
)
|
||||||
.fetch(&mut **transaction)
|
.fetch(&mut *transaction)
|
||||||
.map_ok(|m| m.id)
|
.map_ok(|m| m.id)
|
||||||
.try_collect::<Vec<i64>>()
|
.try_collect::<Vec<i64>>()
|
||||||
.await?;
|
.await?;
|
||||||
@@ -570,7 +570,7 @@ impl DBUser {
|
|||||||
",
|
",
|
||||||
¬ifications
|
¬ifications
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -580,7 +580,7 @@ impl DBUser {
|
|||||||
",
|
",
|
||||||
id as DBUserId
|
id as DBUserId
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -590,7 +590,7 @@ impl DBUser {
|
|||||||
",
|
",
|
||||||
id as DBUserId,
|
id as DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let user_collections = sqlx::query!(
|
let user_collections = sqlx::query!(
|
||||||
@@ -601,7 +601,7 @@ impl DBUser {
|
|||||||
",
|
",
|
||||||
id as DBUserId,
|
id as DBUserId,
|
||||||
)
|
)
|
||||||
.fetch(&mut **transaction)
|
.fetch(&mut *transaction)
|
||||||
.map_ok(|x| DBCollectionId(x.id))
|
.map_ok(|x| DBCollectionId(x.id))
|
||||||
.try_collect::<Vec<_>>()
|
.try_collect::<Vec<_>>()
|
||||||
.await?;
|
.await?;
|
||||||
@@ -620,7 +620,7 @@ impl DBUser {
|
|||||||
",
|
",
|
||||||
id as DBUserId,
|
id as DBUserId,
|
||||||
)
|
)
|
||||||
.fetch(&mut **transaction)
|
.fetch(&mut *transaction)
|
||||||
.map_ok(|x| DBThreadId(x.id))
|
.map_ok(|x| DBThreadId(x.id))
|
||||||
.try_collect::<Vec<_>>()
|
.try_collect::<Vec<_>>()
|
||||||
.await?;
|
.await?;
|
||||||
@@ -636,7 +636,7 @@ impl DBUser {
|
|||||||
",
|
",
|
||||||
id as DBUserId,
|
id as DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -648,7 +648,7 @@ impl DBUser {
|
|||||||
deleted_user as DBUserId,
|
deleted_user as DBUserId,
|
||||||
id as DBUserId,
|
id as DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -658,7 +658,7 @@ impl DBUser {
|
|||||||
",
|
",
|
||||||
id as DBUserId,
|
id as DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -668,7 +668,7 @@ impl DBUser {
|
|||||||
",
|
",
|
||||||
id as DBUserId,
|
id as DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -678,7 +678,7 @@ impl DBUser {
|
|||||||
",
|
",
|
||||||
id as DBUserId,
|
id as DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -690,7 +690,7 @@ impl DBUser {
|
|||||||
deleted_user as DBUserId,
|
deleted_user as DBUserId,
|
||||||
id as DBUserId,
|
id as DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -702,7 +702,7 @@ impl DBUser {
|
|||||||
id as DBUserId,
|
id as DBUserId,
|
||||||
deleted_user as DBUserId,
|
deleted_user as DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -712,7 +712,7 @@ impl DBUser {
|
|||||||
",
|
",
|
||||||
id as DBUserId,
|
id as DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -724,7 +724,7 @@ impl DBUser {
|
|||||||
deleted_user as DBUserId,
|
deleted_user as DBUserId,
|
||||||
id as DBUserId,
|
id as DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -734,7 +734,7 @@ impl DBUser {
|
|||||||
",
|
",
|
||||||
id as DBUserId,
|
id as DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -744,7 +744,7 @@ impl DBUser {
|
|||||||
",
|
",
|
||||||
id as DBUserId,
|
id as DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -754,7 +754,7 @@ impl DBUser {
|
|||||||
",
|
",
|
||||||
id as DBUserId,
|
id as DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -765,7 +765,7 @@ impl DBUser {
|
|||||||
deleted_user as DBUserId,
|
deleted_user as DBUserId,
|
||||||
id as DBUserId,
|
id as DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -774,7 +774,7 @@ impl DBUser {
|
|||||||
WHERE affiliate = $1",
|
WHERE affiliate = $1",
|
||||||
id as DBUserId,
|
id as DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -785,7 +785,7 @@ impl DBUser {
|
|||||||
deleted_user as DBUserId,
|
deleted_user as DBUserId,
|
||||||
id as DBUserId,
|
id as DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -794,16 +794,15 @@ impl DBUser {
|
|||||||
WHERE user_id = $1",
|
WHERE user_id = $1",
|
||||||
id as DBUserId,
|
id as DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let open_subscriptions =
|
let open_subscriptions =
|
||||||
DBUserSubscription::get_all_user(id, &mut **transaction)
|
DBUserSubscription::get_all_user(id, &mut *transaction).await?;
|
||||||
.await?;
|
|
||||||
|
|
||||||
for x in open_subscriptions {
|
for x in open_subscriptions {
|
||||||
let charge =
|
let charge =
|
||||||
DBCharge::get_open_subscription(x.id, &mut **transaction)
|
DBCharge::get_open_subscription(x.id, &mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
if let Some(mut charge) = charge {
|
if let Some(mut charge) = charge {
|
||||||
charge.status = ChargeStatus::Cancelled;
|
charge.status = ChargeStatus::Cancelled;
|
||||||
@@ -823,7 +822,7 @@ impl DBUser {
|
|||||||
deleted_user as DBUserId,
|
deleted_user as DBUserId,
|
||||||
id as DBUserId,
|
id as DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -833,7 +832,7 @@ impl DBUser {
|
|||||||
",
|
",
|
||||||
id as DBUserId,
|
id as DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -843,7 +842,7 @@ impl DBUser {
|
|||||||
",
|
",
|
||||||
id as DBUserId,
|
id as DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(Some(()))
|
Ok(Some(()))
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
|
use crate::database::PgPool;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::PgPool;
|
|
||||||
|
|
||||||
use crate::database::models::DBUserId;
|
use crate::database::models::DBUserId;
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::database::PgTransaction;
|
||||||
use crate::database::models::{
|
use crate::database::models::{
|
||||||
DBProductPriceId, DBUserId, DBUserSubscriptionId, DatabaseError,
|
DBProductPriceId, DBUserId, DBUserSubscriptionId, DatabaseError,
|
||||||
};
|
};
|
||||||
@@ -62,14 +63,14 @@ impl TryFrom<UserSubscriptionQueryResult> for DBUserSubscription {
|
|||||||
impl DBUserSubscription {
|
impl DBUserSubscription {
|
||||||
pub async fn get(
|
pub async fn get(
|
||||||
id: DBUserSubscriptionId,
|
id: DBUserSubscriptionId,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Option<DBUserSubscription>, DatabaseError> {
|
) -> Result<Option<DBUserSubscription>, DatabaseError> {
|
||||||
Ok(Self::get_many(&[id], exec).await?.into_iter().next())
|
Ok(Self::get_many(&[id], exec).await?.into_iter().next())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_many(
|
pub async fn get_many(
|
||||||
ids: &[DBUserSubscriptionId],
|
ids: &[DBUserSubscriptionId],
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Vec<DBUserSubscription>, DatabaseError> {
|
) -> Result<Vec<DBUserSubscription>, DatabaseError> {
|
||||||
let ids = ids.iter().map(|id| id.0).collect_vec();
|
let ids = ids.iter().map(|id| id.0).collect_vec();
|
||||||
let ids_ref: &[i64] = &ids;
|
let ids_ref: &[i64] = &ids;
|
||||||
@@ -88,7 +89,7 @@ impl DBUserSubscription {
|
|||||||
|
|
||||||
pub async fn get_all_user(
|
pub async fn get_all_user(
|
||||||
user_id: DBUserId,
|
user_id: DBUserId,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Vec<DBUserSubscription>, DatabaseError> {
|
) -> Result<Vec<DBUserSubscription>, DatabaseError> {
|
||||||
let user_id = user_id.0;
|
let user_id = user_id.0;
|
||||||
let results = select_user_subscriptions_with_predicate!(
|
let results = select_user_subscriptions_with_predicate!(
|
||||||
@@ -106,7 +107,7 @@ impl DBUserSubscription {
|
|||||||
|
|
||||||
pub async fn get_all_servers(
|
pub async fn get_all_servers(
|
||||||
status: Option<SubscriptionStatus>,
|
status: Option<SubscriptionStatus>,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Vec<DBUserSubscription>, DatabaseError> {
|
) -> Result<Vec<DBUserSubscription>, DatabaseError> {
|
||||||
let status = status.map(|x| x.as_str());
|
let status = status.map(|x| x.as_str());
|
||||||
|
|
||||||
@@ -130,7 +131,7 @@ impl DBUserSubscription {
|
|||||||
|
|
||||||
pub async fn upsert(
|
pub async fn upsert(
|
||||||
&self,
|
&self,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<(), DatabaseError> {
|
) -> Result<(), DatabaseError> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -155,7 +156,7 @@ impl DBUserSubscription {
|
|||||||
self.status.as_str(),
|
self.status.as_str(),
|
||||||
serde_json::to_value(&self.metadata)?,
|
serde_json::to_value(&self.metadata)?,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -163,7 +164,7 @@ impl DBUserSubscription {
|
|||||||
|
|
||||||
pub async fn get_many_by_server_ids(
|
pub async fn get_many_by_server_ids(
|
||||||
server_ids: &[String],
|
server_ids: &[String],
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Vec<DBUserSubscription>, DatabaseError> {
|
) -> Result<Vec<DBUserSubscription>, DatabaseError> {
|
||||||
if server_ids.is_empty() {
|
if server_ids.is_empty() {
|
||||||
return Ok(vec![]);
|
return Ok(vec![]);
|
||||||
|
|||||||
@@ -39,14 +39,14 @@ impl From<UserNotificationPreferenceQueryResult>
|
|||||||
impl UserNotificationPreference {
|
impl UserNotificationPreference {
|
||||||
pub async fn get_user_or_default(
|
pub async fn get_user_or_default(
|
||||||
user_id: DBUserId,
|
user_id: DBUserId,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Vec<UserNotificationPreference>, DatabaseError> {
|
) -> Result<Vec<UserNotificationPreference>, DatabaseError> {
|
||||||
Self::get_many_users_or_default(&[user_id], exec).await
|
Self::get_many_users_or_default(&[user_id], exec).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_many_users_or_default(
|
pub async fn get_many_users_or_default(
|
||||||
user_ids: &[DBUserId],
|
user_ids: &[DBUserId],
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<Vec<UserNotificationPreference>, DatabaseError> {
|
) -> Result<Vec<UserNotificationPreference>, DatabaseError> {
|
||||||
let results = sqlx::query!(
|
let results = sqlx::query!(
|
||||||
r#"
|
r#"
|
||||||
@@ -86,7 +86,7 @@ impl UserNotificationPreference {
|
|||||||
/// Inserts the row into the table and updates its ID.
|
/// Inserts the row into the table and updates its ID.
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
&mut self,
|
&mut self,
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
) -> Result<(), DatabaseError> {
|
) -> Result<(), DatabaseError> {
|
||||||
let id = sqlx::query_scalar!(
|
let id = sqlx::query_scalar!(
|
||||||
"
|
"
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
use crate::database::models::{DBUserId, DBUserSubscriptionId};
|
use crate::database::{
|
||||||
|
PgTransaction,
|
||||||
|
models::{DBUserId, DBUserSubscriptionId},
|
||||||
|
};
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::query_scalar;
|
use sqlx::query_scalar;
|
||||||
@@ -43,7 +46,7 @@ impl DBUserSubscriptionCredit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn insert_many(
|
pub async fn insert_many(
|
||||||
exec: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
exec: &mut PgTransaction<'_>,
|
||||||
subscription_ids: &[DBUserSubscriptionId],
|
subscription_ids: &[DBUserSubscriptionId],
|
||||||
user_ids: &[DBUserId],
|
user_ids: &[DBUserId],
|
||||||
creditor_ids: &[DBUserId],
|
creditor_ids: &[DBUserId],
|
||||||
@@ -74,7 +77,7 @@ impl DBUserSubscriptionCredit {
|
|||||||
&previous_dues[..],
|
&previous_dues[..],
|
||||||
&next_dues[..],
|
&next_dues[..],
|
||||||
)
|
)
|
||||||
.execute(&mut **exec)
|
.execute(&mut *exec)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use super::DatabaseError;
|
use super::DatabaseError;
|
||||||
use super::ids::*;
|
use super::ids::*;
|
||||||
use super::loader_fields::VersionField;
|
use super::loader_fields::VersionField;
|
||||||
|
use crate::database::PgTransaction;
|
||||||
use crate::database::models::loader_fields::{
|
use crate::database::models::loader_fields::{
|
||||||
QueryLoaderField, QueryLoaderFieldEnumValue, QueryVersionField,
|
QueryLoaderField, QueryLoaderFieldEnumValue, QueryVersionField,
|
||||||
};
|
};
|
||||||
@@ -50,7 +51,7 @@ impl DependencyBuilder {
|
|||||||
pub async fn insert_many(
|
pub async fn insert_many(
|
||||||
builders: Vec<Self>,
|
builders: Vec<Self>,
|
||||||
version_id: DBVersionId,
|
version_id: DBVersionId,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<(), DatabaseError> {
|
) -> Result<(), DatabaseError> {
|
||||||
let mut project_ids = Vec::new();
|
let mut project_ids = Vec::new();
|
||||||
for dependency in &builders {
|
for dependency in &builders {
|
||||||
@@ -89,7 +90,7 @@ impl DependencyBuilder {
|
|||||||
&project_ids[..] as &[Option<i64>],
|
&project_ids[..] as &[Option<i64>],
|
||||||
&filenames[..] as &[Option<String>],
|
&filenames[..] as &[Option<String>],
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -97,7 +98,7 @@ impl DependencyBuilder {
|
|||||||
|
|
||||||
async fn try_get_project_id(
|
async fn try_get_project_id(
|
||||||
&self,
|
&self,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<Option<DBProjectId>, DatabaseError> {
|
) -> Result<Option<DBProjectId>, DatabaseError> {
|
||||||
Ok(if let Some(project_id) = self.project_id {
|
Ok(if let Some(project_id) = self.project_id {
|
||||||
Some(project_id)
|
Some(project_id)
|
||||||
@@ -108,7 +109,7 @@ impl DependencyBuilder {
|
|||||||
",
|
",
|
||||||
version_id as DBVersionId,
|
version_id as DBVersionId,
|
||||||
)
|
)
|
||||||
.fetch_optional(&mut **transaction)
|
.fetch_optional(&mut *transaction)
|
||||||
.await?
|
.await?
|
||||||
.map(|x| DBProjectId(x.mod_id))
|
.map(|x| DBProjectId(x.mod_id))
|
||||||
} else {
|
} else {
|
||||||
@@ -131,7 +132,7 @@ impl VersionFileBuilder {
|
|||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
self,
|
self,
|
||||||
version_id: DBVersionId,
|
version_id: DBVersionId,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<DBFileId, DatabaseError> {
|
) -> Result<DBFileId, DatabaseError> {
|
||||||
let file_id = generate_file_id(&mut *transaction).await?;
|
let file_id = generate_file_id(&mut *transaction).await?;
|
||||||
|
|
||||||
@@ -148,7 +149,7 @@ impl VersionFileBuilder {
|
|||||||
self.size as i32,
|
self.size as i32,
|
||||||
self.file_type.map(|x| x.as_str()),
|
self.file_type.map(|x| x.as_str()),
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
for hash in self.hashes {
|
for hash in self.hashes {
|
||||||
@@ -161,12 +162,12 @@ impl VersionFileBuilder {
|
|||||||
hash.algorithm,
|
hash.algorithm,
|
||||||
hash.hash,
|
hash.hash,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(err) = crate::routes::internal::delphi::run(
|
if let Err(err) = crate::routes::internal::delphi::run(
|
||||||
&mut **transaction,
|
&mut *transaction,
|
||||||
DelphiRunParameters {
|
DelphiRunParameters {
|
||||||
file_id: file_id.into(),
|
file_id: file_id.into(),
|
||||||
},
|
},
|
||||||
@@ -189,7 +190,7 @@ pub struct HashBuilder {
|
|||||||
impl VersionBuilder {
|
impl VersionBuilder {
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
self,
|
self,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<DBVersionId, DatabaseError> {
|
) -> Result<DBVersionId, DatabaseError> {
|
||||||
let version = DBVersion {
|
let version = DBVersion {
|
||||||
id: self.version_id,
|
id: self.version_id,
|
||||||
@@ -217,7 +218,7 @@ impl VersionBuilder {
|
|||||||
",
|
",
|
||||||
self.project_id as DBProjectId,
|
self.project_id as DBProjectId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let VersionBuilder {
|
let VersionBuilder {
|
||||||
@@ -263,7 +264,7 @@ pub struct DBLoaderVersion {
|
|||||||
impl DBLoaderVersion {
|
impl DBLoaderVersion {
|
||||||
pub async fn insert_many(
|
pub async fn insert_many(
|
||||||
items: Vec<Self>,
|
items: Vec<Self>,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<(), DatabaseError> {
|
) -> Result<(), DatabaseError> {
|
||||||
let (loader_ids, version_ids): (Vec<_>, Vec<_>) = items
|
let (loader_ids, version_ids): (Vec<_>, Vec<_>) = items
|
||||||
.iter()
|
.iter()
|
||||||
@@ -277,7 +278,7 @@ impl DBLoaderVersion {
|
|||||||
&loader_ids[..],
|
&loader_ids[..],
|
||||||
&version_ids[..],
|
&version_ids[..],
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -304,7 +305,7 @@ pub struct DBVersion {
|
|||||||
impl DBVersion {
|
impl DBVersion {
|
||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
&self,
|
&self,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<(), sqlx::error::Error> {
|
) -> Result<(), sqlx::error::Error> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -332,7 +333,7 @@ impl DBVersion {
|
|||||||
self.status.as_str(),
|
self.status.as_str(),
|
||||||
self.ordering
|
self.ordering
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -341,9 +342,9 @@ impl DBVersion {
|
|||||||
pub async fn remove_full(
|
pub async fn remove_full(
|
||||||
id: DBVersionId,
|
id: DBVersionId,
|
||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<Option<()>, DatabaseError> {
|
) -> Result<Option<()>, DatabaseError> {
|
||||||
let result = Self::get(id, &mut **transaction, redis).await?;
|
let result = Self::get(id, &mut *transaction, redis).await?;
|
||||||
|
|
||||||
let Some(result) = result else {
|
let Some(result) = result else {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
@@ -359,7 +360,7 @@ impl DBVersion {
|
|||||||
",
|
",
|
||||||
id as DBVersionId,
|
id as DBVersionId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -369,7 +370,7 @@ impl DBVersion {
|
|||||||
",
|
",
|
||||||
id as DBVersionId,
|
id as DBVersionId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -379,7 +380,7 @@ impl DBVersion {
|
|||||||
",
|
",
|
||||||
id as DBVersionId,
|
id as DBVersionId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -393,7 +394,7 @@ impl DBVersion {
|
|||||||
",
|
",
|
||||||
id as DBVersionId
|
id as DBVersionId
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -403,7 +404,7 @@ impl DBVersion {
|
|||||||
",
|
",
|
||||||
id as DBVersionId,
|
id as DBVersionId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// Sync dependencies
|
// Sync dependencies
|
||||||
@@ -414,7 +415,7 @@ impl DBVersion {
|
|||||||
",
|
",
|
||||||
id as DBVersionId,
|
id as DBVersionId,
|
||||||
)
|
)
|
||||||
.fetch_one(&mut **transaction)
|
.fetch_one(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -426,7 +427,7 @@ impl DBVersion {
|
|||||||
id as DBVersionId,
|
id as DBVersionId,
|
||||||
project_id.mod_id,
|
project_id.mod_id,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -434,7 +435,7 @@ impl DBVersion {
|
|||||||
DELETE FROM dependencies WHERE mod_dependency_id = NULL AND dependency_id = NULL AND dependency_file_name = NULL
|
DELETE FROM dependencies WHERE mod_dependency_id = NULL AND dependency_id = NULL AND dependency_file_name = NULL
|
||||||
",
|
",
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -443,7 +444,7 @@ impl DBVersion {
|
|||||||
",
|
",
|
||||||
id as DBVersionId,
|
id as DBVersionId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// delete version
|
// delete version
|
||||||
@@ -454,7 +455,7 @@ impl DBVersion {
|
|||||||
",
|
",
|
||||||
id as DBVersionId,
|
id as DBVersionId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
crate::database::models::DBProject::clear_cache(
|
crate::database::models::DBProject::clear_cache(
|
||||||
@@ -474,7 +475,7 @@ impl DBVersion {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Option<VersionQueryResult>, DatabaseError>
|
) -> Result<Option<VersionQueryResult>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Acquire<'a, Database = sqlx::Postgres>,
|
E: crate::database::Acquire<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
Self::get_many(&[id], executor, redis)
|
Self::get_many(&[id], executor, redis)
|
||||||
.await
|
.await
|
||||||
@@ -487,7 +488,7 @@ impl DBVersion {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<VersionQueryResult>, DatabaseError>
|
) -> Result<Vec<VersionQueryResult>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Acquire<'a, Database = sqlx::Postgres>,
|
E: crate::database::Acquire<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let mut val = redis.get_cached_keys(
|
let mut val = redis.get_cached_keys(
|
||||||
VERSIONS_NAMESPACE,
|
VERSIONS_NAMESPACE,
|
||||||
@@ -504,7 +505,7 @@ impl DBVersion {
|
|||||||
",
|
",
|
||||||
&version_ids
|
&version_ids
|
||||||
)
|
)
|
||||||
.fetch(&mut *exec)
|
.fetch(&mut exec)
|
||||||
.try_fold(
|
.try_fold(
|
||||||
DashMap::new(),
|
DashMap::new(),
|
||||||
|acc: DashMap<DBVersionId, Vec<QueryVersionField>>, m| {
|
|acc: DashMap<DBVersionId, Vec<QueryVersionField>>, m| {
|
||||||
@@ -554,7 +555,7 @@ impl DBVersion {
|
|||||||
GROUP BY version_id
|
GROUP BY version_id
|
||||||
",
|
",
|
||||||
&version_ids
|
&version_ids
|
||||||
).fetch(&mut *exec)
|
).fetch(&mut exec)
|
||||||
.map_ok(|m| {
|
.map_ok(|m| {
|
||||||
let version_id = DBVersionId(m.version_id);
|
let version_id = DBVersionId(m.version_id);
|
||||||
|
|
||||||
@@ -585,7 +586,7 @@ impl DBVersion {
|
|||||||
",
|
",
|
||||||
&loader_field_ids.iter().map(|x| x.0).collect::<Vec<_>>()
|
&loader_field_ids.iter().map(|x| x.0).collect::<Vec<_>>()
|
||||||
)
|
)
|
||||||
.fetch(&mut *exec)
|
.fetch(&mut exec)
|
||||||
.map_ok(|m| QueryLoaderField {
|
.map_ok(|m| QueryLoaderField {
|
||||||
id: LoaderFieldId(m.id),
|
id: LoaderFieldId(m.id),
|
||||||
field: m.field,
|
field: m.field,
|
||||||
@@ -610,7 +611,7 @@ impl DBVersion {
|
|||||||
.map(|x| x.0)
|
.map(|x| x.0)
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
)
|
)
|
||||||
.fetch(&mut *exec)
|
.fetch(&mut exec)
|
||||||
.map_ok(|m| QueryLoaderFieldEnumValue {
|
.map_ok(|m| QueryLoaderFieldEnumValue {
|
||||||
id: LoaderFieldEnumValueId(m.id),
|
id: LoaderFieldEnumValueId(m.id),
|
||||||
enum_id: LoaderFieldEnumId(m.enum_id),
|
enum_id: LoaderFieldEnumId(m.enum_id),
|
||||||
@@ -648,7 +649,7 @@ impl DBVersion {
|
|||||||
WHERE f.version_id = ANY($1)
|
WHERE f.version_id = ANY($1)
|
||||||
",
|
",
|
||||||
&version_ids
|
&version_ids
|
||||||
).fetch(&mut *exec)
|
).fetch(&mut exec)
|
||||||
.try_fold(DashMap::new(), |acc : DashMap<DBVersionId, Vec<File>>, m| {
|
.try_fold(DashMap::new(), |acc : DashMap<DBVersionId, Vec<File>>, m| {
|
||||||
let file = File {
|
let file = File {
|
||||||
id: DBFileId(m.id),
|
id: DBFileId(m.id),
|
||||||
@@ -677,7 +678,7 @@ impl DBVersion {
|
|||||||
",
|
",
|
||||||
&file_ids.iter().map(|x| x.0).collect::<Vec<_>>()
|
&file_ids.iter().map(|x| x.0).collect::<Vec<_>>()
|
||||||
)
|
)
|
||||||
.fetch(&mut *exec)
|
.fetch(&mut exec)
|
||||||
.try_fold(DashMap::new(), |acc: DashMap<DBVersionId, Vec<Hash>>, m| {
|
.try_fold(DashMap::new(), |acc: DashMap<DBVersionId, Vec<Hash>>, m| {
|
||||||
if let Some(found_hash) = m.hash {
|
if let Some(found_hash) = m.hash {
|
||||||
let hash = Hash {
|
let hash = Hash {
|
||||||
@@ -701,7 +702,7 @@ impl DBVersion {
|
|||||||
WHERE dependent_id = ANY($1)
|
WHERE dependent_id = ANY($1)
|
||||||
",
|
",
|
||||||
&version_ids
|
&version_ids
|
||||||
).fetch(&mut *exec)
|
).fetch(&mut exec)
|
||||||
.try_fold(DashMap::new(), |acc : DashMap<_,Vec<DependencyQueryResult>>, m| {
|
.try_fold(DashMap::new(), |acc : DashMap<_,Vec<DependencyQueryResult>>, m| {
|
||||||
let dependency = DependencyQueryResult {
|
let dependency = DependencyQueryResult {
|
||||||
project_id: m.dependency_project_id.map(DBProjectId),
|
project_id: m.dependency_project_id.map(DBProjectId),
|
||||||
@@ -727,7 +728,7 @@ impl DBVersion {
|
|||||||
",
|
",
|
||||||
&version_ids
|
&version_ids
|
||||||
)
|
)
|
||||||
.fetch(&mut *exec)
|
.fetch(&mut exec)
|
||||||
.try_fold(DashMap::new(), |acc, v| {
|
.try_fold(DashMap::new(), |acc, v| {
|
||||||
let version_id = DBVersionId(v.id);
|
let version_id = DBVersionId(v.id);
|
||||||
let VersionLoaderData {
|
let VersionLoaderData {
|
||||||
@@ -827,7 +828,7 @@ impl DBVersion {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Option<DBFile>, DatabaseError>
|
) -> Result<Option<DBFile>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres> + Copy,
|
||||||
{
|
{
|
||||||
Self::get_files_from_hash(algo, &[hash], executor, redis)
|
Self::get_files_from_hash(algo, &[hash], executor, redis)
|
||||||
.await
|
.await
|
||||||
@@ -844,7 +845,7 @@ impl DBVersion {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<DBFile>, DatabaseError>
|
) -> Result<Vec<DBFile>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres> + Copy,
|
||||||
{
|
{
|
||||||
let val = redis.get_cached_keys(
|
let val = redis.get_cached_keys(
|
||||||
VERSION_FILES_NAMESPACE,
|
VERSION_FILES_NAMESPACE,
|
||||||
|
|||||||
@@ -1,12 +1,23 @@
|
|||||||
use eyre::Context;
|
use eyre::Context;
|
||||||
use prometheus::{IntGauge, Registry};
|
use prometheus::{IntGauge, Registry};
|
||||||
use sqlx::migrate::{MigrateDatabase, Migrator};
|
use sqlx::migrate::{MigrateDatabase, Migrator};
|
||||||
use sqlx::postgres::{PgPool, PgPoolOptions};
|
use sqlx::postgres::PgPoolOptions;
|
||||||
use sqlx::{Connection, PgConnection, Postgres};
|
use sqlx::{Connection, Postgres};
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
|
|
||||||
|
// TODO tracing spans
|
||||||
|
pub type PgPool = sqlx_tracing::Pool<Postgres>;
|
||||||
|
pub type PgTransaction<'c> = sqlx_tracing::Transaction<'c, Postgres>;
|
||||||
|
pub use sqlx_tracing::Acquire;
|
||||||
|
pub use sqlx_tracing::Executor;
|
||||||
|
|
||||||
|
// pub type PgPool = sqlx::PgPool;
|
||||||
|
// pub type PgTransaction<'c> = sqlx::Transaction<'c, Postgres>;
|
||||||
|
// pub use sqlx::Acquire;
|
||||||
|
// pub use sqlx::Executor;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
pub struct ReadOnlyPgPool(PgPool);
|
pub struct ReadOnlyPgPool(PgPool);
|
||||||
@@ -71,6 +82,7 @@ pub async fn connect_all() -> Result<(PgPool, ReadOnlyPgPool), sqlx::Error> {
|
|||||||
.max_lifetime(Some(Duration::from_secs(60 * 60)))
|
.max_lifetime(Some(Duration::from_secs(60 * 60)))
|
||||||
.connect(&database_url)
|
.connect(&database_url)
|
||||||
.await?;
|
.await?;
|
||||||
|
let pool = PgPool::from(pool);
|
||||||
|
|
||||||
if let Ok(url) = dotenvy::var("READONLY_DATABASE_URL") {
|
if let Ok(url) = dotenvy::var("READONLY_DATABASE_URL") {
|
||||||
let ro_pool = PgPoolOptions::new()
|
let ro_pool = PgPoolOptions::new()
|
||||||
@@ -90,6 +102,7 @@ pub async fn connect_all() -> Result<(PgPool, ReadOnlyPgPool), sqlx::Error> {
|
|||||||
.max_lifetime(Some(Duration::from_secs(60 * 60)))
|
.max_lifetime(Some(Duration::from_secs(60 * 60)))
|
||||||
.connect(&url)
|
.connect(&url)
|
||||||
.await?;
|
.await?;
|
||||||
|
let ro_pool = PgPool::from(ro_pool);
|
||||||
|
|
||||||
Ok((pool, ReadOnlyPgPool(ro_pool)))
|
Ok((pool, ReadOnlyPgPool(ro_pool)))
|
||||||
} else {
|
} else {
|
||||||
@@ -114,9 +127,10 @@ pub async fn check_for_migrations() -> eyre::Result<()> {
|
|||||||
|
|
||||||
info!("Applying migrations...");
|
info!("Applying migrations...");
|
||||||
|
|
||||||
let mut conn: PgConnection = PgConnection::connect(uri)
|
let mut conn: sqlx::PgConnection =
|
||||||
.await
|
sqlx::PgConnection::connect(uri)
|
||||||
.wrap_err("failed to connect to database")?;
|
.await
|
||||||
|
.wrap_err("failed to connect to database")?;
|
||||||
MIGRATOR
|
MIGRATOR
|
||||||
.run(&mut conn)
|
.run(&mut conn)
|
||||||
.await
|
.await
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ use queue::{
|
|||||||
analytics::AnalyticsQueue, email::EmailQueue, payouts::PayoutsQueue,
|
analytics::AnalyticsQueue, email::EmailQueue, payouts::PayoutsQueue,
|
||||||
session::AuthQueue, socket::ActiveSockets,
|
session::AuthQueue, socket::ActiveSockets,
|
||||||
};
|
};
|
||||||
use sqlx::Postgres;
|
|
||||||
use tracing::{debug, info, warn};
|
use tracing::{debug, info, warn};
|
||||||
|
|
||||||
extern crate clickhouse as clickhouse_crate;
|
extern crate clickhouse as clickhouse_crate;
|
||||||
@@ -16,7 +15,7 @@ use util::cors::default_cors;
|
|||||||
use util::gotenberg::GotenbergClient;
|
use util::gotenberg::GotenbergClient;
|
||||||
|
|
||||||
use crate::background_task::update_versions;
|
use crate::background_task::update_versions;
|
||||||
use crate::database::ReadOnlyPgPool;
|
use crate::database::{PgPool, ReadOnlyPgPool};
|
||||||
use crate::queue::billing::{index_billing, index_subscriptions};
|
use crate::queue::billing::{index_billing, index_subscriptions};
|
||||||
use crate::queue::moderation::AutomatedModerationQueue;
|
use crate::queue::moderation::AutomatedModerationQueue;
|
||||||
use crate::search::MeilisearchReadClient;
|
use crate::search::MeilisearchReadClient;
|
||||||
@@ -50,7 +49,7 @@ pub struct Pepper {
|
|||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct LabrinthConfig {
|
pub struct LabrinthConfig {
|
||||||
pub pool: sqlx::Pool<Postgres>,
|
pub pool: PgPool,
|
||||||
pub ro_pool: ReadOnlyPgPool,
|
pub ro_pool: ReadOnlyPgPool,
|
||||||
pub redis_pool: RedisPool,
|
pub redis_pool: RedisPool,
|
||||||
pub clickhouse: Client,
|
pub clickhouse: Client,
|
||||||
@@ -74,7 +73,7 @@ pub struct LabrinthConfig {
|
|||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn app_setup(
|
pub fn app_setup(
|
||||||
pool: sqlx::Pool<Postgres>,
|
pool: PgPool,
|
||||||
ro_pool: ReadOnlyPgPool,
|
ro_pool: ReadOnlyPgPool,
|
||||||
redis_pool: RedisPool,
|
redis_pool: RedisPool,
|
||||||
search_config: search::SearchConfig,
|
search_config: search::SearchConfig,
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ impl LegacyProject {
|
|||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<Vec<Self>, DatabaseError>
|
) -> Result<Vec<Self>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Acquire<'a, Database = sqlx::Postgres>,
|
E: crate::database::Acquire<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
let version_ids: Vec<_> = data
|
let version_ids: Vec<_> = data
|
||||||
.iter()
|
.iter()
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
|
use crate::database::PgPool;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::PgPool;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
database::models::{DBUserId, user_limits::DBUserLimits},
|
database::models::{DBUserId, user_limits::DBUserLimits},
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::database::PgPool;
|
||||||
use crate::database::models::DatabaseError;
|
use crate::database::models::DatabaseError;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use crate::models::analytics::{
|
use crate::models::analytics::{
|
||||||
@@ -6,7 +7,6 @@ use crate::models::analytics::{
|
|||||||
use crate::routes::ApiError;
|
use crate::routes::ApiError;
|
||||||
use dashmap::{DashMap, DashSet};
|
use dashmap::{DashMap, DashSet};
|
||||||
use redis::cmd;
|
use redis::cmd;
|
||||||
use sqlx::PgPool;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
const DOWNLOADS_NAMESPACE: &str = "downloads";
|
const DOWNLOADS_NAMESPACE: &str = "downloads";
|
||||||
@@ -255,7 +255,7 @@ impl AnalyticsQueue {
|
|||||||
)
|
)
|
||||||
.bind(version_downloads.keys().copied().collect::<Vec<_>>())
|
.bind(version_downloads.keys().copied().collect::<Vec<_>>())
|
||||||
.bind(version_downloads.values().copied().collect::<Vec<_>>())
|
.bind(version_downloads.values().copied().collect::<Vec<_>>())
|
||||||
.execute(&mut *transaction)
|
.execute(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query(
|
sqlx::query(
|
||||||
@@ -268,7 +268,7 @@ impl AnalyticsQueue {
|
|||||||
)
|
)
|
||||||
.bind(project_downloads.keys().copied().collect::<Vec<_>>())
|
.bind(project_downloads.keys().copied().collect::<Vec<_>>())
|
||||||
.bind(project_downloads.values().copied().collect::<Vec<_>>())
|
.bind(project_downloads.values().copied().collect::<Vec<_>>())
|
||||||
.execute(&mut *transaction)
|
.execute(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
transaction.commit().await?;
|
transaction.commit().await?;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ use crate::database::models::{
|
|||||||
product_item, user_subscription_item, users_redeemals,
|
product_item, user_subscription_item, users_redeemals,
|
||||||
};
|
};
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
|
use crate::database::{PgPool, PgTransaction};
|
||||||
use crate::models::billing::{
|
use crate::models::billing::{
|
||||||
ChargeStatus, ChargeType, PaymentPlatform, Price, PriceDuration,
|
ChargeStatus, ChargeType, PaymentPlatform, Price, PriceDuration,
|
||||||
ProductMetadata, SubscriptionMetadata, SubscriptionStatus,
|
ProductMetadata, SubscriptionMetadata, SubscriptionStatus,
|
||||||
@@ -28,7 +29,6 @@ use ariadne::ids::base62_impl::to_base62;
|
|||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use futures::FutureExt;
|
use futures::FutureExt;
|
||||||
use futures::stream::{FuturesUnordered, StreamExt};
|
use futures::stream::{FuturesUnordered, StreamExt};
|
||||||
use sqlx::PgPool;
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
@@ -49,7 +49,7 @@ async fn update_tax_amounts(
|
|||||||
loop {
|
loop {
|
||||||
let mut txn = pg.begin().await?;
|
let mut txn = pg.begin().await?;
|
||||||
|
|
||||||
let charges = DBCharge::get_updateable_lock(&mut *txn, 5).await?;
|
let charges = DBCharge::get_updateable_lock(&mut txn, 5).await?;
|
||||||
|
|
||||||
if charges.is_empty() {
|
if charges.is_empty() {
|
||||||
info!("No more charges to process");
|
info!("No more charges to process");
|
||||||
@@ -273,7 +273,7 @@ async fn update_anrok_transactions(
|
|||||||
) -> Result<(), ApiError> {
|
) -> Result<(), ApiError> {
|
||||||
async fn process_charge(
|
async fn process_charge(
|
||||||
stripe_client: &stripe::Client,
|
stripe_client: &stripe::Client,
|
||||||
txn: &mut sqlx::PgTransaction<'_>,
|
txn: &mut PgTransaction<'_>,
|
||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
anrok_client: &anrok::Client,
|
anrok_client: &anrok::Client,
|
||||||
mut c: DBCharge,
|
mut c: DBCharge,
|
||||||
@@ -341,7 +341,7 @@ async fn update_anrok_transactions(
|
|||||||
.and_then(|x| x.billing_details.address);
|
.and_then(|x| x.billing_details.address);
|
||||||
|
|
||||||
let stripe_customer_id =
|
let stripe_customer_id =
|
||||||
DBUser::get_id(c.user_id, &mut **txn, redis)
|
DBUser::get_id(c.user_id, &mut *txn, redis)
|
||||||
.await?
|
.await?
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
ApiError::from(DatabaseError::Database(
|
ApiError::from(DatabaseError::Database(
|
||||||
@@ -395,7 +395,7 @@ async fn update_anrok_transactions(
|
|||||||
(address, tax_platform_id, customer_id)
|
(address, tax_platform_id, customer_id)
|
||||||
};
|
};
|
||||||
|
|
||||||
let tax_id = DBProductsTaxIdentifier::get_price(c.price_id, &mut **txn)
|
let tax_id = DBProductsTaxIdentifier::get_price(c.price_id, &mut *txn)
|
||||||
.await?
|
.await?
|
||||||
.ok_or_else(|| DatabaseError::Database(sqlx::Error::RowNotFound))?;
|
.ok_or_else(|| DatabaseError::Database(sqlx::Error::RowNotFound))?;
|
||||||
|
|
||||||
@@ -466,7 +466,7 @@ async fn update_anrok_transactions(
|
|||||||
let mut txn = pg.begin().await?;
|
let mut txn = pg.begin().await?;
|
||||||
|
|
||||||
let mut charges =
|
let mut charges =
|
||||||
DBCharge::get_missing_tax_identifier_lock(&mut *txn, offset, 1)
|
DBCharge::get_missing_tax_identifier_lock(&mut txn, offset, 1)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let Some(c) = charges.pop() else {
|
let Some(c) = charges.pop() else {
|
||||||
@@ -654,7 +654,7 @@ pub async fn try_process_user_redeemal(
|
|||||||
|
|
||||||
// Update `users_redeemal`, mark subscription as redeemed.
|
// Update `users_redeemal`, mark subscription as redeemed.
|
||||||
user_redeemal.status = users_redeemals::Status::Processed;
|
user_redeemal.status = users_redeemals::Status::Processed;
|
||||||
user_redeemal.update(&mut *txn).await?;
|
user_redeemal.update(&mut txn).await?;
|
||||||
|
|
||||||
txn.commit().await?;
|
txn.commit().await?;
|
||||||
|
|
||||||
@@ -896,7 +896,7 @@ async fn unprovision_subscriptions(
|
|||||||
badges.bits() as i64,
|
badges.bits() as i64,
|
||||||
user.id as DBUserId,
|
user.id as DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut *transaction)
|
.execute(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
true
|
true
|
||||||
@@ -942,7 +942,7 @@ async fn unprovision_subscriptions(
|
|||||||
|
|
||||||
DBUsersSubscriptionsAffiliations::deactivate(
|
DBUsersSubscriptionsAffiliations::deactivate(
|
||||||
subscription.id,
|
subscription.id,
|
||||||
&mut *transaction,
|
&mut transaction,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.wrap_internal_err(
|
.wrap_internal_err(
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use crate::database::models::notifications_deliveries_item::DBNotificationDelive
|
|||||||
use crate::database::models::notifications_template_item::NotificationTemplate;
|
use crate::database::models::notifications_template_item::NotificationTemplate;
|
||||||
use crate::database::models::user_item::DBUser;
|
use crate::database::models::user_item::DBUser;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
|
use crate::database::{PgPool, PgTransaction};
|
||||||
use crate::models::notifications::{NotificationBody, NotificationType};
|
use crate::models::notifications::{NotificationBody, NotificationType};
|
||||||
use crate::models::v3::notifications::{
|
use crate::models::v3::notifications::{
|
||||||
NotificationChannel, NotificationDeliveryStatus,
|
NotificationChannel, NotificationDeliveryStatus,
|
||||||
@@ -16,7 +17,6 @@ use lettre::transport::smtp::authentication::Credentials;
|
|||||||
use lettre::transport::smtp::client::{Tls, TlsParameters};
|
use lettre::transport::smtp::client::{Tls, TlsParameters};
|
||||||
use lettre::{AsyncSmtpTransport, AsyncTransport, Tokio1Executor};
|
use lettre::{AsyncSmtpTransport, AsyncTransport, Tokio1Executor};
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use sqlx::PgPool;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use tokio::sync::Mutex as TokioMutex;
|
use tokio::sync::Mutex as TokioMutex;
|
||||||
@@ -204,12 +204,9 @@ impl EmailQueue {
|
|||||||
futures.push(async move {
|
futures.push(async move {
|
||||||
let mut txn = this.pg.begin().await?;
|
let mut txn = this.pg.begin().await?;
|
||||||
|
|
||||||
let maybe_user = DBUser::get_id(
|
let maybe_user =
|
||||||
notification.user_id,
|
DBUser::get_id(notification.user_id, &mut txn, &this.redis)
|
||||||
&mut *txn,
|
.await?;
|
||||||
&this.redis,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let Some(mailbox) = maybe_user
|
let Some(mailbox) = maybe_user
|
||||||
.and_then(|user| user.email)
|
.and_then(|user| user.email)
|
||||||
@@ -301,7 +298,7 @@ impl EmailQueue {
|
|||||||
|
|
||||||
pub async fn send_one(
|
pub async fn send_one(
|
||||||
&self,
|
&self,
|
||||||
txn: &mut sqlx::PgTransaction<'_>,
|
txn: &mut PgTransaction<'_>,
|
||||||
notification: NotificationBody,
|
notification: NotificationBody,
|
||||||
user_id: DBUserId,
|
user_id: DBUserId,
|
||||||
address: Mailbox,
|
address: Mailbox,
|
||||||
@@ -319,7 +316,7 @@ impl EmailQueue {
|
|||||||
|
|
||||||
async fn send_one_with_transport(
|
async fn send_one_with_transport(
|
||||||
&self,
|
&self,
|
||||||
txn: &mut sqlx::PgTransaction<'_>,
|
txn: &mut PgTransaction<'_>,
|
||||||
transport: Arc<AsyncSmtpTransport<Tokio1Executor>>,
|
transport: Arc<AsyncSmtpTransport<Tokio1Executor>>,
|
||||||
notification: NotificationBody,
|
notification: NotificationBody,
|
||||||
user_id: DBUserId,
|
user_id: DBUserId,
|
||||||
@@ -330,7 +327,7 @@ impl EmailQueue {
|
|||||||
|
|
||||||
let Some(template) = NotificationTemplate::list_channel(
|
let Some(template) = NotificationTemplate::list_channel(
|
||||||
NotificationChannel::Email,
|
NotificationChannel::Email,
|
||||||
&mut **txn,
|
&mut *txn,
|
||||||
&self.redis,
|
&self.redis,
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use super::MailError;
|
use super::MailError;
|
||||||
|
use crate::database::PgTransaction;
|
||||||
use crate::database::models::ids::*;
|
use crate::database::models::ids::*;
|
||||||
use crate::database::models::notifications_template_item::{
|
use crate::database::models::notifications_template_item::{
|
||||||
NotificationTemplate, get_or_set_cached_dynamic_html,
|
NotificationTemplate, get_or_set_cached_dynamic_html,
|
||||||
@@ -105,7 +106,7 @@ impl MailingIdentity {
|
|||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub async fn build_email(
|
pub async fn build_email(
|
||||||
exec: &mut sqlx::PgTransaction<'_>,
|
exec: &mut PgTransaction<'_>,
|
||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
client: &reqwest::Client,
|
client: &reqwest::Client,
|
||||||
user_id: DBUserId,
|
user_id: DBUserId,
|
||||||
@@ -147,7 +148,7 @@ pub async fn build_email(
|
|||||||
reply_address,
|
reply_address,
|
||||||
} = from;
|
} = from;
|
||||||
|
|
||||||
let db_user = DBUser::get_id(user_id, &mut **exec, redis)
|
let db_user = DBUser::get_id(user_id, &mut *exec, redis)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(DatabaseError::Database(sqlx::Error::RowNotFound))?;
|
.ok_or(DatabaseError::Database(sqlx::Error::RowNotFound))?;
|
||||||
|
|
||||||
@@ -297,7 +298,7 @@ enum EmailTemplate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn collect_template_variables(
|
async fn collect_template_variables(
|
||||||
exec: &mut sqlx::PgTransaction<'_>,
|
exec: &mut PgTransaction<'_>,
|
||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
user_id: DBUserId,
|
user_id: DBUserId,
|
||||||
n: &NotificationBody,
|
n: &NotificationBody,
|
||||||
@@ -339,7 +340,7 @@ async fn collect_template_variables(
|
|||||||
"#,
|
"#,
|
||||||
report_id.0 as i64
|
report_id.0 as i64
|
||||||
)
|
)
|
||||||
.fetch_one(&mut **exec)
|
.fetch_one(&mut *exec)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
map.insert(REPORT_ID, to_base62(report_id.0));
|
map.insert(REPORT_ID, to_base62(report_id.0));
|
||||||
@@ -361,7 +362,7 @@ async fn collect_template_variables(
|
|||||||
"#,
|
"#,
|
||||||
report_id.0 as i64
|
report_id.0 as i64
|
||||||
)
|
)
|
||||||
.fetch_one(&mut **exec)
|
.fetch_one(&mut *exec)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
map.insert(REPORT_TITLE, result.title);
|
map.insert(REPORT_TITLE, result.title);
|
||||||
@@ -376,7 +377,7 @@ async fn collect_template_variables(
|
|||||||
"#,
|
"#,
|
||||||
project_id.0 as i64
|
project_id.0 as i64
|
||||||
)
|
)
|
||||||
.fetch_one(&mut **exec)
|
.fetch_one(&mut *exec)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
map.insert(PROJECT_ID, to_base62(project_id.0));
|
map.insert(PROJECT_ID, to_base62(project_id.0));
|
||||||
@@ -414,7 +415,7 @@ async fn collect_template_variables(
|
|||||||
} => {
|
} => {
|
||||||
let project = DBProject::get_id(
|
let project = DBProject::get_id(
|
||||||
DBProjectId(project_id.0 as i64),
|
DBProjectId(project_id.0 as i64),
|
||||||
&mut **exec,
|
&mut *exec,
|
||||||
redis,
|
redis,
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
@@ -428,7 +429,7 @@ async fn collect_template_variables(
|
|||||||
if let Some(new_owner_user_id) = new_owner_user_id {
|
if let Some(new_owner_user_id) = new_owner_user_id {
|
||||||
let user = DBUser::get_id(
|
let user = DBUser::get_id(
|
||||||
DBUserId(new_owner_user_id.0 as i64),
|
DBUserId(new_owner_user_id.0 as i64),
|
||||||
&mut **exec,
|
&mut *exec,
|
||||||
redis,
|
redis,
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
@@ -444,7 +445,7 @@ async fn collect_template_variables(
|
|||||||
{
|
{
|
||||||
let org = DBOrganization::get_id(
|
let org = DBOrganization::get_id(
|
||||||
DBOrganizationId(new_owner_organization_id.0 as i64),
|
DBOrganizationId(new_owner_organization_id.0 as i64),
|
||||||
&mut **exec,
|
&mut *exec,
|
||||||
redis,
|
redis,
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
@@ -484,7 +485,7 @@ async fn collect_template_variables(
|
|||||||
project_id.0 as i64,
|
project_id.0 as i64,
|
||||||
user_id.0 as i64
|
user_id.0 as i64
|
||||||
)
|
)
|
||||||
.fetch_one(&mut **exec)
|
.fetch_one(&mut *exec)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
map.insert(TEAMINVITE_INVITER_NAME, result.inviter_name);
|
map.insert(TEAMINVITE_INVITER_NAME, result.inviter_name);
|
||||||
@@ -516,7 +517,7 @@ async fn collect_template_variables(
|
|||||||
organization_id.0 as i64,
|
organization_id.0 as i64,
|
||||||
user_id.0 as i64
|
user_id.0 as i64
|
||||||
)
|
)
|
||||||
.fetch_one(&mut **exec)
|
.fetch_one(&mut *exec)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
map.insert(ORGINVITE_INVITER_NAME, result.inviter_name);
|
map.insert(ORGINVITE_INVITER_NAME, result.inviter_name);
|
||||||
@@ -544,7 +545,7 @@ async fn collect_template_variables(
|
|||||||
project_id.0 as i64,
|
project_id.0 as i64,
|
||||||
user_id.0 as i64,
|
user_id.0 as i64,
|
||||||
)
|
)
|
||||||
.fetch_one(&mut **exec)
|
.fetch_one(&mut *exec)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
map.insert(STATUSCHANGE_PROJECT_NAME, result.project_name);
|
map.insert(STATUSCHANGE_PROJECT_NAME, result.project_name);
|
||||||
@@ -706,12 +707,12 @@ async fn collect_template_variables(
|
|||||||
// Resolve product metadata via price_id join
|
// Resolve product metadata via price_id join
|
||||||
if let Some(info) = crate::database::models::user_subscription_item::DBUserSubscription::get(
|
if let Some(info) = crate::database::models::user_subscription_item::DBUserSubscription::get(
|
||||||
(*subscription_id).into(),
|
(*subscription_id).into(),
|
||||||
&mut **exec,
|
&mut *exec,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.ok()
|
.ok()
|
||||||
.flatten()
|
.flatten()
|
||||||
&& let Ok(Some(pinfo)) = crate::database::models::products_tax_identifier_item::product_info_by_product_price_id(info.price_id, &mut **exec).await {
|
&& let Ok(Some(pinfo)) = crate::database::models::products_tax_identifier_item::product_info_by_product_price_id(info.price_id, &mut *exec).await {
|
||||||
let label = match pinfo.product_metadata {
|
let label = match pinfo.product_metadata {
|
||||||
crate::models::billing::ProductMetadata::Pyro { .. } => "server".to_string(),
|
crate::models::billing::ProductMetadata::Pyro { .. } => "server".to_string(),
|
||||||
crate::models::billing::ProductMetadata::Medal { .. } => "server".to_string(),
|
crate::models::billing::ProductMetadata::Medal { .. } => "server".to_string(),
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use crate::auth::checks::filter_visible_versions;
|
use crate::auth::checks::filter_visible_versions;
|
||||||
use crate::database;
|
use crate::database;
|
||||||
|
use crate::database::PgPool;
|
||||||
use crate::database::models::notification_item::NotificationBuilder;
|
use crate::database::models::notification_item::NotificationBuilder;
|
||||||
use crate::database::models::thread_item::ThreadMessageBuilder;
|
use crate::database::models::thread_item::ThreadMessageBuilder;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
@@ -14,7 +15,6 @@ use hex::ToHex;
|
|||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sha1::Digest;
|
use sha1::Digest;
|
||||||
use sqlx::PgPool;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
use std::io::{Cursor, Read};
|
use std::io::{Cursor, Read};
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
|
use crate::database::PgPool;
|
||||||
use chrono::{Datelike, Duration, TimeZone, Utc};
|
use chrono::{Datelike, Duration, TimeZone, Utc};
|
||||||
use eyre::{Context, Result, eyre};
|
use eyre::{Context, Result, eyre};
|
||||||
use rust_decimal::{Decimal, dec};
|
use rust_decimal::{Decimal, dec};
|
||||||
use sqlx::PgPool;
|
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
|
|
||||||
use crate::database::models::{DBAffiliateCodeId, DBUserId};
|
use crate::database::models::{DBAffiliateCodeId, DBUserId};
|
||||||
@@ -58,7 +58,7 @@ pub async fn process_affiliate_payouts(postgres: &PgPool) -> Result<()> {
|
|||||||
)
|
)
|
||||||
"#
|
"#
|
||||||
)
|
)
|
||||||
.fetch_all(&mut *txn)
|
.fetch_all(&mut txn)
|
||||||
.await
|
.await
|
||||||
.wrap_err("failed to fetch charges awaiting affiliate payout")?;
|
.wrap_err("failed to fetch charges awaiting affiliate payout")?;
|
||||||
|
|
||||||
@@ -147,7 +147,7 @@ pub async fn process_affiliate_payouts(postgres: &PgPool) -> Result<()> {
|
|||||||
available,
|
available,
|
||||||
affiliate_code_id as _,
|
affiliate_code_id as _,
|
||||||
)
|
)
|
||||||
.fetch_one(&mut *txn)
|
.fetch_one(&mut txn)
|
||||||
.await
|
.await
|
||||||
.wrap_err_with(|| eyre!("failed to insert payout value for ({affiliate_user_id:?}, {affiliate_code_id:?})"))?
|
.wrap_err_with(|| eyre!("failed to insert payout value for ({affiliate_user_id:?}, {affiliate_code_id:?})"))?
|
||||||
.id;
|
.id;
|
||||||
@@ -170,7 +170,7 @@ pub async fn process_affiliate_payouts(postgres: &PgPool) -> Result<()> {
|
|||||||
&insert_usap_affiliate_codes[..],
|
&insert_usap_affiliate_codes[..],
|
||||||
&insert_usap_payout_values[..],
|
&insert_usap_payout_values[..],
|
||||||
)
|
)
|
||||||
.execute(&mut *txn)
|
.execute(&mut txn)
|
||||||
.await
|
.await
|
||||||
.wrap_err("failed to associate charges with affiliate payouts")?;
|
.wrap_err("failed to associate charges with affiliate payouts")?;
|
||||||
|
|
||||||
@@ -221,7 +221,7 @@ pub async fn remove_payouts_for_refunded_charges(
|
|||||||
AND refund_charges.charge_type = 'refund'
|
AND refund_charges.charge_type = 'refund'
|
||||||
"#
|
"#
|
||||||
)
|
)
|
||||||
.fetch_all(&mut *txn)
|
.fetch_all(&mut txn)
|
||||||
.await
|
.await
|
||||||
.wrap_err("failed to fetch refundable affiliate payouts")?;
|
.wrap_err("failed to fetch refundable affiliate payouts")?;
|
||||||
|
|
||||||
@@ -248,7 +248,7 @@ pub async fn remove_payouts_for_refunded_charges(
|
|||||||
",
|
",
|
||||||
&usap_ids[..]
|
&usap_ids[..]
|
||||||
)
|
)
|
||||||
.execute(&mut *txn)
|
.execute(&mut txn)
|
||||||
.await
|
.await
|
||||||
.wrap_err("failed to delete affiliate payout associations")?;
|
.wrap_err("failed to delete affiliate payout associations")?;
|
||||||
|
|
||||||
@@ -260,7 +260,7 @@ pub async fn remove_payouts_for_refunded_charges(
|
|||||||
",
|
",
|
||||||
&payout_value_ids[..]
|
&payout_value_ids[..]
|
||||||
)
|
)
|
||||||
.execute(&mut *txn)
|
.execute(&mut txn)
|
||||||
.await
|
.await
|
||||||
.wrap_err("failed to delete payout values")?;
|
.wrap_err("failed to delete payout values")?;
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
use eyre::eyre;
|
use eyre::eyre;
|
||||||
use modrinth_util::decimal::Decimal2dp;
|
use modrinth_util::decimal::Decimal2dp;
|
||||||
use rust_decimal::Decimal;
|
use rust_decimal::Decimal;
|
||||||
use sqlx::PgTransaction;
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
pub mod mural;
|
pub mod mural;
|
||||||
@@ -12,7 +11,10 @@ pub mod paypal;
|
|||||||
pub mod tremendous;
|
pub mod tremendous;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
database::models::{DBPayoutId, DBUser},
|
database::{
|
||||||
|
PgTransaction,
|
||||||
|
models::{DBPayoutId, DBUser},
|
||||||
|
},
|
||||||
models::payouts::{PayoutMethodRequest, Withdrawal},
|
models::payouts::{PayoutMethodRequest, Withdrawal},
|
||||||
queue::payouts::PayoutsQueue,
|
queue::payouts::PayoutsQueue,
|
||||||
routes::ApiError,
|
routes::ApiError,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use crate::database::models::notification_item::NotificationBuilder;
|
use crate::database::models::notification_item::NotificationBuilder;
|
||||||
use crate::database::models::payouts_values_notifications;
|
use crate::database::models::payouts_values_notifications;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
|
use crate::database::{PgPool, PgTransaction};
|
||||||
use crate::models::payouts::{
|
use crate::models::payouts::{
|
||||||
PayoutDecimal, PayoutInterval, PayoutMethod, PayoutMethodType,
|
PayoutDecimal, PayoutInterval, PayoutMethod, PayoutMethodType,
|
||||||
TremendousForexResponse,
|
TremendousForexResponse,
|
||||||
@@ -26,7 +27,6 @@ use rust_decimal::prelude::ToPrimitive;
|
|||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use sqlx::PgPool;
|
|
||||||
use sqlx::postgres::PgQueryResult;
|
use sqlx::postgres::PgQueryResult;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
@@ -1023,7 +1023,7 @@ pub async fn process_payout(
|
|||||||
.map(|x| x.to_string())
|
.map(|x| x.to_string())
|
||||||
.collect::<Vec<String>>(),
|
.collect::<Vec<String>>(),
|
||||||
)
|
)
|
||||||
.fetch(&mut *transaction)
|
.fetch(&mut transaction)
|
||||||
.try_fold(DashMap::new(), |acc: DashMap<i64, HashMap<i64, Decimal>>, r| {
|
.try_fold(DashMap::new(), |acc: DashMap<i64, HashMap<i64, Decimal>>, r| {
|
||||||
acc.entry(r.id)
|
acc.entry(r.id)
|
||||||
.or_default()
|
.or_default()
|
||||||
@@ -1046,7 +1046,7 @@ pub async fn process_payout(
|
|||||||
.map(|x| x.to_string())
|
.map(|x| x.to_string())
|
||||||
.collect::<Vec<String>>(),
|
.collect::<Vec<String>>(),
|
||||||
)
|
)
|
||||||
.fetch(&mut *transaction)
|
.fetch(&mut transaction)
|
||||||
.try_fold(
|
.try_fold(
|
||||||
DashMap::new(),
|
DashMap::new(),
|
||||||
|acc: DashMap<i64, HashMap<i64, Decimal>>, r| {
|
|acc: DashMap<i64, HashMap<i64, Decimal>>, r| {
|
||||||
@@ -1193,7 +1193,7 @@ pub async fn process_payout(
|
|||||||
&insert_starts[..],
|
&insert_starts[..],
|
||||||
&insert_availables[..]
|
&insert_availables[..]
|
||||||
)
|
)
|
||||||
.execute(&mut *transaction)
|
.execute(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
transaction.commit().await?;
|
transaction.commit().await?;
|
||||||
@@ -1208,7 +1208,7 @@ pub async fn insert_payouts(
|
|||||||
insert_payouts: Vec<Decimal>,
|
insert_payouts: Vec<Decimal>,
|
||||||
insert_starts: Vec<DateTime<Utc>>,
|
insert_starts: Vec<DateTime<Utc>>,
|
||||||
insert_availables: Vec<DateTime<Utc>>,
|
insert_availables: Vec<DateTime<Utc>>,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> sqlx::Result<PgQueryResult> {
|
) -> sqlx::Result<PgQueryResult> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
@@ -1221,7 +1221,7 @@ pub async fn insert_payouts(
|
|||||||
&insert_starts[..],
|
&insert_starts[..],
|
||||||
&insert_availables[..],
|
&insert_availables[..],
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1234,11 +1234,11 @@ pub async fn index_payouts_notifications(
|
|||||||
let mut transaction = pool.begin().await?;
|
let mut transaction = pool.begin().await?;
|
||||||
|
|
||||||
payouts_values_notifications::synchronize_future_payout_values(
|
payouts_values_notifications::synchronize_future_payout_values(
|
||||||
&mut *transaction,
|
&mut transaction,
|
||||||
200,
|
200,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
let items = payouts_values_notifications::PayoutsValuesNotification::unnotified_users_with_available_payouts_with_limit(&mut *transaction, 200).await?;
|
let items = payouts_values_notifications::PayoutsValuesNotification::unnotified_users_with_available_payouts_with_limit(&mut transaction, 200).await?;
|
||||||
|
|
||||||
let payout_ref_ids = items.iter().map(|x| x.id).collect::<Vec<_>>();
|
let payout_ref_ids = items.iter().map(|x| x.id).collect::<Vec<_>>();
|
||||||
let dates_available =
|
let dates_available =
|
||||||
@@ -1254,7 +1254,7 @@ pub async fn index_payouts_notifications(
|
|||||||
.await?;
|
.await?;
|
||||||
payouts_values_notifications::PayoutsValuesNotification::set_notified_many(
|
payouts_values_notifications::PayoutsValuesNotification::set_notified_many(
|
||||||
&payout_ref_ids,
|
&payout_ref_ids,
|
||||||
&mut *transaction,
|
&mut transaction,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@@ -1320,7 +1320,7 @@ pub async fn insert_bank_balances_and_webhook(
|
|||||||
&insert_pending[..],
|
&insert_pending[..],
|
||||||
&insert_recorded[..],
|
&insert_recorded[..],
|
||||||
)
|
)
|
||||||
.fetch_one(&mut *transaction)
|
.fetch_one(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if inserted {
|
if inserted {
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
|
use crate::database::PgPool;
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use eyre::{Result, eyre};
|
use eyre::{Result, eyre};
|
||||||
use futures::{StreamExt, TryFutureExt, stream::FuturesUnordered};
|
use futures::{StreamExt, TryFutureExt, stream::FuturesUnordered};
|
||||||
use modrinth_util::decimal::Decimal2dp;
|
use modrinth_util::decimal::Decimal2dp;
|
||||||
use rust_decimal::{Decimal, prelude::ToPrimitive};
|
use rust_decimal::{Decimal, prelude::ToPrimitive};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::PgPool;
|
|
||||||
use tracing::{info, trace, warn};
|
use tracing::{info, trace, warn};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -177,7 +177,7 @@ pub async fn sync_pending_payouts_from_mural(
|
|||||||
.collect::<Vec<String>>(),
|
.collect::<Vec<String>>(),
|
||||||
i64::from(limit),
|
i64::from(limit),
|
||||||
)
|
)
|
||||||
.fetch_all(&mut *txn)
|
.fetch_all(&mut txn)
|
||||||
.await
|
.await
|
||||||
.wrap_internal_err("failed to fetch incomplete Mural payouts")?;
|
.wrap_internal_err("failed to fetch incomplete Mural payouts")?;
|
||||||
|
|
||||||
@@ -235,7 +235,7 @@ pub async fn sync_pending_payouts_from_mural(
|
|||||||
&payout_ids,
|
&payout_ids,
|
||||||
&payout_statuses,
|
&payout_statuses,
|
||||||
)
|
)
|
||||||
.execute(&mut *txn)
|
.execute(&mut txn)
|
||||||
.await
|
.await
|
||||||
.wrap_internal_err("failed to update payout statuses")?;
|
.wrap_internal_err("failed to update payout statuses")?;
|
||||||
|
|
||||||
@@ -452,7 +452,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn setup_test_db_with_payouts(
|
async fn setup_test_db_with_payouts(
|
||||||
db: &sqlx::PgPool,
|
db: &PgPool,
|
||||||
payouts: Vec<(i64, String, PayoutStatus)>,
|
payouts: Vec<(i64, String, PayoutStatus)>,
|
||||||
) -> Result<(), eyre::Error> {
|
) -> Result<(), eyre::Error> {
|
||||||
for (id, platform_id, status) in payouts {
|
for (id, platform_id, status) in payouts {
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ use crate::database::models::{
|
|||||||
DBOAuthAccessTokenId, DBPatId, DBSessionId, DBUserId, DatabaseError,
|
DBOAuthAccessTokenId, DBPatId, DBSessionId, DBUserId, DatabaseError,
|
||||||
};
|
};
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
|
use crate::database::{PgPool, PgTransaction};
|
||||||
use crate::routes::internal::session::SessionMetadata;
|
use crate::routes::internal::session::SessionMetadata;
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use sqlx::PgPool;
|
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
@@ -55,14 +55,14 @@ impl AuthQueue {
|
|||||||
let mut queue = self.session_queue.lock().await;
|
let mut queue = self.session_queue.lock().await;
|
||||||
let len = queue.len();
|
let len = queue.len();
|
||||||
|
|
||||||
std::mem::replace(&mut queue, HashMap::with_capacity(len))
|
std::mem::replace(&mut *queue, HashMap::with_capacity(len))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn take_hashset<T>(queue: &Mutex<HashSet<T>>) -> HashSet<T> {
|
pub async fn take_hashset<T>(queue: &Mutex<HashSet<T>>) -> HashSet<T> {
|
||||||
let mut queue = queue.lock().await;
|
let mut queue = queue.lock().await;
|
||||||
let len = queue.len();
|
let len = queue.len();
|
||||||
|
|
||||||
std::mem::replace(&mut queue, HashSet::with_capacity(len))
|
std::mem::replace(&mut *queue, HashSet::with_capacity(len))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn index(
|
pub async fn index(
|
||||||
@@ -100,7 +100,7 @@ impl AuthQueue {
|
|||||||
metadata.platform,
|
metadata.platform,
|
||||||
metadata.user_agent,
|
metadata.user_agent,
|
||||||
)
|
)
|
||||||
.execute(&mut *transaction)
|
.execute(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ impl AuthQueue {
|
|||||||
WHERE refresh_expires <= NOW()
|
WHERE refresh_expires <= NOW()
|
||||||
"
|
"
|
||||||
)
|
)
|
||||||
.fetch(&mut *transaction)
|
.fetch(&mut transaction)
|
||||||
.map_ok(|x| (DBSessionId(x.id), x.session, DBUserId(x.user_id)))
|
.map_ok(|x| (DBSessionId(x.id), x.session, DBUserId(x.user_id)))
|
||||||
.try_collect::<Vec<(DBSessionId, String, DBUserId)>>()
|
.try_collect::<Vec<(DBSessionId, String, DBUserId)>>()
|
||||||
.await?;
|
.await?;
|
||||||
@@ -143,7 +143,7 @@ impl AuthQueue {
|
|||||||
&ids[..],
|
&ids[..],
|
||||||
Utc::now(),
|
Utc::now(),
|
||||||
)
|
)
|
||||||
.execute(&mut *transaction)
|
.execute(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
update_oauth_access_token_last_used(
|
update_oauth_access_token_last_used(
|
||||||
@@ -162,7 +162,7 @@ impl AuthQueue {
|
|||||||
|
|
||||||
async fn update_oauth_access_token_last_used(
|
async fn update_oauth_access_token_last_used(
|
||||||
oauth_access_token_queue: HashSet<DBOAuthAccessTokenId>,
|
oauth_access_token_queue: HashSet<DBOAuthAccessTokenId>,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<(), DatabaseError> {
|
) -> Result<(), DatabaseError> {
|
||||||
let ids = oauth_access_token_queue.iter().map(|id| id.0).collect_vec();
|
let ids = oauth_access_token_queue.iter().map(|id| id.0).collect_vec();
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -175,7 +175,7 @@ async fn update_oauth_access_token_last_used(
|
|||||||
&ids[..],
|
&ids[..],
|
||||||
Utc::now()
|
Utc::now()
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use crate::auth::get_user_from_headers;
|
use crate::auth::get_user_from_headers;
|
||||||
|
use crate::database::PgPool;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use crate::models::analytics::{PageView, Playtime};
|
use crate::models::analytics::{PageView, Playtime};
|
||||||
use crate::models::pats::Scopes;
|
use crate::models::pats::Scopes;
|
||||||
@@ -10,7 +11,6 @@ use crate::util::env::parse_strings_from_var;
|
|||||||
use actix_web::{HttpRequest, HttpResponse};
|
use actix_web::{HttpRequest, HttpResponse};
|
||||||
use actix_web::{post, web};
|
use actix_web::{post, web};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use sqlx::PgPool;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::net::Ipv4Addr;
|
use std::net::Ipv4Addr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use crate::auth::validate::get_user_record_from_bearer_token;
|
use crate::auth::validate::get_user_record_from_bearer_token;
|
||||||
|
use crate::database::PgPool;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use crate::models::analytics::Download;
|
use crate::models::analytics::Download;
|
||||||
use crate::models::ids::ProjectId;
|
use crate::models::ids::ProjectId;
|
||||||
@@ -11,7 +12,6 @@ use crate::util::date::get_current_tenths_of_ms;
|
|||||||
use crate::util::guards::admin_key_guard;
|
use crate::util::guards::admin_key_guard;
|
||||||
use actix_web::{HttpRequest, HttpResponse, patch, post, web};
|
use actix_web::{HttpRequest, HttpResponse, patch, post, web};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use sqlx::PgPool;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::net::Ipv4Addr;
|
use std::net::Ipv4Addr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use std::{collections::HashMap, net::Ipv4Addr, sync::Arc};
|
use std::{collections::HashMap, net::Ipv4Addr, sync::Arc};
|
||||||
|
|
||||||
|
use crate::database::PgPool;
|
||||||
use crate::{
|
use crate::{
|
||||||
auth::get_user_from_headers,
|
auth::get_user_from_headers,
|
||||||
database::{
|
database::{
|
||||||
@@ -21,7 +22,6 @@ use actix_web::{HttpRequest, delete, get, patch, post, put, web};
|
|||||||
use ariadne::ids::UserId;
|
use ariadne::ids::UserId;
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::PgPool;
|
|
||||||
use tracing::trace;
|
use tracing::trace;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
@@ -254,7 +254,7 @@ async fn create(
|
|||||||
affiliate: affiliate_id,
|
affiliate: affiliate_id,
|
||||||
source_name: body.source_name.clone(),
|
source_name: body.source_name.clone(),
|
||||||
};
|
};
|
||||||
code.insert(&mut *transaction)
|
code.insert(&mut transaction)
|
||||||
.await
|
.await
|
||||||
.wrap_internal_err("failed to insert affiliate code")?;
|
.wrap_internal_err("failed to insert affiliate code")?;
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ use crate::database::models::{
|
|||||||
user_subscription_item,
|
user_subscription_item,
|
||||||
};
|
};
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
|
use crate::database::{PgPool, PgTransaction};
|
||||||
use crate::models::billing::{
|
use crate::models::billing::{
|
||||||
Charge, ChargeStatus, ChargeType, PaymentPlatform, Price, PriceDuration,
|
Charge, ChargeStatus, ChargeType, PaymentPlatform, Price, PriceDuration,
|
||||||
Product, ProductMetadata, ProductPrice, SubscriptionMetadata,
|
Product, ProductMetadata, ProductPrice, SubscriptionMetadata,
|
||||||
@@ -29,7 +30,6 @@ use chrono::{Duration, Utc};
|
|||||||
use rust_decimal::Decimal;
|
use rust_decimal::Decimal;
|
||||||
use rust_decimal::prelude::ToPrimitive;
|
use rust_decimal::prelude::ToPrimitive;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::{PgPool, Postgres, Transaction};
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use stripe::{
|
use stripe::{
|
||||||
@@ -449,7 +449,7 @@ pub async fn reprocess_charge_tax(
|
|||||||
|
|
||||||
let mut txn = pool.begin().await?;
|
let mut txn = pool.begin().await?;
|
||||||
|
|
||||||
let charge_refund = charge_item::DBCharge::get(id.into(), &mut *txn)
|
let charge_refund = charge_item::DBCharge::get(id.into(), &mut txn)
|
||||||
.await?
|
.await?
|
||||||
.ok_or_else(|| ApiError::NotFound)?;
|
.ok_or_else(|| ApiError::NotFound)?;
|
||||||
|
|
||||||
@@ -466,10 +466,9 @@ pub async fn reprocess_charge_tax(
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let charge =
|
let charge = charge_item::DBCharge::get(parent_charge_id, &mut txn)
|
||||||
charge_item::DBCharge::get(parent_charge_id, &mut *txn)
|
.await?
|
||||||
.await?
|
.ok_or_else(|| ApiError::NotFound)?;
|
||||||
.ok_or_else(|| ApiError::NotFound)?;
|
|
||||||
|
|
||||||
let payment_platform_id = charge
|
let payment_platform_id = charge
|
||||||
.payment_platform_id
|
.payment_platform_id
|
||||||
@@ -503,7 +502,7 @@ pub async fn reprocess_charge_tax(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let tax_id =
|
let tax_id =
|
||||||
product_info_by_product_price_id(charge.price_id, &mut *txn)
|
product_info_by_product_price_id(charge.price_id, &mut txn)
|
||||||
.await?
|
.await?
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
ApiError::InvalidInput(
|
ApiError::InvalidInput(
|
||||||
@@ -634,13 +633,13 @@ pub async fn edit_subscription(
|
|||||||
/// if this operation will require immediate payment or if the user can be
|
/// if this operation will require immediate payment or if the user can be
|
||||||
/// charged only after the promotion interval ends.
|
/// charged only after the promotion interval ends.
|
||||||
async fn promotion_payment_requirement(
|
async fn promotion_payment_requirement(
|
||||||
txn: &mut sqlx::PgTransaction<'_>,
|
txn: &mut PgTransaction<'_>,
|
||||||
current_product_price: &product_item::DBProductPrice,
|
current_product_price: &product_item::DBProductPrice,
|
||||||
new_product_price: &product_item::DBProductPrice,
|
new_product_price: &product_item::DBProductPrice,
|
||||||
) -> Result<PaymentRequirement, ApiError> {
|
) -> Result<PaymentRequirement, ApiError> {
|
||||||
let new_product = product_item::DBProduct::get(
|
let new_product = product_item::DBProduct::get(
|
||||||
new_product_price.product_id,
|
new_product_price.product_id,
|
||||||
&mut **txn,
|
&mut *txn,
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
@@ -650,7 +649,7 @@ pub async fn edit_subscription(
|
|||||||
})?;
|
})?;
|
||||||
let current_product = product_item::DBProduct::get(
|
let current_product = product_item::DBProduct::get(
|
||||||
current_product_price.product_id,
|
current_product_price.product_id,
|
||||||
&mut **txn,
|
&mut *txn,
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
@@ -769,7 +768,7 @@ pub async fn edit_subscription(
|
|||||||
|
|
||||||
let mut open_charge = charge_item::DBCharge::get_open_subscription(
|
let mut open_charge = charge_item::DBCharge::get_open_subscription(
|
||||||
subscription.id,
|
subscription.id,
|
||||||
&mut *transaction,
|
&mut transaction,
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
@@ -780,7 +779,7 @@ pub async fn edit_subscription(
|
|||||||
|
|
||||||
let current_price = product_item::DBProductPrice::get(
|
let current_price = product_item::DBProductPrice::get(
|
||||||
subscription.price_id,
|
subscription.price_id,
|
||||||
&mut *transaction,
|
&mut transaction,
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
@@ -798,7 +797,7 @@ pub async fn edit_subscription(
|
|||||||
if cancelled {
|
if cancelled {
|
||||||
DBUsersSubscriptionsAffiliations::deactivate(
|
DBUsersSubscriptionsAffiliations::deactivate(
|
||||||
subscription.id,
|
subscription.id,
|
||||||
&mut *transaction,
|
&mut transaction,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
open_charge.status = ChargeStatus::Cancelled;
|
open_charge.status = ChargeStatus::Cancelled;
|
||||||
@@ -822,7 +821,7 @@ pub async fn edit_subscription(
|
|||||||
open_charge.status = if cancelled {
|
open_charge.status = if cancelled {
|
||||||
DBUsersSubscriptionsAffiliations::deactivate(
|
DBUsersSubscriptionsAffiliations::deactivate(
|
||||||
subscription.id,
|
subscription.id,
|
||||||
&mut *transaction,
|
&mut transaction,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
ChargeStatus::Cancelled
|
ChargeStatus::Cancelled
|
||||||
@@ -845,7 +844,7 @@ pub async fn edit_subscription(
|
|||||||
let new_product_price =
|
let new_product_price =
|
||||||
product_item::DBProductPrice::get_all_product_prices(
|
product_item::DBProductPrice::get_all_product_prices(
|
||||||
product_id.into(),
|
product_id.into(),
|
||||||
&mut *transaction,
|
&mut transaction,
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@@ -1650,7 +1649,7 @@ pub async fn stripe_webhook(
|
|||||||
pool: &PgPool,
|
pool: &PgPool,
|
||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
charge_status: ChargeStatus,
|
charge_status: ChargeStatus,
|
||||||
transaction: &mut Transaction<'_, Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<PaymentIntentMetadata, ApiError> {
|
) -> Result<PaymentIntentMetadata, ApiError> {
|
||||||
'metadata: {
|
'metadata: {
|
||||||
let Some(user_id) = metadata
|
let Some(user_id) = metadata
|
||||||
@@ -1977,7 +1976,7 @@ pub async fn stripe_webhook(
|
|||||||
metadata.user_item.id
|
metadata.user_item.id
|
||||||
as crate::database::models::ids::DBUserId,
|
as crate::database::models::ids::DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut *transaction)
|
.execute(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
ProductMetadata::Pyro {
|
ProductMetadata::Pyro {
|
||||||
@@ -2161,7 +2160,7 @@ pub async fn stripe_webhook(
|
|||||||
{
|
{
|
||||||
let open_charge = DBCharge::get_open_subscription(
|
let open_charge = DBCharge::get_open_subscription(
|
||||||
subscription.id,
|
subscription.id,
|
||||||
&mut *transaction,
|
&mut transaction,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@@ -2269,7 +2268,7 @@ pub async fn stripe_webhook(
|
|||||||
),
|
),
|
||||||
deactivated_at: None,
|
deactivated_at: None,
|
||||||
}
|
}
|
||||||
.insert(&mut *transaction)
|
.insert(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -2409,7 +2408,7 @@ pub async fn stripe_webhook(
|
|||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
async fn apply_credit_many(
|
async fn apply_credit_many(
|
||||||
transaction: &mut Transaction<'_, Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
current_user_id: crate::database::models::ids::DBUserId,
|
current_user_id: crate::database::models::ids::DBUserId,
|
||||||
subscription_ids: Vec<crate::models::ids::UserSubscriptionId>,
|
subscription_ids: Vec<crate::models::ids::UserSubscriptionId>,
|
||||||
@@ -2423,7 +2422,7 @@ async fn apply_credit_many(
|
|||||||
.collect();
|
.collect();
|
||||||
let subs = user_subscription_item::DBUserSubscription::get_many(
|
let subs = user_subscription_item::DBUserSubscription::get_many(
|
||||||
&subs_ids,
|
&subs_ids,
|
||||||
&mut **transaction,
|
&mut *transaction,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@@ -2451,7 +2450,7 @@ async fn apply_credit_many(
|
|||||||
|
|
||||||
let mut open_charge = charge_item::DBCharge::get_open_subscription(
|
let mut open_charge = charge_item::DBCharge::get_open_subscription(
|
||||||
subscription.id,
|
subscription.id,
|
||||||
&mut **transaction,
|
&mut *transaction,
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
@@ -2598,7 +2597,7 @@ pub async fn credit(
|
|||||||
server_ids.dedup();
|
server_ids.dedup();
|
||||||
let subs = user_subscription_item::DBUserSubscription::get_many_by_server_ids(
|
let subs = user_subscription_item::DBUserSubscription::get_many_by_server_ids(
|
||||||
&server_ids,
|
&server_ids,
|
||||||
&mut *transaction,
|
&mut transaction,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
if subs.is_empty() {
|
if subs.is_empty() {
|
||||||
@@ -2622,7 +2621,7 @@ pub async fn credit(
|
|||||||
archon_client.get_active_servers_by_region(®ion).await?;
|
archon_client.get_active_servers_by_region(®ion).await?;
|
||||||
let subs = user_subscription_item::DBUserSubscription::get_many_by_server_ids(
|
let subs = user_subscription_item::DBUserSubscription::get_many_by_server_ids(
|
||||||
&servers.into_iter().map(|id| id.to_string()).collect::<Vec<String>>(),
|
&servers.into_iter().map(|id| id.to_string()).collect::<Vec<String>>(),
|
||||||
&mut *transaction,
|
&mut transaction,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
if subs.is_empty() {
|
if subs.is_empty() {
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ use crate::models::v3::users::User;
|
|||||||
use crate::routes::ApiError;
|
use crate::routes::ApiError;
|
||||||
use crate::util::anrok;
|
use crate::util::anrok;
|
||||||
|
|
||||||
|
use crate::database::PgPool;
|
||||||
use ariadne::ids::base62_impl::to_base62;
|
use ariadne::ids::base62_impl::to_base62;
|
||||||
use ariadne::ids::*;
|
use ariadne::ids::*;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use sqlx::PgPool;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use stripe::{
|
use stripe::{
|
||||||
@@ -92,7 +92,7 @@ impl AttachedCharge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn from_charge_request_type(
|
pub async fn from_charge_request_type(
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
charge_request_type: ChargeRequestType,
|
charge_request_type: ChargeRequestType,
|
||||||
) -> Result<Self, ApiError> {
|
) -> Result<Self, ApiError> {
|
||||||
Ok(match charge_request_type {
|
Ok(match charge_request_type {
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
use std::{collections::HashMap, fmt::Write, sync::LazyLock, time::Instant};
|
use std::{collections::HashMap, fmt::Write, sync::LazyLock, time::Instant};
|
||||||
|
|
||||||
|
use crate::database::PgPool;
|
||||||
use actix_web::{HttpRequest, HttpResponse, get, post, web};
|
use actix_web::{HttpRequest, HttpResponse, get, post, web};
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use eyre::eyre;
|
use eyre::eyre;
|
||||||
use reqwest::header::{HeaderMap, HeaderValue, USER_AGENT};
|
use reqwest::header::{HeaderMap, HeaderValue, USER_AGENT};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use sqlx::PgPool;
|
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
|
|
||||||
@@ -200,7 +200,7 @@ async fn ingest_report_deserialized(
|
|||||||
"#,
|
"#,
|
||||||
DBProjectId::from(report.project_id) as _,
|
DBProjectId::from(report.project_id) as _,
|
||||||
)
|
)
|
||||||
.fetch_one(&mut *transaction)
|
.fetch_one(&mut transaction)
|
||||||
.await
|
.await
|
||||||
.wrap_internal_err("failed to check if pending issue details exist")?;
|
.wrap_internal_err("failed to check if pending issue details exist")?;
|
||||||
|
|
||||||
@@ -292,7 +292,7 @@ async fn ingest_report_deserialized(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn run(
|
pub async fn run(
|
||||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
exec: impl crate::database::Executor<'_, Database = sqlx::Postgres>,
|
||||||
run_parameters: DelphiRunParameters,
|
run_parameters: DelphiRunParameters,
|
||||||
) -> Result<HttpResponse, ApiError> {
|
) -> Result<HttpResponse, ApiError> {
|
||||||
let file_data = sqlx::query!(
|
let file_data = sqlx::query!(
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use crate::auth::get_user_from_headers;
|
use crate::auth::get_user_from_headers;
|
||||||
|
use crate::database::PgPool;
|
||||||
use crate::database::models::ids::DBUserId;
|
use crate::database::models::ids::DBUserId;
|
||||||
use crate::database::models::notification_item::NotificationBuilder;
|
use crate::database::models::notification_item::NotificationBuilder;
|
||||||
use crate::database::models::user_item::DBUser;
|
use crate::database::models::user_item::DBUser;
|
||||||
@@ -14,7 +15,6 @@ use actix_web::web;
|
|||||||
use actix_web::{HttpResponse, post};
|
use actix_web::{HttpResponse, post};
|
||||||
use ariadne::ids::UserId;
|
use ariadne::ids::UserId;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use sqlx::PgPool;
|
|
||||||
|
|
||||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||||
cfg.service(create).service(send_custom_email);
|
cfg.service(create).service(send_custom_email);
|
||||||
@@ -41,7 +41,7 @@ pub async fn create(
|
|||||||
|
|
||||||
let mut txn = pool.begin().await?;
|
let mut txn = pool.begin().await?;
|
||||||
|
|
||||||
if !DBUser::exists_many(&user_ids, &mut *txn).await? {
|
if !DBUser::exists_many(&user_ids, &mut txn).await? {
|
||||||
return Err(ApiError::InvalidInput(
|
return Err(ApiError::InvalidInput(
|
||||||
"One of the specified users do not exist.".to_owned(),
|
"One of the specified users do not exist.".to_owned(),
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ use crate::auth::validate::{
|
|||||||
get_full_user_from_headers, get_user_record_from_bearer_token,
|
get_full_user_from_headers, get_user_record_from_bearer_token,
|
||||||
};
|
};
|
||||||
use crate::auth::{AuthProvider, AuthenticationError, get_user_from_headers};
|
use crate::auth::{AuthProvider, AuthenticationError, get_user_from_headers};
|
||||||
|
use crate::database::PgPool;
|
||||||
|
use crate::database::PgTransaction;
|
||||||
use crate::database::models::flow_item::DBFlow;
|
use crate::database::models::flow_item::DBFlow;
|
||||||
use crate::database::models::notification_item::NotificationBuilder;
|
use crate::database::models::notification_item::NotificationBuilder;
|
||||||
use crate::database::models::{DBUser, DBUserId};
|
use crate::database::models::{DBUser, DBUserId};
|
||||||
@@ -34,7 +36,6 @@ use rand_chacha::ChaCha20Rng;
|
|||||||
use rand_chacha::rand_core::SeedableRng;
|
use rand_chacha::rand_core::SeedableRng;
|
||||||
use reqwest::header::AUTHORIZATION;
|
use reqwest::header::AUTHORIZATION;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::postgres::PgPool;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@@ -80,7 +81,7 @@ impl TempUser {
|
|||||||
async fn create_account(
|
async fn create_account(
|
||||||
self,
|
self,
|
||||||
provider: AuthProvider,
|
provider: AuthProvider,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
client: &PgPool,
|
client: &PgPool,
|
||||||
file_host: &Arc<dyn FileHost + Send + Sync>,
|
file_host: &Arc<dyn FileHost + Send + Sync>,
|
||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
@@ -834,7 +835,7 @@ impl AuthProvider {
|
|||||||
executor: E,
|
executor: E,
|
||||||
) -> Result<Option<crate::database::models::DBUserId>, AuthenticationError>
|
) -> Result<Option<crate::database::models::DBUserId>, AuthenticationError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
E: crate::database::Executor<'a, Database = sqlx::Postgres>,
|
||||||
{
|
{
|
||||||
Ok(match self {
|
Ok(match self {
|
||||||
AuthProvider::GitHub => {
|
AuthProvider::GitHub => {
|
||||||
@@ -918,7 +919,7 @@ impl AuthProvider {
|
|||||||
&self,
|
&self,
|
||||||
user_id: crate::database::models::DBUserId,
|
user_id: crate::database::models::DBUserId,
|
||||||
id: Option<&str>,
|
id: Option<&str>,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<(), AuthenticationError> {
|
) -> Result<(), AuthenticationError> {
|
||||||
match self {
|
match self {
|
||||||
AuthProvider::GitHub => {
|
AuthProvider::GitHub => {
|
||||||
@@ -931,7 +932,7 @@ impl AuthProvider {
|
|||||||
user_id as crate::database::models::DBUserId,
|
user_id as crate::database::models::DBUserId,
|
||||||
id.and_then(|x| x.parse::<i64>().ok())
|
id.and_then(|x| x.parse::<i64>().ok())
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
AuthProvider::Discord => {
|
AuthProvider::Discord => {
|
||||||
@@ -944,7 +945,7 @@ impl AuthProvider {
|
|||||||
user_id as crate::database::models::DBUserId,
|
user_id as crate::database::models::DBUserId,
|
||||||
id.and_then(|x| x.parse::<i64>().ok())
|
id.and_then(|x| x.parse::<i64>().ok())
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
AuthProvider::Microsoft => {
|
AuthProvider::Microsoft => {
|
||||||
@@ -957,7 +958,7 @@ impl AuthProvider {
|
|||||||
user_id as crate::database::models::DBUserId,
|
user_id as crate::database::models::DBUserId,
|
||||||
id,
|
id,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
AuthProvider::GitLab => {
|
AuthProvider::GitLab => {
|
||||||
@@ -970,7 +971,7 @@ impl AuthProvider {
|
|||||||
user_id as crate::database::models::DBUserId,
|
user_id as crate::database::models::DBUserId,
|
||||||
id.and_then(|x| x.parse::<i64>().ok())
|
id.and_then(|x| x.parse::<i64>().ok())
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
AuthProvider::Google => {
|
AuthProvider::Google => {
|
||||||
@@ -983,7 +984,7 @@ impl AuthProvider {
|
|||||||
user_id as crate::database::models::DBUserId,
|
user_id as crate::database::models::DBUserId,
|
||||||
id,
|
id,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
AuthProvider::Steam => {
|
AuthProvider::Steam => {
|
||||||
@@ -996,7 +997,7 @@ impl AuthProvider {
|
|||||||
user_id as crate::database::models::DBUserId,
|
user_id as crate::database::models::DBUserId,
|
||||||
id.and_then(|x| x.parse::<i64>().ok())
|
id.and_then(|x| x.parse::<i64>().ok())
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
AuthProvider::PayPal => {
|
AuthProvider::PayPal => {
|
||||||
@@ -1009,7 +1010,7 @@ impl AuthProvider {
|
|||||||
",
|
",
|
||||||
user_id as crate::database::models::DBUserId,
|
user_id as crate::database::models::DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
} else {
|
} else {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -1021,7 +1022,7 @@ impl AuthProvider {
|
|||||||
user_id as crate::database::models::DBUserId,
|
user_id as crate::database::models::DBUserId,
|
||||||
id,
|
id,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1217,7 +1218,7 @@ pub async fn auth_callback(
|
|||||||
oauth_user.id,
|
oauth_user.id,
|
||||||
existing_user_id as DBUserId,
|
existing_user_id as DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut *transaction)
|
.execute(&mut transaction)
|
||||||
.await
|
.await
|
||||||
.wrap_err("failed to update user PayPal info")?;
|
.wrap_err("failed to update user PayPal info")?;
|
||||||
|
|
||||||
@@ -1649,7 +1650,7 @@ async fn validate_2fa_code(
|
|||||||
user_id: crate::database::models::DBUserId,
|
user_id: crate::database::models::DBUserId,
|
||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
pool: &PgPool,
|
pool: &PgPool,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
) -> Result<bool, AuthenticationError> {
|
) -> Result<bool, AuthenticationError> {
|
||||||
let totp = totp_rs::TOTP::new(
|
let totp = totp_rs::TOTP::new(
|
||||||
totp_rs::Algorithm::SHA1,
|
totp_rs::Algorithm::SHA1,
|
||||||
@@ -1705,7 +1706,7 @@ async fn validate_2fa_code(
|
|||||||
user_id as crate::database::models::ids::DBUserId,
|
user_id as crate::database::models::ids::DBUserId,
|
||||||
code as i64,
|
code as i64,
|
||||||
)
|
)
|
||||||
.execute(&mut **transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
crate::database::models::DBUser::clear_caches(
|
crate::database::models::DBUser::clear_caches(
|
||||||
@@ -1867,7 +1868,7 @@ pub async fn finish_2fa_flow(
|
|||||||
secret,
|
secret,
|
||||||
user_id as crate::database::models::ids::DBUserId,
|
user_id as crate::database::models::ids::DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut *transaction)
|
.execute(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -1877,7 +1878,7 @@ pub async fn finish_2fa_flow(
|
|||||||
",
|
",
|
||||||
user_id as crate::database::models::ids::DBUserId,
|
user_id as crate::database::models::ids::DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut *transaction)
|
.execute(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let mut codes = Vec::new();
|
let mut codes = Vec::new();
|
||||||
@@ -1898,7 +1899,7 @@ pub async fn finish_2fa_flow(
|
|||||||
user_id as crate::database::models::ids::DBUserId,
|
user_id as crate::database::models::ids::DBUserId,
|
||||||
val as i64,
|
val as i64,
|
||||||
)
|
)
|
||||||
.execute(&mut *transaction)
|
.execute(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
codes.push(to_base62(val));
|
codes.push(to_base62(val));
|
||||||
@@ -1986,7 +1987,7 @@ pub async fn remove_2fa(
|
|||||||
",
|
",
|
||||||
user.id as crate::database::models::ids::DBUserId,
|
user.id as crate::database::models::ids::DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut *transaction)
|
.execute(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -1996,7 +1997,7 @@ pub async fn remove_2fa(
|
|||||||
",
|
",
|
||||||
user.id as crate::database::models::ids::DBUserId,
|
user.id as crate::database::models::ids::DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut *transaction)
|
.execute(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
NotificationBuilder {
|
NotificationBuilder {
|
||||||
@@ -2036,7 +2037,7 @@ pub async fn reset_password_begin(
|
|||||||
let user =
|
let user =
|
||||||
match crate::database::models::DBUser::get_by_case_insensitive_email(
|
match crate::database::models::DBUser::get_by_case_insensitive_email(
|
||||||
&reset_password.username_or_email,
|
&reset_password.username_or_email,
|
||||||
&mut *txn,
|
&mut txn,
|
||||||
)
|
)
|
||||||
.await?[..]
|
.await?[..]
|
||||||
{
|
{
|
||||||
@@ -2044,7 +2045,7 @@ pub async fn reset_password_begin(
|
|||||||
// Try finding by username or ID
|
// Try finding by username or ID
|
||||||
crate::database::models::DBUser::get(
|
crate::database::models::DBUser::get(
|
||||||
&reset_password.username_or_email,
|
&reset_password.username_or_email,
|
||||||
&mut *txn,
|
&mut txn,
|
||||||
&redis,
|
&redis,
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
@@ -2053,7 +2054,7 @@ pub async fn reset_password_begin(
|
|||||||
// If there is only one user with the given email, ignoring case,
|
// If there is only one user with the given email, ignoring case,
|
||||||
// we can assume it's the user we want to reset the password for
|
// we can assume it's the user we want to reset the password for
|
||||||
crate::database::models::DBUser::get_id(
|
crate::database::models::DBUser::get_id(
|
||||||
user_id, &mut *txn, &redis,
|
user_id, &mut txn, &redis,
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
}
|
}
|
||||||
@@ -2065,12 +2066,12 @@ pub async fn reset_password_begin(
|
|||||||
if let Some(user_id) =
|
if let Some(user_id) =
|
||||||
crate::database::models::DBUser::get_by_email(
|
crate::database::models::DBUser::get_by_email(
|
||||||
&reset_password.username_or_email,
|
&reset_password.username_or_email,
|
||||||
&mut *txn,
|
&mut txn,
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
{
|
{
|
||||||
crate::database::models::DBUser::get_id(
|
crate::database::models::DBUser::get_id(
|
||||||
user_id, &mut *txn, &redis,
|
user_id, &mut txn, &redis,
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
} else {
|
} else {
|
||||||
@@ -2232,7 +2233,7 @@ pub async fn change_password(
|
|||||||
update_password,
|
update_password,
|
||||||
user.id as crate::database::models::ids::DBUserId,
|
user.id as crate::database::models::ids::DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut *transaction)
|
.execute(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if let Some(flow) = &change_password.flow {
|
if let Some(flow) = &change_password.flow {
|
||||||
@@ -2317,7 +2318,7 @@ pub async fn set_email(
|
|||||||
email_address.email,
|
email_address.email,
|
||||||
user.id.0 as i64,
|
user.id.0 as i64,
|
||||||
)
|
)
|
||||||
.execute(&mut *transaction)
|
.execute(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if let Some(user_email) = user.email.clone() {
|
if let Some(user_email) = user.email.clone() {
|
||||||
@@ -2473,7 +2474,7 @@ pub async fn verify_email(
|
|||||||
",
|
",
|
||||||
user.id as crate::database::models::ids::DBUserId,
|
user.id as crate::database::models::ids::DBUserId,
|
||||||
)
|
)
|
||||||
.execute(&mut *transaction)
|
.execute(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
DBFlow::remove(&email.flow, &redis).await?;
|
DBFlow::remove(&email.flow, &redis).await?;
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use crate::auth::get_user_from_headers;
|
use crate::auth::get_user_from_headers;
|
||||||
|
use crate::database::PgPool;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use crate::models::pats::Scopes;
|
use crate::models::pats::Scopes;
|
||||||
use crate::queue::session::AuthQueue;
|
use crate::queue::session::AuthQueue;
|
||||||
use crate::routes::ApiError;
|
use crate::routes::ApiError;
|
||||||
use actix_web::{HttpRequest, HttpResponse, post, web};
|
use actix_web::{HttpRequest, HttpResponse, post, web};
|
||||||
use sqlx::PgPool;
|
|
||||||
|
|
||||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||||
cfg.service(web::scope("gdpr").service(export));
|
cfg.service(web::scope("gdpr").service(export));
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
|
use crate::database::PgPool;
|
||||||
use actix_web::{HttpResponse, post, web};
|
use actix_web::{HttpResponse, post, web};
|
||||||
use ariadne::ids::UserId;
|
use ariadne::ids::UserId;
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::PgPool;
|
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
|
|
||||||
use crate::database::models::users_redeemals::{
|
use crate::database::models::users_redeemals::{
|
||||||
@@ -63,7 +63,7 @@ pub async fn redeem(
|
|||||||
|
|
||||||
let maybe_fields =
|
let maybe_fields =
|
||||||
RedeemalLookupFields::redeemal_status_by_username_and_offer(
|
RedeemalLookupFields::redeemal_status_by_username_and_offer(
|
||||||
&mut *txn,
|
&mut txn,
|
||||||
&username,
|
&username,
|
||||||
Offer::Medal,
|
Offer::Medal,
|
||||||
)
|
)
|
||||||
@@ -93,7 +93,7 @@ pub async fn redeem(
|
|||||||
n_attempts: 0,
|
n_attempts: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
redeemal.insert(&mut *txn).await?;
|
redeemal.insert(&mut txn).await?;
|
||||||
|
|
||||||
txn.commit().await?;
|
txn.commit().await?;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use super::ApiError;
|
use super::ApiError;
|
||||||
use crate::auth::get_user_from_headers;
|
use crate::auth::get_user_from_headers;
|
||||||
use crate::database;
|
use crate::database;
|
||||||
|
use crate::database::PgPool;
|
||||||
use crate::database::models::DBModerationLock;
|
use crate::database::models::DBModerationLock;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use crate::models::ids::OrganizationId;
|
use crate::models::ids::OrganizationId;
|
||||||
@@ -14,7 +15,6 @@ use ariadne::ids::{UserId, random_base62};
|
|||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use ownership::get_projects_ownership;
|
use ownership::get_projects_ownership;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::PgPool;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
mod ownership;
|
mod ownership;
|
||||||
@@ -462,7 +462,7 @@ async fn set_project_meta(
|
|||||||
.bind(&links[..])
|
.bind(&links[..])
|
||||||
.bind(&proofs[..])
|
.bind(&proofs[..])
|
||||||
.bind(&flame_ids[..])
|
.bind(&flame_ids[..])
|
||||||
.execute(&mut *transaction)
|
.execute(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query(
|
sqlx::query(
|
||||||
@@ -475,7 +475,7 @@ async fn set_project_meta(
|
|||||||
)
|
)
|
||||||
.bind(&file_hashes[..])
|
.bind(&file_hashes[..])
|
||||||
.bind(&ids[..])
|
.bind(&ids[..])
|
||||||
.execute(&mut *transaction)
|
.execute(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
transaction.commit().await?;
|
transaction.commit().await?;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::database::PgPool;
|
||||||
use crate::database::models::{DBOrganization, DBTeamId, DBTeamMember, DBUser};
|
use crate::database::models::{DBOrganization, DBTeamId, DBTeamMember, DBUser};
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use crate::models::ids::OrganizationId;
|
use crate::models::ids::OrganizationId;
|
||||||
@@ -5,7 +6,6 @@ use crate::routes::internal::moderation::Ownership;
|
|||||||
use crate::util::error::Context;
|
use crate::util::error::Context;
|
||||||
use ariadne::ids::UserId;
|
use ariadne::ids::UserId;
|
||||||
use eyre::eyre;
|
use eyre::eyre;
|
||||||
use sqlx::PgPool;
|
|
||||||
|
|
||||||
/// Fetches ownership information for multiple projects efficiently
|
/// Fetches ownership information for multiple projects efficiently
|
||||||
pub async fn get_projects_ownership(
|
pub async fn get_projects_ownership(
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use std::{collections::HashMap, fmt};
|
use std::{collections::HashMap, fmt};
|
||||||
|
|
||||||
|
use crate::database::PgPool;
|
||||||
use actix_web::{HttpRequest, get, patch, post, put, web};
|
use actix_web::{HttpRequest, get, patch, post, put, web};
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::PgPool;
|
|
||||||
|
|
||||||
use super::ownership::get_projects_ownership;
|
use super::ownership::get_projects_ownership;
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -986,7 +986,7 @@ async fn submit_report(
|
|||||||
"#,
|
"#,
|
||||||
project_id as _,
|
project_id as _,
|
||||||
)
|
)
|
||||||
.fetch_all(&mut *txn)
|
.fetch_all(&mut txn)
|
||||||
.await
|
.await
|
||||||
.wrap_internal_err("failed to fetch pending issues")?;
|
.wrap_internal_err("failed to fetch pending issues")?;
|
||||||
|
|
||||||
@@ -1016,7 +1016,7 @@ async fn submit_report(
|
|||||||
",
|
",
|
||||||
project_id as _,
|
project_id as _,
|
||||||
)
|
)
|
||||||
.execute(&mut *txn)
|
.execute(&mut txn)
|
||||||
.await
|
.await
|
||||||
.wrap_internal_err("failed to delete dummy issue")?;
|
.wrap_internal_err("failed to delete dummy issue")?;
|
||||||
|
|
||||||
@@ -1029,7 +1029,7 @@ async fn submit_report(
|
|||||||
"#,
|
"#,
|
||||||
project_id as _,
|
project_id as _,
|
||||||
)
|
)
|
||||||
.fetch_one(&mut *txn)
|
.fetch_one(&mut txn)
|
||||||
.await
|
.await
|
||||||
.wrap_internal_err("failed to update reports")?;
|
.wrap_internal_err("failed to update reports")?;
|
||||||
|
|
||||||
@@ -1087,7 +1087,7 @@ async fn submit_report(
|
|||||||
ProjectStatus::Rejected.as_str(),
|
ProjectStatus::Rejected.as_str(),
|
||||||
project_id as _,
|
project_id as _,
|
||||||
)
|
)
|
||||||
.fetch_one(&mut *txn)
|
.fetch_one(&mut txn)
|
||||||
.await
|
.await
|
||||||
.wrap_internal_err("failed to mark project as rejected")?;
|
.wrap_internal_err("failed to mark project as rejected")?;
|
||||||
|
|
||||||
@@ -1182,7 +1182,7 @@ async fn update_issue_detail(
|
|||||||
status as _,
|
status as _,
|
||||||
issue_detail_id as _,
|
issue_detail_id as _,
|
||||||
)
|
)
|
||||||
.execute(&mut *txn)
|
.execute(&mut txn)
|
||||||
.await
|
.await
|
||||||
.wrap_internal_err("failed to update issue detail")?;
|
.wrap_internal_err("failed to update issue detail")?;
|
||||||
if results.rows_affected() == 0 {
|
if results.rows_affected() == 0 {
|
||||||
@@ -1240,7 +1240,7 @@ async fn add_report(
|
|||||||
"#,
|
"#,
|
||||||
DBFileId::from(file_id) as _,
|
DBFileId::from(file_id) as _,
|
||||||
)
|
)
|
||||||
.fetch_one(&mut *txn)
|
.fetch_one(&mut txn)
|
||||||
.await
|
.await
|
||||||
.wrap_internal_err("failed to fetch file")?;
|
.wrap_internal_err("failed to fetch file")?;
|
||||||
|
|
||||||
|
|||||||
@@ -13,13 +13,13 @@ use rand::distributions::Alphanumeric;
|
|||||||
use rand_chacha::ChaCha20Rng;
|
use rand_chacha::ChaCha20Rng;
|
||||||
use rand_chacha::rand_core::SeedableRng;
|
use rand_chacha::rand_core::SeedableRng;
|
||||||
|
|
||||||
|
use crate::database::PgPool;
|
||||||
use crate::database::models::notification_item::NotificationBuilder;
|
use crate::database::models::notification_item::NotificationBuilder;
|
||||||
use crate::models::notifications::NotificationBody;
|
use crate::models::notifications::NotificationBody;
|
||||||
use crate::models::pats::{PersonalAccessToken, Scopes};
|
use crate::models::pats::{PersonalAccessToken, Scopes};
|
||||||
use crate::queue::session::AuthQueue;
|
use crate::queue::session::AuthQueue;
|
||||||
use crate::util::validate::validation_errors_to_string;
|
use crate::util::validate::validation_errors_to_string;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use sqlx::postgres::PgPool;
|
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
|
|
||||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||||
@@ -216,7 +216,7 @@ pub async fn edit_pat(
|
|||||||
scopes.bits() as i64,
|
scopes.bits() as i64,
|
||||||
pat.id.0
|
pat.id.0
|
||||||
)
|
)
|
||||||
.execute(&mut *transaction)
|
.execute(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
if let Some(name) = &info.name {
|
if let Some(name) = &info.name {
|
||||||
@@ -229,7 +229,7 @@ pub async fn edit_pat(
|
|||||||
name,
|
name,
|
||||||
pat.id.0
|
pat.id.0
|
||||||
)
|
)
|
||||||
.execute(&mut *transaction)
|
.execute(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
if let Some(expires) = &info.expires {
|
if let Some(expires) = &info.expires {
|
||||||
@@ -248,7 +248,7 @@ pub async fn edit_pat(
|
|||||||
expires,
|
expires,
|
||||||
pat.id.0
|
pat.id.0
|
||||||
)
|
)
|
||||||
.execute(&mut *transaction)
|
.execute(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use crate::database::models::DBUserId;
|
|||||||
use crate::database::models::session_item::DBSession;
|
use crate::database::models::session_item::DBSession;
|
||||||
use crate::database::models::session_item::SessionBuilder;
|
use crate::database::models::session_item::SessionBuilder;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
|
use crate::database::{PgPool, PgTransaction};
|
||||||
use crate::models::pats::Scopes;
|
use crate::models::pats::Scopes;
|
||||||
use crate::models::sessions::Session;
|
use crate::models::sessions::Session;
|
||||||
use crate::queue::session::AuthQueue;
|
use crate::queue::session::AuthQueue;
|
||||||
@@ -15,7 +16,6 @@ use chrono::Utc;
|
|||||||
use rand::distributions::Alphanumeric;
|
use rand::distributions::Alphanumeric;
|
||||||
use rand::{Rng, SeedableRng};
|
use rand::{Rng, SeedableRng};
|
||||||
use rand_chacha::ChaCha20Rng;
|
use rand_chacha::ChaCha20Rng;
|
||||||
use sqlx::PgPool;
|
|
||||||
use woothee::parser::Parser;
|
use woothee::parser::Parser;
|
||||||
|
|
||||||
pub fn config(cfg: &mut ServiceConfig) {
|
pub fn config(cfg: &mut ServiceConfig) {
|
||||||
@@ -86,7 +86,7 @@ pub async fn get_session_metadata(
|
|||||||
pub async fn issue_session(
|
pub async fn issue_session(
|
||||||
req: HttpRequest,
|
req: HttpRequest,
|
||||||
user_id: DBUserId,
|
user_id: DBUserId,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut PgTransaction<'_>,
|
||||||
redis: &RedisPool,
|
redis: &RedisPool,
|
||||||
) -> Result<DBSession, AuthenticationError> {
|
) -> Result<DBSession, AuthenticationError> {
|
||||||
let metadata = get_session_metadata(&req).await?;
|
let metadata = get_session_metadata(&req).await?;
|
||||||
@@ -112,7 +112,7 @@ pub async fn issue_session(
|
|||||||
.insert(transaction)
|
.insert(transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let session = DBSession::get_id(id, &mut **transaction, redis)
|
let session = DBSession::get_id(id, &mut *transaction, redis)
|
||||||
.await?
|
.await?
|
||||||
.ok_or_else(|| AuthenticationError::InvalidCredentials)?;
|
.ok_or_else(|| AuthenticationError::InvalidCredentials)?;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use crate::auth::AuthenticationError;
|
use crate::auth::AuthenticationError;
|
||||||
use crate::auth::validate::get_user_record_from_bearer_token;
|
use crate::auth::validate::get_user_record_from_bearer_token;
|
||||||
|
use crate::database::PgPool;
|
||||||
use crate::database::models::friend_item::DBFriend;
|
use crate::database::models::friend_item::DBFriend;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use crate::models::pats::Scopes;
|
use crate::models::pats::Scopes;
|
||||||
@@ -27,7 +28,6 @@ use futures_util::future::select;
|
|||||||
use futures_util::{StreamExt, TryStreamExt};
|
use futures_util::{StreamExt, TryStreamExt};
|
||||||
use redis::AsyncCommands;
|
use redis::AsyncCommands;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use sqlx::PgPool;
|
|
||||||
use std::pin::pin;
|
use std::pin::pin;
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
use tokio::sync::oneshot::error::TryRecvError;
|
use tokio::sync::oneshot::error::TryRecvError;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use crate::auth::checks::{is_visible_project, is_visible_version};
|
use crate::auth::checks::{is_visible_project, is_visible_version};
|
||||||
|
use crate::database::PgPool;
|
||||||
use crate::database::models::legacy_loader_fields::MinecraftGameVersion;
|
use crate::database::models::legacy_loader_fields::MinecraftGameVersion;
|
||||||
use crate::database::models::loader_fields::Loader;
|
use crate::database::models::loader_fields::Loader;
|
||||||
use crate::database::models::project_item::ProjectQueryResult;
|
use crate::database::models::project_item::ProjectQueryResult;
|
||||||
@@ -12,7 +13,6 @@ use crate::queue::session::AuthQueue;
|
|||||||
use crate::routes::ApiError;
|
use crate::routes::ApiError;
|
||||||
use crate::{auth::get_user_from_headers, database};
|
use crate::{auth::get_user_from_headers, database};
|
||||||
use actix_web::{HttpRequest, HttpResponse, get, route, web};
|
use actix_web::{HttpRequest, HttpResponse, get, route, web};
|
||||||
use sqlx::PgPool;
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use yaserde::YaSerialize;
|
use yaserde::YaSerialize;
|
||||||
|
|
||||||
|
|||||||
@@ -105,11 +105,11 @@ pub enum ApiError {
|
|||||||
Env(#[from] dotenvy::Error),
|
Env(#[from] dotenvy::Error),
|
||||||
#[error("Error while uploading file: {0}")]
|
#[error("Error while uploading file: {0}")]
|
||||||
FileHosting(#[from] FileHostingError),
|
FileHosting(#[from] FileHostingError),
|
||||||
#[error("Database error: {0}")]
|
#[error("database error")]
|
||||||
Database(#[from] crate::database::models::DatabaseError),
|
Database(#[from] crate::database::models::DatabaseError),
|
||||||
#[error("SQLx database error: {0}")]
|
#[error("Postgres database error")]
|
||||||
SqlxDatabase(#[from] sqlx::Error),
|
SqlxDatabase(#[from] sqlx::Error),
|
||||||
#[error("Redis database error: {0}")]
|
#[error("redis database error")]
|
||||||
RedisDatabase(#[from] redis::RedisError),
|
RedisDatabase(#[from] redis::RedisError),
|
||||||
#[error("Clickhouse error: {0}")]
|
#[error("Clickhouse error: {0}")]
|
||||||
Clickhouse(#[from] clickhouse::error::Error),
|
Clickhouse(#[from] clickhouse::error::Error),
|
||||||
@@ -125,7 +125,7 @@ pub enum ApiError {
|
|||||||
Validation(String),
|
Validation(String),
|
||||||
#[error("Search error: {0}")]
|
#[error("Search error: {0}")]
|
||||||
Search(#[from] meilisearch_sdk::errors::Error),
|
Search(#[from] meilisearch_sdk::errors::Error),
|
||||||
#[error("Indexing error: {0}")]
|
#[error("search indexing error")]
|
||||||
Indexing(#[from] crate::search::indexing::IndexingError),
|
Indexing(#[from] crate::search::indexing::IndexingError),
|
||||||
#[error("Payments error: {0}")]
|
#[error("Payments error: {0}")]
|
||||||
Payments(String),
|
Payments(String),
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use crate::database::PgPool;
|
||||||
use actix_web::{HttpRequest, HttpResponse, get, web};
|
use actix_web::{HttpRequest, HttpResponse, get, web};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::PgPool;
|
|
||||||
|
|
||||||
use crate::auth::checks::{filter_visible_versions, is_visible_project};
|
use crate::auth::checks::{filter_visible_versions, is_visible_project};
|
||||||
use crate::auth::get_user_from_headers;
|
use crate::auth::get_user_from_headers;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use super::ApiError;
|
use super::ApiError;
|
||||||
|
use crate::database::PgPool;
|
||||||
use crate::models::projects::Project;
|
use crate::models::projects::Project;
|
||||||
use crate::models::v2::projects::LegacyProject;
|
use crate::models::v2::projects::LegacyProject;
|
||||||
use crate::queue::session::AuthQueue;
|
use crate::queue::session::AuthQueue;
|
||||||
@@ -6,7 +7,6 @@ use crate::routes::internal;
|
|||||||
use crate::{database::redis::RedisPool, routes::v2_reroute};
|
use crate::{database::redis::RedisPool, routes::v2_reroute};
|
||||||
use actix_web::{HttpRequest, HttpResponse, get, web};
|
use actix_web::{HttpRequest, HttpResponse, get, web};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use sqlx::PgPool;
|
|
||||||
|
|
||||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||||
cfg.service(web::scope("moderation").service(get_projects));
|
cfg.service(web::scope("moderation").service(get_projects));
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::database::PgPool;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use crate::models::ids::NotificationId;
|
use crate::models::ids::NotificationId;
|
||||||
use crate::models::notifications::Notification;
|
use crate::models::notifications::Notification;
|
||||||
@@ -8,7 +9,6 @@ use crate::routes::v2_reroute;
|
|||||||
use crate::routes::v3;
|
use crate::routes::v3;
|
||||||
use actix_web::{HttpRequest, HttpResponse, delete, get, patch, web};
|
use actix_web::{HttpRequest, HttpResponse, delete, get, patch, web};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::PgPool;
|
|
||||||
|
|
||||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||||
cfg.service(notifications_get);
|
cfg.service(notifications_get);
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::database::PgPool;
|
||||||
use crate::database::models::version_item;
|
use crate::database::models::version_item;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use crate::file_hosting::FileHost;
|
use crate::file_hosting::FileHost;
|
||||||
@@ -16,7 +17,6 @@ use actix_web::web::Data;
|
|||||||
use actix_web::{HttpRequest, HttpResponse, post};
|
use actix_web::{HttpRequest, HttpResponse, post};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use sqlx::postgres::PgPool;
|
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::database::PgPool;
|
||||||
use crate::database::models::categories::LinkPlatform;
|
use crate::database::models::categories::LinkPlatform;
|
||||||
use crate::database::models::{project_item, version_item};
|
use crate::database::models::{project_item, version_item};
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
@@ -18,7 +19,6 @@ use crate::search::{
|
|||||||
};
|
};
|
||||||
use actix_web::{HttpRequest, HttpResponse, delete, get, patch, post, web};
|
use actix_web::{HttpRequest, HttpResponse, delete, get, patch, post, web};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::PgPool;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::database::PgPool;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use crate::models::reports::Report;
|
use crate::models::reports::Report;
|
||||||
use crate::models::v2::reports::LegacyReport;
|
use crate::models::v2::reports::LegacyReport;
|
||||||
@@ -5,7 +6,6 @@ use crate::queue::session::AuthQueue;
|
|||||||
use crate::routes::{ApiError, v2_reroute, v3};
|
use crate::routes::{ApiError, v2_reroute, v3};
|
||||||
use actix_web::{HttpRequest, HttpResponse, delete, get, patch, post, web};
|
use actix_web::{HttpRequest, HttpResponse, delete, get, patch, post, web};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use sqlx::PgPool;
|
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
|
|
||||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
|
use crate::database::PgPool;
|
||||||
use crate::routes::{
|
use crate::routes::{
|
||||||
ApiError, v2_reroute,
|
ApiError, v2_reroute,
|
||||||
v3::{self, statistics::V3Stats},
|
v3::{self, statistics::V3Stats},
|
||||||
};
|
};
|
||||||
use actix_web::{HttpResponse, get, web};
|
use actix_web::{HttpResponse, get, web};
|
||||||
use sqlx::PgPool;
|
|
||||||
|
|
||||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||||
cfg.service(get_stats);
|
cfg.service(get_stats);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use super::ApiError;
|
use super::ApiError;
|
||||||
|
use crate::database::PgPool;
|
||||||
use crate::database::models::loader_fields::LoaderFieldEnumValue;
|
use crate::database::models::loader_fields::LoaderFieldEnumValue;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use crate::models::v2::projects::LegacySideType;
|
use crate::models::v2::projects::LegacySideType;
|
||||||
@@ -10,7 +11,6 @@ use crate::routes::{v2_reroute, v3};
|
|||||||
use actix_web::{HttpResponse, get, web};
|
use actix_web::{HttpResponse, get, web};
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use sqlx::PgPool;
|
|
||||||
|
|
||||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||||
cfg.service(
|
cfg.service(
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::database::PgPool;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use crate::models::ids::TeamId;
|
use crate::models::ids::TeamId;
|
||||||
use crate::models::teams::{
|
use crate::models::teams::{
|
||||||
@@ -10,7 +11,6 @@ use actix_web::{HttpRequest, HttpResponse, delete, get, patch, post, web};
|
|||||||
use ariadne::ids::UserId;
|
use ariadne::ids::UserId;
|
||||||
use rust_decimal::Decimal;
|
use rust_decimal::Decimal;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::PgPool;
|
|
||||||
|
|
||||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||||
cfg.service(teams_get);
|
cfg.service(teams_get);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use crate::database::PgPool;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use crate::file_hosting::FileHost;
|
use crate::file_hosting::FileHost;
|
||||||
use crate::models::ids::{ThreadId, ThreadMessageId};
|
use crate::models::ids::{ThreadId, ThreadMessageId};
|
||||||
@@ -9,7 +10,6 @@ use crate::queue::session::AuthQueue;
|
|||||||
use crate::routes::{ApiError, v2_reroute, v3};
|
use crate::routes::{ApiError, v2_reroute, v3};
|
||||||
use actix_web::{HttpRequest, HttpResponse, delete, get, post, web};
|
use actix_web::{HttpRequest, HttpResponse, delete, get, post, web};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use sqlx::PgPool;
|
|
||||||
|
|
||||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||||
cfg.service(
|
cfg.service(
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::database::PgPool;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use crate::file_hosting::FileHost;
|
use crate::file_hosting::FileHost;
|
||||||
use crate::models::notifications::Notification;
|
use crate::models::notifications::Notification;
|
||||||
@@ -10,7 +11,6 @@ use crate::queue::session::AuthQueue;
|
|||||||
use crate::routes::{ApiError, v2_reroute, v3};
|
use crate::routes::{ApiError, v2_reroute, v3};
|
||||||
use actix_web::{HttpRequest, HttpResponse, delete, get, patch, web};
|
use actix_web::{HttpRequest, HttpResponse, delete, get, patch, web};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::PgPool;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::database::PgPool;
|
||||||
use crate::database::models::loader_fields::VersionField;
|
use crate::database::models::loader_fields::VersionField;
|
||||||
use crate::database::models::{project_item, version_item};
|
use crate::database::models::{project_item, version_item};
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
@@ -18,7 +19,6 @@ use actix_web::web::Data;
|
|||||||
use actix_web::{HttpRequest, HttpResponse, post, web};
|
use actix_web::{HttpRequest, HttpResponse, post, web};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use sqlx::postgres::PgPool;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use super::ApiError;
|
use super::ApiError;
|
||||||
|
use crate::database::PgPool;
|
||||||
use crate::database::ReadOnlyPgPool;
|
use crate::database::ReadOnlyPgPool;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use crate::models::projects::{Project, Version, VersionType};
|
use crate::models::projects::{Project, Version, VersionType};
|
||||||
@@ -8,7 +9,6 @@ use crate::routes::v3::version_file::HashQuery;
|
|||||||
use crate::routes::{v2_reroute, v3};
|
use crate::routes::{v2_reroute, v3};
|
||||||
use actix_web::{HttpRequest, HttpResponse, delete, get, post, web};
|
use actix_web::{HttpRequest, HttpResponse, delete, get, post, web};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::PgPool;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use super::ApiError;
|
use super::ApiError;
|
||||||
|
use crate::database::PgPool;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use crate::models;
|
use crate::models;
|
||||||
use crate::models::ids::VersionId;
|
use crate::models::ids::VersionId;
|
||||||
@@ -13,7 +14,6 @@ use crate::routes::{v2_reroute, v3};
|
|||||||
use crate::search::SearchConfig;
|
use crate::search::SearchConfig;
|
||||||
use actix_web::{HttpRequest, HttpResponse, delete, get, patch, web};
|
use actix_web::{HttpRequest, HttpResponse, delete, get, patch, web};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::PgPool;
|
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
|
|
||||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||||
|
|||||||
@@ -11,13 +11,13 @@ mod old;
|
|||||||
|
|
||||||
use std::num::NonZeroU64;
|
use std::num::NonZeroU64;
|
||||||
|
|
||||||
|
use crate::database::PgPool;
|
||||||
use actix_web::{HttpRequest, post, web};
|
use actix_web::{HttpRequest, post, web};
|
||||||
use chrono::{DateTime, TimeDelta, Utc};
|
use chrono::{DateTime, TimeDelta, Utc};
|
||||||
use eyre::eyre;
|
use eyre::eyre;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use rust_decimal::Decimal;
|
use rust_decimal::Decimal;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::PgPool;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
auth::{AuthenticationError, get_user_from_headers},
|
auth::{AuthenticationError, get_user_from_headers},
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use super::ApiError;
|
use super::ApiError;
|
||||||
use crate::database;
|
use crate::database;
|
||||||
|
use crate::database::PgPool;
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
use crate::models::teams::ProjectPermissions;
|
use crate::models::teams::ProjectPermissions;
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -15,7 +16,6 @@ use ariadne::ids::base62_impl::to_base62;
|
|||||||
use chrono::{DateTime, Duration, Utc};
|
use chrono::{DateTime, Duration, Utc};
|
||||||
use eyre::eyre;
|
use eyre::eyre;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::PgPool;
|
|
||||||
use sqlx::postgres::types::PgInterval;
|
use sqlx::postgres::types::PgInterval;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use crate::auth::checks::is_visible_collection;
|
use crate::auth::checks::is_visible_collection;
|
||||||
use crate::auth::{filter_visible_collections, get_user_from_headers};
|
use crate::auth::{filter_visible_collections, get_user_from_headers};
|
||||||
|
use crate::database::PgPool;
|
||||||
use crate::database::models::{
|
use crate::database::models::{
|
||||||
collection_item, generate_collection_id, project_item,
|
collection_item, generate_collection_id, project_item,
|
||||||
};
|
};
|
||||||
@@ -24,7 +25,6 @@ use chrono::Utc;
|
|||||||
use eyre::eyre;
|
use eyre::eyre;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::PgPool;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
|
|
||||||
@@ -96,7 +96,7 @@ pub async fn collection_create(
|
|||||||
|
|
||||||
let initial_project_ids = project_item::DBProject::get_many(
|
let initial_project_ids = project_item::DBProject::get_many(
|
||||||
&collection_create_data.projects,
|
&collection_create_data.projects,
|
||||||
&mut *transaction,
|
&mut transaction,
|
||||||
&redis,
|
&redis,
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
@@ -274,7 +274,7 @@ pub async fn collection_edit(
|
|||||||
name.trim(),
|
name.trim(),
|
||||||
id as database::models::ids::DBCollectionId,
|
id as database::models::ids::DBCollectionId,
|
||||||
)
|
)
|
||||||
.execute(&mut *transaction)
|
.execute(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,7 +288,7 @@ pub async fn collection_edit(
|
|||||||
description.as_ref(),
|
description.as_ref(),
|
||||||
id as database::models::ids::DBCollectionId,
|
id as database::models::ids::DBCollectionId,
|
||||||
)
|
)
|
||||||
.execute(&mut *transaction)
|
.execute(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,7 +311,7 @@ pub async fn collection_edit(
|
|||||||
status.to_string(),
|
status.to_string(),
|
||||||
id as database::models::ids::DBCollectionId,
|
id as database::models::ids::DBCollectionId,
|
||||||
)
|
)
|
||||||
.execute(&mut *transaction)
|
.execute(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -324,7 +324,7 @@ pub async fn collection_edit(
|
|||||||
",
|
",
|
||||||
collection_item.id as database::models::ids::DBCollectionId,
|
collection_item.id as database::models::ids::DBCollectionId,
|
||||||
)
|
)
|
||||||
.execute(&mut *transaction)
|
.execute(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let collection_item_ids = new_project_ids
|
let collection_item_ids = new_project_ids
|
||||||
@@ -352,7 +352,7 @@ pub async fn collection_edit(
|
|||||||
&collection_item_ids[..],
|
&collection_item_ids[..],
|
||||||
&validated_project_ids[..],
|
&validated_project_ids[..],
|
||||||
)
|
)
|
||||||
.execute(&mut *transaction)
|
.execute(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
@@ -363,7 +363,7 @@ pub async fn collection_edit(
|
|||||||
",
|
",
|
||||||
collection_item.id as database::models::ids::DBCollectionId,
|
collection_item.id as database::models::ids::DBCollectionId,
|
||||||
)
|
)
|
||||||
.execute(&mut *transaction)
|
.execute(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -458,7 +458,7 @@ pub async fn collection_icon_edit(
|
|||||||
upload_result.color.map(|x| x as i32),
|
upload_result.color.map(|x| x as i32),
|
||||||
collection_item.id as database::models::ids::DBCollectionId,
|
collection_item.id as database::models::ids::DBCollectionId,
|
||||||
)
|
)
|
||||||
.execute(&mut *transaction)
|
.execute(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
transaction.commit().await?;
|
transaction.commit().await?;
|
||||||
@@ -517,7 +517,7 @@ pub async fn delete_collection_icon(
|
|||||||
",
|
",
|
||||||
collection_item.id as database::models::ids::DBCollectionId,
|
collection_item.id as database::models::ids::DBCollectionId,
|
||||||
)
|
)
|
||||||
.execute(&mut *transaction)
|
.execute(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
transaction.commit().await?;
|
transaction.commit().await?;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use crate::auth::get_user_from_headers;
|
use crate::auth::get_user_from_headers;
|
||||||
|
use crate::database::PgPool;
|
||||||
use crate::database::models::friend_item::DBFriend;
|
use crate::database::models::friend_item::DBFriend;
|
||||||
use crate::database::models::{DBUser, DBUserId};
|
use crate::database::models::{DBUser, DBUserId};
|
||||||
use crate::database::redis::RedisPool;
|
use crate::database::redis::RedisPool;
|
||||||
@@ -15,7 +16,6 @@ use crate::sync::status::get_user_status;
|
|||||||
use actix_web::{HttpRequest, HttpResponse, delete, get, post, web};
|
use actix_web::{HttpRequest, HttpResponse, delete, get, post, web};
|
||||||
use ariadne::networking::message::ServerToClientMessage;
|
use ariadne::networking::message::ServerToClientMessage;
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use sqlx::PgPool;
|
|
||||||
|
|
||||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||||
cfg.service(add_friend);
|
cfg.service(add_friend);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use super::threads::is_authorized_thread;
|
|||||||
use crate::auth::checks::{is_team_member_project, is_team_member_version};
|
use crate::auth::checks::{is_team_member_project, is_team_member_version};
|
||||||
use crate::auth::get_user_from_headers;
|
use crate::auth::get_user_from_headers;
|
||||||
use crate::database;
|
use crate::database;
|
||||||
|
use crate::database::PgPool;
|
||||||
use crate::database::models::{
|
use crate::database::models::{
|
||||||
project_item, report_item, thread_item, version_item,
|
project_item, report_item, thread_item, version_item,
|
||||||
};
|
};
|
||||||
@@ -17,7 +18,6 @@ use crate::util::img::upload_image_optimized;
|
|||||||
use crate::util::routes::read_limited_from_payload;
|
use crate::util::routes::read_limited_from_payload;
|
||||||
use actix_web::{HttpRequest, HttpResponse, web};
|
use actix_web::{HttpRequest, HttpResponse, web};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::PgPool;
|
|
||||||
|
|
||||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||||
cfg.route("image", web::post().to(images_add));
|
cfg.route("image", web::post().to(images_add));
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::database::PgPool;
|
||||||
use crate::{
|
use crate::{
|
||||||
auth::get_user_from_headers,
|
auth::get_user_from_headers,
|
||||||
database::redis::RedisPool,
|
database::redis::RedisPool,
|
||||||
@@ -6,7 +7,6 @@ use crate::{
|
|||||||
routes::ApiError,
|
routes::ApiError,
|
||||||
};
|
};
|
||||||
use actix_web::{HttpRequest, web};
|
use actix_web::{HttpRequest, web};
|
||||||
use sqlx::PgPool;
|
|
||||||
|
|
||||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||||
cfg.service(
|
cfg.service(
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user