From ba4216c21ecd617b8a0f1e121a4d3baf30d69a43 Mon Sep 17 00:00:00 2001 From: Louis Hollingworth Date: Thu, 26 Oct 2023 18:14:26 +0100 Subject: [PATCH] (feat) Switched to sqlx. Signed-off-by: Louis Hollingworth --- .gitignore | 1 + Cargo.lock | 1040 +++++++++++++---- Cargo.toml | 8 +- diesel.toml | 13 - migrations/.keep | 0 .../up.sql | 42 - .../2023-10-15-172149_create_posts/down.sql | 6 - .../2023-10-15-172149_create_posts/up.sql | 17 - .../2023-10-15-172156_create_blogs/down.sql | 6 - .../2023-10-15-172156_create_blogs/up.sql | 18 - .../down.sql | 8 - .../up.sql | 8 - .../down.sql => 20231026121809_init.down.sql} | 5 +- migrations/20231026121809_init.up.sql | 24 + ...l => 20231026131105_create_users.down.sql} | 2 +- ...sql => 20231026131105_create_users.up.sql} | 11 +- src/lib.rs | 55 +- src/main.rs | 114 +- src/models.rs | 71 -- src/models/mod.rs | 5 + src/models/user.rs | 28 + src/schema.rs | 54 - 22 files changed, 957 insertions(+), 579 deletions(-) delete mode 100644 diesel.toml delete mode 100644 migrations/.keep delete mode 100644 migrations/00000000000000_diesel_initial_setup/up.sql delete mode 100644 migrations/2023-10-15-172149_create_posts/down.sql delete mode 100644 migrations/2023-10-15-172149_create_posts/up.sql delete mode 100644 migrations/2023-10-15-172156_create_blogs/down.sql delete mode 100644 migrations/2023-10-15-172156_create_blogs/up.sql delete mode 100644 migrations/2023-10-17-164429_posts_add_blog_ref/down.sql delete mode 100644 migrations/2023-10-17-164429_posts_add_blog_ref/up.sql rename migrations/{00000000000000_diesel_initial_setup/down.sql => 20231026121809_init.down.sql} (52%) create mode 100644 migrations/20231026121809_init.up.sql rename migrations/{2023-10-15-172140_create_users/down.sql => 20231026131105_create_users.down.sql} (75%) rename migrations/{2023-10-15-172140_create_users/up.sql => 20231026131105_create_users.up.sql} (68%) delete mode 100644 src/models.rs create mode 100644 src/models/mod.rs create mode 100644 src/models/user.rs delete mode 100644 src/schema.rs diff --git a/.gitignore b/.gitignore index 43e427c..b14ddbe 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ /target .DS_Store .env +/.sqlx diff --git a/Cargo.lock b/Cargo.lock index 46357d8..6eb1c4f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,6 +23,25 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a" +dependencies = [ + "cfg-if", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "allocator-api2" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" + [[package]] name = "android-tzdata" version = "0.1.1" @@ -38,6 +57,12 @@ dependencies = [ "libc", ] +[[package]] +name = "anyhow" +version = "1.0.75" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" + [[package]] name = "argon2" version = "0.5.2" @@ -58,7 +83,16 @@ checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.38", +] + +[[package]] +name = "atoi" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28d99ec8bfea296261ca1af174f24225171fea9664ba9003cbebee704810528" +dependencies = [ + "num-traits", ] [[package]] @@ -132,7 +166,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn", + "syn 2.0.38", ] [[package]] @@ -150,25 +184,18 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.21.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" + [[package]] name = "base64ct" version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" -[[package]] -name = "bigdecimal" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06619be423ea5bb86c95f087d5707942791a08a85530df0db2209a3ecfb8bc9" -dependencies = [ - "autocfg", - "libm", - "num-bigint", - "num-integer", - "num-traits", -] - [[package]] name = "bitflags" version = "1.3.2" @@ -180,6 +207,9 @@ name = "bitflags" version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +dependencies = [ + "serde", +] [[package]] name = "blake2" @@ -247,6 +277,12 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "const-oid" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28c122c3980598d243d63d9a704629a2d748d101f278052ff068be5a4423ab6f" + [[package]] name = "core-foundation-sys" version = "0.8.4" @@ -262,6 +298,40 @@ dependencies = [ "libc", ] +[[package]] +name = "crc" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86ec7a15cbe22e59248fc7eadb1907dab5ba09372595da4d73dd805ed4417dfe" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cace84e55f07e7301bae1c519df89cdad8cc3cd868413d3fdbdeca9ff3db484" + +[[package]] +name = "crossbeam-queue" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1cfb3ea8a53f37c40dea2c7bedcbd88bdfae54f5e2175d6ecaff1c988353add" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" +dependencies = [ + "cfg-if", +] + [[package]] name = "crypto" version = "0.5.1" @@ -283,68 +353,14 @@ dependencies = [ ] [[package]] -name = "deranged" -version = "0.3.9" +name = "der" +version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f32d04922c60427da6f9fef14d042d9edddef64cb9d4ce0d64d0685fbeb1fd3" +checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" dependencies = [ - "powerfmt", -] - -[[package]] -name = "diesel" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2268a214a6f118fce1838edba3d1561cf0e78d8de785475957a580a7f8c69d33" -dependencies = [ - "bigdecimal", - "bitflags 2.4.1", - "byteorder", - "chrono", - "diesel_derives", - "ipnetwork", - "itoa", - "libc", - "num-bigint", - "num-integer", - "num-traits", - "pq-sys", - "r2d2", - "serde_json", - "time", - "uuid", -] - -[[package]] -name = "diesel_derives" -version = "2.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef8337737574f55a468005a83499da720f20c65586241ffea339db9ecdfd2b44" -dependencies = [ - "diesel_table_macro_syntax", - "proc-macro2", - "quote", - "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]] -name = "diesel_table_macro_syntax" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc5557efc453706fed5e4fa85006fe9817c224c3f480a34c7e5959fd700921c5" -dependencies = [ - "syn", + "const-oid", + "pem-rfc7468", + "zeroize", ] [[package]] @@ -354,6 +370,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", + "const-oid", "crypto-common", "subtle", ] @@ -364,30 +381,90 @@ version = "0.15.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" +[[package]] +name = "either" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +dependencies = [ + "serde", +] + [[package]] name = "equivalent" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "errno" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3e13f66a2f95e32a39eaa81f6b95d42878ca0e1db0c7543723dfe12557e860" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "etcetera" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "136d1b5283a1ab77bd9257427ffd09d8667ced0570b6f938942bc7568ed5b943" +dependencies = [ + "cfg-if", + "home", + "windows-sys", +] + +[[package]] +name = "event-listener" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + +[[package]] +name = "fastrand" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" + [[package]] name = "fediblog" version = "0.1.0" dependencies = [ + "anyhow", "argon2", "axum", "chrono", "crypto", - "diesel", - "diesel_migrations", "dotenvy", "rand", "serde", "serde_json", + "sqlx", + "thiserror", "tokio", "uuid", ] +[[package]] +name = "finl_unicode" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fcfdc7a0362c9f4444381a9e697c79d435fe65b52a37466fc2c1184cee9edc6" + +[[package]] +name = "flume" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55ac459de2512911e4b674ce33cf20befaba382d05b62b008afc1c8b57cbf181" +dependencies = [ + "futures-core", + "futures-sink", + "spin 0.9.8", +] + [[package]] name = "fnv" version = "1.0.7" @@ -410,6 +487,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" dependencies = [ "futures-core", + "futures-sink", ] [[package]] @@ -418,6 +496,40 @@ version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" +[[package]] +name = "futures-executor" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-intrusive" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d930c203dd0b6ff06e0201a4a2fe9149b43c684fd4420555b26d21b1a02956f" +dependencies = [ + "futures-core", + "lock_api", + "parking_lot", +] + +[[package]] +name = "futures-io" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" + +[[package]] +name = "futures-sink" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" + [[package]] name = "futures-task" version = "0.3.28" @@ -431,9 +543,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" dependencies = [ "futures-core", + "futures-io", + "futures-sink", "futures-task", + "memchr", "pin-project-lite", "pin-utils", + "slab", ] [[package]] @@ -468,12 +584,28 @@ name = "hashbrown" version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156" +dependencies = [ + "ahash", + "allocator-api2", +] + +[[package]] +name = "hashlink" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8094feaf31ff591f651a2664fb9cfd92bba7a60ce3197265e9482ebe753c8f7" +dependencies = [ + "hashbrown", +] [[package]] name = "heck" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +dependencies = [ + "unicode-segmentation", +] [[package]] name = "hermit-abi" @@ -481,6 +613,39 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hkdf" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "791a029f6b9fc27657f6f188ec6e5e43f6911f6f878e0dc5501396e09809d437" +dependencies = [ + "hmac", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] +name = "home" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" +dependencies = [ + "windows-sys", +] + [[package]] name = "http" version = "0.2.9" @@ -561,6 +726,16 @@ dependencies = [ "cc", ] +[[package]] +name = "idna" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "indexmap" version = "2.0.2" @@ -572,12 +747,12 @@ dependencies = [ ] [[package]] -name = "ipnetwork" -version = "0.20.0" +name = "itertools" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf466541e9d546596ee94f9f69590f89473455f88372423e0008fc1a7daf100e" +checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" dependencies = [ - "serde", + "either", ] [[package]] @@ -595,6 +770,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +dependencies = [ + "spin 0.5.2", +] + [[package]] name = "libc" version = "0.2.149" @@ -607,6 +791,23 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" +[[package]] +name = "libsqlite3-sys" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc22eff61b133b115c6e8c74e818c628d6d5e7a502afea6f64dee076dd94326" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "linux-raw-sys" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f" + [[package]] name = "lock_api" version = "0.4.11" @@ -629,39 +830,34 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" +[[package]] +name = "md-5" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" +dependencies = [ + "cfg-if", + "digest", +] + [[package]] name = "memchr" version = "2.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" 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", -] - -[[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]] name = "mime" version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" version = "0.7.1" @@ -683,14 +879,30 @@ dependencies = [ ] [[package]] -name = "num-bigint" -version = "0.4.4" +name = "nom" +version = "7.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" dependencies = [ - "autocfg", + "memchr", + "minimal-lexical", +] + +[[package]] +name = "num-bigint-dig" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc84195820f291c7697304f3cbdadd1cb7199c0efc917ff5eafd71225c136151" +dependencies = [ + "byteorder", + "lazy_static", + "libm", "num-integer", + "num-iter", "num-traits", + "rand", + "smallvec", + "zeroize", ] [[package]] @@ -703,6 +915,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-iter" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.17" @@ -710,6 +933,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", + "libm", ] [[package]] @@ -755,7 +979,7 @@ checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" dependencies = [ "cfg-if", "libc", - "redox_syscall", + "redox_syscall 0.4.1", "smallvec", "windows-targets", ] @@ -771,6 +995,21 @@ dependencies = [ "subtle", ] +[[package]] +name = "paste" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" + +[[package]] +name = "pem-rfc7468" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +dependencies = [ + "base64ct", +] + [[package]] name = "percent-encoding" version = "2.3.0" @@ -794,7 +1033,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.38", ] [[package]] @@ -810,10 +1049,31 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] -name = "powerfmt" -version = "0.2.0" +name = "pkcs1" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" +checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" +dependencies = [ + "der", + "pkcs8", + "spki", +] + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "pkg-config" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" [[package]] name = "ppv-lite86" @@ -821,15 +1081,6 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" -[[package]] -name = "pq-sys" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31c0052426df997c0cbd30789eb44ca097e3541717a7b8fa36b1c464ee7edebd" -dependencies = [ - "vcpkg", -] - [[package]] name = "proc-macro2" version = "1.0.69" @@ -848,17 +1099,6 @@ dependencies = [ "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]] name = "rand" version = "0.8.5" @@ -889,6 +1129,15 @@ dependencies = [ "getrandom", ] +[[package]] +name = "redox_syscall" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +dependencies = [ + "bitflags 1.3.2", +] + [[package]] name = "redox_syscall" version = "0.4.1" @@ -898,12 +1147,47 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "rsa" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ab43bb47d23c1a631b4b680199a45255dce26fa9ab2fa902581f624ff13e6a8" +dependencies = [ + "byteorder", + "const-oid", + "digest", + "num-bigint-dig", + "num-integer", + "num-iter", + "num-traits", + "pkcs1", + "pkcs8", + "rand_core", + "signature", + "spki", + "subtle", + "zeroize", +] + [[package]] name = "rustc-demangle" version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +[[package]] +name = "rustix" +version = "0.38.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67ce50cb2e16c2903e30d1cbccfd8387a74b9d4c938b6a4c5ec6cc7556f7a8a0" +dependencies = [ + "bitflags 2.4.1", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + [[package]] name = "rustversion" version = "1.0.14" @@ -916,15 +1200,6 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" 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]] name = "scopeguard" version = "1.2.0" @@ -948,7 +1223,7 @@ checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.38", ] [[package]] @@ -972,15 +1247,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_spanned" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12022b835073e5b11e90a14f86838ceb1c8fb0325b72416845c487ac0fa95e80" -dependencies = [ - "serde", -] - [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -993,6 +1259,28 @@ dependencies = [ "serde", ] +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "signal-hook-registry" version = "1.4.1" @@ -1002,6 +1290,25 @@ dependencies = [ "libc", ] +[[package]] +name = "signature" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e1788eed21689f9cf370582dfc467ef36ed9c707f073528ddafa8d83e3b8500" +dependencies = [ + "digest", + "rand_core", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + [[package]] name = "smallvec" version = "1.11.1" @@ -1028,12 +1335,273 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "spki" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d1e996ef02c474957d681f1b05213dfb0abab947b446a62d37770b23500184a" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "sqlformat" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b7b278788e7be4d0d29c0f39497a0eef3fba6bbc8e70d8bf7fde46edeaa9e85" +dependencies = [ + "itertools", + "nom", + "unicode_categories", +] + +[[package]] +name = "sqlx" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e50c216e3624ec8e7ecd14c6a6a6370aad6ee5d8cfc3ab30b5162eeeef2ed33" +dependencies = [ + "sqlx-core", + "sqlx-macros", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", +] + +[[package]] +name = "sqlx-core" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d6753e460c998bbd4cd8c6f0ed9a64346fcca0723d6e75e52fdc351c5d2169d" +dependencies = [ + "ahash", + "atoi", + "byteorder", + "bytes", + "chrono", + "crc", + "crossbeam-queue", + "dotenvy", + "either", + "event-listener", + "futures-channel", + "futures-core", + "futures-intrusive", + "futures-io", + "futures-util", + "hashlink", + "hex", + "indexmap", + "log", + "memchr", + "once_cell", + "paste", + "percent-encoding", + "serde", + "serde_json", + "sha2", + "smallvec", + "sqlformat", + "thiserror", + "tokio", + "tokio-stream", + "tracing", + "url", + "uuid", +] + +[[package]] +name = "sqlx-macros" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a793bb3ba331ec8359c1853bd39eed32cdd7baaf22c35ccf5c92a7e8d1189ec" +dependencies = [ + "proc-macro2", + "quote", + "sqlx-core", + "sqlx-macros-core", + "syn 1.0.109", +] + +[[package]] +name = "sqlx-macros-core" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a4ee1e104e00dedb6aa5ffdd1343107b0a4702e862a84320ee7cc74782d96fc" +dependencies = [ + "dotenvy", + "either", + "heck", + "hex", + "once_cell", + "proc-macro2", + "quote", + "serde", + "serde_json", + "sha2", + "sqlx-core", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", + "syn 1.0.109", + "tempfile", + "tokio", + "url", +] + +[[package]] +name = "sqlx-mysql" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "864b869fdf56263f4c95c45483191ea0af340f9f3e3e7b4d57a61c7c87a970db" +dependencies = [ + "atoi", + "base64", + "bitflags 2.4.1", + "byteorder", + "bytes", + "chrono", + "crc", + "digest", + "dotenvy", + "either", + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "generic-array", + "hex", + "hkdf", + "hmac", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "percent-encoding", + "rand", + "rsa", + "serde", + "sha1", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror", + "tracing", + "uuid", + "whoami", +] + +[[package]] +name = "sqlx-postgres" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb7ae0e6a97fb3ba33b23ac2671a5ce6e3cabe003f451abd5a56e7951d975624" +dependencies = [ + "atoi", + "base64", + "bitflags 2.4.1", + "byteorder", + "chrono", + "crc", + "dotenvy", + "etcetera", + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "hex", + "hkdf", + "hmac", + "home", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "rand", + "serde", + "serde_json", + "sha1", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror", + "tracing", + "uuid", + "whoami", +] + +[[package]] +name = "sqlx-sqlite" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d59dc83cf45d89c555a577694534fcd1b55c545a816c816ce51f20bbe56a4f3f" +dependencies = [ + "atoi", + "chrono", + "flume", + "futures-channel", + "futures-core", + "futures-executor", + "futures-intrusive", + "futures-util", + "libsqlite3-sys", + "log", + "percent-encoding", + "serde", + "sqlx-core", + "tracing", + "url", + "uuid", +] + +[[package]] +name = "stringprep" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb41d74e231a107a1b4ee36bd1214b11285b77768d2e3824aedafa988fd36ee6" +dependencies = [ + "finl_unicode", + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "subtle" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn" version = "2.0.38" @@ -1052,33 +1620,53 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" [[package]] -name = "time" -version = "0.3.30" +name = "tempfile" +version = "3.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5" +checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" dependencies = [ - "deranged", - "powerfmt", - "serde", - "time-core", - "time-macros", + "cfg-if", + "fastrand", + "redox_syscall 0.3.5", + "rustix", + "windows-sys", ] [[package]] -name = "time-core" -version = "0.1.2" +name = "thiserror" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" +checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" +dependencies = [ + "thiserror-impl", +] [[package]] -name = "time-macros" -version = "0.2.15" +name = "thiserror-impl" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ad70d68dba9e1f8aceda7aa6711965dfec1cac869f311a51bd08b3a2ccbce20" +checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" dependencies = [ - "time-core", + "proc-macro2", + "quote", + "syn 2.0.38", ] +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + [[package]] name = "tokio" version = "1.33.0" @@ -1106,41 +1694,18 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.38", ] [[package]] -name = "toml" -version = "0.7.8" +name = "tokio-stream" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd79e69d3b627db300ff956027cc6c3798cef26d22526befdfcd12feeb6d2257" +checksum = "397c988d37662c7dda6d2208364a706264bf3d6138b11d436cbac0ad38832842" dependencies = [ - "serde", - "serde_spanned", - "toml_datetime", - "toml_edit", -] - -[[package]] -name = "toml_datetime" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" -dependencies = [ - "serde", -] - -[[package]] -name = "toml_edit" -version = "0.19.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" -dependencies = [ - "indexmap", - "serde", - "serde_spanned", - "toml_datetime", - "winnow", + "futures-core", + "pin-project-lite", + "tokio", ] [[package]] @@ -1179,9 +1744,21 @@ checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ "log", "pin-project-lite", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.38", +] + [[package]] name = "tracing-core" version = "0.1.32" @@ -1203,12 +1780,50 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" +[[package]] +name = "unicode-bidi" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" + [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-segmentation" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" + +[[package]] +name = "unicode_categories" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" + +[[package]] +name = "url" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + [[package]] name = "uuid" version = "1.5.0" @@ -1268,7 +1883,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 2.0.38", "wasm-bindgen-shared", ] @@ -1290,7 +1905,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.38", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1301,6 +1916,12 @@ version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" +[[package]] +name = "whoami" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22fc3756b8a9133049b26c7f61ab35416c130e8c09b660f5b3958b446f52cc50" + [[package]] name = "winapi" version = "0.3.9" @@ -1399,10 +2020,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] -name = "winnow" -version = "0.5.17" +name = "zerocopy" +version = "0.7.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3b801d0e0a6726477cc207f60162da452f3a95adb368399bef20a946e06f65c" +checksum = "81ba595b9f2772fbee2312de30eeb80ec773b4cb2f1e8098db024afadda6c06f" dependencies = [ - "memchr", + "zerocopy-derive", ] + +[[package]] +name = "zerocopy-derive" +version = "0.7.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "772666c41fb6dceaf520b564b962d738a8e1a83b41bd48945f50837aed78bb1d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.38", +] + +[[package]] +name = "zeroize" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" diff --git a/Cargo.toml b/Cargo.toml index 5db528f..1c9767a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,11 +19,15 @@ argon2 = { version = "0.5.2", features = ["password-hash", "std"] } axum = {version = "0.6.20", features = ["macros"]} chrono = {version = "0.4.31", features = ["serde"]} crypto = { version = "0.5.1", features = ["password-hash"] } -diesel = { version = "2.1.3", features = ["postgres", "extras", "uuid", "r2d2"] } -diesel_migrations = { version = "2.1.0", features = ["postgres"] } dotenvy = "0.15.7" rand = "0.8.5" serde = { version = "1.0.189", features = ["derive"] } serde_json = "1.0.107" tokio = { version = "1.33.0", features = ["full"] } uuid = { version = "1.0.0", features = ["serde", "v4", "v7"] } +sqlx = { version = "0.7", features = ["runtime-tokio", "postgres", "macros", "migrate", "uuid", "chrono", "json"] } +anyhow = "1.0.75" +thiserror = "1.0.50" + +[profile.dev.package.sqlx-macros] +opt-level = 3 diff --git a/diesel.toml b/diesel.toml deleted file mode 100644 index a2acdb8..0000000 --- a/diesel.toml +++ /dev/null @@ -1,13 +0,0 @@ -# SPDX-FileCopyrightText: 2023 Louis Hollingworth -# -# SPDX-License-Identifier: AGPL-3.0-or-later - -# For documentation on how to configure this file, -# see https://diesel.rs/guides/configuring-diesel-cli - -[print_schema] -file = "src/schema.rs" -custom_type_derives = ["diesel::query_builder::QueryId"] - -[migrations_directory] -dir = "migrations" diff --git a/migrations/.keep b/migrations/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/migrations/00000000000000_diesel_initial_setup/up.sql b/migrations/00000000000000_diesel_initial_setup/up.sql deleted file mode 100644 index a547da4..0000000 --- a/migrations/00000000000000_diesel_initial_setup/up.sql +++ /dev/null @@ -1,42 +0,0 @@ --- SPDX-FileCopyrightText: 2023 Louis Hollingworth --- --- SPDX-License-Identifier: AGPL-3.0-or-later - --- This file was automatically created by Diesel to setup helper functions --- and other internal bookkeeping. This file is safe to edit, any future --- changes will be added to existing projects as new migrations. - - - - --- Sets up a trigger for the given table to automatically set a column called --- `updated_at` whenever the row is modified (unless `updated_at` was included --- in the modified columns) --- --- # Example --- --- ```sql --- CREATE TABLE users (id SERIAL PRIMARY KEY, updated_at TIMESTAMP NOT NULL DEFAULT NOW()); --- --- SELECT diesel_manage_updated_at('users'); --- ``` -CREATE OR REPLACE FUNCTION diesel_manage_updated_at(_tbl regclass) RETURNS VOID AS $$ -BEGIN - EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s - FOR EACH ROW EXECUTE PROCEDURE diesel_set_updated_at()', _tbl); -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE FUNCTION diesel_set_updated_at() RETURNS trigger AS $$ -BEGIN - IF ( - NEW IS DISTINCT FROM OLD AND - NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at - ) THEN - NEW.updated_at := current_timestamp; - END IF; - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - - diff --git a/migrations/2023-10-15-172149_create_posts/down.sql b/migrations/2023-10-15-172149_create_posts/down.sql deleted file mode 100644 index 1ea0b58..0000000 --- a/migrations/2023-10-15-172149_create_posts/down.sql +++ /dev/null @@ -1,6 +0,0 @@ --- SPDX-FileCopyrightText: 2023 Louis Hollingworth --- --- SPDX-License-Identifier: AGPL-3.0-or-later - --- This file should undo anything in `up.sql` -DROP TABLE posts; diff --git a/migrations/2023-10-15-172149_create_posts/up.sql b/migrations/2023-10-15-172149_create_posts/up.sql deleted file mode 100644 index 66867ba..0000000 --- a/migrations/2023-10-15-172149_create_posts/up.sql +++ /dev/null @@ -1,17 +0,0 @@ --- SPDX-FileCopyrightText: 2023 Louis Hollingworth --- --- SPDX-License-Identifier: AGPL-3.0-or-later - --- Your SQL goes here - -CREATE TABLE posts ( - id SERIAL PRIMARY KEY, - slug VARCHAR NOT NULL, - title VARCHAR NOT NULL, - body TEXT NOT NULL, - published BOOLEAN NOT NULL DEFAULT FALSE, - user_id UUID NOT NULL REFERENCES users(id), - created_at TIMESTAMP NOT NULL DEFAULT NOW(), - updated_at TIMESTAMP NOT NULL DEFAULT NOW() -); -SELECT diesel_manage_updated_at('posts'); diff --git a/migrations/2023-10-15-172156_create_blogs/down.sql b/migrations/2023-10-15-172156_create_blogs/down.sql deleted file mode 100644 index af245cd..0000000 --- a/migrations/2023-10-15-172156_create_blogs/down.sql +++ /dev/null @@ -1,6 +0,0 @@ --- SPDX-FileCopyrightText: 2023 Louis Hollingworth --- --- SPDX-License-Identifier: AGPL-3.0-or-later - --- This file should undo anything in `up.sql` -DROP TABLE blogs; diff --git a/migrations/2023-10-15-172156_create_blogs/up.sql b/migrations/2023-10-15-172156_create_blogs/up.sql deleted file mode 100644 index c9ea5fb..0000000 --- a/migrations/2023-10-15-172156_create_blogs/up.sql +++ /dev/null @@ -1,18 +0,0 @@ --- SPDX-FileCopyrightText: 2023 Louis Hollingworth --- --- SPDX-License-Identifier: AGPL-3.0-or-later - --- Your SQL goes here -CREATE TABLE blogs ( - id SERIAL PRIMARY KEY, - slug VARCHAR NOT NULL, - name VARCHAR NOT NULL, - description TEXT NOT NULL, - url TEXT NOT NULL, - user_id UUID NOT NULL REFERENCES users(id), - created_at TIMESTAMP NOT NULL DEFAULT NOW(), - updated_at TIMESTAMP NOT NULL DEFAULT NOW() -); - -SELECT diesel_manage_updated_at('blogs'); - diff --git a/migrations/2023-10-17-164429_posts_add_blog_ref/down.sql b/migrations/2023-10-17-164429_posts_add_blog_ref/down.sql deleted file mode 100644 index 089f535..0000000 --- a/migrations/2023-10-17-164429_posts_add_blog_ref/down.sql +++ /dev/null @@ -1,8 +0,0 @@ --- SPDX-FileCopyrightText: 2023 Louis Hollingworth --- --- SPDX-License-Identifier: AGPL-3.0-or-later - --- This file should undo anything in `up.sql` - -ALTER TABLE posts -DROP COLUMN blog_id; diff --git a/migrations/2023-10-17-164429_posts_add_blog_ref/up.sql b/migrations/2023-10-17-164429_posts_add_blog_ref/up.sql deleted file mode 100644 index ba032c7..0000000 --- a/migrations/2023-10-17-164429_posts_add_blog_ref/up.sql +++ /dev/null @@ -1,8 +0,0 @@ --- SPDX-FileCopyrightText: 2023 Louis Hollingworth --- --- SPDX-License-Identifier: AGPL-3.0-or-later - --- Your SQL goes here - -ALTER TABLE posts -ADD COLUMN blog_id INTEGER NOT NULL REFERENCES blogs(id); diff --git a/migrations/00000000000000_diesel_initial_setup/down.sql b/migrations/20231026121809_init.down.sql similarity index 52% rename from migrations/00000000000000_diesel_initial_setup/down.sql rename to migrations/20231026121809_init.down.sql index 3d373d4..e377a9c 100644 --- a/migrations/00000000000000_diesel_initial_setup/down.sql +++ b/migrations/20231026121809_init.down.sql @@ -2,9 +2,6 @@ -- -- SPDX-License-Identifier: AGPL-3.0-or-later --- This file was automatically created by Diesel to setup helper functions --- and other internal bookkeeping. This file is safe to edit, any future --- changes will be added to existing projects as new migrations. - +-- Add down migration script here DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass); DROP FUNCTION IF EXISTS diesel_set_updated_at(); diff --git a/migrations/20231026121809_init.up.sql b/migrations/20231026121809_init.up.sql new file mode 100644 index 0000000..46ba377 --- /dev/null +++ b/migrations/20231026121809_init.up.sql @@ -0,0 +1,24 @@ +-- SPDX-FileCopyrightText: 2023 Louis Hollingworth +-- +-- SPDX-License-Identifier: AGPL-3.0-or-later + +-- Add up migration script here + +CREATE OR REPLACE FUNCTION manage_updated_at(_tbl regclass) RETURNS VOID AS $$ +BEGIN + EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s + FOR EACH ROW EXECUTE PROCEDURE set_updated_at()', _tbl); +END; +$$ LANGUAGE plpgsql; + +CREATE OR REPLACE FUNCTION set_updated_at() RETURNS trigger AS $$ +BEGIN + IF ( + NEW IS DISTINCT FROM OLD AND + NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at + ) THEN + NEW.updated_at := NOW(); + END IF; + RETURN NEW; +END; +$$ LANGUAGE plpgsql diff --git a/migrations/2023-10-15-172140_create_users/down.sql b/migrations/20231026131105_create_users.down.sql similarity index 75% rename from migrations/2023-10-15-172140_create_users/down.sql rename to migrations/20231026131105_create_users.down.sql index dad4a62..b2323c7 100644 --- a/migrations/2023-10-15-172140_create_users/down.sql +++ b/migrations/20231026131105_create_users.down.sql @@ -2,5 +2,5 @@ -- -- SPDX-License-Identifier: AGPL-3.0-or-later --- This file should undo anything in `up.sql` +-- Add down migration script here DROP TABLE users; diff --git a/migrations/2023-10-15-172140_create_users/up.sql b/migrations/20231026131105_create_users.up.sql similarity index 68% rename from migrations/2023-10-15-172140_create_users/up.sql rename to migrations/20231026131105_create_users.up.sql index 91b91f9..9d55f4c 100644 --- a/migrations/2023-10-15-172140_create_users/up.sql +++ b/migrations/20231026131105_create_users.up.sql @@ -2,17 +2,16 @@ -- -- SPDX-License-Identifier: AGPL-3.0-or-later --- Your SQL goes here +-- Add up migration script here CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; CREATE TABLE users ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), - username VARCHAR NOT NULL, - epost VARCHAR NOT NULL, + username VARCHAR UNIQUE NOT NULL, + epost VARCHAR UNIQUE NOT NULL, pass VARCHAR NOT NULL, created_at TIMESTAMP NOT NULL DEFAULT NOW(), updated_at TIMESTAMP NOT NULL DEFAULT NOW(), - main_fedi TEXT, - UNIQUE(username, epost) + main_fedi TEXT ); -SELECT diesel_manage_updated_at('users'); +SELECT manage_updated_at('users'); diff --git a/src/lib.rs b/src/lib.rs index aca851b..61fa6c2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,27 +2,52 @@ // // SPDX-License-Identifier: AGPL-3.0-or-later pub mod models; -pub mod schema; -use diesel::prelude::*; +use thiserror::Error; -pub type DbPool = diesel::r2d2::Pool>; +#[derive(Error, Debug)] +pub enum FbError { + #[error("Database Error: {0}")] + DbError(sqlx::Error), -pub fn establish_connection() -> diesel::pg::PgConnection { + #[error("Internal Error: {0}")] + IError(String) +} + +pub async fn connection_pool() -> Result, sqlx::Error> { dotenvy::dotenv().ok(); let database_url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set"); - diesel::pg::PgConnection::establish(&database_url) - .unwrap_or_else(|_| panic!("Error connecting to {}", database_url)) + + Ok(sqlx::postgres::PgPoolOptions::new() + .max_connections(5) + .connect(&database_url).await?) } -pub fn connection_pool() -> DbPool { - dotenvy::dotenv().ok(); +pub async fn get_user_by_name_for_auth(username: String, pool: sqlx::Pool) -> Result { + let user = sqlx::query_as!(models::user::AuthUser, "SELECT id, username, pass FROM users WHERE username = $1", username).fetch_one(&pool).await.unwrap(); - let database_url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set"); - let manager = diesel::r2d2::ConnectionManager::::new(database_url); - - diesel::r2d2::Pool::builder() - .test_on_check_out(true) - .build(manager) - .expect("Could not build connection pool") + Ok(user) +} + + +pub async fn get_all_users(pool: sqlx::Pool) -> Result, sqlx::Error> { + let users = sqlx::query_as!(models::user::User, "SELECT * FROM users").fetch_all(&pool).await.unwrap(); + + Ok(users) +} + +/// Creates user in database. No need to salt and hash the password, the function does it for you. +pub async fn create_user(user: models::user::NewUser, pool: sqlx::Pool) -> Result<(), FbError> { + use argon2::password_hash::{PasswordHasher, SaltString}; + + let argon = argon2::Argon2::default(); + let salt = SaltString::generate(&mut rand::thread_rng()); + let hashed: String = match argon.hash_password(&user.pass.into_bytes(), &salt) { + Err(_) => return Err(FbError::IError("Error while hashing password".to_string())), + Ok(pswd) => pswd.to_string() + }; + let _ = sqlx::query_as!(models::user::NewUser, " + INSERT INTO users (username, epost, pass) + VALUES ($1, $2, $3)", user.username, user.epost, hashed).execute(&pool).await.unwrap(); + Ok(()) } diff --git a/src/main.rs b/src/main.rs index 858508e..3ba0446 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,18 +3,16 @@ * * SPDX-License-Identifier: AGPL-3.0-or-later */ -use argon2::password_hash::{PasswordHasher, SaltString}; use axum::{routing::{get, post}, Router, response::Json, extract::State}; -use diesel::prelude::*; #[tokio::main] async fn main() { - let pool: fediblog::DbPool = fediblog::connection_pool(); + let pool = fediblog::connection_pool().await.unwrap(); let app = Router::new() .route("/health", get(health_check)) .route("/api/v0/user", post(create_user)) - .route("/api/v0/user", get(get_user)) +// .route("/api/v0/user", get(get_user)) .with_state(pool); axum::Server::bind(&"0.0.0.0:7654".parse().unwrap()) @@ -23,115 +21,17 @@ async fn main() { .unwrap(); } -#[axum::debug_handler] async fn create_user( - State(pool): State, - Json(new_user): Json, -) -> Result, (axum::http::StatusCode, String)> { - use fediblog::schema::users::dsl::*; - let argon = argon2::Argon2::default(); - let salt = SaltString::generate(&mut rand::thread_rng()); - let hashed_pass: String = match argon.hash_password(&new_user.pass.into_bytes(), &salt) { - Err(_) => { - return Err(( - axum::http::StatusCode::INTERNAL_SERVER_ERROR, - "Error hashing password".to_string(), - )) - } - Ok(pswd) => pswd.to_string(), - }; - diesel::insert_into(users) - .values(( - username.eq(new_user.username.clone()), - epost.eq(new_user.epost.clone()), - pass.eq(hashed_pass), - )) - .execute(&mut pool.get().unwrap()) - .expect("Error saving new user"); + State(pool): State>, + Json(u): Json +) -> &'static str { + let _ = fediblog::create_user(u, pool).await; - let uid = get_userid_from_name(new_user.username.clone(), &mut pool.get().unwrap()); - - match uid { - None => return Err((axum::http::StatusCode::INTERNAL_SERVER_ERROR, "There was an error creating this account".to_string())), - Some(user_id) => return Ok(Json( - UserResponse { - id: user_id, - username: new_user.username, - epost: Some(new_user.epost.to_string()), - main_fedi: None - } - )) - } -} - -fn get_userid_from_name(username: String, pool: &mut diesel::r2d2::PooledConnection>) -> Option { - let uv: Result, diesel::result::Error> = pool.build_transaction().read_only().run(|conn| { - let userv = fediblog::schema::users::dsl::users - .select((fediblog::schema::users::dsl::id, fediblog::schema::users::dsl::username)) - .load::(conn); - Ok(userv.unwrap()) - }); - - find_userid_from_base_user(uv.unwrap(), username) -} - -fn find_userid_from_base_user(usrs: Vec, usrn: String) -> Option { - for u in usrs { - if u.username == usrn { - return Some(u.id); - } - } - None -} - - -async fn get_user( - State(pool): State, - Json(auth_user): Json -) ->Result, (axum::http::StatusCode, String)> { - let conn = &mut pool.get().unwrap(); - - let uid = get_userid_from_name(auth_user.username, conn).unwrap(); - - - let userv = diesel::sql_query(format!("SELECT * FROM users WHERE id = {}", uid.to_string())).load::(conn); - - match userv { - Ok(usrs) => return Ok(Json(UserResponse{ - id: usrs[0].id, - - })) - } - - Ok(Json(UserResponse{ - id: user.id, - username: user.username.clone(), - epost: None, - main_fedi: None - })) + "All done :)" } async fn health_check() -> &'static str { "Saluton, amiko! Looks like we are running!" } -#[derive(Clone, serde::Deserialize, serde::Serialize)] -struct NewUser { - username: String, - epost: String, - pass: String, -} -#[derive(Clone, serde::Deserialize, serde::Serialize)] -struct AuthUser { - username: String, - pass: String, -} - -#[derive(serde::Deserialize, serde::Serialize)] -struct UserResponse { - id: uuid::Uuid, - username: String, - epost: Option, - main_fedi: Option, -} diff --git a/src/models.rs b/src/models.rs deleted file mode 100644 index 3923450..0000000 --- a/src/models.rs +++ /dev/null @@ -1,71 +0,0 @@ -// SPDX-FileCopyrightText: 2023 Louis Hollingworth -// -// SPDX-License-Identifier: AGPL-3.0-or-later - -use diesel::prelude::*; -use serde::{Deserialize, Serialize}; -use uuid::Uuid; - -#[derive( - Selectable, Debug, Queryable, QueryableByName -)] -#[diesel(table_name = crate::schema::users)] -#[diesel(check_for_backend(diesel::pg::Pg))] -pub struct User { - pub id: Uuid, - pub username: String, - pub epost: String, - pub pass: String, - pub created_at: chrono::NaiveDateTime, - pub updated_at: chrono::NaiveDateTime, - pub main_fedi: Option, -} - -#[derive(Queryable, PartialEq, Debug)] -#[diesel(table_name = crate::schema::users)] -pub struct BaseUser { - pub id: Uuid, - pub username: String, -} - -#[derive(Insertable, Debug, Selectable)] -#[diesel(table_name = crate::schema::users)] -pub struct NewUser { - pub username: String, - pub epost: String, - pub pass: String -} - -#[derive( - Queryable, Selectable, Identifiable, Associations, Debug, PartialEq, Serialize, Deserialize, -)] -#[diesel(belongs_to(User))] -#[diesel(table_name = crate::schema::blogs)] -pub struct Blog { - pub id: isize, - pub slug: String, - pub name: String, - pub description: String, - pub url: String, - pub user_id: Uuid, - pub created_at: chrono::NaiveDateTime, - pub updated_at: chrono::NaiveDateTime, -} - -#[derive( - Queryable, Selectable, Identifiable, Associations, Debug, PartialEq, Serialize, Deserialize, -)] -#[diesel(belongs_to(User))] -#[diesel(belongs_to(Blog))] -#[diesel(table_name = crate::schema::posts)] -pub struct Post { - pub id: isize, - pub slug: String, - pub title: String, - pub body: String, - pub published: bool, - pub user_id: Uuid, - pub blog_id: isize, - pub created_at: chrono::NaiveDateTime, - pub updated_at: chrono::NaiveDateTime, -} diff --git a/src/models/mod.rs b/src/models/mod.rs new file mode 100644 index 0000000..29697b1 --- /dev/null +++ b/src/models/mod.rs @@ -0,0 +1,5 @@ +// SPDX-FileCopyrightText: 2023 Louis Hollingworth +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +pub mod user; diff --git a/src/models/user.rs b/src/models/user.rs new file mode 100644 index 0000000..253b628 --- /dev/null +++ b/src/models/user.rs @@ -0,0 +1,28 @@ +// SPDX-FileCopyrightText: 2023 Louis Hollingworth +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +#[derive(serde::Serialize, serde::Deserialize, sqlx::FromRow)] +pub struct AuthUser { + pub id: uuid::Uuid, + pub username: String, + pub pass: String, +} + +#[derive(serde::Serialize, serde::Deserialize, sqlx::FromRow)] +pub struct NewUser { + pub username: String, + pub pass: String, + pub epost: String +} + +#[derive(serde::Deserialize, serde::Serialize, sqlx::FromRow)] +pub struct User { + pub id: uuid::Uuid, + pub username: String, + pub epost: String, + pub pass: String, + pub created_at: chrono::NaiveDateTime, + pub updated_at: chrono::NaiveDateTime, + pub main_fedi: Option +} diff --git a/src/schema.rs b/src/schema.rs deleted file mode 100644 index 9614c14..0000000 --- a/src/schema.rs +++ /dev/null @@ -1,54 +0,0 @@ -// SPDX-FileCopyrightText: 2023 Louis Hollingworth -// -// SPDX-License-Identifier: AGPL-3.0-or-later - -// @generated automatically by Diesel CLI. - -diesel::table! { - blogs (id) { - id -> Int4, - slug -> Varchar, - name -> Varchar, - description -> Text, - url -> Text, - user_id -> Uuid, - created_at -> Timestamp, - updated_at -> Timestamp, - } -} - -diesel::table! { - posts (id) { - id -> Int4, - slug -> Varchar, - title -> Varchar, - body -> Text, - published -> Bool, - user_id -> Uuid, - created_at -> Timestamp, - updated_at -> Timestamp, - blog_id -> Int4, - } -} - -diesel::table! { - users (id) { - id -> Uuid, - username -> Varchar, - epost -> Varchar, - pass -> Varchar, - created_at -> Timestamp, - updated_at -> Timestamp, - main_fedi -> Nullable, - } -} - -diesel::joinable!(blogs -> users (user_id)); -diesel::joinable!(posts -> blogs (blog_id)); -diesel::joinable!(posts -> users (user_id)); - -diesel::allow_tables_to_appear_in_same_query!( - blogs, - posts, - users, -);