From d98e9ea9e31d4408d3b9f8dc02b7e9b4b16371ea Mon Sep 17 00:00:00 2001 From: Patrick Michl Date: Sun, 24 Jul 2022 23:08:02 +0200 Subject: [PATCH] add events and rooms migrations --- .drone.yml | 8 +- Cargo.lock | 440 +++++++----------- neo-entity/Cargo.toml | 2 +- neo-entity/src/events.rs | 21 +- neo-entity/src/lib.rs | 2 + neo-entity/src/rooms.rs | 13 +- neo-migration/Cargo.toml | 3 +- neo-migration/src/lib.rs | 6 +- .../src/m20220707_092851_create_users.rs | 7 +- .../src/m20220707_112339_create_devices.rs | 7 +- .../src/m20220707_143304_create_sessions.rs | 7 +- .../src/m20220724_223253_create_rooms.rs | 26 ++ .../src/m20220724_223335_create_events.rs | 72 +++ neo-util/src/events.rs | 20 + neo-util/src/lib.rs | 1 + neo/Cargo.toml | 2 +- neo/src/main.rs | 2 +- 17 files changed, 324 insertions(+), 315 deletions(-) create mode 100644 neo-migration/src/m20220724_223253_create_rooms.rs create mode 100644 neo-migration/src/m20220724_223335_create_events.rs create mode 100644 neo-util/src/events.rs diff --git a/.drone.yml b/.drone.yml index 44b339b..8f0fe56 100644 --- a/.drone.yml +++ b/.drone.yml @@ -8,10 +8,4 @@ steps: environment: SQLX_OFFLINE: 'true' commands: - - cargo check -- name: cargo test - image: rust:latest - environment: - SQLX_OFFLINE: 'true' - commands: - - cargo test \ No newline at end of file + - cargo check \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index a1bfd3c..8c53322 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -60,12 +60,6 @@ dependencies = [ "password-hash", ] -[[package]] -name = "arrayvec" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" - [[package]] name = "assign" version = "1.1.1" @@ -219,9 +213,9 @@ dependencies = [ [[package]] name = "atoi" -version = "0.4.0" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "616896e05fc0e2649463a93a15183c6a16bf03413a7af88ef1285ddedfa9cda5" +checksum = "d7c57d12312ff59c811c0643f4d80830505833c9ffaebd193d819392b265be8e" dependencies = [ "num-traits", ] @@ -249,6 +243,17 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "automod" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "117ef242fcde2cbfb384aa94277f9d452654feb0dd6c8d9d6ad51b6869db30cd" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "axum" version = "0.5.11" @@ -307,12 +312,6 @@ dependencies = [ "syn", ] -[[package]] -name = "base-x" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270" - [[package]] name = "base64" version = "0.13.0" @@ -418,23 +417,47 @@ dependencies = [ "num-integer", "num-traits", "serde", - "time 0.1.44", + "time", "winapi", ] [[package]] name = "clap" -version = "2.34.0" +version = "3.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +checksum = "54635806b078b7925d6e36810b1755f2a4b5b4d57560432c1ecf60bcbe10602b" dependencies = [ - "ansi_term", "atty", "bitflags", + "clap_derive", + "clap_lex", + "indexmap", + "once_cell", "strsim", + "termcolor", "textwrap", - "unicode-width", - "vec_map", +] + +[[package]] +name = "clap_derive" +version = "3.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "759bf187376e1afa7b85b959e6a664a3e7a95203415dba952ad19139e798f902" +dependencies = [ + "heck 0.4.0", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +dependencies = [ + "os_str_bytes", ] [[package]] @@ -452,12 +475,6 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d6f2aa4d0537bcc1c74df8755072bd31c1ef1a3a1b85a68e8404a8c353b7b8b" -[[package]] -name = "const_fn" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbdcdcb6d86f71c5e97409ad45898af11cbc995b4ee8112d59095a28d376c935" - [[package]] name = "core-foundation" version = "0.9.3" @@ -485,18 +502,18 @@ dependencies = [ [[package]] name = "crc" -version = "2.1.0" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49fc9a695bca7f35f5f4c15cddc84415f66a74ea78eef08e90c5024f2b540e23" +checksum = "53757d12b596c16c78b83458d732a5d1a17ab3f53f2f7412f6fb57cc8a140ab3" dependencies = [ "crc-catalog", ] [[package]] name = "crc-catalog" -version = "1.1.1" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccaeedb56da03b09f598226e25e80088cb4cd25f316e6e4df7d695f0feeb1403" +checksum = "2d0165d2900ae6778e36e80bbc4da3b5eefccee9ba939761f9c2882a5d9af3ff" [[package]] name = "crossbeam-queue" @@ -580,12 +597,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "discard" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" - [[package]] name = "dotenv" version = "0.15.0" @@ -627,6 +638,12 @@ version = "2.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77f3309417938f28bf8228fcff79a4a37103981e3e186d2ccd19c74b38f4eb71" +[[package]] +name = "fallible-iterator" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" + [[package]] name = "fastrand" version = "1.7.0" @@ -840,26 +857,20 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.11.2" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +checksum = "db0d4cf898abf0081f964436dc980e96670a0f36863e4b83aaacdb65c9d7ccc3" dependencies = [ "ahash", ] -[[package]] -name = "hashbrown" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db0d4cf898abf0081f964436dc980e96670a0f36863e4b83aaacdb65c9d7ccc3" - [[package]] name = "hashlink" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7249a3129cbc1ffccd74857f81464a323a152173cdb134e0fd81bc803b29facf" +checksum = "d452c155cb93fecdfb02a73dd57b5d8e442c2063bd7aac72f1bc5e4263a43086" dependencies = [ - "hashbrown 0.11.2", + "hashbrown", ] [[package]] @@ -895,6 +906,15 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest 0.10.3", +] + [[package]] name = "http" version = "0.2.8" @@ -976,7 +996,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" dependencies = [ "autocfg", - "hashbrown 0.12.1", + "hashbrown", "serde", ] @@ -1110,6 +1130,15 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73cbba799671b762df5a175adf59ce145165747bb891505c43d09aefbbf38beb" +[[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.5.0" @@ -1178,7 +1207,7 @@ dependencies = [ "tower-http 0.2.5", "tracing", "tracing-subscriber", - "uuid 1.1.2", + "uuid", ] [[package]] @@ -1189,13 +1218,14 @@ dependencies = [ "sea-orm", "serde", "serde_json", - "uuid 1.1.2", + "uuid", ] [[package]] name = "neo-migration" version = "0.1.0" dependencies = [ + "automod", "neo-entity", "sea-orm-migration", ] @@ -1219,17 +1249,6 @@ dependencies = [ "minimal-lexical", ] -[[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", -] - [[package]] name = "num-integer" version = "0.1.45" @@ -1316,6 +1335,12 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "os_str_bytes" +version = "6.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "648001efe5d5c0102d8cea768e348da85d90af8ba91f0bea908f157951493cd4" + [[package]] name = "ouroboros" version = "0.15.0" @@ -1479,6 +1504,39 @@ dependencies = [ "winapi", ] +[[package]] +name = "postgres-protocol" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "878c6cbf956e03af9aa8204b407b9cbf47c072164800aa918c516cd4b056c50c" +dependencies = [ + "base64", + "byteorder", + "bytes", + "fallible-iterator", + "hmac", + "md-5", + "memchr", + "rand 0.8.5", + "sha2 0.10.2", + "stringprep", +] + +[[package]] +name = "postgres-types" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebd6e8b7189a73169290e89bd24c771071f1012d8fe6f738f5226531f0b03d89" +dependencies = [ + "bytes", + "chrono", + "fallible-iterator", + "postgres-protocol", + "serde", + "serde_json", + "uuid", +] + [[package]] name = "ppv-lite86" version = "0.2.16" @@ -1519,12 +1577,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "proc-macro-hack" -version = "0.5.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" - [[package]] name = "proc-macro2" version = "1.0.40" @@ -1768,26 +1820,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "rust_decimal" -version = "1.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34a3bb58e85333f1ab191bf979104b586ebd77475bc6681882825f4532dfe87c" -dependencies = [ - "arrayvec", - "num-traits", - "serde", -] - -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -dependencies = [ - "semver", -] - [[package]] name = "rustversion" version = "1.0.7" @@ -1818,35 +1850,34 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "sea-orm" -version = "0.8.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51de529763804dd4f74c133055f53eccdda2221bdded94351009be28cc80d2fb" +checksum = "e05961693fe32ef4dfc964e48dcd0363151e3fab0215e3f3e138e034710339ca" dependencies = [ "async-stream", "async-trait", "chrono", "futures", "futures-util", + "log", "once_cell", "ouroboros", - "rust_decimal", "sea-orm-macros", "sea-query", "sea-strum", "serde", "serde_json", "sqlx", - "time 0.2.27", "tracing", "url", - "uuid 0.8.2", + "uuid", ] [[package]] name = "sea-orm-cli" -version = "0.8.1" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fca862fdba12c753bffba9c9adf95d3d3f5dcc82fd589b12faeee7068bb173d5" +checksum = "f527a5c69fc9b9cd8d243fa45f5bcf14e5e2a3e94b003267be1b075221c5b04b" dependencies = [ "async-std", "chrono", @@ -1861,9 +1892,9 @@ dependencies = [ [[package]] name = "sea-orm-macros" -version = "0.8.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f9378e21366b119d281489013c8170c49972fd3709c2155eb4504a913715d2d" +checksum = "6a8c8c00c8a57ae61991b34822f32ded409afb66a971d4952d857c329efbc355" dependencies = [ "bae", "heck 0.3.3", @@ -1874,9 +1905,9 @@ dependencies = [ [[package]] name = "sea-orm-migration" -version = "0.8.3" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15589f057677f57bea393572bd8eb9e8feb843a5f09b4fa518be6cef3a6ffedc" +checksum = "697d983cc6fd0ec497934cbfd16b3872b7e95be369e8851bdc65770c3b5ec57d" dependencies = [ "async-trait", "clap", @@ -1890,17 +1921,16 @@ dependencies = [ [[package]] name = "sea-query" -version = "0.24.6" +version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b0fa62db5ae33dfc61e805b0b0c9d579c3733f1ed90326b3779f5b38f30fa2a" +checksum = "2997a3e57614c0ff2212890e143deadb4a31f8057cbe7fc163daa3f297a33527" dependencies = [ "chrono", - "rust_decimal", + "postgres-types", "sea-query-derive", "sea-query-driver", "serde_json", - "time 0.2.27", - "uuid 0.8.2", + "uuid", ] [[package]] @@ -1918,9 +1948,9 @@ dependencies = [ [[package]] name = "sea-query-driver" -version = "0.1.1" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e3953baee94dcb90f0e19e8b4b91b91e9394867b0fc1886d0221cfc6d0439f5" +checksum = "fbda46eb3484cae1efb7bc68bca50f553a5b42c076cf4cbfae05b27f707549d4" dependencies = [ "proc-macro2", "quote", @@ -1929,9 +1959,9 @@ dependencies = [ [[package]] name = "sea-schema" -version = "0.8.1" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a01a736b624984160b22a10a6d8efcb95958af68d3dd0a06a529092056ddc902" +checksum = "94d070aba647637b533bd669a8e430bdc8f7d5249c9b53402da34347563bbfca" dependencies = [ "futures", "sea-query", @@ -1995,21 +2025,6 @@ dependencies = [ "libc", ] -[[package]] -name = "semver" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -dependencies = [ - "semver-parser", -] - -[[package]] -name = "semver-parser" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" - [[package]] name = "serde" version = "1.0.138" @@ -2053,21 +2068,6 @@ dependencies = [ "serde", ] -[[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.9.9" @@ -2169,9 +2169,9 @@ dependencies = [ [[package]] name = "sqlx" -version = "0.5.13" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "551873805652ba0d912fec5bbb0f8b4cdd96baf8e2ebf5970e5671092966019b" +checksum = "1f82cbe94f41641d6c410ded25bbf5097c240cefdf8e3b06d04198d0a96af6a4" dependencies = [ "sqlx-core", "sqlx-macros", @@ -2179,9 +2179,9 @@ dependencies = [ [[package]] name = "sqlx-core" -version = "0.5.13" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e48c61941ccf5ddcada342cd59e3e5173b007c509e1e8e990dafc830294d9dc5" +checksum = "6b69bf218860335ddda60d6ce85ee39f6cf6e5630e300e19757d1de15886a093" dependencies = [ "ahash", "atoi", @@ -2207,11 +2207,9 @@ dependencies = [ "libsqlite3-sys", "log", "memchr", - "num-bigint", "once_cell", "paste", "percent-encoding", - "rust_decimal", "serde", "serde_json", "sha2 0.10.2", @@ -2220,17 +2218,16 @@ dependencies = [ "sqlx-rt", "stringprep", "thiserror", - "time 0.2.27", "tokio-stream", "url", - "uuid 0.8.2", + "uuid", ] [[package]] name = "sqlx-macros" -version = "0.5.13" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc0fba2b0cae21fc00fe6046f8baa4c7fcb49e379f0f592b04696607f69ed2e1" +checksum = "f40c63177cf23d356b159b60acd27c54af7423f1736988502e36bae9a712118f" dependencies = [ "dotenv", "either", @@ -2248,9 +2245,9 @@ dependencies = [ [[package]] name = "sqlx-rt" -version = "0.5.13" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4db708cd3e459078f85f39f96a00960bd841f66ee2a669e90bf36907f5a79aae" +checksum = "874e93a365a598dc3dadb197565952cb143ae4aa716f7bcc933a8d836f6bf89f" dependencies = [ "native-tls", "once_cell", @@ -2264,64 +2261,6 @@ 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 = "stdweb" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5" -dependencies = [ - "discard", - "rustc_version", - "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 = "stringprep" version = "0.1.2" @@ -2334,9 +2273,9 @@ dependencies = [ [[package]] name = "strsim" -version = "0.8.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "subtle" @@ -2388,14 +2327,20 @@ dependencies = [ ] [[package]] -name = "textwrap" -version = "0.11.0" +name = "termcolor" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" dependencies = [ - "unicode-width", + "winapi-util", ] +[[package]] +name = "textwrap" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" + [[package]] name = "thiserror" version = "1.0.31" @@ -2436,44 +2381,6 @@ 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.6.0" @@ -2718,12 +2625,6 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99" -[[package]] -name = "unicode-width" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" - [[package]] name = "unicode-xid" version = "0.2.3" @@ -2748,16 +2649,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "uuid" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" -dependencies = [ - "getrandom 0.2.7", - "serde", -] - [[package]] name = "uuid" version = "1.1.2" @@ -2790,12 +2681,6 @@ 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" @@ -2943,6 +2828,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/neo-entity/Cargo.toml b/neo-entity/Cargo.toml index cd13738..d9a38a0 100644 --- a/neo-entity/Cargo.toml +++ b/neo-entity/Cargo.toml @@ -6,7 +6,7 @@ publish = false [dependencies] chrono = {version = "0.4", features = ["serde"] } -sea-orm = { version = "^0.8", features = ["macros", "with-chrono", "with-uuid", "with-json"], default-features = false } +sea-orm = { version = "^0.9", features = ["macros", "with-chrono", "with-uuid", "with-json"], default-features = false } serde = "1.0" serde_json = "1.0" uuid = { version = "*", features = ["v4", "serde"]} \ No newline at end of file diff --git a/neo-entity/src/events.rs b/neo-entity/src/events.rs index 72fbffa..d074533 100644 --- a/neo-entity/src/events.rs +++ b/neo-entity/src/events.rs @@ -1,16 +1,16 @@ -use sea_orm::entity::prelude::*; +use sea_orm::{entity::prelude::*, Set}; #[derive(Clone, Debug, PartialEq, DeriveEntityModel)] #[sea_orm(table_name = "events")] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] - pub uuid: String, - pub room_uuid: String, + pub uuid: Uuid, + pub room_uuid: Uuid, pub r#type: String, pub state_key: Option, - pub sender_uuid: String, - pub origin_server_ts: i32, - pub content: String, + pub sender_uuid: Uuid, + pub origin_server_ts: i64, + pub content: Json, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] @@ -45,4 +45,11 @@ impl Related for Entity { } } -impl ActiveModelBehavior for ActiveModel {} +impl ActiveModelBehavior for ActiveModel { + fn new() -> Self { + Self { + uuid: Set(Uuid::new_v4()), + ..ActiveModelTrait::default() + } + } +} diff --git a/neo-entity/src/lib.rs b/neo-entity/src/lib.rs index cc94a95..9d57fba 100644 --- a/neo-entity/src/lib.rs +++ b/neo-entity/src/lib.rs @@ -1,4 +1,6 @@ pub mod devices; +pub mod events; pub mod prelude; +pub mod rooms; pub mod sessions; pub mod users; diff --git a/neo-entity/src/rooms.rs b/neo-entity/src/rooms.rs index e331276..718cce7 100644 --- a/neo-entity/src/rooms.rs +++ b/neo-entity/src/rooms.rs @@ -1,10 +1,10 @@ -use sea_orm::entity::prelude::*; +use sea_orm::{entity::prelude::*, Set}; #[derive(Clone, Debug, PartialEq, DeriveEntityModel)] #[sea_orm(table_name = "rooms")] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] - pub uuid: String, + pub uuid: Uuid, pub name: String, } @@ -20,4 +20,11 @@ impl Related for Entity { } } -impl ActiveModelBehavior for ActiveModel {} +impl ActiveModelBehavior for ActiveModel { + fn new() -> Self { + Self { + uuid: Set(Uuid::new_v4()), + ..ActiveModelTrait::default() + } + } +} diff --git a/neo-migration/Cargo.toml b/neo-migration/Cargo.toml index a053534..3144ba6 100644 --- a/neo-migration/Cargo.toml +++ b/neo-migration/Cargo.toml @@ -5,5 +5,6 @@ edition = "2021" publish = false [dependencies] -sea-orm-migration = "^0.8" +sea-orm-migration = "^0.9" neo-entity = { path = "../neo-entity" } +automod = "1" \ No newline at end of file diff --git a/neo-migration/src/lib.rs b/neo-migration/src/lib.rs index dde53f7..1e1b2ff 100644 --- a/neo-migration/src/lib.rs +++ b/neo-migration/src/lib.rs @@ -1,8 +1,6 @@ pub use sea_orm_migration::prelude::*; -mod m20220707_092851_create_users; -mod m20220707_112339_create_devices; -mod m20220707_143304_create_sessions; +automod::dir!("src"); pub struct Migrator; @@ -13,6 +11,8 @@ impl MigratorTrait for Migrator { Box::new(m20220707_092851_create_users::Migration), Box::new(m20220707_112339_create_devices::Migration), Box::new(m20220707_143304_create_sessions::Migration), + Box::new(m20220724_223253_create_rooms::Migration), + Box::new(m20220724_223335_create_events::Migration), ] } } diff --git a/neo-migration/src/m20220707_092851_create_users.rs b/neo-migration/src/m20220707_092851_create_users.rs index ea5753a..e57b401 100644 --- a/neo-migration/src/m20220707_092851_create_users.rs +++ b/neo-migration/src/m20220707_092851_create_users.rs @@ -1,14 +1,9 @@ use neo_entity::users::{self, Entity as User}; use sea_orm_migration::prelude::*; +#[derive(DeriveMigrationName)] pub struct Migration; -impl MigrationName for Migration { - fn name(&self) -> &str { - "m20220707_092851_create_users" - } -} - #[async_trait::async_trait] impl MigrationTrait for Migration { async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { diff --git a/neo-migration/src/m20220707_112339_create_devices.rs b/neo-migration/src/m20220707_112339_create_devices.rs index e602490..efb3889 100644 --- a/neo-migration/src/m20220707_112339_create_devices.rs +++ b/neo-migration/src/m20220707_112339_create_devices.rs @@ -1,14 +1,9 @@ use neo_entity::devices::{self, Entity as Device}; use sea_orm_migration::prelude::*; +#[derive(DeriveMigrationName)] pub struct Migration; -impl MigrationName for Migration { - fn name(&self) -> &str { - "m20220707_112339_create_devices.rs" - } -} - #[async_trait::async_trait] impl MigrationTrait for Migration { async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { diff --git a/neo-migration/src/m20220707_143304_create_sessions.rs b/neo-migration/src/m20220707_143304_create_sessions.rs index 94b6444..4d6448f 100644 --- a/neo-migration/src/m20220707_143304_create_sessions.rs +++ b/neo-migration/src/m20220707_143304_create_sessions.rs @@ -1,14 +1,9 @@ use neo_entity::sessions::{self, Entity as Session}; use sea_orm_migration::prelude::*; +#[derive(DeriveMigrationName)] pub struct Migration; -impl MigrationName for Migration { - fn name(&self) -> &str { - "m20220707_143304_create_sessions.rs" - } -} - #[async_trait::async_trait] impl MigrationTrait for Migration { async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { diff --git a/neo-migration/src/m20220724_223253_create_rooms.rs b/neo-migration/src/m20220724_223253_create_rooms.rs new file mode 100644 index 0000000..5ee30ef --- /dev/null +++ b/neo-migration/src/m20220724_223253_create_rooms.rs @@ -0,0 +1,26 @@ +use neo_entity::rooms::{self, Entity as Room}; +use sea_orm_migration::prelude::*; + +#[derive(DeriveMigrationName)] +pub struct Migration; + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .create_table( + Table::create() + .table(Room) + .if_not_exists() + .col( + ColumnDef::new(rooms::Column::Uuid) + .uuid() + .primary_key() + .not_null(), + ) + .col(ColumnDef::new(rooms::Column::Name).string().not_null()) + .to_owned(), + ) + .await + } +} diff --git a/neo-migration/src/m20220724_223335_create_events.rs b/neo-migration/src/m20220724_223335_create_events.rs new file mode 100644 index 0000000..79f7b8d --- /dev/null +++ b/neo-migration/src/m20220724_223335_create_events.rs @@ -0,0 +1,72 @@ +use neo_entity::events::{self, Entity as Event}; +use sea_orm_migration::prelude::*; + +#[derive(DeriveMigrationName)] +pub struct Migration; + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .create_table( + Table::create() + .table(Event) + .if_not_exists() + .col( + ColumnDef::new(events::Column::Uuid) + .uuid() + .primary_key() + .not_null(), + ) + .col(ColumnDef::new(events::Column::RoomUuid).uuid().not_null()) + .col(ColumnDef::new(events::Column::Type).string().not_null()) + .col(ColumnDef::new(events::Column::StateKey).string()) + .col(ColumnDef::new(events::Column::SenderUuid).uuid().not_null()) + .col( + ColumnDef::new(events::Column::OriginServerTs) + .integer() + .not_null(), + ) + .col(ColumnDef::new(events::Column::Content).json().not_null()) + .to_owned(), + ) + .await?; + manager + .create_index( + Index::create() + .name("room_uuid_index") + .table(Event) + .col(events::Column::RoomUuid) + .to_owned(), + ) + .await?; + manager + .create_index( + Index::create() + .name("type_index") + .table(Event) + .col(events::Column::Type) + .to_owned(), + ) + .await?; + manager + .create_index( + Index::create() + .name("state_key_index") + .table(Event) + .col(events::Column::StateKey) + .to_owned(), + ) + .await?; + manager + .create_index( + Index::create() + .name("type_state_key_index") + .table(Event) + .col(events::Column::Type) + .col(events::Column::StateKey) + .to_owned(), + ) + .await + } +} diff --git a/neo-util/src/events.rs b/neo-util/src/events.rs new file mode 100644 index 0000000..f3c50b9 --- /dev/null +++ b/neo-util/src/events.rs @@ -0,0 +1,20 @@ +pub static STATE_EVENTS: &[&str] = &[ + "m.room.create", + "m.room.canonical_alias", + "m.room.join_rules", + "m.room.member", + "m.room.power_levels", +]; + +pub enum EventCategory { + StateEvent, + MessageEvent, +} + +pub fn classify_event(event_type: &str) -> EventCategory { + if STATE_EVENTS.contains(&event_type) { + EventCategory::StateEvent + } else { + EventCategory::MessageEvent + } +} diff --git a/neo-util/src/lib.rs b/neo-util/src/lib.rs index c72e4b9..487d211 100644 --- a/neo-util/src/lib.rs +++ b/neo-util/src/lib.rs @@ -1 +1,2 @@ +pub mod events; pub mod password; diff --git a/neo/Cargo.toml b/neo/Cargo.toml index 6af392c..19687af 100644 --- a/neo/Cargo.toml +++ b/neo/Cargo.toml @@ -17,7 +17,7 @@ rand = { version = "0.8.5", features = ["std"] } uuid = { version = "1.0", features = ["v4"] } ruma = { version = "0.6.4", features = ["client-api", "compat"] } http = "0.2.8" -sea-orm = { version = "^0.8", features = ["sqlx-sqlite", "runtime-tokio-native-tls", "macros"], default-features = false } +sea-orm = { version = "^0.9", features = ["sqlx-sqlite", "runtime-tokio-native-tls", "macros"], default-features = false } neo-entity = { version = "*", path = "../neo-entity" } neo-migration = { version = "*", path = "../neo-migration" } neo-util = { version = "*", path = "../neo-util" } diff --git a/neo/src/main.rs b/neo/src/main.rs index e8dd0df..3203562 100644 --- a/neo/src/main.rs +++ b/neo/src/main.rs @@ -24,7 +24,7 @@ mod types; #[tokio::main] async fn main() -> anyhow::Result<()> { if std::env::var("RUST_LOG").is_err() { - std::env::set_var("RUST_LOG", "debug"); + std::env::set_var("RUST_LOG", "debug,sqlx=off"); } tracing_subscriber::fmt::init();