From 26c7df783b6d66796dea757932cc55c735fb873c Mon Sep 17 00:00:00 2001 From: trivernis Date: Fri, 29 Apr 2022 17:16:31 +0200 Subject: [PATCH] Remove diesel and use sea orm instead Signed-off-by: trivernis --- Cargo.lock | 1249 +++++++++++++++-- Cargo.toml | 2 +- bot-database/Cargo.toml | 13 +- bot-database/diesel.toml | 5 - bot-database/migration/Cargo.toml | 12 + bot-database/migration/README.md | 37 + bot-database/migration/src/lib.rs | 16 + ...20220029_164527_change_timestamp_format.rs | 82 ++ .../src/m20220101_000001_create_table.rs | 288 ++++ bot-database/migration/src/main.rs | 7 + bot-database/migrations/.gitkeep | 0 .../down.sql | 6 - .../up.sql | 36 - .../2021-04-09-075309_create_tables/down.sql | 2 - .../2021-04-09-075309_create_tables/up.sql | 6 - .../down.sql | 2 - .../up.sql | 7 - .../2021-04-12-115141_create_gifs/down.sql | 2 - .../2021-04-12-115141_create_gifs/up.sql | 8 - .../down.sql | 2 - .../up.sql | 9 - .../down.sql | 2 - .../up.sql | 11 - .../down.sql | 2 - .../up.sql | 7 - .../down.sql | 2 - .../up.sql | 2 - .../src/database/ephemeral_messages.rs | 47 +- bot-database/src/database/guild_playlists.rs | 65 +- bot-database/src/database/guild_settings.rs | 86 +- bot-database/src/database/media.rs | 64 +- bot-database/src/database/mod.rs | 17 +- bot-database/src/database/statistics.rs | 59 +- bot-database/src/database/youtube_songs.rs | 83 +- bot-database/src/entity/ephemeral_messages.rs | 24 + bot-database/src/entity/guild_playlists.rs | 24 + bot-database/src/entity/guild_settings.rs | 24 + bot-database/src/entity/media.rs | 24 + bot-database/src/entity/mod.rs | 10 + bot-database/src/entity/prelude.rs | 8 + bot-database/src/entity/statistics.rs | 27 + bot-database/src/entity/youtube_songs.rs | 27 + bot-database/src/error.rs | 16 +- bot-database/src/lib.rs | 52 +- bot-database/src/models.rs | 102 +- bot-database/src/schema.rs | 64 - src/client.rs | 6 +- src/commands/misc/add_media.rs | 2 +- src/commands/settings/get.rs | 4 +- src/commands/weeb/mod.rs | 3 +- src/providers/music/mod.rs | 2 +- src/providers/settings.rs | 2 +- src/utils/mod.rs | 12 +- 53 files changed, 1955 insertions(+), 716 deletions(-) delete mode 100644 bot-database/diesel.toml create mode 100644 bot-database/migration/Cargo.toml create mode 100644 bot-database/migration/README.md create mode 100644 bot-database/migration/src/lib.rs create mode 100644 bot-database/migration/src/m20220029_164527_change_timestamp_format.rs create mode 100644 bot-database/migration/src/m20220101_000001_create_table.rs create mode 100644 bot-database/migration/src/main.rs delete mode 100644 bot-database/migrations/.gitkeep delete mode 100644 bot-database/migrations/00000000000000_diesel_initial_setup/down.sql delete mode 100644 bot-database/migrations/00000000000000_diesel_initial_setup/up.sql delete mode 100644 bot-database/migrations/2021-04-09-075309_create_tables/down.sql delete mode 100644 bot-database/migrations/2021-04-09-075309_create_tables/up.sql delete mode 100644 bot-database/migrations/2021-04-09-095329_create_guild_playlists/down.sql delete mode 100644 bot-database/migrations/2021-04-09-095329_create_guild_playlists/up.sql delete mode 100644 bot-database/migrations/2021-04-12-115141_create_gifs/down.sql delete mode 100644 bot-database/migrations/2021-04-12-115141_create_gifs/up.sql delete mode 100644 bot-database/migrations/2021-04-12-133308_create_statistics/down.sql delete mode 100644 bot-database/migrations/2021-04-12-133308_create_statistics/up.sql delete mode 100644 bot-database/migrations/2021-04-13-144951_create_youtube_songs/down.sql delete mode 100644 bot-database/migrations/2021-04-13-144951_create_youtube_songs/up.sql delete mode 100644 bot-database/migrations/2021-04-16-064403_create_ephemeral_messages/down.sql delete mode 100644 bot-database/migrations/2021-04-16-064403_create_ephemeral_messages/up.sql delete mode 100644 bot-database/migrations/2021-04-21-095152_rename_gifs_table/down.sql delete mode 100644 bot-database/migrations/2021-04-21-095152_rename_gifs_table/up.sql create mode 100644 bot-database/src/entity/ephemeral_messages.rs create mode 100644 bot-database/src/entity/guild_playlists.rs create mode 100644 bot-database/src/entity/guild_settings.rs create mode 100644 bot-database/src/entity/media.rs create mode 100644 bot-database/src/entity/mod.rs create mode 100644 bot-database/src/entity/prelude.rs create mode 100644 bot-database/src/entity/statistics.rs create mode 100644 bot-database/src/entity/youtube_songs.rs delete mode 100644 bot-database/src/schema.rs diff --git a/Cargo.lock b/Cargo.lock index c05c859..c13f119 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "Inflector" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" + [[package]] name = "adler" version = "1.0.2" @@ -18,6 +24,17 @@ dependencies = [ "rand_core 0.6.3", ] +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom 0.2.6", + "once_cell", + "version_check", +] + [[package]] name = "aho-corasick" version = "0.7.18" @@ -27,6 +44,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "aliasable" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "250f629c0161ad8107cf89319e990051fae62832fd343083bea452d93e2205fd" + [[package]] name = "animethemes-rs" version = "0.3.0" @@ -56,6 +79,12 @@ dependencies = [ "nodrop", ] +[[package]] +name = "arrayvec" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" + [[package]] name = "aspotify" version = "0.7.1" @@ -77,6 +106,150 @@ dependencies = [ "url", ] +[[package]] +name = "async-attributes" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3203e79f4dd9bdda415ed03cf14dae5a2bf775c683a00f94e9cd1faf0f596e5" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "async-channel" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2114d64672151c0c5eaa5e131ec84a74f06e1e559830dabba01ca30605d66319" +dependencies = [ + "concurrent-queue", + "event-listener", + "futures-core", +] + +[[package]] +name = "async-executor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "871f9bb5e0a22eeb7e8cf16641feb87c9dc67032ccf8ff49e772eb9941d3a965" +dependencies = [ + "async-task", + "concurrent-queue", + "fastrand", + "futures-lite", + "once_cell", + "slab", +] + +[[package]] +name = "async-global-executor" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c290043c9a95b05d45e952fb6383c67bcb61471f60cfa21e890dba6654234f43" +dependencies = [ + "async-channel", + "async-executor", + "async-io", + "async-mutex", + "blocking", + "futures-lite", + "num_cpus", + "once_cell", + "tokio", +] + +[[package]] +name = "async-io" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a811e6a479f2439f0c04038796b5cfb3d2ad56c230e0f2d3f7b04d68cfee607b" +dependencies = [ + "concurrent-queue", + "futures-lite", + "libc", + "log", + "once_cell", + "parking", + "polling", + "slab", + "socket2", + "waker-fn", + "winapi", +] + +[[package]] +name = "async-lock" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e97a171d191782fba31bb902b14ad94e24a68145032b7eedf871ab0bc0d077b6" +dependencies = [ + "event-listener", +] + +[[package]] +name = "async-mutex" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479db852db25d9dbf6204e6cb6253698f175c15726470f78af0d918e99d6156e" +dependencies = [ + "event-listener", +] + +[[package]] +name = "async-std" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52580991739c5cdb36cde8b2a516371c0a3b70dda36d916cc08b82372916808c" +dependencies = [ + "async-attributes", + "async-channel", + "async-global-executor", + "async-io", + "async-lock", + "crossbeam-utils", + "futures-channel", + "futures-core", + "futures-io", + "futures-lite", + "gloo-timers", + "kv-log-macro", + "log", + "memchr", + "num_cpus", + "once_cell", + "pin-project-lite", + "pin-utils", + "slab", + "wasm-bindgen-futures", +] + +[[package]] +name = "async-stream" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dad5c83079eae9969be7fadefe640a1c566901f05ff91ab221de4b6f68d9507e" +dependencies = [ + "async-stream-impl", + "futures-core", +] + +[[package]] +name = "async-stream-impl" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10f203db73a71dfa2fb6dd22763990fa26f3d2625a6da2da900d23b87d26be27" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "async-task" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30696a84d817107fc028e049980e09d5e140e8da8f1caeb17e8e950658a3cea9" + [[package]] name = "async-trait" version = "0.1.53" @@ -138,6 +311,32 @@ dependencies = [ "tungstenite 0.16.0", ] +[[package]] +name = "atoi" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "616896e05fc0e2649463a93a15183c6a16bf03413a7af88ef1285ddedfa9cda5" +dependencies = [ + "num-traits 0.2.14", +] + +[[package]] +name = "atomic-waker" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a" + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + [[package]] name = "audiopus" version = "0.2.0" @@ -163,6 +362,25 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "bae" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33b8de67cc41132507eeece2584804efcb15f85ba516e34c944b7667f480397a" +dependencies = [ + "heck 0.3.3", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "base-x" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc19a4937b4fbd3fe3379793130e42060d10627a360f2127802b10b87e7baf74" + [[package]] name = "base64" version = "0.12.3" @@ -205,6 +423,29 @@ dependencies = [ "generic-array", ] +[[package]] +name = "block-buffer" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324" +dependencies = [ + "generic-array", +] + +[[package]] +name = "blocking" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6ccb65d468978a086b69884437ded69a90faab3bbe6e67f242173ea728acccc" +dependencies = [ + "async-channel", + "async-task", + "atomic-waker", + "fastrand", + "futures-lite", + "once_cell", +] + [[package]] name = "bot-coreutils" version = "0.1.1" @@ -221,13 +462,11 @@ name = "bot-database" version = "0.6.0" dependencies = [ "chrono", - "diesel", - "diesel_migrations", "dotenv", - "log", - "r2d2", + "migration", + "sea-orm", "thiserror", - "tokio-diesel", + "tracing", ] [[package]] @@ -267,6 +506,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" +[[package]] +name = "cache-padded" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1db59621ec70f09c5e9b597b220c7a2b43611f4710dc03ceb8748637775692c" + [[package]] name = "cc" version = "1.0.73" @@ -295,7 +540,7 @@ dependencies = [ "num-integer", "num-traits 0.2.14", "serde", - "time", + "time 0.1.44", "winapi", ] @@ -330,6 +575,21 @@ dependencies = [ "generic-array", ] +[[package]] +name = "clap" +version = "2.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +dependencies = [ + "ansi_term", + "atty", + "bitflags", + "strsim", + "textwrap", + "unicode-width", + "vec_map", +] + [[package]] name = "command_attr" version = "0.3.8" @@ -341,6 +601,21 @@ dependencies = [ "syn", ] +[[package]] +name = "concurrent-queue" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30ed07550be01594c6026cff2a1d7fe9c8f683caa798e12b68694ac9e88286a3" +dependencies = [ + "cache-padded", +] + +[[package]] +name = "const_fn" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbdcdcb6d86f71c5e97409ad45898af11cbc995b4ee8112d59095a28d376c935" + [[package]] name = "convert_case" version = "0.4.0" @@ -372,6 +647,21 @@ dependencies = [ "libc", ] +[[package]] +name = "crc" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49fc9a695bca7f35f5f4c15cddc84415f66a74ea78eef08e90c5024f2b540e23" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccaeedb56da03b09f598226e25e80088cb4cd25f316e6e4df7d695f0feeb1403" + [[package]] name = "crc32fast" version = "1.3.2" @@ -416,6 +706,16 @@ dependencies = [ "scopeguard", ] +[[package]] +name = "crossbeam-queue" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f25d8400f4a7a5778f0e4e52384a48cbd9b5c495d110786187fc750075277a2" +dependencies = [ + "cfg-if 1.0.0", + "crossbeam-utils", +] + [[package]] name = "crossbeam-utils" version = "0.8.8" @@ -426,6 +726,16 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "crypto-common" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57952ca27b5e3606ff4dd79b0020231aaf9d6aa76dc05fd30137538c50bd3ce8" +dependencies = [ + "generic-array", + "typenum", +] + [[package]] name = "cssparser" version = "0.27.2" @@ -453,6 +763,16 @@ dependencies = [ "syn", ] +[[package]] +name = "ctor" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f877be4f7c9f246b183111634f75baa039715e3f46ce860677d3b19a69fb229c" +dependencies = [ + "quote", + "syn", +] + [[package]] name = "dashmap" version = "4.0.2" @@ -488,49 +808,51 @@ dependencies = [ ] [[package]] -name = "diesel" -version = "1.4.8" +name = "digest" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b28135ecf6b7d446b43e27e225622a038cc4e2930a1022f51cdb97ada19b8e4d" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" dependencies = [ - "bitflags", - "byteorder", - "chrono", - "diesel_derives", - "pq-sys", - "r2d2", + "generic-array", ] [[package]] -name = "diesel_derives" -version = "1.4.1" +name = "digest" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45f5098f628d02a7a0f68ddba586fb61e80edec3bdc1be3b921f4ceec60858d3" +checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506" dependencies = [ - "proc-macro2", - "quote", - "syn", + "block-buffer 0.10.2", + "crypto-common", + "subtle", ] [[package]] -name = "diesel_migrations" -version = "1.4.0" +name = "dirs" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf3cde8413353dc7f5d72fa8ce0b99a560a359d2c5ef1e5817ca731cd9008f4c" +checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" dependencies = [ - "migrations_internals", - "migrations_macros", + "dirs-sys", ] [[package]] -name = "digest" -version = "0.9.0" +name = "dirs-sys" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" dependencies = [ - "generic-array", + "libc", + "redox_users", + "winapi", ] +[[package]] +name = "discard" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" + [[package]] name = "discortp" version = "0.4.0" @@ -592,6 +914,12 @@ dependencies = [ "num-traits 0.1.43", ] +[[package]] +name = "event-listener" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77f3309417938f28bf8228fcff79a4a37103981e3e186d2ccd19c74b38f4eb71" + [[package]] name = "fastrand" version = "1.7.0" @@ -709,12 +1037,38 @@ dependencies = [ "futures-util", ] +[[package]] +name = "futures-intrusive" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62007592ac46aa7c2b6416f7deb9a8a8f63a01e0f1d6e1787d5630170db2b63e" +dependencies = [ + "futures-core", + "lock_api", + "parking_lot 0.11.2", +] + [[package]] name = "futures-io" version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b" +[[package]] +name = "futures-lite" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7694489acd39452c77daa48516b894c153f192c3578d5a839b62c58099fcbf48" +dependencies = [ + "fastrand", + "futures-core", + "futures-io", + "memchr", + "parking", + "pin-project-lite", + "waker-fn", +] + [[package]] name = "futures-macro" version = "0.3.21" @@ -814,45 +1168,111 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad" dependencies = [ - "cfg-if 1.0.0", - "js-sys", + "cfg-if 1.0.0", + "js-sys", + "libc", + "wasi 0.10.0+wasi-snapshot-preview1", + "wasm-bindgen", +] + +[[package]] +name = "gloo-timers" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fb7d06c1c8cc2a29bee7ec961009a0b2caa0793ee4900c2ffb348734ba1c8f9" +dependencies = [ + "futures-channel", + "futures-core", + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "h2" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37a82c6d637fc9515a4694bbf1cb2457b79d81ce52b3108bdeea58b07dd34a57" +dependencies = [ + "bytes 1.1.0", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util 0.7.1", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +dependencies = [ + "ahash", +] + +[[package]] +name = "hashlink" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7249a3129cbc1ffccd74857f81464a323a152173cdb134e0fd81bc803b29facf" +dependencies = [ + "hashbrown", +] + +[[package]] +name = "heck" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "heck" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ "libc", - "wasi 0.10.0+wasi-snapshot-preview1", - "wasm-bindgen", ] [[package]] -name = "h2" -version = "0.3.13" +name = "hex" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37a82c6d637fc9515a4694bbf1cb2457b79d81ce52b3108bdeea58b07dd34a57" -dependencies = [ - "bytes 1.1.0", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util 0.7.1", - "tracing", -] +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] -name = "hashbrown" -version = "0.11.2" +name = "hkdf" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +checksum = "791a029f6b9fc27657f6f188ec6e5e43f6911f6f878e0dc5501396e09809d437" +dependencies = [ + "hmac", +] [[package]] -name = "hermit-abi" -version = "0.1.19" +name = "hmac" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" dependencies = [ - "libc", + "digest 0.10.3", ] [[package]] @@ -1075,6 +1495,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "kv-log-macro" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" +dependencies = [ + "log", +] + [[package]] name = "lavalink-rs" version = "0.9.0-rc.3" @@ -1129,6 +1558,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6389c490849ff5bc16be905ae24bc913a9c8892e19b2341dbc175e14c341c2b8" dependencies = [ "cfg-if 1.0.0", + "value-bag", ] [[package]] @@ -1191,6 +1621,15 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" +[[package]] +name = "md-5" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "658646b21e0b72f7866c7038ab086d3d5e1cd6271f060fd37defb241949d0582" +dependencies = [ + "digest 0.10.3", +] + [[package]] name = "memchr" version = "2.4.1" @@ -1207,24 +1646,10 @@ dependencies = [ ] [[package]] -name = "migrations_internals" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b4fc84e4af020b837029e017966f86a1c2d5e83e64b589963d5047525995860" -dependencies = [ - "diesel", -] - -[[package]] -name = "migrations_macros" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9753f12909fd8d923f75ae5c3258cae1ed3c8ec052e1b38c93c21a6d157f789c" +name = "migration" +version = "0.1.0" dependencies = [ - "migrations_internals", - "proc-macro2", - "quote", - "syn", + "sea-schema", ] [[package]] @@ -1258,6 +1683,12 @@ dependencies = [ "thiserror", ] +[[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.4.4" @@ -1330,6 +1761,16 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" +[[package]] +name = "nom" +version = "7.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36" +dependencies = [ + "memchr", + "minimal-lexical", +] + [[package]] name = "ntapi" version = "0.3.7" @@ -1339,6 +1780,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "num-bigint" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f6f7833f2cbf2360a6cfd58cd41a53aa7a90bd4c202f5b1c7dd2ed73c57b2c3" +dependencies = [ + "autocfg", + "num-integer", + "num-traits 0.2.14", +] + [[package]] name = "num-integer" version = "0.1.44" @@ -1422,6 +1874,36 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "ouroboros" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f31a3b678685b150cba82b702dcdc5e155893f63610cf388d30cd988d4ca2bf" +dependencies = [ + "aliasable", + "ouroboros_macro", + "stable_deref_trait", +] + +[[package]] +name = "ouroboros_macro" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "084fd65d5dd8b3772edccb5ffd1e4b7eba43897ecd0f9401e330e8c542959408" +dependencies = [ + "Inflector", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "parking" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72" + [[package]] name = "parking_lot" version = "0.11.2" @@ -1479,6 +1961,12 @@ dependencies = [ "regex", ] +[[package]] +name = "paste" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c520e05135d6e763148b6426a837e239041653ba7becd2e538c076c738025fc" + [[package]] name = "percent-encoding" version = "2.1.0" @@ -1643,6 +2131,19 @@ dependencies = [ "pnet_base", ] +[[package]] +name = "polling" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "685404d509889fade3e86fe3a5803bca2ec09b0c0778d5ada6ec8bf7a8de5259" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "log", + "wepoll-ffi", + "winapi", +] + [[package]] name = "poly1305" version = "0.7.2" @@ -1661,19 +2162,34 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" [[package]] -name = "pq-sys" -version = "0.4.6" +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro-error" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ac25eee5a0582f45a67e837e350d784e7003bd29a5f460796772061ca49ffda" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ - "vcpkg", + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", ] [[package]] -name = "precomputed-hash" -version = "0.1.1" +name = "proc-macro-error-attr" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] [[package]] name = "proc-macro-hack" @@ -1699,17 +2215,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "r2d2" -version = "0.8.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "545c5bc2b880973c9c10e4067418407a0ccaa3091781d1671d46eb35107cb26f" -dependencies = [ - "log", - "parking_lot 0.11.2", - "scheduled-thread-pool", -] - [[package]] name = "rand" version = "0.7.3" @@ -1825,6 +2330,17 @@ dependencies = [ "bitflags", ] +[[package]] +name = "redox_users" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +dependencies = [ + "getrandom 0.2.6", + "redox_syscall", + "thiserror", +] + [[package]] name = "regex" version = "1.5.5" @@ -1918,6 +2434,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "rust_decimal" +version = "1.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22dc69eadbf0ee2110b8d20418c0c6edbaefec2811c4963dc17b6344e11fe0f8" +dependencies = [ + "arrayvec 0.7.2", + "num-traits 0.2.14", + "serde", +] + [[package]] name = "rustc_version" version = "0.2.3" @@ -2028,15 +2555,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "scheduled-thread-pool" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc6f74fd1204073fa02d5d5d68bec8021be4c38690b61264b2fdb48083d0e7d7" -dependencies = [ - "parking_lot 0.11.2", -] - [[package]] name = "scoped-tls" version = "1.0.0" @@ -2050,39 +2568,166 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] -name = "scraper" -version = "0.12.0" +name = "scraper" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e02aa790c80c2e494130dec6a522033b6a23603ffc06360e9fe6c611ea2c12" +dependencies = [ + "cssparser", + "ego-tree", + "getopts", + "html5ever", + "matches", + "selectors", + "smallvec", + "tendril", +] + +[[package]] +name = "sct" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b362b83898e0e69f38515b82ee15aa80636befe47c3b6d3d89a911e78fc228ce" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "sct" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "sea-orm" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27dbb8a742003f8dbf2ba290d128134d4275a6b55fd02f4d728683b6b55ea9bf" +dependencies = [ + "async-stream", + "async-trait", + "chrono", + "futures", + "futures-util", + "once_cell", + "ouroboros", + "rust_decimal", + "sea-orm-macros", + "sea-query 0.23.0", + "sea-strum", + "serde", + "serde_json", + "sqlx", + "time 0.2.27", + "tracing", + "url", + "uuid", +] + +[[package]] +name = "sea-orm-macros" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953bf5fb9f6ec985c139c4a98550b600c2f7c97bea74e2acc4025438469cb5a2" +dependencies = [ + "bae", + "heck 0.3.3", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "sea-query" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "727090e8d1e61edd07305d237664315226748ad559e16daa6293fa26c4e7a3c3" +dependencies = [ + "sea-query-derive", +] + +[[package]] +name = "sea-query" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bf24fc03259e206d8cd4c957ce7446fe54ab00ba5ada4cdb028aa3513e26231" +dependencies = [ + "chrono", + "rust_decimal", + "sea-query-derive", + "serde_json", + "time 0.2.27", + "uuid", +] + +[[package]] +name = "sea-query-derive" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34cdc022b4f606353fe5dc85b09713a04e433323b70163e81513b141c6ae6eb5" +dependencies = [ + "heck 0.3.3", + "proc-macro2", + "quote", + "syn", + "thiserror", +] + +[[package]] +name = "sea-schema" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d492f4550a428d2be29e4df8e43b2e9e46717424c9603fafa3365ae6079bd73" +dependencies = [ + "async-std", + "async-trait", + "clap", + "dotenv", + "log", + "sea-orm", + "sea-query 0.22.0", + "sea-schema-derive", + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "sea-schema-derive" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48e02aa790c80c2e494130dec6a522033b6a23603ffc06360e9fe6c611ea2c12" +checksum = "56821b7076f5096b8f726e2791ad255a99c82498e08ec477a65a96c461ff1927" dependencies = [ - "cssparser", - "ego-tree", - "getopts", - "html5ever", - "matches", - "selectors", - "smallvec", - "tendril", + "heck 0.3.3", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "sct" -version = "0.6.1" +name = "sea-strum" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b362b83898e0e69f38515b82ee15aa80636befe47c3b6d3d89a911e78fc228ce" +checksum = "391d06a6007842cfe79ac6f7f53911b76dfd69fc9a6769f1cf6569d12ce20e1b" dependencies = [ - "ring", - "untrusted", + "sea-strum_macros", ] [[package]] -name = "sct" -version = "0.7.0" +name = "sea-strum_macros" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" +checksum = "69b4397b825df6ccf1e98bcdabef3bbcfc47ff5853983467850eeab878384f21" dependencies = [ - "ring", - "untrusted", + "heck 0.3.3", + "proc-macro2", + "quote", + "rustversion", + "syn", ] [[package]] @@ -2305,13 +2950,50 @@ version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6" dependencies = [ - "block-buffer", + "block-buffer 0.9.0", "cfg-if 1.0.0", "cpufeatures", - "digest", + "digest 0.9.0", "opaque-debug", ] +[[package]] +name = "sha-1" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "028f48d513f9678cda28f6e4064755b3fbb2af6acd672f2c209b62323f7aea0f" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures", + "digest 0.10.3", +] + +[[package]] +name = "sha1" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1da05c97445caa12d05e848c4a4fcbbea29e748ac28f7e80e9b010392063770" +dependencies = [ + "sha1_smol", +] + +[[package]] +name = "sha1_smol" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" + +[[package]] +name = "sha2" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55deaec60f81eefe3cce0dc50bda92d6d8e88f2a27df7c5033b42afeb1ed2676" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures", + "digest 0.10.3", +] + [[package]] name = "sharded-slab" version = "0.1.4" @@ -2416,18 +3098,183 @@ dependencies = [ "winapi", ] +[[package]] +name = "sqlformat" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4b7922be017ee70900be125523f38bdd644f4f06a1b16e8fa5a8ee8c34bffd4" +dependencies = [ + "itertools", + "nom", + "unicode_categories", +] + +[[package]] +name = "sqlx" +version = "0.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "551873805652ba0d912fec5bbb0f8b4cdd96baf8e2ebf5970e5671092966019b" +dependencies = [ + "sqlx-core", + "sqlx-macros", +] + +[[package]] +name = "sqlx-core" +version = "0.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e48c61941ccf5ddcada342cd59e3e5173b007c509e1e8e990dafc830294d9dc5" +dependencies = [ + "ahash", + "atoi", + "base64 0.13.0", + "bitflags", + "byteorder", + "bytes 1.1.0", + "chrono", + "crc", + "crossbeam-queue", + "dirs", + "either", + "event-listener", + "futures-channel", + "futures-core", + "futures-intrusive", + "futures-util", + "hashlink", + "hex", + "hkdf", + "hmac", + "indexmap", + "itoa 1.0.1", + "libc", + "log", + "md-5", + "memchr", + "num-bigint", + "once_cell", + "paste", + "percent-encoding", + "rand 0.8.5", + "rust_decimal", + "serde", + "serde_json", + "sha-1 0.10.0", + "sha2", + "smallvec", + "sqlformat", + "sqlx-rt", + "stringprep", + "thiserror", + "time 0.2.27", + "tokio-stream", + "url", + "uuid", + "whoami", +] + +[[package]] +name = "sqlx-macros" +version = "0.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc0fba2b0cae21fc00fe6046f8baa4c7fcb49e379f0f592b04696607f69ed2e1" +dependencies = [ + "dotenv", + "either", + "heck 0.4.0", + "once_cell", + "proc-macro2", + "quote", + "serde_json", + "sha2", + "sqlx-core", + "sqlx-rt", + "syn", + "url", +] + +[[package]] +name = "sqlx-rt" +version = "0.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4db708cd3e459078f85f39f96a00960bd841f66ee2a669e90bf36907f5a79aae" +dependencies = [ + "native-tls", + "once_cell", + "tokio", + "tokio-native-tls", +] + [[package]] name = "stable_deref_trait" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" +[[package]] +name = "standback" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e113fb6f3de07a243d434a56ec6f186dfd51cb08448239fe7bcae73f87ff28ff" +dependencies = [ + "version_check", +] + [[package]] name = "static_assertions" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "stdweb" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5" +dependencies = [ + "discard", + "rustc_version 0.2.3", + "stdweb-derive", + "stdweb-internal-macros", + "stdweb-internal-runtime", + "wasm-bindgen", +] + +[[package]] +name = "stdweb-derive" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" +dependencies = [ + "proc-macro2", + "quote", + "serde", + "serde_derive", + "syn", +] + +[[package]] +name = "stdweb-internal-macros" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11" +dependencies = [ + "base-x", + "proc-macro2", + "quote", + "serde", + "serde_derive", + "serde_json", + "sha1", + "syn", +] + +[[package]] +name = "stdweb-internal-runtime" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" + [[package]] name = "streamcatcher" version = "0.1.1" @@ -2471,6 +3318,22 @@ dependencies = [ "quote", ] +[[package]] +name = "stringprep" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ee348cb74b87454fff4b551cbf727025810a004f88aeacae7f85b87f4e9a1c1" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + [[package]] name = "subtle" version = "2.4.1" @@ -2483,7 +3346,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e32b956473d98c601dac257fab8a7700d42e49fdd7a33432dd5dc7fdd2448dd" dependencies = [ - "arrayvec", + "arrayvec 0.4.12", "bitflags", "byteorder", "lazy_static", @@ -2541,6 +3404,15 @@ dependencies = [ "utf-8", ] +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "unicode-width", +] + [[package]] name = "thin-slice" version = "0.1.1" @@ -2587,6 +3459,44 @@ dependencies = [ "winapi", ] +[[package]] +name = "time" +version = "0.2.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4752a97f8eebd6854ff91f1c1824cd6160626ac4bd44287f7f4ea2035a02a242" +dependencies = [ + "const_fn", + "libc", + "standback", + "stdweb", + "time-macros", + "version_check", + "winapi", +] + +[[package]] +name = "time-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "957e9c6e26f12cb6d0dd7fc776bb67a706312e7299aed74c8dd5b17ebb27e2f1" +dependencies = [ + "proc-macro-hack", + "time-macros-impl", +] + +[[package]] +name = "time-macros-impl" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd3c141a1b43194f3f56a1411225df8646c55781d5f26db825b3d98507eb482f" +dependencies = [ + "proc-macro-hack", + "proc-macro2", + "quote", + "standback", + "syn", +] + [[package]] name = "tinyvec" version = "1.5.1" @@ -2659,18 +3569,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "tokio-diesel" -version = "0.3.0" -source = "git+https://github.com/Trivernis/tokio-diesel#f4af42558246ab323600622ba8d08803d3c18842" -dependencies = [ - "async-trait", - "diesel", - "futures", - "r2d2", - "tokio", -] - [[package]] name = "tokio-macros" version = "1.7.0" @@ -2714,6 +3612,17 @@ dependencies = [ "webpki 0.22.0", ] +[[package]] +name = "tokio-stream" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50145484efff8818b5ccd256697f36863f587da82cf8b409c53adf1e840798e3" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "tokio-util" version = "0.6.9" @@ -2750,9 +3659,9 @@ checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" [[package]] name = "tracing" -version = "0.1.33" +version = "0.1.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80b9fa4360528139bc96100c160b7ae879f5567f49f1782b0b02035b0358ebf3" +checksum = "5d0ecdcb44a79f0fe9844f0c4f33a342cbcbb5117de8001e6ba0dc2351327d09" dependencies = [ "cfg-if 1.0.0", "log", @@ -2852,7 +3761,7 @@ dependencies = [ "log", "native-tls", "rand 0.7.3", - "sha-1", + "sha-1 0.9.8", "url", "utf-8", ] @@ -2872,7 +3781,7 @@ dependencies = [ "log", "rand 0.8.5", "rustls 0.19.1", - "sha-1", + "sha-1 0.9.8", "thiserror", "url", "utf-8", @@ -2894,7 +3803,7 @@ dependencies = [ "log", "native-tls", "rand 0.8.5", - "sha-1", + "sha-1 0.9.8", "thiserror", "url", "utf-8", @@ -2945,6 +3854,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-segmentation" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99" + [[package]] name = "unicode-width" version = "0.1.9" @@ -2957,6 +3872,12 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +[[package]] +name = "unicode_categories" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" + [[package]] name = "universal-hash" version = "0.4.1" @@ -3004,6 +3925,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" dependencies = [ "getrandom 0.2.6", + "serde", ] [[package]] @@ -3018,18 +3940,40 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "value-bag" +version = "1.0.0-alpha.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79923f7731dc61ebfba3633098bf3ac533bbd35ccd8c57e7088d9a5eebe0263f" +dependencies = [ + "ctor", + "version_check", +] + [[package]] name = "vcpkg" version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + [[package]] name = "version_check" version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "waker-fn" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" + [[package]] name = "want" version = "0.3.0" @@ -3181,6 +4125,25 @@ dependencies = [ "webpki 0.22.0", ] +[[package]] +name = "wepoll-ffi" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d743fdedc5c64377b5fc2bc036b01c7fd642205a0d96356034ae3404d49eb7fb" +dependencies = [ + "cc", +] + +[[package]] +name = "whoami" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524b58fa5a20a2fb3014dd6358b70e6579692a56ef6fce928834e488f42f65e8" +dependencies = [ + "wasm-bindgen", + "web-sys", +] + [[package]] name = "winapi" version = "0.3.9" @@ -3278,7 +4241,7 @@ dependencies = [ "log", "mac", "markup5ever", - "time", + "time 0.1.44", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index b2c48c3..cfaf2f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members=["bot-coreutils", "bot-database", "."] +members=["bot-coreutils", "bot-database", "bot-database/migration", "."] [package] name = "tobi-rs" diff --git a/bot-database/Cargo.toml b/bot-database/Cargo.toml index 5e0eedf..5528ac9 100644 --- a/bot-database/Cargo.toml +++ b/bot-database/Cargo.toml @@ -10,8 +10,11 @@ edition = "2018" dotenv = "0.15.0" chrono = "0.4.19" thiserror = "1.0.30" -diesel = { version = "1.4.8", features = ["postgres", "r2d2", "chrono"] } -log = "0.4.16" -diesel_migrations = "1.4.0" -r2d2 = "0.8.9" -tokio-diesel = {git = "https://github.com/Trivernis/tokio-diesel"} +tracing = "0.1.34" + +[dependencies.sea-orm] +version = "0.7.1" +features = ["runtime-tokio-native-tls", "sqlx-postgres"] + +[dependencies.migration] +path = "./migration" \ No newline at end of file diff --git a/bot-database/diesel.toml b/bot-database/diesel.toml deleted file mode 100644 index 92267c8..0000000 --- a/bot-database/diesel.toml +++ /dev/null @@ -1,5 +0,0 @@ -# For documentation on how to configure this file, -# see diesel.rs/guides/configuring-diesel-cli - -[print_schema] -file = "src/schema.rs" diff --git a/bot-database/migration/Cargo.toml b/bot-database/migration/Cargo.toml new file mode 100644 index 0000000..73d34bf --- /dev/null +++ b/bot-database/migration/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "migration" +version = "0.1.0" +edition = "2021" +publish = false + +[lib] +name = "migration" +path = "src/lib.rs" + +[dependencies] +sea-schema = { version = "^0.7.0", default-features = false, features = [ "migration", "debug-print" ] } diff --git a/bot-database/migration/README.md b/bot-database/migration/README.md new file mode 100644 index 0000000..963caae --- /dev/null +++ b/bot-database/migration/README.md @@ -0,0 +1,37 @@ +# Running Migrator CLI + +- Apply all pending migrations + ```sh + cargo run + ``` + ```sh + cargo run -- up + ``` +- Apply first 10 pending migrations + ```sh + cargo run -- up -n 10 + ``` +- Rollback last applied migrations + ```sh + cargo run -- down + ``` +- Rollback last 10 applied migrations + ```sh + cargo run -- down -n 10 + ``` +- Drop all tables from the database, then reapply all migrations + ```sh + cargo run -- fresh + ``` +- Rollback all applied migrations, then reapply all migrations + ```sh + cargo run -- refresh + ``` +- Rollback all applied migrations + ```sh + cargo run -- reset + ``` +- Check the status of all migrations + ```sh + cargo run -- status + ``` diff --git a/bot-database/migration/src/lib.rs b/bot-database/migration/src/lib.rs new file mode 100644 index 0000000..a2686cc --- /dev/null +++ b/bot-database/migration/src/lib.rs @@ -0,0 +1,16 @@ +pub use sea_schema::migration::prelude::*; + +mod m20220029_164527_change_timestamp_format; +mod m20220101_000001_create_table; + +pub struct Migrator; + +#[async_trait::async_trait] +impl MigratorTrait for Migrator { + fn migrations() -> Vec> { + vec![ + Box::new(m20220029_164527_change_timestamp_format::Migration), + Box::new(m20220101_000001_create_table::Migration), + ] + } +} diff --git a/bot-database/migration/src/m20220029_164527_change_timestamp_format.rs b/bot-database/migration/src/m20220029_164527_change_timestamp_format.rs new file mode 100644 index 0000000..ab5d762 --- /dev/null +++ b/bot-database/migration/src/m20220029_164527_change_timestamp_format.rs @@ -0,0 +1,82 @@ +use crate::{DbErr, Table}; +use sea_schema::migration::prelude::*; + +#[derive(Iden)] +pub enum Statistics { + Table, + ExecutedAt, +} + +#[derive(Iden)] +pub enum EphemeralMessages { + Table, + Timeout, +} + +pub struct Migration; + +impl MigrationName for Migration { + fn name(&self) -> &str { + "m20220029_164527_change_timestamp_format" + } +} + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .alter_table( + Table::alter() + .table(Statistics::Table) + .modify_column( + ColumnDef::new(Statistics::ExecutedAt) + .timestamp_with_time_zone() + .not_null(), + ) + .to_owned(), + ) + .await?; + manager + .alter_table( + Table::alter() + .table(EphemeralMessages::Table) + .modify_column( + ColumnDef::new(EphemeralMessages::Timeout) + .timestamp_with_time_zone() + .not_null(), + ) + .to_owned(), + ) + .await?; + Ok(()) + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .alter_table( + Table::alter() + .table(Statistics::Table) + .modify_column( + ColumnDef::new(Statistics::ExecutedAt) + .timestamp() + .not_null(), + ) + .to_owned(), + ) + .await?; + manager + .alter_table( + Table::alter() + .table(EphemeralMessages::Table) + .modify_column( + ColumnDef::new(EphemeralMessages::Timeout) + .timestamp() + .not_null(), + ) + .to_owned(), + ) + .await?; + + Ok(()) + } +} diff --git a/bot-database/migration/src/m20220101_000001_create_table.rs b/bot-database/migration/src/m20220101_000001_create_table.rs new file mode 100644 index 0000000..2f36269 --- /dev/null +++ b/bot-database/migration/src/m20220101_000001_create_table.rs @@ -0,0 +1,288 @@ +use sea_query::Table; +use sea_schema::migration::prelude::*; + +pub struct Migration; + +#[derive(Iden)] +pub enum EphemeralMessages { + Table, + ChannelId, + MessageId, + Timeout, +} + +#[derive(Iden)] +pub enum GuildPlaylists { + Table, + GuildId, + Name, + Url, +} + +#[derive(Iden)] +pub enum GuildSettings { + Table, + GuildId, + Key, + Value, +} + +#[derive(Iden)] +pub enum Media { + Table, + Id, + Category, + Name, + Url, +} + +#[derive(Iden)] +pub enum Statistics { + Table, + Id, + Version, + Command, + ExecutedAt, + Success, + ErrorMsg, +} + +#[derive(Iden)] +pub enum YoutubeSongs { + Table, + Id, + SpotifyId, + Artist, + Title, + Album, + Url, + Score, +} + +impl MigrationName for Migration { + fn name(&self) -> &str { + "m20220101_000001_create_table" + } +} + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager.create_table(ephemeral_messages()).await?; + manager.create_table(guild_playlists()).await?; + manager.create_table(guild_settings()).await?; + manager.create_table(media()).await?; + manager.create_table(statistics()).await?; + manager.create_table(youtube_songs()).await?; + + Ok(()) + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .drop_table(Table::drop().table(EphemeralMessages::Table).to_owned()) + .await?; + manager + .drop_table(Table::drop().table(GuildPlaylists::Table).to_owned()) + .await?; + manager + .drop_table(Table::drop().table(GuildSettings::Table).to_owned()) + .await?; + manager + .drop_table(Table::drop().table(Media::Table).to_owned()) + .await?; + manager + .drop_table(Table::drop().table(Statistics::Table).to_owned()) + .await?; + manager + .drop_table(Table::drop().table(YoutubeSongs::Table).to_owned()) + .await?; + + Ok(()) + } +} + +fn ephemeral_messages() -> TableCreateStatement { + Table::create() + .table(EphemeralMessages::Table) + .if_not_exists() + .col( + ColumnDef::new(EphemeralMessages::ChannelId) + .big_integer() + .not_null(), + ) + .col( + ColumnDef::new(EphemeralMessages::MessageId) + .big_integer() + .not_null(), + ) + .col( + ColumnDef::new(EphemeralMessages::Timeout) + .timestamp() + .not_null(), + ) + .primary_key( + Index::create() + .col(EphemeralMessages::ChannelId) + .col(EphemeralMessages::MessageId), + ) + .to_owned() +} + +fn guild_playlists() -> TableCreateStatement { + Table::create() + .table(GuildPlaylists::Table) + .if_not_exists() + .col( + ColumnDef::new(GuildPlaylists::GuildId) + .big_integer() + .not_null(), + ) + .col( + ColumnDef::new(GuildPlaylists::Name) + .string_len(255) + .not_null(), + ) + .col( + ColumnDef::new(GuildPlaylists::Url) + .string_len(1204) + .not_null(), + ) + .primary_key( + Index::create() + .col(GuildPlaylists::GuildId) + .col(GuildPlaylists::Name), + ) + .to_owned() +} + +fn guild_settings() -> TableCreateStatement { + Table::create() + .table(GuildSettings::Table) + .if_not_exists() + .col( + ColumnDef::new(GuildSettings::GuildId) + .big_integer() + .not_null(), + ) + .col( + ColumnDef::new(GuildSettings::Key) + .string_len(255) + .not_null(), + ) + .col( + ColumnDef::new(GuildSettings::Value) + .string_len(1024) + .not_null(), + ) + .primary_key( + Index::create() + .col(GuildSettings::GuildId) + .col(GuildSettings::Key), + ) + .to_owned() +} + +fn media() -> TableCreateStatement { + Table::create() + .table(Media::Table) + .if_not_exists() + .col( + ColumnDef::new(Media::Id) + .big_integer() + .auto_increment() + .not_null() + .primary_key(), + ) + .col(ColumnDef::new(Media::Category).string_len(128)) + .col(ColumnDef::new(Media::Name).string_len(128)) + .col(ColumnDef::new(Media::Url).string_len(128)) + .index( + Index::create() + .unique() + .col(Media::Category) + .col(Media::Name), + ) + .to_owned() +} + +fn statistics() -> TableCreateStatement { + Table::create() + .table(Statistics::Table) + .if_not_exists() + .col( + ColumnDef::new(Statistics::Id) + .big_integer() + .auto_increment() + .primary_key(), + ) + .col( + ColumnDef::new(Statistics::Version) + .string_len(32) + .not_null(), + ) + .col( + ColumnDef::new(Statistics::Command) + .string_len(255) + .not_null(), + ) + .col( + ColumnDef::new(Statistics::ExecutedAt) + .timestamp() + .not_null(), + ) + .col( + ColumnDef::new(Statistics::Success) + .boolean() + .not_null() + .default(true), + ) + .col(ColumnDef::new(Statistics::ErrorMsg).string()) + .to_owned() +} + +fn youtube_songs() -> TableCreateStatement { + Table::create() + .table(YoutubeSongs::Table) + .if_not_exists() + .col( + ColumnDef::new(YoutubeSongs::Id) + .big_integer() + .primary_key() + .auto_increment(), + ) + .col( + ColumnDef::new(YoutubeSongs::SpotifyId) + .string_len(255) + .not_null(), + ) + .col( + ColumnDef::new(YoutubeSongs::Artist) + .string_len(128) + .not_null(), + ) + .col( + ColumnDef::new(YoutubeSongs::Title) + .string_len(255) + .not_null(), + ) + .col( + ColumnDef::new(YoutubeSongs::Album) + .string_len(255) + .not_null(), + ) + .col(ColumnDef::new(YoutubeSongs::Url).string_len(128).not_null()) + .col( + ColumnDef::new(YoutubeSongs::Score) + .integer() + .default(0) + .not_null(), + ) + .index( + Index::create() + .unique() + .col(YoutubeSongs::SpotifyId) + .col(YoutubeSongs::Url), + ) + .to_owned() +} diff --git a/bot-database/migration/src/main.rs b/bot-database/migration/src/main.rs new file mode 100644 index 0000000..89b349c --- /dev/null +++ b/bot-database/migration/src/main.rs @@ -0,0 +1,7 @@ +use migration::Migrator; +use sea_schema::migration::prelude::*; + +#[async_std::main] +async fn main() { + cli::run_cli(Migrator).await; +} diff --git a/bot-database/migrations/.gitkeep b/bot-database/migrations/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/bot-database/migrations/00000000000000_diesel_initial_setup/down.sql b/bot-database/migrations/00000000000000_diesel_initial_setup/down.sql deleted file mode 100644 index a9f5260..0000000 --- a/bot-database/migrations/00000000000000_diesel_initial_setup/down.sql +++ /dev/null @@ -1,6 +0,0 @@ --- 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. - -DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass); -DROP FUNCTION IF EXISTS diesel_set_updated_at(); diff --git a/bot-database/migrations/00000000000000_diesel_initial_setup/up.sql b/bot-database/migrations/00000000000000_diesel_initial_setup/up.sql deleted file mode 100644 index d68895b..0000000 --- a/bot-database/migrations/00000000000000_diesel_initial_setup/up.sql +++ /dev/null @@ -1,36 +0,0 @@ --- 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/bot-database/migrations/2021-04-09-075309_create_tables/down.sql b/bot-database/migrations/2021-04-09-075309_create_tables/down.sql deleted file mode 100644 index c54e2c1..0000000 --- a/bot-database/migrations/2021-04-09-075309_create_tables/down.sql +++ /dev/null @@ -1,2 +0,0 @@ --- This file should undo anything in `up.sql` -DROP TABLE guild_settings; \ No newline at end of file diff --git a/bot-database/migrations/2021-04-09-075309_create_tables/up.sql b/bot-database/migrations/2021-04-09-075309_create_tables/up.sql deleted file mode 100644 index d8eb9b1..0000000 --- a/bot-database/migrations/2021-04-09-075309_create_tables/up.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE TABLE guild_settings ( - guild_id BIGINT NOT NULL, - key VARCHAR(255) NOT NULL, - value VARCHAR(1024), - PRIMARY KEY (guild_id, key) -); \ No newline at end of file diff --git a/bot-database/migrations/2021-04-09-095329_create_guild_playlists/down.sql b/bot-database/migrations/2021-04-09-095329_create_guild_playlists/down.sql deleted file mode 100644 index 2050c9d..0000000 --- a/bot-database/migrations/2021-04-09-095329_create_guild_playlists/down.sql +++ /dev/null @@ -1,2 +0,0 @@ --- This file should undo anything in `up.sql` -DROP TABLE guild_playlists; \ No newline at end of file diff --git a/bot-database/migrations/2021-04-09-095329_create_guild_playlists/up.sql b/bot-database/migrations/2021-04-09-095329_create_guild_playlists/up.sql deleted file mode 100644 index ab1947a..0000000 --- a/bot-database/migrations/2021-04-09-095329_create_guild_playlists/up.sql +++ /dev/null @@ -1,7 +0,0 @@ --- Your SQL goes here -CREATE TABLE guild_playlists ( - guild_id BIGINT NOT NULL, - name VARCHAR(255) NOT NULL, - url VARCHAR(1024) NOT NULL, - PRIMARY KEY (guild_id, name) -) \ No newline at end of file diff --git a/bot-database/migrations/2021-04-12-115141_create_gifs/down.sql b/bot-database/migrations/2021-04-12-115141_create_gifs/down.sql deleted file mode 100644 index 8ea133c..0000000 --- a/bot-database/migrations/2021-04-12-115141_create_gifs/down.sql +++ /dev/null @@ -1,2 +0,0 @@ --- This file should undo anything in `up.sql` -DROP TABLE gifs; \ No newline at end of file diff --git a/bot-database/migrations/2021-04-12-115141_create_gifs/up.sql b/bot-database/migrations/2021-04-12-115141_create_gifs/up.sql deleted file mode 100644 index 07ebbd0..0000000 --- a/bot-database/migrations/2021-04-12-115141_create_gifs/up.sql +++ /dev/null @@ -1,8 +0,0 @@ --- Your SQL goes here -CREATE TABLE gifs ( - id BIGSERIAL PRIMARY KEY , - category VARCHAR(128), - name VARCHAR(128), - url VARCHAR(128) NOT NULL, - UNIQUE (category, name) -) \ No newline at end of file diff --git a/bot-database/migrations/2021-04-12-133308_create_statistics/down.sql b/bot-database/migrations/2021-04-12-133308_create_statistics/down.sql deleted file mode 100644 index b660849..0000000 --- a/bot-database/migrations/2021-04-12-133308_create_statistics/down.sql +++ /dev/null @@ -1,2 +0,0 @@ --- This file should undo anything in `up.sql` -DROP TABLE statistics; \ No newline at end of file diff --git a/bot-database/migrations/2021-04-12-133308_create_statistics/up.sql b/bot-database/migrations/2021-04-12-133308_create_statistics/up.sql deleted file mode 100644 index 75d42be..0000000 --- a/bot-database/migrations/2021-04-12-133308_create_statistics/up.sql +++ /dev/null @@ -1,9 +0,0 @@ --- Your SQL goes here -CREATE TABLE statistics ( - id BIGSERIAL PRIMARY KEY, - version VARCHAR(32) NOT NULL, - command VARCHAR(255) NOT NULL, - executed_at TIMESTAMP NOT NULL, - success BOOLEAN NOT NULL DEFAULT TRUE, - error_msg TEXT -) \ No newline at end of file diff --git a/bot-database/migrations/2021-04-13-144951_create_youtube_songs/down.sql b/bot-database/migrations/2021-04-13-144951_create_youtube_songs/down.sql deleted file mode 100644 index 06da346..0000000 --- a/bot-database/migrations/2021-04-13-144951_create_youtube_songs/down.sql +++ /dev/null @@ -1,2 +0,0 @@ --- This file should undo anything in `up.sql` -DROP TABLE youtube_songs; \ No newline at end of file diff --git a/bot-database/migrations/2021-04-13-144951_create_youtube_songs/up.sql b/bot-database/migrations/2021-04-13-144951_create_youtube_songs/up.sql deleted file mode 100644 index a778969..0000000 --- a/bot-database/migrations/2021-04-13-144951_create_youtube_songs/up.sql +++ /dev/null @@ -1,11 +0,0 @@ --- Your SQL goes here -CREATE TABLE youtube_songs ( - id BIGSERIAL PRIMARY KEY, - spotify_id VARCHAR(255) NOT NULL, - artist VARCHAR(128) NOT NULL, - title VARCHAR(255) NOT NULL, - album VARCHAR(255) NOT NULL, - url VARCHAR(128) NOT NULL, - score INTEGER DEFAULT 0 NOT NULL, - UNIQUE (spotify_id, url) -) \ No newline at end of file diff --git a/bot-database/migrations/2021-04-16-064403_create_ephemeral_messages/down.sql b/bot-database/migrations/2021-04-16-064403_create_ephemeral_messages/down.sql deleted file mode 100644 index 42cb080..0000000 --- a/bot-database/migrations/2021-04-16-064403_create_ephemeral_messages/down.sql +++ /dev/null @@ -1,2 +0,0 @@ --- This file should undo anything in `up.sql` -DROP TABLE ephemeral_messages; \ No newline at end of file diff --git a/bot-database/migrations/2021-04-16-064403_create_ephemeral_messages/up.sql b/bot-database/migrations/2021-04-16-064403_create_ephemeral_messages/up.sql deleted file mode 100644 index 0e34084..0000000 --- a/bot-database/migrations/2021-04-16-064403_create_ephemeral_messages/up.sql +++ /dev/null @@ -1,7 +0,0 @@ --- Your SQL goes here -CREATE TABLE ephemeral_messages ( - channel_id BIGINT NOT NULL, - message_id BIGINT NOT NULL, - timeout TIMESTAMP NOT NULL, - PRIMARY KEY (channel_id, message_id) -) \ No newline at end of file diff --git a/bot-database/migrations/2021-04-21-095152_rename_gifs_table/down.sql b/bot-database/migrations/2021-04-21-095152_rename_gifs_table/down.sql deleted file mode 100644 index e3b46cf..0000000 --- a/bot-database/migrations/2021-04-21-095152_rename_gifs_table/down.sql +++ /dev/null @@ -1,2 +0,0 @@ --- This file should undo anything in `up.sql` -ALTER TABLE media RENAME TO gifs; \ No newline at end of file diff --git a/bot-database/migrations/2021-04-21-095152_rename_gifs_table/up.sql b/bot-database/migrations/2021-04-21-095152_rename_gifs_table/up.sql deleted file mode 100644 index 65b3f9a..0000000 --- a/bot-database/migrations/2021-04-21-095152_rename_gifs_table/up.sql +++ /dev/null @@ -1,2 +0,0 @@ --- Your SQL goes here -ALTER TABLE gifs RENAME TO media; \ No newline at end of file diff --git a/bot-database/src/database/ephemeral_messages.rs b/bot-database/src/database/ephemeral_messages.rs index fbcf33f..b6fe3be 100644 --- a/bot-database/src/database/ephemeral_messages.rs +++ b/bot-database/src/database/ephemeral_messages.rs @@ -1,56 +1,49 @@ +use sea_orm::ActiveValue::Set; use std::time::SystemTime; -use diesel::prelude::*; -use diesel::{delete, insert_into}; -use tokio_diesel::*; - +use crate::entity::ephemeral_messages; use crate::error::DatabaseResult; -use crate::models::*; -use crate::schema::*; -use crate::Database; +use sea_orm::prelude::*; -impl Database { +impl super::BotDatabase { /// Adds a command statistic to the database + #[tracing::instrument(level = "debug", skip(self))] pub async fn add_ephemeral_message( &self, channel_id: u64, message_id: u64, timeout: SystemTime, ) -> DatabaseResult<()> { - use ephemeral_messages::dsl; - insert_into(dsl::ephemeral_messages) - .values(EphemeralMessageInsert { - channel_id: channel_id as i64, - message_id: message_id as i64, - timeout, - }) - .execute_async(&self.pool) - .await?; + let model = ephemeral_messages::ActiveModel { + channel_id: Set(channel_id as i64), + message_id: Set(message_id as i64), + timeout: Set(DateTimeLocal::from(timeout).into()), + ..Default::default() + }; + model.insert(&self.db).await?; Ok(()) } /// Returns a vec of all ephemeral messages - pub async fn get_ephemeral_messages(&self) -> DatabaseResult> { - use ephemeral_messages::dsl; - let messages: Vec = dsl::ephemeral_messages - .load_async::(&self.pool) - .await?; + #[tracing::instrument(level = "debug", skip(self))] + pub async fn get_ephemeral_messages(&self) -> DatabaseResult> { + let messages = ephemeral_messages::Entity::find().all(&self.db).await?; Ok(messages) } /// Deletes a single ephemeral message + #[tracing::instrument(level = "debug", skip(self))] pub async fn delete_ephemeral_message( &self, channel_id: i64, message_id: i64, ) -> DatabaseResult<()> { - use ephemeral_messages::dsl; - delete(dsl::ephemeral_messages) - .filter(dsl::channel_id.eq(channel_id)) - .filter(dsl::message_id.eq(message_id)) - .execute_async(&self.pool) + ephemeral_messages::Entity::delete_many() + .filter(ephemeral_messages::Column::ChannelId.eq(channel_id)) + .filter(ephemeral_messages::Column::MessageId.eq(message_id)) + .exec(&self.db) .await?; Ok(()) diff --git a/bot-database/src/database/guild_playlists.rs b/bot-database/src/database/guild_playlists.rs index e3cffaf..b7670a5 100644 --- a/bot-database/src/database/guild_playlists.rs +++ b/bot-database/src/database/guild_playlists.rs @@ -1,65 +1,54 @@ -use diesel::insert_into; -use diesel::prelude::*; -use tokio_diesel::*; - +use crate::entity::guild_playlists; use crate::error::DatabaseResult; -use crate::models::*; -use crate::schema::*; -use crate::Database; +use sea_orm::prelude::*; +use sea_orm::ActiveValue::Set; -impl Database { +impl super::BotDatabase { /// Returns a list of all guild playlists - pub async fn get_guild_playlists(&self, guild_id: u64) -> DatabaseResult> { - use guild_playlists::dsl; - log::debug!("Retrieving guild playlists for guild {}", guild_id); - - let playlists: Vec = dsl::guild_playlists - .filter(dsl::guild_id.eq(guild_id as i64)) - .load_async::(&self.pool) + #[tracing::instrument(level = "debug", skip(self))] + pub async fn get_guild_playlists( + &self, + guild_id: u64, + ) -> DatabaseResult> { + let playlists = guild_playlists::Entity::find() + .filter(guild_playlists::Column::GuildId.eq(guild_id)) + .all(&self.db) .await?; Ok(playlists) } /// Returns a guild playlist by name + #[tracing::instrument(level = "debug", skip(self))] pub async fn get_guild_playlist( &self, guild_id: u64, name: String, - ) -> DatabaseResult> { - use guild_playlists::dsl; - log::debug!("Retriving guild playlist '{}' for guild {}", name, guild_id); - - let playlists: Vec = dsl::guild_playlists - .filter(dsl::guild_id.eq(guild_id as i64)) - .filter(dsl::name.eq(name)) - .load_async::(&self.pool) + ) -> DatabaseResult> { + let playlist = guild_playlists::Entity::find() + .filter(guild_playlists::Column::GuildId.eq(guild_id)) + .filter(guild_playlists::Column::Name.eq(name)) + .one(&self.db) .await?; - Ok(playlists.into_iter().next()) + Ok(playlist) } /// Adds a new playlist to the database overwriting the old one + #[tracing::instrument(level = "debug", skip(self))] pub async fn add_guild_playlist( &self, guild_id: u64, name: String, url: String, ) -> DatabaseResult<()> { - use guild_playlists::dsl; - log::debug!("Inserting guild playlist '{}' for guild {}", name, guild_id); - - insert_into(dsl::guild_playlists) - .values(GuildPlaylistInsert { - guild_id: guild_id as i64, - name: name.clone(), - url: url.clone(), - }) - .on_conflict((dsl::guild_id, dsl::name)) - .do_update() - .set(dsl::url.eq(url)) - .execute_async(&self.pool) - .await?; + let model = guild_playlists::ActiveModel { + guild_id: Set(guild_id as i64), + name: Set(name), + url: Set(url), + ..Default::default() + }; + model.insert(&self.db).await?; Ok(()) } diff --git a/bot-database/src/database/guild_settings.rs b/bot-database/src/database/guild_settings.rs index 1e14766..be01af2 100644 --- a/bot-database/src/database/guild_settings.rs +++ b/bot-database/src/database/guild_settings.rs @@ -1,53 +1,46 @@ +use sea_orm::ActiveValue::Set; use std::any; use std::fmt::Debug; use std::str::FromStr; -use diesel::prelude::*; -use diesel::{delete, insert_into}; -use tokio_diesel::*; - +use crate::entity::guild_settings; use crate::error::DatabaseResult; -use crate::models::*; -use crate::schema::*; -use crate::Database; +use sea_orm::prelude::*; -impl Database { +impl super::BotDatabase { /// Returns a guild setting from the database - pub async fn get_guild_setting( + #[tracing::instrument(level = "debug", skip(self))] + pub async fn get_guild_setting + Debug>( &self, guild_id: u64, - key: String, + key: S, ) -> DatabaseResult> where T: FromStr, { - use guild_settings::dsl; - log::debug!("Retrieving setting '{}' for guild {}", key, guild_id); - - let entries: Vec = dsl::guild_settings - .filter(dsl::guild_id.eq(guild_id as i64)) - .filter(dsl::key.eq(key)) - .load_async::(&self.pool) + let setting = guild_settings::Entity::find() + .filter(guild_settings::Column::GuildId.eq(guild_id as i64)) + .filter(guild_settings::Column::Key.eq(key.as_ref())) + .one(&self.db) .await?; - log::trace!("Result is {:?}", entries); - - if let Some(first) = entries.first() { + if let Some(setting) = setting { if any::TypeId::of::() == any::TypeId::of::() { - Ok(first + Ok(setting .value .clone() .unwrap_or("false".to_string()) .parse::() .ok()) } else { - Ok(first.value.clone().and_then(|v| v.parse::().ok())) + Ok(setting.value.clone().and_then(|v| v.parse::().ok())) } } else { - return Ok(None); + Ok(None) } } /// Upserting a guild setting + #[tracing::instrument(level = "debug", skip(self))] pub async fn set_guild_setting( &self, guild_id: u64, @@ -55,33 +48,38 @@ impl Database { value: T, ) -> DatabaseResult<()> where - T: ToString + Debug, + T: 'static + ToString + FromStr + Debug, { - use guild_settings::dsl; - log::debug!("Setting '{}' to '{:?}' for guild {}", key, value, guild_id); - - insert_into(dsl::guild_settings) - .values(GuildSettingInsert { - guild_id: guild_id as i64, - key: key.to_string(), - value: value.to_string(), - }) - .on_conflict((dsl::guild_id, dsl::key)) - .do_update() - .set(dsl::value.eq(value.to_string())) - .execute_async(&self.pool) - .await?; + let model = guild_settings::ActiveModel { + guild_id: Set(guild_id as i64), + key: Set(key.clone()), + value: Set(Some(value.to_string())), + ..Default::default() + }; + if self + .get_guild_setting::(guild_id, &key) + .await? + .is_some() + { + model.update(&self.db).await?; + } else { + model.insert(&self.db).await?; + } Ok(()) } /// Deletes a guild setting - pub async fn delete_guild_setting(&self, guild_id: u64, key: String) -> DatabaseResult<()> { - use guild_settings::dsl; - delete(dsl::guild_settings) - .filter(dsl::guild_id.eq(guild_id as i64)) - .filter(dsl::key.eq(key)) - .execute_async(&self.pool) + #[tracing::instrument(level = "debug", skip(self))] + pub async fn delete_guild_setting + Debug>( + &self, + guild_id: u64, + key: S, + ) -> DatabaseResult<()> { + guild_settings::Entity::delete_many() + .filter(guild_settings::Column::GuildId.eq(guild_id)) + .filter(guild_settings::Column::Key.eq(key.as_ref())) + .exec(&self.db) .await?; Ok(()) diff --git a/bot-database/src/database/media.rs b/bot-database/src/database/media.rs index 1bf19ce..935bded 100644 --- a/bot-database/src/database/media.rs +++ b/bot-database/src/database/media.rs @@ -1,59 +1,47 @@ -use diesel::insert_into; -use diesel::prelude::*; -use tokio_diesel::*; - +use crate::entity::media; use crate::error::DatabaseResult; -use crate::models::*; -use crate::schema::*; -use crate::Database; +use sea_orm::prelude::*; +use sea_orm::ActiveValue::Set; +use std::fmt::Debug; -impl Database { +impl super::BotDatabase { /// Returns a list of all gifs in the database - pub async fn get_all_media(&self) -> DatabaseResult> { - use media::dsl; - log::debug!("Loading all gifs from the database"); + #[tracing::instrument(level = "debug", skip(self))] + pub async fn get_all_media(&self) -> DatabaseResult> { + let entries = media::Entity::find().all(&self.db).await?; - let gifs: Vec = dsl::media.load_async::(&self.pool).await?; - Ok(gifs) + Ok(entries) } /// Returns a list of gifs by assigned category - pub async fn get_media_by_category + 'static>( + #[tracing::instrument(level = "debug", skip(self))] + pub async fn get_media_by_category + 'static + Debug>( &self, category: S, - ) -> DatabaseResult> { - use media::dsl; - log::debug!("Searching for gifs in category '{}'", category.as_ref()); - - let gifs: Vec = dsl::media - .filter(dsl::category.eq(category.as_ref())) - .load_async::(&self.pool) + ) -> DatabaseResult> { + let entries = media::Entity::find() + .filter(media::Column::Category.eq(category.as_ref())) + .all(&self.db) .await?; - Ok(gifs) + + Ok(entries) } /// Adds a gif to the database + #[tracing::instrument(level = "debug", skip(self))] pub async fn add_media( &self, - url: &str, + url: String, category: Option, name: Option, ) -> DatabaseResult<()> { - use media::dsl; - log::debug!( - "Inserting gif with url '{}' and name {:?} and category {:?}", - url, - name, - category - ); - insert_into(dsl::media) - .values(MediaInsert { - url: url.to_string(), - name, - category, - }) - .execute_async(&self.pool) - .await?; + let model = media::ActiveModel { + url: Set(url), + category: Set(category), + name: Set(name), + ..Default::default() + }; + model.insert(&self.db).await?; Ok(()) } diff --git a/bot-database/src/database/mod.rs b/bot-database/src/database/mod.rs index 1bd144d..935e1e5 100644 --- a/bot-database/src/database/mod.rs +++ b/bot-database/src/database/mod.rs @@ -2,11 +2,10 @@ pub use ephemeral_messages::*; pub use guild_playlists::*; pub use guild_playlists::*; pub use media::*; +use sea_orm::DatabaseConnection; pub use statistics::*; pub use youtube_songs::*; -use crate::PoolConnection; - mod ephemeral_messages; mod guild_playlists; mod guild_settings; @@ -15,16 +14,12 @@ mod statistics; mod youtube_songs; #[derive(Clone)] -pub struct Database { - pool: PoolConnection, +pub struct BotDatabase { + db: DatabaseConnection, } -unsafe impl Send for Database {} - -unsafe impl Sync for Database {} - -impl Database { - pub fn new(pool: PoolConnection) -> Self { - Self { pool } +impl BotDatabase { + pub fn new(db: DatabaseConnection) -> Self { + Self { db } } } diff --git a/bot-database/src/database/statistics.rs b/bot-database/src/database/statistics.rs index 261aa2f..05050df 100644 --- a/bot-database/src/database/statistics.rs +++ b/bot-database/src/database/statistics.rs @@ -1,50 +1,49 @@ +use crate::entity::statistics; +use crate::error::DatabaseResult; +use sea_orm::prelude::*; +use sea_orm::ActiveValue::Set; +use sea_orm::{FromQueryResult, QuerySelect}; use std::time::SystemTime; -use diesel::dsl::count; -use diesel::insert_into; -use diesel::prelude::*; -use tokio_diesel::*; - -use crate::error::DatabaseResult; -use crate::models::*; -use crate::schema::*; -use crate::Database; +#[derive(FromQueryResult)] +struct CommandCount { + count: i64, +} -impl Database { +impl super::BotDatabase { /// Adds a command statistic to the database + #[tracing::instrument(level = "debug", skip(self))] pub async fn add_statistic( &self, - version: &str, - command: &str, + version: String, + command: String, executed_at: SystemTime, success: bool, error_msg: Option, ) -> DatabaseResult<()> { - use statistics::dsl; - log::trace!("Adding statistic to database"); - insert_into(dsl::statistics) - .values(StatisticInsert { - version: version.to_string(), - command: command.to_string(), - executed_at, - success, - error_msg, - }) - .execute_async(&self.pool) - .await?; + let model = statistics::ActiveModel { + version: Set(version), + command: Set(command), + executed_at: Set(DateTimeLocal::from(executed_at).into()), + success: Set(success), + error_msg: Set(error_msg), + ..Default::default() + }; + model.insert(&self.db).await?; Ok(()) } /// Returns the total number of commands executed + #[tracing::instrument(level = "debug", skip(self))] pub async fn get_total_commands_statistic(&self) -> DatabaseResult { - use statistics::dsl; - log::trace!("Querying total number of commands"); - let total_count: i64 = dsl::statistics - .select(count(dsl::id)) - .first_async::(&self.pool) + let total_count: Option = statistics::Entity::find() + .select_only() + .column_as(statistics::Column::Id.count(), "count") + .into_model::() + .one(&self.db) .await?; - Ok(total_count as u64) + Ok(total_count.unwrap().count as u64) } } diff --git a/bot-database/src/database/youtube_songs.rs b/bot-database/src/database/youtube_songs.rs index e294ba0..8fff8b2 100644 --- a/bot-database/src/database/youtube_songs.rs +++ b/bot-database/src/database/youtube_songs.rs @@ -1,69 +1,56 @@ -use diesel::prelude::*; -use diesel::{delete, insert_into}; -use tokio_diesel::*; - +use crate::entity::youtube_songs; use crate::error::DatabaseResult; -use crate::models::*; -use crate::schema::*; -use crate::Database; +use sea_orm::prelude::*; +use sea_orm::ActiveValue::Set; -impl Database { +impl super::BotDatabase { /// Adds a song to the database or increments the score when it /// already exists + #[tracing::instrument(level = "debug", skip(self))] pub async fn add_song( &self, - spotify_id: &str, - artist: &str, - title: &str, - album: &str, - url: &str, + spotify_id: String, + artist: String, + title: String, + album: String, + url: String, ) -> DatabaseResult<()> { - use youtube_songs::dsl; - log::debug!( - "Inserting/Updating song in database spotify_id: '{}' artist: '{}', title: '{}', album: '{}', url: '{}'", - spotify_id, - artist, - title, - album, - url, - ); - - insert_into(dsl::youtube_songs) - .values(YoutubeSongInsert { - spotify_id: spotify_id.to_string(), - artist: artist.to_string(), - title: title.to_string(), - album: album.to_string(), - url: url.to_string(), - }) - .on_conflict((dsl::spotify_id, dsl::url)) - .do_update() - .set(dsl::score.eq(dsl::score + 1)) - .execute_async(&self.pool) - .await?; + if let Some(model) = self.get_song(&spotify_id).await? { + let mut active_model: youtube_songs::ActiveModel = model.into(); + active_model.score = Set(active_model.score.unwrap() + 1); + active_model.update(&self.db).await?; + } else { + let model = youtube_songs::ActiveModel { + spotify_id: Set(spotify_id), + artist: Set(artist), + title: Set(title), + album: Set(album), + url: Set(url), + ..Default::default() + }; + model.insert(&self.db).await?; + } Ok(()) } /// Returns the song with the best score for the given query - pub async fn get_song(&self, spotify_id: &str) -> DatabaseResult> { - use youtube_songs::dsl; - let songs: Vec = dsl::youtube_songs - .filter(dsl::spotify_id.eq(spotify_id)) - .order(dsl::score.desc()) - .limit(1) - .load_async::(&self.pool) + #[tracing::instrument(level = "debug", skip(self))] + pub async fn get_song(&self, spotify_id: &str) -> DatabaseResult> { + let song = youtube_songs::Entity::find() + .filter(youtube_songs::Column::SpotifyId.eq(spotify_id)) + .one(&self.db) .await?; - Ok(songs.into_iter().next()) + Ok(song) } /// Deletes a song from the database + #[tracing::instrument(level = "debug", skip(self))] pub async fn delete_song(&self, id: i64) -> DatabaseResult<()> { - use youtube_songs::dsl; - delete(dsl::youtube_songs) - .filter(dsl::id.eq(id)) - .execute_async(&self.pool) + youtube_songs::Entity::delete_many() + .filter(youtube_songs::Column::Id.eq(id)) + .exec(&self.db) .await?; Ok(()) diff --git a/bot-database/src/entity/ephemeral_messages.rs b/bot-database/src/entity/ephemeral_messages.rs new file mode 100644 index 0000000..b1fb847 --- /dev/null +++ b/bot-database/src/entity/ephemeral_messages.rs @@ -0,0 +1,24 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.7.0 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "ephemeral_messages")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub channel_id: i64, + #[sea_orm(primary_key, auto_increment = false)] + pub message_id: i64, + pub timeout: DateTimeWithTimeZone, +} + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation {} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + panic!("No RelationDef") + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/bot-database/src/entity/guild_playlists.rs b/bot-database/src/entity/guild_playlists.rs new file mode 100644 index 0000000..fc2ecd3 --- /dev/null +++ b/bot-database/src/entity/guild_playlists.rs @@ -0,0 +1,24 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.7.0 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "guild_playlists")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub guild_id: i64, + #[sea_orm(primary_key, auto_increment = false)] + pub name: String, + pub url: String, +} + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation {} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + panic!("No RelationDef") + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/bot-database/src/entity/guild_settings.rs b/bot-database/src/entity/guild_settings.rs new file mode 100644 index 0000000..750c1b7 --- /dev/null +++ b/bot-database/src/entity/guild_settings.rs @@ -0,0 +1,24 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.7.0 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "guild_settings")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub guild_id: i64, + #[sea_orm(primary_key, auto_increment = false)] + pub key: String, + pub value: Option, +} + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation {} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + panic!("No RelationDef") + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/bot-database/src/entity/media.rs b/bot-database/src/entity/media.rs new file mode 100644 index 0000000..4093001 --- /dev/null +++ b/bot-database/src/entity/media.rs @@ -0,0 +1,24 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.7.0 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "media")] +pub struct Model { + #[sea_orm(primary_key)] + pub id: i64, + pub category: Option, + pub name: Option, + pub url: String, +} + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation {} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + panic!("No RelationDef") + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/bot-database/src/entity/mod.rs b/bot-database/src/entity/mod.rs new file mode 100644 index 0000000..a467c1f --- /dev/null +++ b/bot-database/src/entity/mod.rs @@ -0,0 +1,10 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.7.0 + +pub mod prelude; + +pub mod ephemeral_messages; +pub mod guild_playlists; +pub mod guild_settings; +pub mod media; +pub mod statistics; +pub mod youtube_songs; diff --git a/bot-database/src/entity/prelude.rs b/bot-database/src/entity/prelude.rs new file mode 100644 index 0000000..b8fd0d0 --- /dev/null +++ b/bot-database/src/entity/prelude.rs @@ -0,0 +1,8 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.7.0 + +pub use super::ephemeral_messages::Entity as EphemeralMessages; +pub use super::guild_playlists::Entity as GuildPlaylists; +pub use super::guild_settings::Entity as GuildSettings; +pub use super::media::Entity as Media; +pub use super::statistics::Entity as Statistics; +pub use super::youtube_songs::Entity as YoutubeSongs; diff --git a/bot-database/src/entity/statistics.rs b/bot-database/src/entity/statistics.rs new file mode 100644 index 0000000..8589446 --- /dev/null +++ b/bot-database/src/entity/statistics.rs @@ -0,0 +1,27 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.7.0 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "statistics")] +pub struct Model { + #[sea_orm(primary_key)] + pub id: i64, + pub version: String, + pub command: String, + pub executed_at: DateTimeWithTimeZone, + pub success: bool, + #[sea_orm(column_type = "Text", nullable)] + pub error_msg: Option, +} + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation {} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + panic!("No RelationDef") + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/bot-database/src/entity/youtube_songs.rs b/bot-database/src/entity/youtube_songs.rs new file mode 100644 index 0000000..3a31272 --- /dev/null +++ b/bot-database/src/entity/youtube_songs.rs @@ -0,0 +1,27 @@ +//! SeaORM Entity. Generated by sea-orm-codegen 0.7.0 + +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] +#[sea_orm(table_name = "youtube_songs")] +pub struct Model { + #[sea_orm(primary_key)] + pub id: i64, + pub spotify_id: String, + pub artist: String, + pub title: String, + pub album: String, + pub url: String, + pub score: i32, +} + +#[derive(Copy, Clone, Debug, EnumIter)] +pub enum Relation {} + +impl RelationTrait for Relation { + fn def(&self) -> RelationDef { + panic!("No RelationDef") + } +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/bot-database/src/error.rs b/bot-database/src/error.rs index 285d342..83336a1 100644 --- a/bot-database/src/error.rs +++ b/bot-database/src/error.rs @@ -7,20 +7,8 @@ pub enum DatabaseError { #[error("DotEnv Error: {0}")] DotEnv(#[from] dotenv::Error), - #[error("Connection Error: {0}")] - ConnectionError(#[from] diesel::prelude::ConnectionError), - - #[error("Pool Connection Error: {0}")] - PoolConnectionError(#[from] r2d2::Error), - - #[error("Migration Error: {0}")] - MigrationError(#[from] diesel_migrations::RunMigrationsError), - - #[error("Result Error: {0}")] - ResultError(#[from] diesel::result::Error), - - #[error("AsyncError: {0}")] - AsyncError(#[from] tokio_diesel::AsyncError), + #[error("{0}")] + SeaOrm(#[from] sea_orm::error::DbErr), #[error("{0}")] Msg(String), diff --git a/bot-database/src/lib.rs b/bot-database/src/lib.rs index 364a7ab..ee4c0d3 100644 --- a/bot-database/src/lib.rs +++ b/bot-database/src/lib.rs @@ -1,47 +1,31 @@ -#[macro_use] -extern crate diesel; - -#[macro_use] -extern crate diesel_migrations; - -use crate::error::{DatabaseError, DatabaseResult}; -use diesel::prelude::*; -use diesel::r2d2::{ConnectionManager, ManageConnection, Pool}; +use crate::error::DatabaseResult; use std::env; pub mod database; +pub mod entity; pub mod error; pub mod models; -pub mod schema; pub static VERSION: &str = env!("CARGO_PKG_VERSION"); -pub use database::Database; - -type PoolConnection = Pool>; +pub use database::BotDatabase as Database; +use migration::MigratorTrait; +use sea_orm::{ConnectOptions, Database as SeaDatabase, DatabaseConnection}; -embed_migrations!("../bot-database/migrations"); - -fn get_connection() -> DatabaseResult { +#[tracing::instrument] +async fn get_connection() -> DatabaseResult { let database_url = env::var("DATABASE_URL").expect("No DATABASE_URL in path"); - log::debug!("Establishing database connection..."); - let manager = ConnectionManager::::new(database_url); - log::trace!("Connecting..."); - manager - .connect() - .map_err(|e| DatabaseError::Msg(format!("{:?}", e)))?; - log::trace!("Creating pool..."); - let pool = Pool::builder().max_size(16).build(manager)?; - log::trace!("Getting one connection to run migrations..."); - let connection = pool.get()?; - log::debug!("Running migrations..."); - embedded_migrations::run(&connection)?; - log::debug!("Migrations finished"); - log::info!("Database connection initialized"); - - Ok(pool) + tracing::debug!("Establishing database connection..."); + let opt = ConnectOptions::new(database_url); + let db = SeaDatabase::connect(opt).await?; + tracing::debug!("Running migrations..."); + migration::Migrator::up(&db, None).await?; + tracing::debug!("Migrations finished"); + tracing::info!("Database connection initialized"); + + Ok(db) } -pub fn get_database() -> DatabaseResult { - let conn = get_connection()?; +pub async fn get_database() -> DatabaseResult { + let conn = get_connection().await?; Ok(Database::new(conn)) } diff --git a/bot-database/src/models.rs b/bot-database/src/models.rs index 5240fb1..7a88a4f 100644 --- a/bot-database/src/models.rs +++ b/bot-database/src/models.rs @@ -1,94 +1,8 @@ -use crate::schema::*; -use std::time::SystemTime; - -#[derive(Queryable, Debug)] -pub struct GuildSetting { - pub guild_id: i64, - pub key: String, - pub value: Option, -} - -#[derive(Insertable, Debug)] -#[table_name = "guild_settings"] -pub struct GuildSettingInsert { - pub guild_id: i64, - pub key: String, - pub value: String, -} - -#[derive(Queryable, Debug)] -pub struct GuildPlaylist { - pub guild_id: i64, - pub name: String, - pub url: String, -} - -#[derive(Insertable, Debug)] -#[table_name = "guild_playlists"] -pub struct GuildPlaylistInsert { - pub guild_id: i64, - pub name: String, - pub url: String, -} - -#[derive(Queryable, Debug, Clone)] -pub struct Media { - pub id: i64, - pub category: Option, - pub name: Option, - pub url: String, -} - -#[derive(Insertable, Debug)] -#[table_name = "media"] -pub struct MediaInsert { - pub category: Option, - pub name: Option, - pub url: String, -} - -#[derive(Insertable, Debug)] -#[table_name = "statistics"] -pub struct StatisticInsert { - pub version: String, - pub command: String, - pub executed_at: SystemTime, - pub success: bool, - pub error_msg: Option, -} - -#[derive(Queryable, Debug, Clone)] -pub struct YoutubeSong { - pub id: i64, - pub spotify_id: String, - pub artist: String, - pub title: String, - pub album: String, - pub url: String, - pub score: i32, -} - -#[derive(Insertable, Debug)] -#[table_name = "youtube_songs"] -pub struct YoutubeSongInsert { - pub spotify_id: String, - pub artist: String, - pub title: String, - pub album: String, - pub url: String, -} - -#[derive(Queryable, Debug, Clone)] -pub struct EphemeralMessage { - pub channel_id: i64, - pub message_id: i64, - pub timeout: SystemTime, -} - -#[derive(Insertable, Debug)] -#[table_name = "ephemeral_messages"] -pub struct EphemeralMessageInsert { - pub channel_id: i64, - pub message_id: i64, - pub timeout: SystemTime, -} +use super::entity; + +pub use entity::ephemeral_messages::Model as EphemeralMessage; +pub use entity::guild_playlists::Model as GuildPlaylist; +pub use entity::guild_settings::Model as GuildSetting; +pub use entity::media::Model as Media; +pub use entity::statistics::Model as Statistic; +pub use entity::youtube_songs::Model as YoutubeSong; diff --git a/bot-database/src/schema.rs b/bot-database/src/schema.rs deleted file mode 100644 index 3395b30..0000000 --- a/bot-database/src/schema.rs +++ /dev/null @@ -1,64 +0,0 @@ -table! { - ephemeral_messages (channel_id, message_id) { - channel_id -> Int8, - message_id -> Int8, - timeout -> Timestamp, - } -} - -table! { - guild_playlists (guild_id, name) { - guild_id -> Int8, - name -> Varchar, - url -> Varchar, - } -} - -table! { - guild_settings (guild_id, key) { - guild_id -> Int8, - key -> Varchar, - value -> Nullable, - } -} - -table! { - media (id) { - id -> Int8, - category -> Nullable, - name -> Nullable, - url -> Varchar, - } -} - -table! { - statistics (id) { - id -> Int8, - version -> Varchar, - command -> Varchar, - executed_at -> Timestamp, - success -> Bool, - error_msg -> Nullable, - } -} - -table! { - youtube_songs (id) { - id -> Int8, - spotify_id -> Varchar, - artist -> Varchar, - title -> Varchar, - album -> Varchar, - url -> Varchar, - score -> Int4, - } -} - -allow_tables_to_appear_in_same_query!( - ephemeral_messages, - guild_playlists, - guild_settings, - media, - statistics, - youtube_songs, -); diff --git a/src/client.rs b/src/client.rs index 240498f..fce77d0 100644 --- a/src/client.rs +++ b/src/client.rs @@ -24,7 +24,7 @@ use crate::utils::error::{BotError, BotResult}; pub async fn get_client() -> BotResult { let token = env::var("BOT_TOKEN").map_err(|_| BotError::MissingToken)?; - let database = get_database()?; + let database = get_database().await?; let client = Client::builder(token) .register_rich_interactions_with(get_raw_event_handler()) .event_handler(Handler) @@ -107,8 +107,8 @@ async fn after_hook(ctx: &Context, msg: &Message, cmd_name: &str, error: Command let database = get_database_from_context(ctx).await; let _ = database .add_statistic( - crate::VERSION, - cmd_name, + crate::VERSION.to_string(), + cmd_name.to_string(), SystemTime::now(), error_msg.is_none(), error_msg, diff --git a/src/commands/misc/add_media.rs b/src/commands/misc/add_media.rs index 21e1abb..82d7721 100644 --- a/src/commands/misc/add_media.rs +++ b/src/commands/misc/add_media.rs @@ -26,7 +26,7 @@ async fn add_media(ctx: &Context, msg: &Message, mut args: Args) -> CommandResul let name = args.single_quoted::().ok(); let database = get_database_from_context(&ctx).await; - database.add_media(&url, category, name).await?; + database.add_media(url, category, name).await?; EphemeralMessage::create(&ctx.http, msg.channel_id, SHORT_TIMEOUT, |c| { c.reference_message(msg) .content("Media entry added to the database.") diff --git a/src/commands/settings/get.rs b/src/commands/settings/get.rs index a00c311..7389fd6 100644 --- a/src/commands/settings/get.rs +++ b/src/commands/settings/get.rs @@ -23,7 +23,7 @@ async fn get(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { if let Some(key) = args.single::().ok() { tracing::debug!("Displaying guild setting of '{}'", key); let setting = database - .get_guild_setting::(guild.id.0, key.clone()) + .get_guild_setting::(guild.id.0, key.clone()) .await?; match setting { @@ -47,7 +47,7 @@ async fn get(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { { match database - .get_guild_setting::(guild.id.0, key.clone()) + .get_guild_setting::(guild.id.0, key.clone()) .await? { Some(value) => kv_pairs.push(format!("`{}` = `{}`", key, value)), diff --git a/src/commands/weeb/mod.rs b/src/commands/weeb/mod.rs index 2b9443d..12eb97a 100644 --- a/src/commands/weeb/mod.rs +++ b/src/commands/weeb/mod.rs @@ -3,6 +3,7 @@ use serenity::client::Context; use serenity::framework::standard::macros::group; use serenity::framework::standard::CommandResult; use serenity::model::channel::Message; +use std::fmt::Debug; use hololive::amelia::AMELIA_COMMAND; use hololive::fubuki::FUBUKI_COMMAND; @@ -37,7 +38,7 @@ mod theme; pub struct Weeb; /// Posts a random media entry with the given category -async fn post_random_media + 'static>( +async fn post_random_media + 'static + Debug>( ctx: &Context, msg: &Message, category: S, diff --git a/src/providers/music/mod.rs b/src/providers/music/mod.rs index 8d438d6..4556584 100644 --- a/src/providers/music/mod.rs +++ b/src/providers/music/mod.rs @@ -73,7 +73,7 @@ pub async fn add_youtube_song_to_database( if let Some(id) = track.id { database - .add_song(&id, &artists, &track.name, &track.album.name, &url) + .add_song(id, artists, track.name, track.album.name, url) .await?; } diff --git a/src/providers/settings.rs b/src/providers/settings.rs index 14f4f38..3b475b2 100644 --- a/src/providers/settings.rs +++ b/src/providers/settings.rs @@ -38,7 +38,7 @@ pub async fn get_setting( let data = ctx.data.read().await; let database = data.get::().unwrap(); database - .get_guild_setting::(guild_id.0, setting.to_string()) + .get_guild_setting::(guild_id.0, setting.to_string()) .await .map_err(BotError::from) } diff --git a/src/utils/mod.rs b/src/utils/mod.rs index c218201..627bbc1 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,3 +1,4 @@ +use chrono::{DateTime, FixedOffset, Local}; use std::env; use std::ops::Add; use std::sync::Arc; @@ -49,13 +50,14 @@ pub async fn get_previous_message_or_reply( Ok(referenced) } -/// Deletes all expired ephemeral messages that are stored in the database +/// deletes all expired ephemeral messages that are stored in the database pub async fn delete_messages_from_database(ctx: &Context) -> BotResult<()> { let database = get_database_from_context(ctx).await; let messages = database.get_ephemeral_messages().await?; + let now: DateTime = DateTime::::from(SystemTime::now()).into(); for message in messages { - if message.timeout <= SystemTime::now() { + if message.timeout <= now { tracing::debug!("Deleting message {:?}", message); let _ = ctx .http @@ -73,9 +75,9 @@ pub async fn delete_messages_from_database(ctx: &Context) -> BotResult<()> { ); tokio::spawn(async move { - tokio::time::sleep_until( - Instant::now().add(message.timeout.duration_since(SystemTime::now()).unwrap()), - ) + tokio::time::sleep_until(Instant::now().add(std::time::Duration::from_millis( + (message.timeout - now).num_milliseconds() as u64, + ))) .await; tracing::debug!("Deleting message {:?}", message); let _ = http