i fucking hate this

This commit is contained in:
SadlyNotSappho 2024-01-16 12:03:26 -08:00
parent d124907f47
commit 3a5fbbfb9b
7 changed files with 153 additions and 21 deletions

141
Cargo.lock generated
View File

@ -333,6 +333,7 @@ dependencies = [
"diesel_derives", "diesel_derives",
"itoa", "itoa",
"pq-sys", "pq-sys",
"r2d2",
] ]
[[package]] [[package]]
@ -362,6 +363,17 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "diesel_migrations"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6036b3f0120c5961381b570ee20a02432d7e2d27ea60de9578799cf9156914ac"
dependencies = [
"diesel",
"migrations_internals",
"migrations_macros",
]
[[package]] [[package]]
name = "diesel_table_macro_syntax" name = "diesel_table_macro_syntax"
version = "0.1.0" version = "0.1.0"
@ -434,7 +446,7 @@ dependencies = [
"atomic 0.6.0", "atomic 0.6.0",
"pear", "pear",
"serde", "serde",
"toml", "toml 0.8.8",
"uncased", "uncased",
"version_check", "version_check",
] ]
@ -456,8 +468,10 @@ name = "fossil"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"diesel", "diesel",
"diesel_migrations",
"rocket", "rocket",
"rocket_db_pools", "rocket_db_pools",
"rocket_sync_db_pools",
] ]
[[package]] [[package]]
@ -761,9 +775,9 @@ checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"
[[package]] [[package]]
name = "js-sys" name = "js-sys"
version = "0.3.66" version = "0.3.67"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cee9c64da59eae3b50095c18d3e74f8b73c0b86d2792824ff01bbce68ba229ca" checksum = "9a1d36f1235bc969acba30b7f5990b864423a6068a10f7c90ae8f0112e3a59d1"
dependencies = [ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
@ -842,6 +856,27 @@ version = "2.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
[[package]]
name = "migrations_internals"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f23f71580015254b020e856feac3df5878c2c7a8812297edd6c0a485ac9dada"
dependencies = [
"serde",
"toml 0.7.8",
]
[[package]]
name = "migrations_macros"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cce3325ac70e67bbab5bd837a31cae01f1a6db64e0e744a33cb03a543469ef08"
dependencies = [
"migrations_internals",
"proc-macro2",
"quote",
]
[[package]] [[package]]
name = "mime" name = "mime"
version = "0.3.17" version = "0.3.17"
@ -1110,6 +1145,17 @@ dependencies = [
"proc-macro2", "proc-macro2",
] ]
[[package]]
name = "r2d2"
version = "0.8.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51de85fb3fb6524929c8a2eb85e6b6d363de4e8c48f9e2c2eac4944abc181c93"
dependencies = [
"log",
"parking_lot",
"scheduled-thread-pool",
]
[[package]] [[package]]
name = "rand" name = "rand"
version = "0.8.5" version = "0.8.5"
@ -1325,6 +1371,31 @@ dependencies = [
"uncased", "uncased",
] ]
[[package]]
name = "rocket_sync_db_pools"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d83f32721ed79509adac4328e97f817a8f55a47c4b64799f6fd6cc3adb6e42ff"
dependencies = [
"diesel",
"r2d2",
"rocket",
"rocket_sync_db_pools_codegen",
"serde",
"tokio",
"version_check",
]
[[package]]
name = "rocket_sync_db_pools_codegen"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5cc890925dc79370c28eb15c9957677093fdb7e8c44966d189f38cedb995ee68"
dependencies = [
"devise",
"quote",
]
[[package]] [[package]]
name = "rustc-demangle" name = "rustc-demangle"
version = "0.1.23" version = "0.1.23"
@ -1356,6 +1427,15 @@ version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
[[package]]
name = "scheduled-thread-pool"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3cbc66816425a074528352f5789333ecff06ca41b36b0b0efdfbb29edc391a19"
dependencies = [
"parking_lot",
]
[[package]] [[package]]
name = "scoped-futures" name = "scoped-futures"
version = "0.1.3" version = "0.1.3"
@ -1687,6 +1767,18 @@ dependencies = [
"tracing", "tracing",
] ]
[[package]]
name = "toml"
version = "0.7.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd79e69d3b627db300ff956027cc6c3798cef26d22526befdfcd12feeb6d2257"
dependencies = [
"serde",
"serde_spanned",
"toml_datetime",
"toml_edit 0.19.15",
]
[[package]] [[package]]
name = "toml" name = "toml"
version = "0.8.8" version = "0.8.8"
@ -1696,7 +1788,7 @@ dependencies = [
"serde", "serde",
"serde_spanned", "serde_spanned",
"toml_datetime", "toml_datetime",
"toml_edit", "toml_edit 0.21.0",
] ]
[[package]] [[package]]
@ -1708,6 +1800,19 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "toml_edit"
version = "0.19.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421"
dependencies = [
"indexmap 2.1.0",
"serde",
"serde_spanned",
"toml_datetime",
"winnow",
]
[[package]] [[package]]
name = "toml_edit" name = "toml_edit"
version = "0.21.0" version = "0.21.0"
@ -1821,9 +1926,9 @@ dependencies = [
[[package]] [[package]]
name = "unicode-bidi" name = "unicode-bidi"
version = "0.3.13" version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" checksum = "6f2528f27a9eb2b21e69c95319b30bd0efd85d09c379741b0f78ea1d86be2416"
[[package]] [[package]]
name = "unicode-ident" name = "unicode-ident"
@ -1891,9 +1996,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]] [[package]]
name = "wasm-bindgen" name = "wasm-bindgen"
version = "0.2.89" version = "0.2.90"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e" checksum = "b1223296a201415c7fad14792dbefaace9bd52b62d33453ade1c5b5f07555406"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"wasm-bindgen-macro", "wasm-bindgen-macro",
@ -1901,9 +2006,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-backend" name = "wasm-bindgen-backend"
version = "0.2.89" version = "0.2.90"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826" checksum = "fcdc935b63408d58a32f8cc9738a0bffd8f05cc7c002086c6ef20b7312ad9dcd"
dependencies = [ dependencies = [
"bumpalo", "bumpalo",
"log", "log",
@ -1916,9 +2021,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro" name = "wasm-bindgen-macro"
version = "0.2.89" version = "0.2.90"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0162dbf37223cd2afce98f3d0785506dcb8d266223983e4b5b525859e6e182b2" checksum = "3e4c238561b2d428924c49815533a8b9121c664599558a5d9ec51f8a1740a999"
dependencies = [ dependencies = [
"quote", "quote",
"wasm-bindgen-macro-support", "wasm-bindgen-macro-support",
@ -1926,9 +2031,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro-support" name = "wasm-bindgen-macro-support"
version = "0.2.89" version = "0.2.90"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" checksum = "bae1abb6806dc1ad9e560ed242107c0f6c84335f1749dd4e8ddb012ebd5e25a7"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1939,15 +2044,15 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-shared" name = "wasm-bindgen-shared"
version = "0.2.89" version = "0.2.90"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" checksum = "4d91413b1c31d7539ba5ef2451af3f0b833a005eb27a631cec32bc0635a8602b"
[[package]] [[package]]
name = "web-sys" name = "web-sys"
version = "0.3.66" version = "0.3.67"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50c24a44ec86bb68fbecd1b3efed7e85ea5621b39b35ef2766b66cd984f8010f" checksum = "58cd2333b6e0be7a39605f0e255892fd7418a682d8da8fe042fe25128794d2ed"
dependencies = [ dependencies = [
"js-sys", "js-sys",
"wasm-bindgen", "wasm-bindgen",

View File

@ -7,5 +7,7 @@ edition = "2021"
[dependencies] [dependencies]
diesel = { version = "2.1.4", features = ["postgres"] } diesel = { version = "2.1.4", features = ["postgres"] }
diesel_migrations = { version = "2.1.0", features = ["postgres"] }
rocket = {version="0.5.0",features=["secrets","json"]} rocket = {version="0.5.0",features=["secrets","json"]}
rocket_db_pools = {version="0.1.0",features=["diesel_postgres"]} rocket_db_pools = {version="0.1.0",features=["diesel_postgres"]}
rocket_sync_db_pools = { version = "0.1.0", features = ["diesel_postgres_pool", "diesel"] }

View File

@ -25,7 +25,7 @@ RUN --mount=type=bind,source=src,target=src \
--mount=type=bind,source=Cargo.lock,target=Cargo.lock \ --mount=type=bind,source=Cargo.lock,target=Cargo.lock \
--mount=type=cache,target=/app/target/ \ --mount=type=cache,target=/app/target/ \
--mount=type=cache,target=/usr/local/cargo/registry/ \ --mount=type=cache,target=/usr/local/cargo/registry/ \
--mount=type=bind,source=migrations,target=migrations \ --mount=type=bind,source=db,target=/srv/db \
<<EOF <<EOF
set -e set -e
cargo build --locked --release cargo build --locked --release
@ -44,6 +44,7 @@ EOF
# reproducability is important, consider using a digest # reproducability is important, consider using a digest
# (e.g., debian@sha256:ac707220fbd7b67fc19b112cee8170b41a9e97f703f588b2cdbbcdcecdd8af57). # (e.g., debian@sha256:ac707220fbd7b67fc19b112cee8170b41a9e97f703f588b2cdbbcdcecdd8af57).
FROM debian:stable-slim AS final FROM debian:stable-slim AS final
WORKDIR /
# Create a non-privileged user that the app will run under. # Create a non-privileged user that the app will run under.
# See https://docs.docker.com/develop/develop-images/dockerfile_best-practices/ #user # See https://docs.docker.com/develop/develop-images/dockerfile_best-practices/ #user
@ -64,6 +65,8 @@ USER appuser
# Copy the executable from the "build" stage. # Copy the executable from the "build" stage.
COPY --from=build /bin/server /bin/ COPY --from=build /bin/server /bin/
ADD ./db /srv/db
# Expose the port that the application listens on. # Expose the port that the application listens on.
EXPOSE 8000 EXPOSE 8000

View File

@ -0,0 +1,6 @@
CREATE TABLE posts (
id SERIAL PRIMARY KEY,
title VARCHAR NOT NULL,
body TEXT NOT NULL,
published BOOLEAN NOT NULL DEFAULT FALSE
)

View File

@ -1 +0,0 @@
password goes here!!!

View File

@ -1,12 +1,15 @@
use rocket::fairing::AdHoc;
use rocket::http::Status; use rocket::http::Status;
use rocket::response::content::{self, RawHtml}; use rocket::response::content::{self, RawHtml};
use rocket::Request; use rocket::{Build, Request, Rocket};
use rocket_db_pools::diesel; use rocket_db_pools::diesel;
use rocket_db_pools::diesel::{prelude::*, PgPool, QueryResult}; use rocket_db_pools::diesel::{prelude::*, PgPool, QueryResult};
use rocket_db_pools::{Connection, Database}; use rocket_db_pools::{Connection, Database};
use rocket_sync_db_pools::database;
use std::fs; use std::fs;
#[macro_use] #[macro_use]
extern crate rocket; extern crate rocket;
use rocket::serde::{json::Json, Deserialize}; use rocket::serde::{json::Json, Deserialize};
use rocket::{ use rocket::{
fs::FileServer, fs::FileServer,
@ -105,10 +108,24 @@ fn default_catcher(status: Status, _: &Request) -> RawHtml<String> {
) )
} }
// #[get("/migratetest")]
async fn migrate(mut rocket: Rocket<Build>) -> Rocket<Build> {
let db = Db::fetch(&rocket).unwrap().get().await;
let post_ids: Vec<i64> = posts::table
.select(posts::id)
.load(&mut db)
.await
.unwrap();
rocket
}
#[rocket::main] #[rocket::main]
async fn main() { async fn main() {
let _rocket = rocket::build() let _rocket = rocket::build()
.attach(Db::init()) .attach(Db::init())
.attach(AdHoc::on_ignite("DB Migrations", migrate))
.mount("/", routes![hello, get_book, delay, login, logout, dbtest]) .mount("/", routes![hello, get_book, delay, login, logout, dbtest])
.register("/", catchers![default_catcher]) .register("/", catchers![default_catcher])
.mount("/login", FileServer::from("/srv/web")) .mount("/login", FileServer::from("/srv/web"))