diff --git a/Cargo.lock b/Cargo.lock index 48f0f66..9da9372 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -133,9 +133,12 @@ dependencies = [ "entity", "log", "migration", + "mysql", + "mysql_common", "rust_decimal", "rust_decimal_macros", "sea-orm", + "sqlx", "tokio", "tracing", "tracing-subscriber", @@ -214,7 +217,7 @@ dependencies = [ "polling", "rustix 0.37.23", "slab", - "socket2", + "socket2 0.4.9", "waker-fn", ] @@ -352,6 +355,26 @@ dependencies = [ "num-traits", ] +[[package]] +name = "bindgen" +version = "0.66.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2b84e06fc203107bfbad243f4aba2af864eb7db3b1cf46ea0a023b0b433d2a7" +dependencies = [ + "bitflags 2.3.3", + "cexpr", + "clang-sys", + "lazy_static", + "lazycell", + "peeking_take_while", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn 2.0.28", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -421,7 +444,7 @@ checksum = "0754613691538d51f329cce9af41d7b7ca150bc973056f1156611489475f54f7" dependencies = [ "borsh-derive-internal", "borsh-schema-derive-internal", - "proc-macro-crate", + "proc-macro-crate 0.1.5", "proc-macro2", "syn 1.0.109", ] @@ -448,6 +471,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "bufstream" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40e38929add23cdf8a366df9b0e088953150724bcbe5fc330b0d8eb3b328eec8" + [[package]] name = "bumpalo" version = "3.13.0" @@ -490,13 +519,22 @@ checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" [[package]] name = "cc" -version = "1.0.81" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c6b2562119bf28c3439f7f02db99faf0aa1a8cdfe5772a2ee155d32227239f0" +checksum = "305fe645edc1442a0fa8b6726ba61d422798d37a52e12eaecf4b022ebbb88f01" dependencies = [ "libc", ] +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + [[package]] name = "cfg-if" version = "1.0.0" @@ -516,11 +554,22 @@ dependencies = [ "winapi", ] +[[package]] +name = "clang-sys" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c688fc74432808e3eb684cae8830a86be1d66a2bd58e1f248ed0960a590baf6f" +dependencies = [ + "glob", + "libc", + "libloading", +] + [[package]] name = "clap" -version = "4.3.19" +version = "4.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fd304a20bff958a57f04c4e96a2e7594cc4490a0e809cbd48bb6437edaa452d" +checksum = "c27cdf28c0f604ba3f512b0c9a409f8de8513e4816705deb0498b627e7c3a3fd" dependencies = [ "clap_builder", "clap_derive", @@ -529,9 +578,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.3.19" +version = "4.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01c6a3f08f1fe5662a35cfe393aec09c4df95f60ee93b7556505260f75eee9e1" +checksum = "08a9f1ab5e9f01a9b81f202e8562eb9a10de70abf9eaeac1be465c28b75aa4aa" dependencies = [ "anstream", "anstyle", @@ -557,6 +606,15 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" +[[package]] +name = "cmake" +version = "0.1.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31c789563b815f77f4250caee12365734369f942439b7defd71e18a48197130" +dependencies = [ + "cc", +] + [[package]] name = "color-eyre" version = "0.6.2" @@ -635,6 +693,63 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9cace84e55f07e7301bae1c519df89cdad8cc3cd868413d3fdbdeca9ff3db484" +[[package]] +name = "crc32fast" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2801af0d36612ae591caa9568261fddce32ce6e08a7275ea334a06a4ad021a2c" +dependencies = [ + "cfg-if", + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-epoch", + "crossbeam-queue", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" +dependencies = [ + "cfg-if", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", + "memoffset", + "scopeguard", +] + [[package]] name = "crossbeam-queue" version = "0.3.8" @@ -664,11 +779,46 @@ dependencies = [ "typenum", ] +[[package]] +name = "darling" +version = "0.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0209d94da627ab5605dcccf08bb18afa5009cfbef48d8a8b7d7bdbc79be25c5e" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "177e3443818124b357d8e76f53be906d60937f0d3a90773a664fa63fa253e621" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.28", +] + +[[package]] +name = "darling_macro" +version = "0.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" +dependencies = [ + "darling_core", + "quote", + "syn 2.0.28", +] + [[package]] name = "der" -version = "0.7.7" +version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c7ed52955ce76b1554f509074bb357d3fb8ac9b51288a65a3fd480d1dfba946" +checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" dependencies = [ "const-oid", "pem-rfc7468", @@ -695,6 +845,17 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "derive_utils" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9abcad25e9720609ccb3dcdb795d845e37d8ce34183330a9f48b03a1a71c8e21" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.28", +] + [[package]] name = "digest" version = "0.10.7" @@ -798,6 +959,17 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764" +[[package]] +name = "flate2" +version = "1.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b9429470923de8e8cbd4d2dc513535400b4b3fef0319fb5c4e1f520a7bef743" +dependencies = [ + "crc32fast", + "libz-sys", + "miniz_oxide", +] + [[package]] name = "flume" version = "0.10.14" @@ -810,6 +982,12 @@ dependencies = [ "spin 0.9.8", ] +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + [[package]] name = "form_urlencoded" version = "1.2.0" @@ -1080,6 +1258,12 @@ dependencies = [ "cc", ] +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "idna" version = "0.4.0" @@ -1126,6 +1310,16 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "io-enum" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5305557fa27b460072ae15ce07617e999f5879f14d376c8449f0bfb9f9d8e91e" +dependencies = [ + "derive_utils", + "syn 2.0.28", +] + [[package]] name = "io-lifetimes" version = "1.0.11" @@ -1144,7 +1338,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ "hermit-abi", - "rustix 0.38.6", + "rustix 0.38.7", "windows-sys", ] @@ -1190,12 +1384,101 @@ dependencies = [ "spin 0.5.2", ] +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + +[[package]] +name = "lexical" +version = "6.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7aefb36fd43fef7003334742cbf77b243fcd36418a1d1bdd480d613a67968f6" +dependencies = [ + "lexical-core", +] + +[[package]] +name = "lexical-core" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cde5de06e8d4c2faabc400238f9ae1c74d5412d03a7bd067645ccbc47070e46" +dependencies = [ + "lexical-parse-float", + "lexical-parse-integer", + "lexical-util", + "lexical-write-float", + "lexical-write-integer", +] + +[[package]] +name = "lexical-parse-float" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683b3a5ebd0130b8fb52ba0bdc718cc56815b6a097e28ae5a6997d0ad17dc05f" +dependencies = [ + "lexical-parse-integer", + "lexical-util", + "static_assertions", +] + +[[package]] +name = "lexical-parse-integer" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d0994485ed0c312f6d965766754ea177d07f9c00c9b82a5ee62ed5b47945ee9" +dependencies = [ + "lexical-util", + "static_assertions", +] + +[[package]] +name = "lexical-util" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5255b9ff16ff898710eb9eb63cb39248ea8a5bb036bea8085b1a767ff6c4e3fc" +dependencies = [ + "static_assertions", +] + +[[package]] +name = "lexical-write-float" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accabaa1c4581f05a3923d1b4cfd124c329352288b7b9da09e766b0668116862" +dependencies = [ + "lexical-util", + "lexical-write-integer", + "static_assertions", +] + +[[package]] +name = "lexical-write-integer" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1b6f3d1f4422866b68192d62f77bc5c700bee84f3069f2469d7bc8c77852446" +dependencies = [ + "lexical-util", + "static_assertions", +] + [[package]] name = "libc" version = "0.2.147" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +[[package]] +name = "libloading" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" +dependencies = [ + "cfg-if", + "winapi", +] + [[package]] name = "libm" version = "0.2.7" @@ -1213,6 +1496,17 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "libz-sys" +version = "1.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d97137b25e321a73eef1418d1d5d2eda4d77e12813f8e6dead84bc52c5870a7b" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] + [[package]] name = "linux-raw-sys" version = "0.3.8" @@ -1244,6 +1538,15 @@ dependencies = [ "value-bag", ] +[[package]] +name = "lru" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "718e8fae447df0c7e1ba7f5189829e63fd536945c8988d61444c19039f16b670" +dependencies = [ + "hashbrown 0.13.2", +] + [[package]] name = "matchers" version = "0.1.0" @@ -1268,6 +1571,15 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +[[package]] +name = "memoffset" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" +dependencies = [ + "autocfg", +] + [[package]] name = "migration" version = "0.1.0" @@ -1302,6 +1614,93 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "mysql" +version = "24.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfe2babc5f5b354eab9c0a0e40da3e69c4d77421c8b9b6ee03f97acc75bd7955" +dependencies = [ + "bufstream", + "bytes", + "crossbeam", + "flate2", + "io-enum", + "libc", + "lru", + "mysql_common", + "named_pipe", + "once_cell", + "pem", + "percent-encoding", + "serde", + "serde_json", + "socket2 0.5.3", + "twox-hash", + "url", +] + +[[package]] +name = "mysql-common-derive" +version = "0.30.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56b0d8a0db9bf6d2213e11f2c701cb91387b0614361625ab7b9743b41aa4938f" +dependencies = [ + "darling", + "heck", + "num-bigint", + "proc-macro-crate 1.3.1", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.28", + "termcolor", + "thiserror", +] + +[[package]] +name = "mysql_common" +version = "0.30.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57349d5a326b437989b6ee4dc8f2f34b0cc131202748414712a8e7d98952fc8c" +dependencies = [ + "base64", + "bindgen", + "bitflags 2.3.3", + "bitvec", + "byteorder", + "bytes", + "cc", + "cmake", + "crc32fast", + "flate2", + "lazy_static", + "lexical", + "mysql-common-derive", + "num-bigint", + "num-traits", + "rand", + "regex", + "rust_decimal", + "saturating", + "serde", + "serde_json", + "sha1", + "sha2", + "smallvec", + "subprocess", + "thiserror", + "uuid", +] + +[[package]] +name = "named_pipe" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad9c443cce91fc3e12f017290db75dde490d685cdaaf508d7159d7cf41f0eb2b" +dependencies = [ + "winapi", +] + [[package]] name = "nom" version = "7.1.3" @@ -1486,6 +1885,22 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +[[package]] +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" + +[[package]] +name = "pem" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b13fe415cdf3c8e44518e18a7c95a13431d9bdf6d15367d82b23c377fdd441a" +dependencies = [ + "base64", + "serde", +] + [[package]] name = "pem-rfc7468" version = "0.7.0" @@ -1503,18 +1918,18 @@ checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" [[package]] name = "pin-project" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "030ad2bc4db10a8944cb0d837f158bdfec4d4a4873ab701a95046770d11f8842" +checksum = "fda4ed1c6c173e3fc7a83629421152e01d7b1f9b7f65fb301e490e8cfc656422" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec2e072ecce94ec471b13398d5402c188e76ac03cf74dd1a975161b23a3f6d9c" +checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", @@ -1523,9 +1938,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c40d25201921e5ff0c862a505c6557ea88568a4e3ace775ab55e93f2f4f9d57" +checksum = "2c516611246607d0c04186886dbb3a754368ef82c79e9827a802c6d836dd111c" [[package]] name = "pin-utils" @@ -1591,6 +2006,16 @@ dependencies = [ "toml", ] +[[package]] +name = "proc-macro-crate" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" +dependencies = [ + "once_cell", + "toml_edit", +] + [[package]] name = "proc-macro-error" version = "1.0.4" @@ -1700,13 +2125,13 @@ dependencies = [ [[package]] name = "regex" -version = "1.9.1" +version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575" +checksum = "81bc1d4caf89fac26a70747fe603c130093b53c773888797a6329091246d651a" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.3.4", + "regex-automata 0.3.6", "regex-syntax 0.7.4", ] @@ -1721,9 +2146,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.3.4" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7b6d6190b7594385f61bd3911cd1be99dfddcfc365a4160cc2ab5bff4aed294" +checksum = "fed1ceff11a1dddaee50c9dc8e4938bd106e9d89ae372f192311e7da498e3b69" dependencies = [ "aho-corasick", "memchr", @@ -1849,6 +2274,12 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + [[package]] name = "rustix" version = "0.37.23" @@ -1865,9 +2296,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.6" +version = "0.38.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ee020b1716f0a80e2ace9b03441a749e402e86712f15f16fe8a8f75afac732f" +checksum = "172891ebdceb05aa0005f533a6cbfca599ddd7d966f6f5d4d9b2e70478e70399" dependencies = [ "bitflags 2.3.3", "errno", @@ -1912,6 +2343,12 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" +[[package]] +name = "saturating" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ece8e78b2f38ec51c51f5d475df0a7187ba5111b2a28bdc761ee05b075d40a71" + [[package]] name = "scopeguard" version = "1.2.0" @@ -2095,18 +2532,18 @@ checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" [[package]] name = "serde" -version = "1.0.181" +version = "1.0.183" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d3e73c93c3240c0bda063c239298e633114c69a888c3e37ca8bb33f343e9890" +checksum = "32ac8da02677876d532745a130fc9d8e6edfa81a269b107c5b00829b91d8eb3c" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.181" +version = "1.0.183" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be02f6cb0cd3a5ec20bbcfbcbd749f57daddb1a0882dc2e46a6c236c90b977ed" +checksum = "aafe972d60b0b9bee71a91b92fee2d4fb3c9d7e8f6b179aa99f27203d99a4816" dependencies = [ "proc-macro2", "quote", @@ -2155,6 +2592,12 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "shlex" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" + [[package]] name = "signal-hook-registry" version = "1.4.1" @@ -2205,6 +2648,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "socket2" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2538b18701741680e0322a2302176d3253a35388e2e62f172f64f4f16605f877" +dependencies = [ + "libc", + "windows-sys", +] + [[package]] name = "spin" version = "0.5.2" @@ -2244,8 +2697,7 @@ dependencies = [ [[package]] name = "sqlx" version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e58421b6bc416714d5115a2ca953718f6c621a51b68e4f4922aea5a4391a721" +source = "git+https://github.com/cameronbraid/sqlx?branch=decimal_compatibility_lenient#dcbc6e8ff9e7625cb7ab40eb5761b3c44af267f7" dependencies = [ "sqlx-core", "sqlx-macros", @@ -2257,8 +2709,7 @@ dependencies = [ [[package]] name = "sqlx-core" version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd4cef4251aabbae751a3710927945901ee1d97ee96d757f6880ebb9a79bfd53" +source = "git+https://github.com/cameronbraid/sqlx?branch=decimal_compatibility_lenient#dcbc6e8ff9e7625cb7ab40eb5761b3c44af267f7" dependencies = [ "ahash 0.8.3", "atoi", @@ -2305,8 +2756,7 @@ dependencies = [ [[package]] name = "sqlx-macros" version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "208e3165167afd7f3881b16c1ef3f2af69fa75980897aac8874a0696516d12c2" +source = "git+https://github.com/cameronbraid/sqlx?branch=decimal_compatibility_lenient#dcbc6e8ff9e7625cb7ab40eb5761b3c44af267f7" dependencies = [ "proc-macro2", "quote", @@ -2318,8 +2768,7 @@ dependencies = [ [[package]] name = "sqlx-macros-core" version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a4a8336d278c62231d87f24e8a7a74898156e34c1c18942857be2acb29c7dfc" +source = "git+https://github.com/cameronbraid/sqlx?branch=decimal_compatibility_lenient#dcbc6e8ff9e7625cb7ab40eb5761b3c44af267f7" dependencies = [ "dotenvy", "either", @@ -2344,8 +2793,7 @@ dependencies = [ [[package]] name = "sqlx-mysql" version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ca69bf415b93b60b80dc8fda3cb4ef52b2336614d8da2de5456cc942a110482" +source = "git+https://github.com/cameronbraid/sqlx?branch=decimal_compatibility_lenient#dcbc6e8ff9e7625cb7ab40eb5761b3c44af267f7" dependencies = [ "atoi", "base64", @@ -2391,8 +2839,7 @@ dependencies = [ [[package]] name = "sqlx-postgres" version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0db2df1b8731c3651e204629dd55e52adbae0462fa1bdcbed56a2302c18181e" +source = "git+https://github.com/cameronbraid/sqlx?branch=decimal_compatibility_lenient#dcbc6e8ff9e7625cb7ab40eb5761b3c44af267f7" dependencies = [ "atoi", "base64", @@ -2436,8 +2883,7 @@ dependencies = [ [[package]] name = "sqlx-sqlite" version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4c21bf34c7cae5b283efb3ac1bcc7670df7561124dc2f8bdc0b59be40f79a2" +source = "git+https://github.com/cameronbraid/sqlx?branch=decimal_compatibility_lenient#dcbc6e8ff9e7625cb7ab40eb5761b3c44af267f7" dependencies = [ "atoi", "chrono", @@ -2486,6 +2932,16 @@ version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" +[[package]] +name = "subprocess" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c2e86926081dda636c546d8c5e641661049d7562a68f5488be4a1f7f66f6086" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "subtle" version = "2.5.0" @@ -2522,17 +2978,26 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "tempfile" -version = "3.7.0" +version = "3.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5486094ee78b2e5038a6382ed7645bc084dc2ec433426ca4c3cb61e2007b8998" +checksum = "dc02fddf48964c42031a0b3fe0428320ecf3a73c401040fc0096f97794310651" dependencies = [ "cfg-if", "fastrand 2.0.0", "redox_syscall", - "rustix 0.38.6", + "rustix 0.38.7", "windows-sys", ] +[[package]] +name = "termcolor" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" +dependencies = [ + "winapi-util", +] + [[package]] name = "thiserror" version = "1.0.44" @@ -2621,7 +3086,7 @@ dependencies = [ "parking_lot", "pin-project-lite", "signal-hook-registry", - "socket2", + "socket2 0.4.9", "tokio-macros", "windows-sys", ] @@ -2657,6 +3122,23 @@ dependencies = [ "serde", ] +[[package]] +name = "toml_datetime" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" + +[[package]] +name = "toml_edit" +version = "0.19.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8123f27e969974a3dfba720fdb560be359f57b44302d280ba72e76a74480e8a" +dependencies = [ + "indexmap", + "toml_datetime", + "winnow", +] + [[package]] name = "tracing" version = "0.1.37" @@ -2747,6 +3229,17 @@ dependencies = [ "valuable-serde", ] +[[package]] +name = "twox-hash" +version = "1.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" +dependencies = [ + "cfg-if", + "rand", + "static_assertions", +] + [[package]] name = "typenum" version = "1.16.0" @@ -2971,6 +3464,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" @@ -3052,6 +3554,15 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +[[package]] +name = "winnow" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acaaa1190073b2b101e15083c38ee8ec891b5e05cbee516521e94ec008f61e64" +dependencies = [ + "memchr", +] + [[package]] name = "wyz" version = "0.5.1" diff --git a/Cargo.toml b/Cargo.toml index d67024a..fada577 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,8 @@ edition = "2021" authors = ["Cameron "] [workspace.dependencies] + +[patch.crates-io] +# sqlx = { path = "../sqlx"} +sqlx = { git = "https://github.com/cameronbraid/sqlx", branch = "decimal_compatibility_lenient" } + diff --git a/README.md b/README.md index 67d1bfc..05f0542 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,29 @@ + +# MySQL DECIMAL type issue + +https://github.com/readysettech/readyset/issues/143 + +NOTE: fixed using https://github.com/cameronbraid/sqlx/tree/decimal_compatibility_lenient and this repo is configured to use the fix + To reproduce the error ```shell docker compose up -d -// wait for docker to start +// wait for services to start +// crate schema cargo run --bin migrate_fresh -cargo run --bin has_decimal +// insert a record directly in mysql +cargo run --bin has_decimal_seaorm_mysql_insert + +// select the record from mysql +cargo run --bin has_decimal_seaorm_mysql_select + +// select the record from mysql +cargo run --bin has_decimal_seaorm_readyset_select + ``` You should get out like @@ -23,3 +39,60 @@ To start over run the following, then run the steps above ```shell docker compose kill readyset; sudo rm -rf data/readyset ``` + +--- + + +# MySQL bool type issue + + mysql treats `bool` as an alias for `tinyint(1)` + +So the `view_type` table look like this : + +```sql +CREATE TABLE `view_type` ( + `channel_id` int NOT NULL, + `view_type` varchar(255) NOT NULL, + `enabled` tinyint(1) NOT NULL, + PRIMARY KEY (`channel_id`,`view_type`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci +``` + +To reproduce + +```shell +docker compose up -d + +// wait for services to start + +// crate schema +cargo run --bin migrate_fresh + +// insert a record directly in mysql +cargo run --bin view_type_insert + +// select the record from mysql +cargo run --bin view_type_mysql_select + +// select the records from readyset +cargo run --bin view_type_readyset_select + +``` + +observe the error + +``` +Error: Query Error: error communicating with database: expected to read 4 bytes, got 0 bytes at EOF + +Caused by: + error communicating with database: expected to read 4 bytes, got 0 bytes at EOF + +Location: + app/src/bin/view_type_readyset_select.rs:12:17 +``` + +and the readyset logs in docker + +``` +readyset_seaorm_issues-readyset-1 | 2023-08-10T02:10:09.134045Z ERROR connection{addr=172.25.0.1:56330}:connection{addr=172.25.0.1:56330}: readyset_mysql::backend: encountered error while attempting to write column packet err=tried to use 1 as MYSQL_TYPE_BIT +``` diff --git a/app/Cargo.toml b/app/Cargo.toml index 652474f..4b56b26 100644 --- a/app/Cargo.toml +++ b/app/Cargo.toml @@ -6,7 +6,7 @@ edition.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -sea-orm = { version = "0", features = [ "sqlx-mysql", "runtime-tokio-rustls", "macros", "with-chrono", "with-rust_decimal", "debug-print" ] } +sea-orm = { version = "*", features = [ "sqlx-mysql", "runtime-tokio", "macros", "with-chrono", "with-rust_decimal", "debug-print", "with-bigdecimal" ] } tokio = { version = "1.0", features = ["rt-multi-thread", "macros", "sync", "time","full"] } migration = { path = "../migration" } entity = { path = "../entity" } @@ -15,4 +15,8 @@ rust_decimal = { version = "1.28.0", features = ["serde-float"] } rust_decimal_macros = "1.28.0" tracing = { version = "0.1" } tracing-subscriber = { version = "0.3", features = ["json", "env-filter", "valuable", "fmt", "std"] } -log = "*" \ No newline at end of file +log = "*" +sqlx = { version = "*", features = [ "runtime-tokio", "rust_decimal", "bigdecimal" ] } + +mysql = { version = "*", default-features = false, features = ["minimal", "derive"] } +mysql_common = { version = "*", default-features = false, features = ["rust_decimal"]} diff --git a/app/src/bin/has_decimal.rs b/app/src/bin/has_decimal.rs deleted file mode 100644 index 2e8fad1..0000000 --- a/app/src/bin/has_decimal.rs +++ /dev/null @@ -1,32 +0,0 @@ -use app::docker; -use color_eyre::Result; -use entity::has_decimal; -use rust_decimal_macros::dec; -use sea_orm::ActiveModelTrait; -use sea_orm::EntityTrait; -use sea_orm::Set; - -#[tokio::main] -async fn main() -> Result<()> { - let db = docker::db_connect().await; - - let item = has_decimal::Entity::find_by_id(1).one(&db.mysql).await?; - - if item.is_none() { - has_decimal::ActiveModel { - id: Set(1), - price: Set(dec!(10.0)), - } - .insert(&db.mysql) - .await?; - - tokio::time::sleep(tokio::time::Duration::from_secs(1)).await; - } - - let _item = has_decimal::Entity::find_by_id(1) - .one(&db.readyset) - .await? - .ok_or_else(|| color_eyre::eyre::eyre!("not found in readyset"))?; - - Ok(()) -} diff --git a/app/src/bin/has_decimal_mysql_crate.rs b/app/src/bin/has_decimal_mysql_crate.rs new file mode 100644 index 0000000..7831056 --- /dev/null +++ b/app/src/bin/has_decimal_mysql_crate.rs @@ -0,0 +1,29 @@ +use app::docker; +use color_eyre::Result; +use entity::has_decimal; +use mysql::Pool; +use mysql::prelude::FromRow; +use rust_decimal::Decimal; + +use mysql::prelude::Queryable; +#[tokio::main] +async fn main() -> Result<()> { + + #[derive(FromRow, Debug)] + pub struct Row { + pub id : i64, + pub price: Decimal, + } + + let url = "mysql://user:password@localhost:3307/db?enable_cleartext_plugin=true"; + let pool = Pool::new(url)?; + + let mut conn = pool.get_conn()?; + let row: Option = conn + .exec_first( + "SELECT * from has_decimal",())?; + + println!("row: {:?}", row); + + Ok(()) +} diff --git a/app/src/bin/has_decimal_seaorm_mysql_insert.rs b/app/src/bin/has_decimal_seaorm_mysql_insert.rs new file mode 100644 index 0000000..f052861 --- /dev/null +++ b/app/src/bin/has_decimal_seaorm_mysql_insert.rs @@ -0,0 +1,22 @@ +use app::docker; +use color_eyre::Result; +use entity::has_decimal; +use rust_decimal_macros::dec; +use sea_orm::ActiveModelTrait; +use sea_orm::EntityTrait; +use sea_orm::Set; + +#[tokio::main] +async fn main() -> Result<()> { + let db = docker::db_connect().await; + + let item = has_decimal::ActiveModel { + id: Set(1), + price: Set(dec!(10.0)), + } + .insert(&db.mysql) + .await?; + + println!("item: {:?}", item); + Ok(()) +} diff --git a/app/src/bin/has_decimal_seaorm_mysql_select.rs b/app/src/bin/has_decimal_seaorm_mysql_select.rs new file mode 100644 index 0000000..2afb674 --- /dev/null +++ b/app/src/bin/has_decimal_seaorm_mysql_select.rs @@ -0,0 +1,18 @@ +use app::docker; +use color_eyre::Result; +use entity::has_decimal; +use rust_decimal_macros::dec; +use sea_orm::ActiveModelTrait; +use sea_orm::EntityTrait; +use sea_orm::Set; + +#[tokio::main] +async fn main() -> Result<()> { + let db = docker::db_connect().await; + + let item = has_decimal::Entity::find_by_id(1).one(&db.mysql).await?; + + println!("item: {:?}", item); + + Ok(()) +} diff --git a/app/src/bin/has_decimal_seaorm_readyset_select.rs b/app/src/bin/has_decimal_seaorm_readyset_select.rs new file mode 100644 index 0000000..00cb76c --- /dev/null +++ b/app/src/bin/has_decimal_seaorm_readyset_select.rs @@ -0,0 +1,17 @@ +use app::docker; +use color_eyre::Result; +use entity::has_decimal; +use sea_orm::EntityTrait; + + +#[tokio::main] +async fn main() -> Result<()> { + let db = docker::db_connect().await; + + let item = has_decimal::Entity::find_by_id(1) + .one(&db.readyset) + .await? + .ok_or_else(|| color_eyre::eyre::eyre!("not found in readyset"))?; + println!("item: {:?}", item); + Ok(()) +} diff --git a/app/src/bin/has_decimal_sqlx_mysql.rs b/app/src/bin/has_decimal_sqlx_mysql.rs new file mode 100644 index 0000000..279d35e --- /dev/null +++ b/app/src/bin/has_decimal_sqlx_mysql.rs @@ -0,0 +1,23 @@ +use color_eyre::Result; +use rust_decimal::Decimal; +use sqlx::{MySqlPool, types::BigDecimal}; + +#[tokio::main] +async fn main() -> Result<()> { + + let pool = MySqlPool::connect("mysql://user:password@localhost:3307/db?ssl-mode=disabled").await?; + + #[derive(sqlx::FromRow, Debug)] + pub struct Row { + pub id : i64, + pub price: Decimal, + } + + // Make a simple query to return the given parameter (use a question mark `?` instead of `$1` for MySQL) + let row : Row = sqlx::query_as("SELECT id, price from has_decimal") + .fetch_one(&pool).await?; + + println!("row: {:?}", row); + + Ok(()) +} diff --git a/app/src/bin/has_decimal_sqlx_readyset.rs b/app/src/bin/has_decimal_sqlx_readyset.rs new file mode 100644 index 0000000..5bd8547 --- /dev/null +++ b/app/src/bin/has_decimal_sqlx_readyset.rs @@ -0,0 +1,24 @@ +use color_eyre::Result; +use rust_decimal::Decimal; +use sqlx::MySqlPool; + +#[tokio::main] +async fn main() -> Result<()> { + let pool = + MySqlPool::connect("mysql://user:password@localhost:3307/db?ssl-mode=disabled").await?; + + #[derive(sqlx::FromRow, Debug)] + pub struct Row { + pub id: i64, + pub price: Decimal, + } + + // Make a simple query to return the given parameter (use a question mark `?` instead of `$1` for MySQL) + let row: Row = sqlx::query_as("SELECT id, price from has_decimal") + .fetch_one(&pool) + .await?; + + println!("row: {:?}", row); + + Ok(()) +} diff --git a/app/src/bin/product.rs b/app/src/bin/product.rs new file mode 100644 index 0000000..52d7166 --- /dev/null +++ b/app/src/bin/product.rs @@ -0,0 +1,76 @@ +use app::docker; +use color_eyre::Result; +use entity::product; +use sea_orm::ActiveModelTrait; +use sea_orm::ColumnTrait; +use sea_orm::DbBackend; +use sea_orm::EntityTrait; +use sea_orm::FromQueryResult; +use sea_orm::QueryFilter; +use sea_orm::Set; +use sea_orm::Statement; + +#[tokio::main] +async fn main() -> Result<()> { + let db = docker::db_connect().await; + + let item = product::Entity::find_by_id(1).one(&db.mysql).await?; + + if item.is_none() { + product::ActiveModel { + id: Set(1), + name: Set("test".to_string()), + } + .insert(&db.mysql) + .await?; + + tokio::time::sleep(tokio::time::Duration::from_secs(1)).await; + } + + let _item = product::Entity::find_by_id(1) + .one(&db.readyset) + .await? + .ok_or_else(|| color_eyre::eyre::eyre!("not found in readyset"))?; + + let _item = product::Entity::find() + .filter(product::Column::Id.is_in(vec![1, 2, 3])) + .one(&db.readyset) + .await? + .ok_or_else(|| color_eyre::eyre::eyre!("not found in readyset"))?; + + let _item = product::Entity::find() + .from_raw_sql(Statement::from_sql_and_values( + DbBackend::MySql, + r#"SELECT * FROM product WHERE id = ?"#, + [1.into()], + )) + .one(&db.readyset) + .await? + .ok_or_else(|| color_eyre::eyre::eyre!("not found in readyset"))?; + + let _item = product::Entity::find() + .from_raw_sql(Statement::from_sql_and_values( + DbBackend::MySql, + r#"SELECT * FROM product WHERE id in (1)"#, + [], + )) + .one(&db.readyset) + .await? + .ok_or_else(|| color_eyre::eyre::eyre!("not found in readyset"))?; + + #[derive(Debug, FromQueryResult)] + pub struct ProductName { + pub name: String, + } + + let _foo = ProductName::find_by_statement(Statement::from_sql_and_values( + DbBackend::MySql, + r#"SELECT product.name as name from product left join has_decimal on product.id = has_decimal.id where product.id = 1"#, + [], + )) + .one(&db.readyset) + .await? + .ok_or_else(|| color_eyre::eyre::eyre!("not found in readyset"))?; + + Ok(()) +} diff --git a/app/src/bin/view_type_insert.rs b/app/src/bin/view_type_insert.rs new file mode 100644 index 0000000..f49fe23 --- /dev/null +++ b/app/src/bin/view_type_insert.rs @@ -0,0 +1,21 @@ +use app::docker; +use color_eyre::Result; +use entity::view_type; +use sea_orm::ActiveModelTrait; +use sea_orm::Set; + +#[tokio::main] +async fn main() -> Result<()> { + let db = docker::db_connect().await; + + let item = view_type::ActiveModel { + channel_id: Set(1), + view_type: Set("list".to_string()), + enabled: Set(true) + } + .insert(&db.mysql) + .await?; + + println!("item: {:?}", item); + Ok(()) +} diff --git a/app/src/bin/view_type_mysql_select.rs b/app/src/bin/view_type_mysql_select.rs new file mode 100644 index 0000000..d849846 --- /dev/null +++ b/app/src/bin/view_type_mysql_select.rs @@ -0,0 +1,18 @@ +use app::docker; +use color_eyre::Result; +use entity::view_type; +use sea_orm::ColumnTrait; +use sea_orm::EntityTrait; +use sea_orm::QueryFilter; + +#[tokio::main] +async fn main() -> Result<()> { + let db = docker::db_connect().await; + + let items = view_type::Entity::find() + .filter(view_type::Column::ChannelId.eq(1)) + .all(&db.mysql) + .await?; + println!("items: {:?}", items); + Ok(()) +} diff --git a/app/src/bin/view_type_readyset_select.rs b/app/src/bin/view_type_readyset_select.rs new file mode 100644 index 0000000..e2688d5 --- /dev/null +++ b/app/src/bin/view_type_readyset_select.rs @@ -0,0 +1,18 @@ +use app::docker; +use color_eyre::Result; +use entity::view_type; +use sea_orm::ColumnTrait; +use sea_orm::EntityTrait; +use sea_orm::QueryFilter; + +#[tokio::main] +async fn main() -> Result<()> { + let db = docker::db_connect().await; + + let items = view_type::Entity::find() + .filter(view_type::Column::ChannelId.eq(1)) + .all(&db.readyset) + .await?; + println!("items: {:?}", items); + Ok(()) +} diff --git a/app/src/docker.rs b/app/src/docker.rs index 1daefa7..712c879 100644 --- a/app/src/docker.rs +++ b/app/src/docker.rs @@ -14,7 +14,7 @@ pub async fn db_connect() -> Connections { Connections { mysql: Database::connect({ - let mut opt = ConnectOptions::new("mysql://user:password@localhost:3306/db".to_owned()); + let mut opt = ConnectOptions::new("mysql://user:password@localhost:3306/db?ssl-mode=disabled".to_owned()); opt.sqlx_logging_level(log::LevelFilter::Debug); opt }) diff --git a/docker-compose.yaml b/docker-compose.yaml index efabb4f..66b9aa9 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -9,6 +9,8 @@ services: MYSQL_USER: 'user' MYSQL_PASSWORD: 'password' MYSQL_ROOT_PASSWORD: 'password' + # command: + # - --ssl=off ports: - '3306:3306' volumes: @@ -31,4 +33,5 @@ services: --db-dir=/data --username=user --password=password - --log-level=DEBUG + --log-level=TRACE + --statement-logging diff --git a/entity/Cargo.toml b/entity/Cargo.toml index 3c14ef2..8eeba04 100644 --- a/entity/Cargo.toml +++ b/entity/Cargo.toml @@ -7,7 +7,7 @@ authors.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -sea-orm = { version = "0", features = [ "sqlx-mysql", "runtime-tokio-rustls", "macros", "with-chrono", "with-rust_decimal", "debug-print" ] } +sea-orm = { version = "0", features = [ "sqlx-mysql", "runtime-tokio", "macros", "with-chrono", "with-rust_decimal", "debug-print" ] } [lib] name = "entity" diff --git a/entity/src/lib.rs b/entity/src/lib.rs index 4a3c1b7..a5ba912 100644 --- a/entity/src/lib.rs +++ b/entity/src/lib.rs @@ -1,2 +1,6 @@ pub mod has_decimal; +pub mod product; + pub mod prelude; +pub mod order; +pub mod view_type; \ No newline at end of file diff --git a/entity/src/order.rs b/entity/src/order.rs new file mode 100644 index 0000000..8da7a8d --- /dev/null +++ b/entity/src/order.rs @@ -0,0 +1,13 @@ +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] +#[sea_orm(table_name = "order")] +pub struct Model { + #[sea_orm(primary_key)] + pub id: i32, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation {} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/entity/src/prelude.rs b/entity/src/prelude.rs index 01f456e..47485d1 100644 --- a/entity/src/prelude.rs +++ b/entity/src/prelude.rs @@ -1,2 +1,12 @@ pub use super::has_decimal::Entity as HasDecimal; pub use super::has_decimal::Model as HasDecimalModel; + +pub use super::product::Entity as Product; +pub use super::product::Model as ProductModel; + +pub use super::order::Entity as Order; +pub use super::order::Model as OrderModel; + +pub use sea_orm::QueryOrder; +pub use sea_orm::QuerySelect; +pub use sea_orm::QueryTrait; diff --git a/entity/src/product.rs b/entity/src/product.rs new file mode 100644 index 0000000..584681e --- /dev/null +++ b/entity/src/product.rs @@ -0,0 +1,14 @@ +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] +#[sea_orm(table_name = "product")] +pub struct Model { + #[sea_orm(primary_key)] + pub id: i32, + pub name: String, +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation {} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/entity/src/view_type.rs b/entity/src/view_type.rs new file mode 100644 index 0000000..fdef874 --- /dev/null +++ b/entity/src/view_type.rs @@ -0,0 +1,18 @@ +use sea_orm::entity::prelude::*; + +#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] +#[sea_orm(table_name = "view_type")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub channel_id: i64, + #[sea_orm(primary_key, auto_increment = false)] + pub view_type: String, + + pub enabled: bool, + +} + +#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +pub enum Relation {} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/migration/src/m20220101_000001_create_table.rs b/migration/src/m20220101_000001_create_table.rs index 5941101..86d8b8f 100644 --- a/migration/src/m20220101_000001_create_table.rs +++ b/migration/src/m20220101_000001_create_table.rs @@ -21,13 +21,64 @@ impl MigrationTrait for Migration { .col(ColumnDef::new(HasDecimal::Price).decimal().null()) .to_owned(), ) - .await + .await?; + + manager + .create_table( + Table::create() + .table(Product::Table) + .if_not_exists() + .col( + ColumnDef::new(Product::Id) + .integer() + .not_null() + .auto_increment() + .primary_key(), + ) + .col(ColumnDef::new(Product::Name).string().null()) + .to_owned(), + ) + .await?; + + manager + .create_table( + Table::create() + .table(Order::Table) + .if_not_exists() + .col( + ColumnDef::new(Order::Id) + .integer() + .not_null() + .auto_increment() + .primary_key(), + ) + // .col(ColumnDef::new(Product::Name).string().null()) + .to_owned(), + ) + .await?; + + manager + .create_table( + Table::create() + .table(ViewType::Table) + .if_not_exists() + .col(ColumnDef::new(ViewType::ChannelId).integer().not_null()) + .col(ColumnDef::new(ViewType::ViewType).string().not_null()) + .col(ColumnDef::new(ViewType::Enabled).boolean().not_null()) + .primary_key( + Index::create() + .col(ViewType::ChannelId) + .col(ViewType::ViewType), + ) + .to_owned(), + ) + .await?; + + Ok(()) } async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { - manager - .drop_table(Table::drop().table(HasDecimal::Table).to_owned()) - .await + Ok(()) } } @@ -37,3 +88,24 @@ enum HasDecimal { Id, Price, } + +#[derive(DeriveIden)] +enum Product { + Table, + Id, + Name, +} + +#[derive(DeriveIden)] +enum Order { + Table, + Id, +} + +#[derive(DeriveIden)] +enum ViewType { + Table, + ChannelId, + ViewType, + Enabled, +}