3 Commits

Author SHA1 Message Date
davidskrundz c5475585d4 Migrate to the new entity format 2025-11-02 11:04:19 -07:00
davidskrundz 508c4ed32f Remove home dependency 2025-10-29 13:19:14 -06:00
davidskrundz dd688fdc83 Update sea-orm rc version 2025-10-28 23:07:32 -06:00
69 changed files with 2940 additions and 4248 deletions
Generated
+167 -239
View File
@@ -2,26 +2,11 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 4 version = 4
[[package]]
name = "addr2line"
version = "0.25.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b5d307320b3181d6d7954e663bd7c774a838b8220fe0593c86d9fb09f498b4b"
dependencies = [
"gimli",
]
[[package]]
name = "adler2"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
[[package]] [[package]]
name = "aho-corasick" name = "aho-corasick"
version = "1.1.3" version = "1.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301"
dependencies = [ dependencies = [
"memchr", "memchr",
] ]
@@ -157,21 +142,6 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
[[package]]
name = "backtrace"
version = "0.3.76"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb531853791a215d7c62a30daf0dde835f381ab5de4589cfe7c649d2cbe92bd6"
dependencies = [
"addr2line",
"cfg-if",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
"windows-link",
]
[[package]] [[package]]
name = "base64" name = "base64"
version = "0.22.1" version = "0.22.1"
@@ -186,11 +156,11 @@ checksum = "55248b47b0caf0546f7988906588779981c43bb1bc9d0c44087278f80cdb44ba"
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "2.9.4" version = "2.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394" checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3"
dependencies = [ dependencies = [
"serde", "serde_core",
] ]
[[package]] [[package]]
@@ -222,9 +192,9 @@ checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a"
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.2.41" version = "1.2.44"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac9fe6cdbb24b6ade63616c0a0688e45bb56732262c158df3c0c4bea4ca47cb7" checksum = "37521ac7aabe3d13122dc382493e20c9416f299d2ccd5b3a5340a2570cdeb0f3"
dependencies = [ dependencies = [
"find-msvc-tools", "find-msvc-tools",
"shlex", "shlex",
@@ -232,9 +202,9 @@ dependencies = [
[[package]] [[package]]
name = "cfg-if" name = "cfg-if"
version = "1.0.3" version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]] [[package]]
name = "cfg_aliases" name = "cfg_aliases"
@@ -256,9 +226,9 @@ dependencies = [
[[package]] [[package]]
name = "clap" name = "clap"
version = "4.5.49" version = "4.5.51"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4512b90fa68d3a9932cea5184017c5d200f5921df706d45e853537dea51508f" checksum = "4c26d721170e0295f191a69bd9a1f93efcdb0aff38684b61ab5750468972e5f5"
dependencies = [ dependencies = [
"clap_builder", "clap_builder",
"clap_derive", "clap_derive",
@@ -266,9 +236,9 @@ dependencies = [
[[package]] [[package]]
name = "clap_builder" name = "clap_builder"
version = "4.5.49" version = "4.5.51"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0025e98baa12e766c67ba13ff4695a887a1eba19569aad00a472546795bd6730" checksum = "75835f0c7bf681bfd05abe44e965760fea999a5286c6eb2d59883634fd02011a"
dependencies = [ dependencies = [
"anstream", "anstream",
"anstyle", "anstyle",
@@ -510,7 +480,7 @@ checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127"
[[package]] [[package]]
name = "flix" name = "flix"
version = "0.0.11" version = "0.0.13"
dependencies = [ dependencies = [
"flix-db", "flix-db",
"flix-fs", "flix-fs",
@@ -520,23 +490,24 @@ dependencies = [
[[package]] [[package]]
name = "flix-cli" name = "flix-cli"
version = "0.0.11" version = "0.0.13"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"chrono", "chrono",
"clap", "clap",
"flix", "flix",
"futures", "futures",
"home",
"sea-orm", "sea-orm",
"serde", "serde",
"tokio", "tokio",
"toml", "toml",
"tracing",
"tracing-subscriber",
] ]
[[package]] [[package]]
name = "flix-db" name = "flix-db"
version = "0.0.11" version = "0.0.13"
dependencies = [ dependencies = [
"chrono", "chrono",
"flix-model", "flix-model",
@@ -549,7 +520,7 @@ dependencies = [
[[package]] [[package]]
name = "flix-fs" name = "flix-fs"
version = "0.0.11" version = "0.0.13"
dependencies = [ dependencies = [
"async-stream", "async-stream",
"flix-model", "flix-model",
@@ -561,7 +532,7 @@ dependencies = [
[[package]] [[package]]
name = "flix-model" name = "flix-model"
version = "0.0.11" version = "0.0.13"
dependencies = [ dependencies = [
"seamantic", "seamantic",
"serde", "serde",
@@ -570,7 +541,7 @@ dependencies = [
[[package]] [[package]]
name = "flix-tmdb" name = "flix-tmdb"
version = "0.0.11" version = "0.0.13"
dependencies = [ dependencies = [
"chrono", "chrono",
"flix-model", "flix-model",
@@ -728,30 +699,24 @@ dependencies = [
"cfg-if", "cfg-if",
"js-sys", "js-sys",
"libc", "libc",
"wasi 0.11.1+wasi-snapshot-preview1", "wasi",
"wasm-bindgen", "wasm-bindgen",
] ]
[[package]] [[package]]
name = "getrandom" name = "getrandom"
version = "0.3.3" version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"js-sys", "js-sys",
"libc", "libc",
"r-efi", "r-efi",
"wasi 0.14.7+wasi-0.2.4", "wasip2",
"wasm-bindgen", "wasm-bindgen",
] ]
[[package]]
name = "gimli"
version = "0.32.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e629b9b98ef3dd8afe6ca2bd0f89306cec16d43d907889945bc5d6687f2f13c7"
[[package]] [[package]]
name = "glob" name = "glob"
version = "0.3.3" version = "0.3.3"
@@ -768,7 +733,7 @@ dependencies = [
"futures-sink", "futures-sink",
"futures-timer", "futures-timer",
"futures-util", "futures-util",
"getrandom 0.3.3", "getrandom 0.3.4",
"hashbrown 0.15.5", "hashbrown 0.15.5",
"nonzero_ext", "nonzero_ext",
"parking_lot", "parking_lot",
@@ -843,11 +808,11 @@ dependencies = [
[[package]] [[package]]
name = "home" name = "home"
version = "0.5.11" version = "0.5.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589533453244b0995c858700322199b2becb13b627df2851f64a2775d024abcf" checksum = "cc627f471c528ff0c4a49e1d5e60450c8f6461dd6d10ba9dcd3a61d3dff7728d"
dependencies = [ dependencies = [
"windows-sys 0.59.0", "windows-sys 0.61.2",
] ]
[[package]] [[package]]
@@ -925,7 +890,7 @@ dependencies = [
"tokio", "tokio",
"tokio-rustls", "tokio-rustls",
"tower-service", "tower-service",
"webpki-roots 1.0.3", "webpki-roots 1.0.4",
] ]
[[package]] [[package]]
@@ -978,9 +943,9 @@ dependencies = [
[[package]] [[package]]
name = "icu_collections" name = "icu_collections"
version = "2.0.0" version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "200072f5d0e3614556f94a9930d5dc3e0662a652823904c3a75dc3b0af7fee47" checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43"
dependencies = [ dependencies = [
"displaydoc", "displaydoc",
"potential_utf", "potential_utf",
@@ -991,9 +956,9 @@ dependencies = [
[[package]] [[package]]
name = "icu_locale_core" name = "icu_locale_core"
version = "2.0.0" version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0cde2700ccaed3872079a65fb1a78f6c0a36c91570f28755dda67bc8f7d9f00a" checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6"
dependencies = [ dependencies = [
"displaydoc", "displaydoc",
"litemap", "litemap",
@@ -1004,11 +969,10 @@ dependencies = [
[[package]] [[package]]
name = "icu_normalizer" name = "icu_normalizer"
version = "2.0.0" version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "436880e8e18df4d7bbc06d58432329d6458cc84531f7ac5f024e93deadb37979" checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599"
dependencies = [ dependencies = [
"displaydoc",
"icu_collections", "icu_collections",
"icu_normalizer_data", "icu_normalizer_data",
"icu_properties", "icu_properties",
@@ -1019,42 +983,38 @@ dependencies = [
[[package]] [[package]]
name = "icu_normalizer_data" name = "icu_normalizer_data"
version = "2.0.0" version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00210d6893afc98edb752b664b8890f0ef174c8adbb8d0be9710fa66fbbf72d3" checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a"
[[package]] [[package]]
name = "icu_properties" name = "icu_properties"
version = "2.0.1" version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "016c619c1eeb94efb86809b015c58f479963de65bdb6253345c1a1276f22e32b" checksum = "e93fcd3157766c0c8da2f8cff6ce651a31f0810eaa1c51ec363ef790bbb5fb99"
dependencies = [ dependencies = [
"displaydoc",
"icu_collections", "icu_collections",
"icu_locale_core", "icu_locale_core",
"icu_properties_data", "icu_properties_data",
"icu_provider", "icu_provider",
"potential_utf",
"zerotrie", "zerotrie",
"zerovec", "zerovec",
] ]
[[package]] [[package]]
name = "icu_properties_data" name = "icu_properties_data"
version = "2.0.1" version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "298459143998310acd25ffe6810ed544932242d3f07083eee1084d83a71bd632" checksum = "02845b3647bb045f1100ecd6480ff52f34c35f82d9880e029d329c21d1054899"
[[package]] [[package]]
name = "icu_provider" name = "icu_provider"
version = "2.0.0" version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03c80da27b5f4187909049ee2d72f276f0d9f99a42c306bd0131ecfe04d8e5af" checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614"
dependencies = [ dependencies = [
"displaydoc", "displaydoc",
"icu_locale_core", "icu_locale_core",
"stable_deref_trait",
"tinystr",
"writeable", "writeable",
"yoke", "yoke",
"zerofrom", "zerofrom",
@@ -1091,14 +1051,23 @@ dependencies = [
[[package]] [[package]]
name = "indexmap" name = "indexmap"
version = "2.11.4" version = "2.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b0f83760fb341a774ed326568e19f5a863af4a952def8c39f9ab92fd95b88e5" checksum = "6717a8d2a5a929a1a2eb43a12812498ed141a0bcfb7e8f7844fbdbe4303bba9f"
dependencies = [ dependencies = [
"equivalent", "equivalent",
"hashbrown 0.16.0", "hashbrown 0.16.0",
] ]
[[package]]
name = "indoc"
version = "2.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79cf5c93f93228cf8efb3ba362535fb11199ac548a09ce117c9b1adc3030d706"
dependencies = [
"rustversion",
]
[[package]] [[package]]
name = "inherent" name = "inherent"
version = "1.0.13" version = "1.0.13"
@@ -1111,14 +1080,12 @@ dependencies = [
] ]
[[package]] [[package]]
name = "io-uring" name = "inventory"
version = "0.7.10" version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "046fa2d4d00aea763528b4950358d0ead425372445dc8ff86312b3c69ff7727b" checksum = "bc61209c082fbeb19919bee74b176221b27223e27b65d781eb91af24eb1fb46e"
dependencies = [ dependencies = [
"bitflags", "rustversion",
"cfg-if",
"libc",
] ]
[[package]] [[package]]
@@ -1139,9 +1106,18 @@ dependencies = [
[[package]] [[package]]
name = "is_terminal_polyfill" name = "is_terminal_polyfill"
version = "1.70.1" version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
[[package]]
name = "itertools"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285"
dependencies = [
"either",
]
[[package]] [[package]]
name = "itoa" name = "itoa"
@@ -1151,9 +1127,9 @@ checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
[[package]] [[package]]
name = "js-sys" name = "js-sys"
version = "0.3.81" version = "0.3.82"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec48937a97411dcb524a265206ccd4c90bb711fca92b2792c407f268825b9305" checksum = "b011eec8cc36da2aab2d5cff675ec18454fad408585853910a202391cf9f8e65"
dependencies = [ dependencies = [
"once_cell", "once_cell",
"wasm-bindgen", "wasm-bindgen",
@@ -1204,9 +1180,9 @@ dependencies = [
[[package]] [[package]]
name = "litemap" name = "litemap"
version = "0.8.0" version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "241eaef5fd12c88705a01fc1066c48c4b36e0dd4377dcdc7ec3942cea7a69956" checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77"
[[package]] [[package]]
name = "lock_api" name = "lock_api"
@@ -1254,24 +1230,15 @@ version = "2.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
[[package]]
name = "miniz_oxide"
version = "0.8.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316"
dependencies = [
"adler2",
]
[[package]] [[package]]
name = "mio" name = "mio"
version = "1.0.4" version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78bed444cc8a2160f01cbcf811ef18cac863ad68ae8ca62092e8db51d51c761c" checksum = "69d83b0086dc8ecf3ce9ae2874b2d1290252e2a30720bea58a5c6639b0092873"
dependencies = [ dependencies = [
"libc", "libc",
"wasi 0.11.1+wasi-snapshot-preview1", "wasi",
"windows-sys 0.59.0", "windows-sys 0.61.2",
] ]
[[package]] [[package]]
@@ -1282,11 +1249,10 @@ checksum = "38bf9645c8b145698bb0b18a4637dcacbc421ea49bef2317e4fd8065a387cf21"
[[package]] [[package]]
name = "num-bigint-dig" name = "num-bigint-dig"
version = "0.8.4" version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc84195820f291c7697304f3cbdadd1cb7199c0efc917ff5eafd71225c136151" checksum = "82c79c15c05d4bf82b6f5ef163104cc81a760d8e874d38ac50ab67c8877b647b"
dependencies = [ dependencies = [
"byteorder",
"lazy_static", "lazy_static",
"libm", "libm",
"num-integer", "num-integer",
@@ -1327,15 +1293,6 @@ dependencies = [
"libm", "libm",
] ]
[[package]]
name = "object"
version = "0.37.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff76201f031d8863c38aa7f905eca4f53abbfa15f609db4277d44cd8938f33fe"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "once_cell" name = "once_cell"
version = "1.21.3" version = "1.21.3"
@@ -1344,9 +1301,9 @@ checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]] [[package]]
name = "once_cell_polyfill" name = "once_cell_polyfill"
version = "1.70.1" version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad" checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
[[package]] [[package]]
name = "ordered-float" name = "ordered-float"
@@ -1472,9 +1429,9 @@ checksum = "f84267b20a16ea918e43c6a88433c2d54fa145c92a811b5b047ccbe153674483"
[[package]] [[package]]
name = "potential_utf" name = "potential_utf"
version = "0.1.3" version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84df19adbe5b5a0782edcab45899906947ab039ccf4573713735ee7de1e6b08a" checksum = "b73949432f5e2a09657003c25bca5e19a0e9c84f8058ca374f49e0ebe605af77"
dependencies = [ dependencies = [
"zerovec", "zerovec",
] ]
@@ -1512,9 +1469,9 @@ dependencies = [
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.101" version = "1.0.103"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de" checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
@@ -1559,7 +1516,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1906b49b0c3bc04b5fe5d86a77925ae6524a19b816ae38ce1e426255f1d8a31" checksum = "f1906b49b0c3bc04b5fe5d86a77925ae6524a19b816ae38ce1e426255f1d8a31"
dependencies = [ dependencies = [
"bytes", "bytes",
"getrandom 0.3.3", "getrandom 0.3.4",
"lru-slab", "lru-slab",
"rand 0.9.2", "rand 0.9.2",
"ring", "ring",
@@ -1658,7 +1615,7 @@ version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
dependencies = [ dependencies = [
"getrandom 0.3.3", "getrandom 0.3.4",
] ]
[[package]] [[package]]
@@ -1734,7 +1691,7 @@ dependencies = [
"wasm-bindgen", "wasm-bindgen",
"wasm-bindgen-futures", "wasm-bindgen-futures",
"web-sys", "web-sys",
"webpki-roots 1.0.3", "webpki-roots 1.0.4",
] ]
[[package]] [[package]]
@@ -1771,12 +1728,6 @@ dependencies = [
"zeroize", "zeroize",
] ]
[[package]]
name = "rustc-demangle"
version = "0.1.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56f7d92ca342cea22a06f2121d944b4fd82af56988c270852495420f961d4ace"
[[package]] [[package]]
name = "rustc-hash" name = "rustc-hash"
version = "2.1.1" version = "2.1.1"
@@ -1785,9 +1736,9 @@ checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d"
[[package]] [[package]]
name = "rustls" name = "rustls"
version = "0.23.32" version = "0.23.34"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd3c25631629d034ce7cd9940adc9d45762d46de2b0f57193c4443b92c6d4d40" checksum = "6a9586e9ee2b4f8fab52a0048ca7334d7024eef48e2cb9407e3497bb7cab7fa7"
dependencies = [ dependencies = [
"once_cell", "once_cell",
"ring", "ring",
@@ -1799,9 +1750,9 @@ dependencies = [
[[package]] [[package]]
name = "rustls-pki-types" name = "rustls-pki-types"
version = "1.12.0" version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "229a4a4c221013e7e1f1a043678c5cc39fe5171437c88fb47151a21e6f5b5c79" checksum = "94182ad936a0c91c324cd46c6511b9510ed16af436d7b5bab34beab0afd55f7a"
dependencies = [ dependencies = [
"web-time", "web-time",
"zeroize", "zeroize",
@@ -1809,9 +1760,9 @@ dependencies = [
[[package]] [[package]]
name = "rustls-webpki" name = "rustls-webpki"
version = "0.103.7" version = "0.103.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e10b3f4191e8a80e6b43eebabfac91e5dcecebb27a71f04e820c47ec41d314bf" checksum = "2ffdfa2f5286e2247234e03f680868ac2815974dc39e00ea15adc445d0aafe52"
dependencies = [ dependencies = [
"ring", "ring",
"rustls-pki-types", "rustls-pki-types",
@@ -1851,20 +1802,23 @@ dependencies = [
[[package]] [[package]]
name = "sea-orm" name = "sea-orm"
version = "2.0.0-rc.10" version = "2.0.0-rc.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d10d776a4086bc1dea156d52f4d52f61617b5d074b4c026304b9d7aef7d0117a" checksum = "296a092e16fbbcc3a9969eae3915ef11024b98a43f3b77ff5199bc626c462d7a"
dependencies = [ dependencies = [
"async-stream", "async-stream",
"async-trait", "async-trait",
"chrono", "chrono",
"derive_more", "derive_more",
"futures-util", "futures-util",
"inventory",
"itertools",
"log", "log",
"ouroboros", "ouroboros",
"sea-orm-macros", "sea-orm-macros",
"sea-query", "sea-query",
"sea-query-sqlx", "sea-query-sqlx",
"sea-schema",
"serde", "serde",
"sqlx", "sqlx",
"strum", "strum",
@@ -1875,12 +1829,13 @@ dependencies = [
[[package]] [[package]]
name = "sea-orm-cli" name = "sea-orm-cli"
version = "2.0.0-rc.10" version = "2.0.0-rc.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd68cd7fffcfd5262a2d5ae8f425305c0fccaf1354b9dd9159a4d316efff6ca7" checksum = "301f7ace977d940474b47a154a5fc453714d13e5d53bdb077330c6fc6212a31b"
dependencies = [ dependencies = [
"chrono", "chrono",
"glob", "glob",
"indoc",
"regex", "regex",
"sea-schema", "sea-schema",
"sqlx", "sqlx",
@@ -1892,9 +1847,9 @@ dependencies = [
[[package]] [[package]]
name = "sea-orm-macros" name = "sea-orm-macros"
version = "2.0.0-rc.10" version = "2.0.0-rc.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd736f392dbe4b5bdbae5b57068c3c206fd3d50c2437c14303e1e2d626def5a8" checksum = "e56ee8be52d15a801dc62a5a30d83dc718762401f7c7945b7f2730ef385b8b3d"
dependencies = [ dependencies = [
"heck 0.5.0", "heck 0.5.0",
"proc-macro2", "proc-macro2",
@@ -1906,9 +1861,9 @@ dependencies = [
[[package]] [[package]]
name = "sea-orm-migration" name = "sea-orm-migration"
version = "2.0.0-rc.10" version = "2.0.0-rc.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f963e814a7a2605f1dc30372301d06150d9b447ca19f2365662121fbd612056d" checksum = "b7444940e5b7db32f55dea6d04cfb312480e45ae07753b1391311eccd5753475"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"sea-orm", "sea-orm",
@@ -1920,9 +1875,9 @@ dependencies = [
[[package]] [[package]]
name = "sea-query" name = "sea-query"
version = "1.0.0-rc.14" version = "1.0.0-rc.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fdeac8832b5b36a57b38ef6d2956cd6244c04508669f2a932439c8ca25dbad0f" checksum = "ab2bc1fe7bb8366b536efc69a68e48321671a1030c565b206dc1a1a5ce1cf815"
dependencies = [ dependencies = [
"chrono", "chrono",
"inherent", "inherent",
@@ -1932,9 +1887,9 @@ dependencies = [
[[package]] [[package]]
name = "sea-query-derive" name = "sea-query-derive"
version = "1.0.0-rc.9" version = "1.0.0-rc.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "217e9422de35f26c16c5f671fce3c075a65e10322068dbc66078428634af6195" checksum = "365d236217f5daa4f40d3c9998ff3921351b53472da50308e384388162353b3a"
dependencies = [ dependencies = [
"darling", "darling",
"heck 0.4.1", "heck 0.4.1",
@@ -1957,9 +1912,9 @@ dependencies = [
[[package]] [[package]]
name = "sea-schema" name = "sea-schema"
version = "0.17.0-rc.7" version = "0.17.0-rc.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfb37ec7279ebca303db0da04f0c4db9e869d569ae00bb31114bc945a5d848c6" checksum = "1403428d34276a93f3eb4401730ba6346bd0d04cbbea8f6973916a35e726286f"
dependencies = [ dependencies = [
"futures", "futures",
"sea-query", "sea-query",
@@ -1982,9 +1937,9 @@ dependencies = [
[[package]] [[package]]
name = "seamantic" name = "seamantic"
version = "0.0.7" version = "0.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0c8137251dde6f782c05562e48d5857f5cf7186725dd03382ad2827c264581a" checksum = "6fdfda9081467f15961b506b46c1569ac166f69b1ac17835c59a3104c3b2a79e"
dependencies = [ dependencies = [
"sea-orm", "sea-orm",
"sea-orm-migration", "sea-orm-migration",
@@ -2400,9 +2355,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.106" version = "2.0.108"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" checksum = "da58917d35242480a05c2897064da0a80589a2a0476c9a3f2fdc83b53502e917"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -2460,9 +2415,9 @@ dependencies = [
[[package]] [[package]]
name = "tinystr" name = "tinystr"
version = "0.8.1" version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d4f6d1145dcb577acf783d4e601bc1d76a13337bb54e6233add580b07344c8b" checksum = "42d3e9c45c09de15d06dd8acf5f4e0e399e85927b7f00711024eb7ae10fa4869"
dependencies = [ dependencies = [
"displaydoc", "displaydoc",
"zerovec", "zerovec",
@@ -2485,27 +2440,24 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]] [[package]]
name = "tokio" name = "tokio"
version = "1.47.1" version = "1.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89e49afdadebb872d3145a5638b59eb0691ea23e46ca484037cfab3b76b95038" checksum = "ff360e02eab121e0bc37a2d3b4d4dc622e6eda3a8e5253d5435ecf5bd4c68408"
dependencies = [ dependencies = [
"backtrace",
"bytes", "bytes",
"io-uring",
"libc", "libc",
"mio", "mio",
"pin-project-lite", "pin-project-lite",
"slab",
"socket2", "socket2",
"tokio-macros", "tokio-macros",
"windows-sys 0.59.0", "windows-sys 0.61.2",
] ]
[[package]] [[package]]
name = "tokio-macros" name = "tokio-macros"
version = "2.5.0" version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -2676,24 +2628,24 @@ checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5"
[[package]] [[package]]
name = "unicode-ident" name = "unicode-ident"
version = "1.0.19" version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d" checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
[[package]] [[package]]
name = "unicode-normalization" name = "unicode-normalization"
version = "0.1.24" version = "0.1.25"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" checksum = "5fd4f6878c9cb28d874b009da9e8d183b5abc80117c40bbd187a1fde336be6e8"
dependencies = [ dependencies = [
"tinyvec", "tinyvec",
] ]
[[package]] [[package]]
name = "unicode-properties" name = "unicode-properties"
version = "0.1.3" version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e70f2a8b45122e719eb623c01822704c4e0907e7e426a05927e1a1cfff5b75d0" checksum = "7df058c713841ad818f1dc5d3fd88063241cc61f49f5fbea4b951e8cf5a8d71d"
[[package]] [[package]]
name = "unicode-xid" name = "unicode-xid"
@@ -2767,15 +2719,6 @@ version = "0.11.1+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
[[package]]
name = "wasi"
version = "0.14.7+wasi-0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "883478de20367e224c0090af9cf5f9fa85bed63a95c1abf3afc5c083ebc06e8c"
dependencies = [
"wasip2",
]
[[package]] [[package]]
name = "wasip2" name = "wasip2"
version = "1.0.1+wasi-0.2.4" version = "1.0.1+wasi-0.2.4"
@@ -2793,9 +2736,9 @@ checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b"
[[package]] [[package]]
name = "wasm-bindgen" name = "wasm-bindgen"
version = "0.2.104" version = "0.2.105"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1da10c01ae9f1ae40cbfac0bac3b1e724b320abfcf52229f80b547c0d250e2d" checksum = "da95793dfc411fbbd93f5be7715b0578ec61fe87cb1a42b12eb625caa5c5ea60"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"once_cell", "once_cell",
@@ -2804,25 +2747,11 @@ dependencies = [
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "671c9a5a66f49d8a47345ab942e2cb93c7d1d0339065d4f8139c486121b43b19"
dependencies = [
"bumpalo",
"log",
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-shared",
]
[[package]] [[package]]
name = "wasm-bindgen-futures" name = "wasm-bindgen-futures"
version = "0.4.54" version = "0.4.55"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e038d41e478cc73bae0ff9b36c60cff1c98b8f38f8d7e8061e79ee63608ac5c" checksum = "551f88106c6d5e7ccc7cd9a16f312dd3b5d36ea8b4954304657d5dfba115d4a0"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"js-sys", "js-sys",
@@ -2833,9 +2762,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro" name = "wasm-bindgen-macro"
version = "0.2.104" version = "0.2.105"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ca60477e4c59f5f2986c50191cd972e3a50d8a95603bc9434501cf156a9a119" checksum = "04264334509e04a7bf8690f2384ef5265f05143a4bff3889ab7a3269adab59c2"
dependencies = [ dependencies = [
"quote", "quote",
"wasm-bindgen-macro-support", "wasm-bindgen-macro-support",
@@ -2843,31 +2772,31 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro-support" name = "wasm-bindgen-macro-support"
version = "0.2.104" version = "0.2.105"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f07d2f20d4da7b26400c9f4a0511e6e0345b040694e8a75bd41d578fa4421d7" checksum = "420bc339d9f322e562942d52e115d57e950d12d88983a14c79b86859ee6c7ebc"
dependencies = [ dependencies = [
"bumpalo",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
[[package]] [[package]]
name = "wasm-bindgen-shared" name = "wasm-bindgen-shared"
version = "0.2.104" version = "0.2.105"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bad67dc8b2a1a6e5448428adec4c3e84c43e561d8c9ee8a9e5aabeb193ec41d1" checksum = "76f218a38c84bcb33c25ec7059b07847d465ce0e0a76b995e134a45adcb6af76"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]] [[package]]
name = "web-sys" name = "web-sys"
version = "0.3.81" version = "0.3.82"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9367c417a924a74cae129e6a2ae3b47fabb1f8995595ab474029da749a8be120" checksum = "3a1f95c0d03a47f4ae1f7a64643a6bb97465d9b740f0fa8f90ea33915c99a9a1"
dependencies = [ dependencies = [
"js-sys", "js-sys",
"wasm-bindgen", "wasm-bindgen",
@@ -2889,14 +2818,14 @@ version = "0.26.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "521bc38abb08001b01866da9f51eb7c5d647a19260e00054a8c7fd5f9e57f7a9" checksum = "521bc38abb08001b01866da9f51eb7c5d647a19260e00054a8c7fd5f9e57f7a9"
dependencies = [ dependencies = [
"webpki-roots 1.0.3", "webpki-roots 1.0.4",
] ]
[[package]] [[package]]
name = "webpki-roots" name = "webpki-roots"
version = "1.0.3" version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32b130c0d2d49f8b6889abc456e795e82525204f27c42cf767cf0d7734e089b8" checksum = "b2878ef029c47c6e8cf779119f20fcf52bde7ad42a731b2a304bc221df17571e"
dependencies = [ dependencies = [
"rustls-pki-types", "rustls-pki-types",
] ]
@@ -2988,15 +2917,6 @@ dependencies = [
"windows-targets 0.52.6", "windows-targets 0.52.6",
] ]
[[package]]
name = "windows-sys"
version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
dependencies = [
"windows-targets 0.52.6",
]
[[package]] [[package]]
name = "windows-sys" name = "windows-sys"
version = "0.60.2" version = "0.60.2"
@@ -3006,6 +2926,15 @@ dependencies = [
"windows-targets 0.53.5", "windows-targets 0.53.5",
] ]
[[package]]
name = "windows-sys"
version = "0.61.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
dependencies = [
"windows-link",
]
[[package]] [[package]]
name = "windows-targets" name = "windows-targets"
version = "0.48.5" version = "0.48.5"
@@ -3206,9 +3135,9 @@ checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59"
[[package]] [[package]]
name = "writeable" name = "writeable"
version = "0.6.1" version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea2f10b9bb0928dfb1b42b65e1f9e36f7f54dbdf08457afefb38afcdec4fa2bb" checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9"
[[package]] [[package]]
name = "yansi" name = "yansi"
@@ -3218,11 +3147,10 @@ checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049"
[[package]] [[package]]
name = "yoke" name = "yoke"
version = "0.8.0" version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f41bb01b8226ef4bfd589436a297c53d118f65921786300e427be8d487695cc" checksum = "72d6e5c6afb84d73944e5cedb052c4680d5657337201555f9f2a16b7406d4954"
dependencies = [ dependencies = [
"serde",
"stable_deref_trait", "stable_deref_trait",
"yoke-derive", "yoke-derive",
"zerofrom", "zerofrom",
@@ -3230,9 +3158,9 @@ dependencies = [
[[package]] [[package]]
name = "yoke-derive" name = "yoke-derive"
version = "0.8.0" version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38da3c9736e16c5d3c8c597a9aaa5d1fa565d0532ae05e27c24aa62fb32c0ab6" checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -3289,9 +3217,9 @@ checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0"
[[package]] [[package]]
name = "zerotrie" name = "zerotrie"
version = "0.2.2" version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36f0bbd478583f79edad978b407914f61b2972f5af6fa089686016be8f9af595" checksum = "2a59c17a5562d507e4b54960e8569ebee33bee890c70aa3fe7b97e85a9fd7851"
dependencies = [ dependencies = [
"displaydoc", "displaydoc",
"yoke", "yoke",
@@ -3300,9 +3228,9 @@ dependencies = [
[[package]] [[package]]
name = "zerovec" name = "zerovec"
version = "0.11.4" version = "0.11.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7aa2bd55086f1ab526693ecbe444205da57e25f4489879da80635a46d90e73b" checksum = "6c28719294829477f525be0186d13efa9a3c602f7ec202ca9e353d310fb9a002"
dependencies = [ dependencies = [
"yoke", "yoke",
"zerofrom", "zerofrom",
@@ -3311,9 +3239,9 @@ dependencies = [
[[package]] [[package]]
name = "zerovec-derive" name = "zerovec-derive"
version = "0.11.1" version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b96237efa0c878c64bd89c436f661be4e46b2f3eff1ebb976f7ef2321d2f58f" checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
+11 -10
View File
@@ -35,17 +35,17 @@ overflow-checks = true
strip = "debuginfo" strip = "debuginfo"
[workspace.dependencies] [workspace.dependencies]
flix = { path = "crates/flix", version = "=0.0.11", default-features = false } flix = { path = "crates/flix", version = "=0.0.13", default-features = false }
flix-cli = { path = "crates/cli", version = "=0.0.11", default-features = false } flix-cli = { path = "crates/cli", version = "=0.0.13", default-features = false }
flix-db = { path = "crates/db", version = "=0.0.11", default-features = false } flix-db = { path = "crates/db", version = "=0.0.13", default-features = false }
flix-fs = { path = "crates/fs", version = "=0.0.11", default-features = false } flix-fs = { path = "crates/fs", version = "=0.0.13", default-features = false }
flix-model = { path = "crates/model", version = "=0.0.11", default-features = false } flix-model = { path = "crates/model", version = "=0.0.13", default-features = false }
flix-tmdb = { path = "crates/tmdb", version = "=0.0.11", default-features = false } flix-tmdb = { path = "crates/tmdb", version = "=0.0.13", default-features = false }
seamantic = { version = "0.0.7", default-features = false } seamantic = { version = "0.0.10", default-features = false }
sea-orm = { version = "2.0.0-rc.10", default-features = false } sea-orm = { version = "2.0.0-rc.17", default-features = false }
sea-orm-migration = { version = "2.0.0-rc.10", default-features = false } sea-orm-migration = { version = "2.0.0-rc.17", default-features = false }
anyhow = { version = "^1", default-features = false } anyhow = { version = "^1", default-features = false }
async-stream = { version = "^0.3", default-features = false } async-stream = { version = "^0.3", default-features = false }
@@ -53,7 +53,6 @@ chrono = { version = "^0.4", default-features = false }
clap = { version = "^4", default-features = false, features = ["std"] } clap = { version = "^4", default-features = false, features = ["std"] }
futures = { version = "^0.3", default-features = false } futures = { version = "^0.3", default-features = false }
governor = { version = "^0.10", default-features = false } governor = { version = "^0.10", default-features = false }
home = { version = "^0.5", default-features = false }
nonzero_ext = { version = "^0.3", default-features = false } nonzero_ext = { version = "^0.3", default-features = false }
regex = { version = "^1", default-features = false } regex = { version = "^1", default-features = false }
reqwest = { version = "^0.12", default-features = false } reqwest = { version = "^0.12", default-features = false }
@@ -63,5 +62,7 @@ thiserror = { version = "^2", default-features = false }
tokio = { version = "^1", default-features = false } tokio = { version = "^1", default-features = false }
tokio-stream = { version = "^0.1", default-features = false } tokio-stream = { version = "^0.1", default-features = false }
toml = { version = "^0.9", default-features = false } toml = { version = "^0.9", default-features = false }
tracing = { version = "^0.1", default-features = false }
tracing-subscriber = { version = "^0.3", default-features = false }
url = { version = "^2", default-features = false } url = { version = "^2", default-features = false }
url-macro = { version = "^0.2", default-features = false } url-macro = { version = "^0.2", default-features = false }
+4 -3
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "flix-cli" name = "flix-cli"
version = "0.0.11" version = "0.0.13"
categories = ["command-line-utilities"] categories = ["command-line-utilities"]
description = "CLI for interacting with a flix database" description = "CLI for interacting with a flix database"
@@ -51,8 +51,9 @@ clap = { workspace = true, features = [
"usage", "usage",
] } ] }
futures = { workspace = true } futures = { workspace = true }
home = { workspace = true } sea-orm = { workspace = true, features = ["runtime-tokio", "debug-print"] }
sea-orm = { workspace = true, features = ["runtime-tokio"] }
serde = { workspace = true, features = ["derive"] } serde = { workspace = true, features = ["derive"] }
tokio = { workspace = true, features = ["rt", "fs", "macros"] } tokio = { workspace = true, features = ["rt", "fs", "macros"] }
toml = { workspace = true, features = ["parse", "serde"] } toml = { workspace = true, features = ["parse", "serde"] }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
+5 -1
View File
@@ -16,6 +16,10 @@ pub struct Cli {
#[arg(short, long, value_name = "DATABASE", default_value = "./flix.db")] #[arg(short, long, value_name = "DATABASE", default_value = "./flix.db")]
database: PathBuf, database: PathBuf,
/// Enable tracing
#[arg(short, long)]
pub trace: bool,
#[command(subcommand)] #[command(subcommand)]
command: Command, command: Command,
} }
@@ -24,7 +28,7 @@ impl Cli {
pub fn config_path(&self) -> PathBuf { pub fn config_path(&self) -> PathBuf {
fn expect_home_dir() -> PathBuf { fn expect_home_dir() -> PathBuf {
#[allow(clippy::expect_used)] #[allow(clippy::expect_used)]
home::home_dir().expect("you do not have a home directory") std::env::home_dir().expect("you do not have a home directory")
} }
match self.config.strip_prefix("~/") { match self.config.strip_prefix("~/") {
+7
View File
@@ -28,6 +28,13 @@ async fn main() -> Result<()> {
let client = Client::new(config.tmdb().bearer_token().to_owned()); let client = Client::new(config.tmdb().bearer_token().to_owned());
if cli.trace {
tracing_subscriber::fmt()
.with_max_level(tracing::Level::DEBUG)
.with_test_writer()
.init();
}
match cli.command() { match cli.command() {
Command::Init => exec_init(database_path).await?, Command::Init => exec_init(database_path).await?,
Command::Add { command } => exec_add(client, database_path, command).await?, Command::Add { command } => exec_add(client, database_path, command).await?,
+14 -14
View File
@@ -101,7 +101,7 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
flix_id: Set(flix.id), flix_id: Set(flix.id),
last_update: Set(Utc::now().date_naive()), last_update: Set(Utc::now().date_naive()),
runtime: Set(movie.runtime.into()), runtime: Set(movie.runtime.into()),
collection: Set(movie.collection.map(|c| c.id)), collection_id: Set(movie.collection.map(|c| c.id)),
} }
.insert(txn) .insert(txn)
.await?; .await?;
@@ -206,8 +206,8 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
for season in seasons { for season in seasons {
entity::info::seasons::ActiveModel { entity::info::seasons::ActiveModel {
show: Set(flix.id), show_id: Set(flix.id),
season: Set(season.season_number), season_number: Set(season.season_number),
title: Set(season.title), title: Set(season.title),
overview: Set(season.overview), overview: Set(season.overview),
date: Set(season.air_date), date: Set(season.air_date),
@@ -229,9 +229,9 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
for (season, episodes) in episodes { for (season, episodes) in episodes {
for episode in episodes { for episode in episodes {
entity::info::episodes::ActiveModel { entity::info::episodes::ActiveModel {
show: Set(flix.id), show_id: Set(flix.id),
season: Set(season), season_number: Set(season),
episode: Set(episode.episode_number), episode_number: Set(episode.episode_number),
title: Set(episode.title), title: Set(episode.title),
overview: Set(episode.overview), overview: Set(episode.overview),
date: Set(episode.air_date), date: Set(episode.air_date),
@@ -324,8 +324,8 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
.transaction(|txn| { .transaction(|txn| {
Box::pin(async move { Box::pin(async move {
entity::info::seasons::ActiveModel { entity::info::seasons::ActiveModel {
show: Set(show.flix_id), show_id: Set(show.flix_id),
season: Set(season_number), season_number: Set(season_number),
title: Set(season.title), title: Set(season.title),
overview: Set(season.overview), overview: Set(season.overview),
date: Set(season.air_date), date: Set(season.air_date),
@@ -345,9 +345,9 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
for episode in episodes { for episode in episodes {
entity::info::episodes::ActiveModel { entity::info::episodes::ActiveModel {
show: Set(show.flix_id), show_id: Set(show.flix_id),
season: Set(season_number), season_number: Set(season_number),
episode: Set(episode.episode_number), episode_number: Set(episode.episode_number),
title: Set(episode.title), title: Set(episode.title),
overview: Set(episode.overview), overview: Set(episode.overview),
date: Set(episode.air_date), date: Set(episode.air_date),
@@ -436,9 +436,9 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
.transaction(|txn| { .transaction(|txn| {
Box::pin(async move { Box::pin(async move {
entity::info::episodes::ActiveModel { entity::info::episodes::ActiveModel {
show: Set(flix_id), show_id: Set(flix_id),
season: Set(season), season_number: Set(season),
episode: Set(episode_number), episode_number: Set(episode_number),
title: Set(episode.title), title: Set(episode.title),
overview: Set(episode.overview), overview: Set(episode.overview),
date: Set(episode.air_date), date: Set(episode.air_date),
+6 -2
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "flix-db" name = "flix-db"
version = "0.0.11" version = "0.0.13"
categories = [] categories = []
description = "Types for storing persistent data about media" description = "Types for storing persistent data about media"
@@ -30,7 +30,11 @@ flix-tmdb = { workspace = true, optional = true, features = ["sea-orm"] }
seamantic = { workspace = true, features = ["sqlite"] } seamantic = { workspace = true, features = ["sqlite"] }
chrono = { workspace = true } chrono = { workspace = true }
sea-orm = { workspace = true, features = ["with-chrono"] } sea-orm = { workspace = true, features = [
"entity-registry",
"schema-sync",
"with-chrono",
] }
sea-orm-migration = { workspace = true } sea-orm-migration = { workspace = true }
[dev-dependencies] [dev-dependencies]
+13 -3
View File
@@ -9,9 +9,12 @@ pub struct Connection(DatabaseConnection);
impl Connection { impl Connection {
/// Helper function for applying database migrations while wrapping a /// Helper function for applying database migrations while wrapping a
/// [DatabaseConnection] in a newtype /// [DatabaseConnection] in a newtype
pub async fn try_from(database: DatabaseConnection) -> Result<Self, DbErr> { pub async fn try_from(db: DatabaseConnection) -> Result<Self, DbErr> {
crate::migration::Migrator::up(&database, None).await?; crate::migration::Migrator::down(&db, None).await?;
Ok(Self(database)) db.get_schema_registry("flix_db::*").sync(&db).await?;
db.get_schema_registry("flix_db::*").sync(&db).await?;
crate::migration::Migrator::up(&db, None).await?;
Ok(Self(db))
} }
} }
@@ -20,3 +23,10 @@ impl AsRef<DatabaseConnection> for Connection {
&self.0 &self.0
} }
} }
#[cfg(test)]
impl Connection {
pub(crate) fn take(self) -> DatabaseConnection {
self.0
}
}
+794
View File
@@ -0,0 +1,794 @@
//! This module contains entities for storing media file information
/// Library entity
pub mod libraries {
use flix_model::id::LibraryId;
use seamantic::model::path::PathBytes;
use sea_orm::entity::prelude::*;
/// The database representation of a library media folder
#[sea_orm::model]
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_libraries")]
pub struct Model {
/// The library's ID
#[sea_orm(column_type = "Integer", primary_key, nullable, auto_increment = false)]
pub id: LibraryId,
/// The library's directory
pub directory: PathBytes,
/// Collections that are part of this library
#[sea_orm(has_many, on_update = "Cascade", on_delete = "Cascade")]
pub collections: HasMany<super::collections::Entity>,
/// Movies that are part of this library
#[sea_orm(has_many, on_update = "Cascade", on_delete = "Cascade")]
pub movies: HasMany<super::movies::Entity>,
/// Shows that are part of this library
#[sea_orm(has_many, on_update = "Cascade", on_delete = "Cascade")]
pub shows: HasMany<super::shows::Entity>,
/// Seasons that are part of this library
#[sea_orm(has_many, on_update = "Cascade", on_delete = "Cascade")]
pub seasons: HasMany<super::seasons::Entity>,
/// Episodes that are part of this library
#[sea_orm(has_many, on_update = "Cascade", on_delete = "Cascade")]
pub episodes: HasMany<super::episodes::Entity>,
}
impl ActiveModelBehavior for ActiveModel {}
}
/// Collection entity
pub mod collections {
use flix_model::id::{CollectionId, LibraryId};
use seamantic::model::path::PathBytes;
use sea_orm::entity::prelude::*;
use crate::entity;
/// The database representation of a collection media folder
#[sea_orm::model]
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_collections")]
pub struct Model {
/// The collection's ID
#[sea_orm(column_type = "Integer", primary_key, nullable, auto_increment = false)]
pub id: CollectionId,
/// The collection's parent
#[sea_orm(indexed)]
pub parent_id: Option<CollectionId>,
/// The collection's slug
#[sea_orm(unique)]
pub slug: String,
/// The collection's library ID
pub library_id: LibraryId,
/// The collection's directory
pub directory: PathBytes,
/// The collection's poster path
pub relative_poster_path: Option<String>,
/// This collection's parent
#[sea_orm(self_ref, relation_enum = "Parent", from = "parent_id", to = "id")]
pub parent: HasOne<Entity>,
/// The library this collection belongs to
#[sea_orm(belongs_to, from = "library_id", to = "id")]
pub library: HasOne<super::libraries::Entity>,
/// The info for this collection
#[sea_orm(belongs_to, relation_enum = "Info", from = "id", to = "id")]
pub info: HasOne<entity::info::collections::Entity>,
/// The watched info for this collection
#[sea_orm(has_many, relation_enum = "Watched", from = "id", to = "id")]
pub watched: HasMany<entity::watched::collections::Entity>,
}
impl ActiveModelBehavior for ActiveModel {}
}
/// Movie entity
pub mod movies {
use flix_model::id::{CollectionId, LibraryId, MovieId};
use seamantic::model::path::PathBytes;
use sea_orm::entity::prelude::*;
use crate::entity;
/// The database representation of a movie media folder
#[sea_orm::model]
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_movies")]
pub struct Model {
/// The movie's ID
#[sea_orm(column_type = "Integer", primary_key, nullable, auto_increment = false)]
pub id: MovieId,
/// The movie's parent
#[sea_orm(indexed)]
pub parent_id: Option<CollectionId>,
/// The movie's slug
#[sea_orm(unique)]
pub slug: String,
/// The movie's library
pub library_id: LibraryId,
/// The movie's directory
pub directory: PathBytes,
/// The movie's media path
pub relative_media_path: String,
/// The movie's poster path
pub relative_poster_path: Option<String>,
/// This movie's parent
#[sea_orm(belongs_to, from = "parent_id", to = "id")]
pub parent: HasOne<super::collections::Entity>,
/// The library this movie belongs to
#[sea_orm(belongs_to, from = "library_id", to = "id")]
pub library: HasOne<super::libraries::Entity>,
/// The info for this movie
#[sea_orm(belongs_to, relation_enum = "Info", from = "id", to = "id")]
pub info: HasOne<entity::info::movies::Entity>,
/// The watched info for this movie
#[sea_orm(has_many, relation_enum = "Watched", from = "id", to = "id")]
pub watched: HasMany<entity::watched::movies::Entity>,
}
impl ActiveModelBehavior for ActiveModel {}
}
/// Show entity
pub mod shows {
use flix_model::id::{CollectionId, LibraryId, ShowId};
use seamantic::model::path::PathBytes;
use sea_orm::entity::prelude::*;
use crate::entity;
/// The database representation of a show media folder
#[sea_orm::model]
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_shows")]
pub struct Model {
/// The show's ID
#[sea_orm(column_type = "Integer", primary_key, nullable, auto_increment = false)]
pub id: ShowId,
/// The show's parent
#[sea_orm(indexed)]
pub parent_id: Option<CollectionId>,
/// The show's slug
#[sea_orm(unique)]
pub slug: String,
/// The show's library
pub library_id: LibraryId,
/// The show's directory
pub directory: PathBytes,
/// The show's poster path
pub relative_poster_path: Option<String>,
/// This show's parent
#[sea_orm(belongs_to, from = "parent_id", to = "id")]
pub parent: HasOne<super::collections::Entity>,
/// The library this show belongs to
#[sea_orm(belongs_to, from = "library_id", to = "id")]
pub library: HasOne<super::libraries::Entity>,
/// The info for this show
#[sea_orm(belongs_to, relation_enum = "Info", from = "id", to = "id")]
pub info: HasOne<entity::info::shows::Entity>,
/// The watched info for this show
#[sea_orm(has_many, relation_enum = "Watched", from = "id", to = "id")]
pub watched: HasMany<entity::watched::shows::Entity>,
}
impl ActiveModelBehavior for ActiveModel {}
}
/// Season entity
pub mod seasons {
use flix_model::id::{LibraryId, ShowId};
use flix_model::numbers::SeasonNumber;
use seamantic::model::path::PathBytes;
use sea_orm::entity::prelude::*;
use crate::entity;
/// The database representation of a season media folder
#[sea_orm::model]
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_seasons")]
pub struct Model {
/// The season's show's ID
#[sea_orm(primary_key, auto_increment = false)]
pub show_id: ShowId,
/// The season's number
#[sea_orm(primary_key, auto_increment = false)]
pub season_number: SeasonNumber,
/// The season's slug
#[sea_orm(unique)]
pub slug: String,
/// The season's library
pub library_id: LibraryId,
/// The season's directory
pub directory: PathBytes,
/// The season's poster path
pub relative_poster_path: Option<String>,
/// The library this season belongs to
#[sea_orm(belongs_to, from = "library_id", to = "id")]
pub library: HasOne<super::libraries::Entity>,
/// The info for this season
#[sea_orm(
belongs_to,
relation_enum = "Info",
from = "(show_id, season_number)",
to = "(show_id, season_number)"
)]
pub info: HasOne<entity::info::seasons::Entity>,
/// The watched info for this season
#[sea_orm(
has_many,
relation_enum = "Watched",
from = "(show_id, season_number)",
to = "(show_id, season_number)"
)]
pub watched: HasMany<entity::watched::seasons::Entity>,
}
impl ActiveModelBehavior for ActiveModel {}
}
/// Episode entity
pub mod episodes {
use flix_model::id::{LibraryId, ShowId};
use flix_model::numbers::{EpisodeNumber, SeasonNumber};
use seamantic::model::path::PathBytes;
use sea_orm::entity::prelude::*;
use crate::entity;
/// The database representation of a episode media folder
#[sea_orm::model]
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_episodes")]
pub struct Model {
/// The episode's show's ID
#[sea_orm(primary_key, auto_increment = false)]
pub show_id: ShowId,
/// The episode's season's number
#[sea_orm(primary_key, auto_increment = false)]
pub season_number: SeasonNumber,
/// The episode's number
#[sea_orm(primary_key, auto_increment = false)]
pub episode_number: EpisodeNumber,
/// The number of additional contained episodes
pub count: u8,
/// The episode's slug
#[sea_orm(unique)]
pub slug: String,
/// The episode's library
pub library_id: LibraryId,
/// The episode's directory
pub directory: PathBytes,
/// The episode's media path
pub relative_media_path: String,
/// The episode's poster path
pub relative_poster_path: Option<String>,
/// The library this episode belongs to
#[sea_orm(belongs_to, from = "library_id", to = "id")]
pub library: HasOne<super::libraries::Entity>,
/// The info for this episode
#[sea_orm(
belongs_to,
relation_enum = "Info",
from = "(show_id, season_number, episode_number)",
to = "(show_id, season_number, episode_number)"
)]
pub info: HasOne<entity::info::episodes::Entity>,
/// The watched info for this episode
#[sea_orm(
has_many,
relation_enum = "Watched",
from = "(show_id, season_number, episode_number)",
to = "(show_id, season_number, episode_number)"
)]
pub watched: HasMany<entity::watched::episodes::Entity>,
}
impl ActiveModelBehavior for ActiveModel {}
}
/// Macros for creating content entities
#[cfg(test)]
pub mod test {
macro_rules! make_content_library {
($db:expr, $id:literal) => {
$crate::entity::content::libraries::ActiveModel {
id: Set(::flix_model::id::LibraryId::from_raw($id)),
directory: Set(::std::path::PathBuf::new().into()),
}
.insert($db)
.await
.expect("insert");
};
}
pub(crate) use make_content_library;
macro_rules! make_content_collection {
($db:expr, $lid:literal, $id:literal, $pid:expr) => {
$crate::entity::info::test::make_info_collection!($db, $id);
$crate::entity::content::collections::ActiveModel {
id: Set(::flix_model::id::CollectionId::from_raw($id)),
parent_id: Set($pid.map(::flix_model::id::CollectionId::from_raw)),
slug: Set(concat!("C ", $id).to_string()),
library_id: Set(::flix_model::id::LibraryId::from_raw($lid)),
directory: Set(::std::path::PathBuf::new().into()),
relative_poster_path: Set(::core::option::Option::None),
}
.insert($db)
.await
.expect("insert");
};
}
pub(crate) use make_content_collection;
macro_rules! make_content_movie {
($db:expr, $lid:literal, $id:literal, $pid:expr) => {
$crate::entity::info::test::make_info_movie!($db, $id);
$crate::entity::content::movies::ActiveModel {
id: Set(::flix_model::id::MovieId::from_raw($id)),
parent_id: Set($pid.map(::flix_model::id::CollectionId::from_raw)),
slug: Set(concat!("< ", $id).to_string()),
library_id: Set(::flix_model::id::LibraryId::from_raw($lid)),
directory: Set(::std::path::PathBuf::new().into()),
relative_media_path: Set(::std::string::String::new()),
relative_poster_path: Set(::core::option::Option::None),
}
.insert($db)
.await
.expect("insert");
};
}
pub(crate) use make_content_movie;
macro_rules! make_content_show {
($db:expr, $lid:literal, $id:literal, $pid:expr) => {
$crate::entity::info::test::make_info_show!($db, $id);
$crate::entity::content::shows::ActiveModel {
id: Set(::flix_model::id::ShowId::from_raw($id)),
parent_id: Set($pid.map(::flix_model::id::CollectionId::from_raw)),
slug: Set(concat!("S ", $id).to_string()),
library_id: Set(::flix_model::id::LibraryId::from_raw($lid)),
directory: Set(::std::path::PathBuf::new().into()),
relative_poster_path: Set(::core::option::Option::None),
}
.insert($db)
.await
.expect("insert");
};
}
pub(crate) use make_content_show;
macro_rules! make_content_season {
($db:expr, $lid:literal, $show:literal, $season:literal) => {
$crate::entity::info::test::make_info_season!($db, $show, $season);
$crate::entity::content::seasons::ActiveModel {
show_id: Set(::flix_model::id::ShowId::from_raw($show)),
season_number: Set($season),
slug: Set(concat!("SS ", $show, $season).to_string()),
library_id: Set(::flix_model::id::LibraryId::from_raw($lid)),
directory: Set(::std::path::PathBuf::new().into()),
relative_poster_path: Set(::core::option::Option::None),
}
.insert($db)
.await
.expect("insert");
};
}
pub(crate) use make_content_season;
macro_rules! make_content_episode {
($db:expr, $lid:literal, $show:literal, $season:literal, $episode:literal) => {
make_content_episode!(@make, $db, $lid, $show, $season, $episode, 0);
};
($db:expr, $lid:literal, $show:literal, $season:literal, $episode:literal, >1) => {
make_content_episode!(@make, $db, $lid, $show, $season, $episode, 1);
};
(@make, $db:expr, $lid:literal, $show:literal, $season:literal, $episode:literal, $count:literal) => {
$crate::entity::info::test::make_info_episode!($db, $show, $season, $episode);
$crate::entity::content::episodes::ActiveModel {
show_id: Set(::flix_model::id::ShowId::from_raw($show)),
season_number: Set($season),
episode_number: Set($episode),
count: Set($count),
slug: Set(concat!("SSE ", $show, $season, $episode).to_string()),
library_id: Set(::flix_model::id::LibraryId::from_raw($lid)),
directory: Set(::std::path::PathBuf::new().into()),
relative_media_path: Set(::std::string::String::new()),
relative_poster_path: Set(::core::option::Option::None),
}
.insert($db)
.await
.expect("insert");
};
}
pub(crate) use make_content_episode;
}
#[cfg(test)]
mod tests {
use std::path::Path;
use flix_model::id::{CollectionId, LibraryId, MovieId, ShowId};
use sea_orm::ActiveValue::{NotSet, Set};
use sea_orm::entity::prelude::*;
use sea_orm::sqlx::error::ErrorKind;
use crate::entity::content::test::{
make_content_collection, make_content_episode, make_content_library, make_content_movie,
make_content_season, make_content_show,
};
use crate::entity::info::test::{
make_info_collection, make_info_episode, make_info_movie, make_info_season, make_info_show,
};
use crate::tests::new_initialized_memory_db;
use super::super::tests::get_error_kind;
use super::super::tests::{noneable, notsettable};
#[tokio::test]
async fn use_test_macros() {
let db = new_initialized_memory_db().await;
make_content_library!(&db, 1);
make_content_collection!(&db, 1, 1, None);
make_content_movie!(&db, 1, 1, None);
make_content_show!(&db, 1, 1, None);
make_content_season!(&db, 1, 1, 1);
make_content_episode!(&db, 1, 1, 1, 1);
}
#[tokio::test]
async fn test_round_trip_libraries() {
let db = new_initialized_memory_db().await;
macro_rules! assert_library {
($db:expr, $id:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_library!(@insert, $db, $id $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.id, LibraryId::from_raw($id));
assert_eq!(model.directory, Path::new(concat!("L Directory ", $id)).to_owned().into());
};
($db:expr, $id:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_library!(@insert, $db, $id $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
};
(@insert, $db:expr, $id:literal $(; $($skip:ident),+)?) => {
super::libraries::ActiveModel {
id: notsettable!(id, LibraryId::from_raw($id) $(, $($skip),+)?),
directory: notsettable!(directory, Path::new(concat!("L Directory ", $id)).to_owned().into() $(, $($skip),+)?),
}.insert($db).await
};
}
assert_library!(&db, 1, Success);
assert_library!(&db, 1, UniqueViolation);
assert_library!(&db, 2, Success);
assert_library!(&db, 3, Success; id);
assert_library!(&db, 4, NotNullViolation; directory);
}
#[tokio::test]
async fn test_round_trip_collections() {
let db = new_initialized_memory_db().await;
macro_rules! assert_collection {
($db:expr, $id:literal, $pid:expr, $lid:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_collection!(@insert, $db, $id, $pid, $lid $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.id, CollectionId::from_raw($id));
assert_eq!(model.parent_id, $pid.map(CollectionId::from_raw));
assert_eq!(model.slug, concat!("C Slug ", $id).to_string());
assert_eq!(model.library_id, LibraryId::from_raw($lid));
assert_eq!(model.directory, Path::new(concat!("C Directory ", $id)).to_owned().into());
assert_eq!(model.relative_poster_path, noneable!(relative_poster_path, concat!("C Poster ", $id).to_owned() $(, $($skip),+)?));
};
($db:expr, $id:literal, $pid:expr, $lid:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_collection!(@insert, $db, $id, $pid, $lid $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
};
(@insert, $db:expr, $id:literal, $pid:expr, $lid:literal $(; $($skip:ident),+)?) => {
super::collections::ActiveModel {
id: notsettable!(id, CollectionId::from_raw($id) $(, $($skip),+)?),
parent_id: notsettable!(parent_id, $pid.map(CollectionId::from_raw) $(, $($skip),+)?),
slug: notsettable!(slug, concat!("C Slug ", $id).to_string() $(, $($skip),+)?),
library_id: notsettable!(library_id, LibraryId::from_raw($lid) $(, $($skip),+)?),
directory: notsettable!(directory, Path::new(concat!("C Directory ", $id)).to_owned().into() $(, $($skip),+)?),
relative_poster_path: notsettable!(relative_poster_path, Some(concat!("C Poster ", $id).to_owned()) $(, $($skip),+)?),
}.insert($db).await
};
}
make_content_library!(&db, 1);
assert_collection!(&db, 1, None, 1, ForeignKeyViolation);
make_info_collection!(&db, 1);
assert_collection!(&db, 1, None, 1, Success);
make_info_collection!(&db, 2);
assert_collection!(&db, 2, None, 2, ForeignKeyViolation);
make_content_library!(&db, 2);
assert_collection!(&db, 2, None, 2, Success);
assert_collection!(&db, 1, None, 1, UniqueViolation);
make_info_collection!(&db, 3);
make_info_collection!(&db, 4);
make_info_collection!(&db, 5);
make_info_collection!(&db, 6);
make_info_collection!(&db, 7);
make_info_collection!(&db, 8);
assert_collection!(&db, 3, None, 1, Success; id);
assert_collection!(&db, 4, None, 1, Success; parent_id);
assert_collection!(&db, 5, None, 1, NotNullViolation; slug);
assert_collection!(&db, 6, None, 1, NotNullViolation; library_id);
assert_collection!(&db, 7, None, 1, NotNullViolation; directory);
assert_collection!(&db, 8, None, 1, Success; relative_poster_path);
}
#[tokio::test]
async fn test_round_trip_movies() {
let db = new_initialized_memory_db().await;
macro_rules! assert_movie {
($db:expr, $id:literal, $pid:expr, $lid:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_movie!(@insert, $db, $id, $pid, $lid $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.id, MovieId::from_raw($id));
assert_eq!(model.parent_id, $pid.map(CollectionId::from_raw));
assert_eq!(model.slug, concat!("M Slug ", $id).to_string());
assert_eq!(model.library_id, LibraryId::from_raw($lid));
assert_eq!(model.directory, Path::new(concat!("M Directory ", $id)).to_owned().into());
assert_eq!(model.relative_media_path, concat!("M Media ", $id));
assert_eq!(model.relative_poster_path, noneable!(relative_poster_path, concat!("M Poster ", $id).to_owned() $(, $($skip),+)?));
};
($db:expr, $id:literal, $pid:expr, $lid:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_movie!(@insert, $db, $id, $pid, $lid $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
};
(@insert, $db:expr, $id:literal, $pid:expr, $lid:literal $(; $($skip:ident),+)?) => {
super::movies::ActiveModel {
id: notsettable!(id, MovieId::from_raw($id) $(, $($skip),+)?),
parent_id: notsettable!(parent_id, $pid.map(CollectionId::from_raw) $(, $($skip),+)?),
slug: notsettable!(slug, concat!("M Slug ", $id).to_string() $(, $($skip),+)?),
library_id: notsettable!(library_id, LibraryId::from_raw($lid) $(, $($skip),+)?),
directory: notsettable!(directory, Path::new(concat!("M Directory ", $id)).to_owned().into() $(, $($skip),+)?),
relative_media_path: notsettable!(relative_media_path, concat!("M Media ", $id).to_owned() $(, $($skip),+)?),
relative_poster_path: notsettable!(relative_poster_path, Some(concat!("M Poster ", $id).to_owned()) $(, $($skip),+)?),
}.insert($db).await
};
}
make_content_library!(&db, 1);
assert_movie!(&db, 1, None, 1, ForeignKeyViolation);
make_info_movie!(&db, 1);
assert_movie!(&db, 1, Some(1), 1, ForeignKeyViolation);
make_content_collection!(&db, 1, 1, None);
assert_movie!(&db, 1, Some(1), 1, Success);
assert_movie!(&db, 2, None, 2, ForeignKeyViolation);
make_info_movie!(&db, 2);
assert_movie!(&db, 2, None, 2, ForeignKeyViolation);
make_content_library!(&db, 2);
assert_movie!(&db, 2, None, 2, Success);
assert_movie!(&db, 1, None, 1, UniqueViolation);
make_info_movie!(&db, 3);
make_info_movie!(&db, 4);
make_info_movie!(&db, 5);
make_info_movie!(&db, 6);
make_info_movie!(&db, 7);
make_info_movie!(&db, 8);
make_info_movie!(&db, 9);
assert_movie!(&db, 3, None, 1, Success; id);
assert_movie!(&db, 4, None, 1, Success; parent_id);
assert_movie!(&db, 5, None, 1, NotNullViolation; slug);
assert_movie!(&db, 6, None, 1, NotNullViolation; library_id);
assert_movie!(&db, 7, None, 1, NotNullViolation; directory);
assert_movie!(&db, 8, None, 1, NotNullViolation; relative_media_path);
assert_movie!(&db, 9, None, 1, Success; relative_poster_path);
}
#[tokio::test]
async fn test_round_trip_shows() {
let db = new_initialized_memory_db().await;
macro_rules! assert_show {
($db:expr, $id:literal, $pid:expr, $lid:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_show!(@insert, $db, $id, $pid, $lid $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.id, ShowId::from_raw($id));
assert_eq!(model.parent_id, $pid.map(CollectionId::from_raw));
assert_eq!(model.slug, concat!("S Slug ", $id).to_string());
assert_eq!(model.library_id, LibraryId::from_raw($lid));
assert_eq!(model.directory, Path::new(concat!("S Directory ", $id)).to_owned().into());
assert_eq!(model.relative_poster_path, noneable!(relative_poster_path, concat!("S Poster ", $id).to_owned() $(, $($skip),+)?));
};
($db:expr, $id:literal, $pid:expr, $lid:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_show!(@insert, $db, $id, $pid, $lid $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
};
(@insert, $db:expr, $id:literal, $pid:expr, $lid:literal $(; $($skip:ident),+)?) => {
super::shows::ActiveModel {
id: notsettable!(id, ShowId::from_raw($id) $(, $($skip),+)?),
parent_id: notsettable!(parent_id, $pid.map(CollectionId::from_raw) $(, $($skip),+)?),
slug: notsettable!(slug, concat!("S Slug ", $id).to_string() $(, $($skip),+)?),
library_id: notsettable!(library_id, LibraryId::from_raw($lid) $(, $($skip),+)?),
directory: notsettable!(directory, Path::new(concat!("S Directory ", $id)).to_owned().into() $(, $($skip),+)?),
relative_poster_path: notsettable!(relative_poster_path, Some(concat!("S Poster ", $id).to_owned()) $(, $($skip),+)?),
}.insert($db).await
};
}
make_content_library!(&db, 1);
assert_show!(&db, 1, None, 1, ForeignKeyViolation);
make_info_show!(&db, 1);
assert_show!(&db, 1, Some(1), 1, ForeignKeyViolation);
make_content_collection!(&db, 1, 1, None);
assert_show!(&db, 1, Some(1), 1, Success);
assert_show!(&db, 2, None, 2, ForeignKeyViolation);
make_info_show!(&db, 2);
assert_show!(&db, 2, None, 2, ForeignKeyViolation);
make_content_library!(&db, 2);
assert_show!(&db, 2, None, 2, Success);
assert_show!(&db, 1, None, 1, UniqueViolation);
make_info_show!(&db, 3);
make_info_show!(&db, 4);
make_info_show!(&db, 5);
make_info_show!(&db, 6);
make_info_show!(&db, 7);
make_info_show!(&db, 8);
assert_show!(&db, 3, None, 1, Success; id);
assert_show!(&db, 4, None, 1, Success; parent_id);
assert_show!(&db, 5, None, 1, NotNullViolation; slug);
assert_show!(&db, 6, None, 1, NotNullViolation; library_id);
assert_show!(&db, 7, None, 1, NotNullViolation; directory);
assert_show!(&db, 8, None, 1, Success; relative_poster_path);
}
#[tokio::test]
async fn test_round_trip_seasons() {
let db = new_initialized_memory_db().await;
macro_rules! assert_season {
($db:expr, $id:literal, $season:literal, $lid:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_season!(@insert, $db, $id, $season, $lid $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.show_id, ShowId::from_raw($id));
assert_eq!(model.season_number, $season);
assert_eq!(model.slug, concat!("SS Slug ", $id, ",", $season).to_string());
assert_eq!(model.library_id, LibraryId::from_raw($lid));
assert_eq!(model.directory, Path::new(concat!("SS Directory ", $id, ",", $season)).to_owned().into());
assert_eq!(model.relative_poster_path, noneable!(relative_poster_path, concat!("SS Poster ", $id, ",", $season).to_owned() $(, $($skip),+)?));
};
($db:expr, $id:literal, $season:literal, $lid:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_season!(@insert, $db, $id, $season, $lid $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
};
(@insert, $db:expr, $id:literal, $season:literal, $lid:literal $(; $($skip:ident),+)?) => {
super::seasons::ActiveModel {
show_id: notsettable!(show_id, ShowId::from_raw($id) $(, $($skip),+)?),
season_number: notsettable!(season_number, $season $(, $($skip),+)?),
slug: notsettable!(slug, concat!("SS Slug ", $id, ",", $season).to_string() $(, $($skip),+)?),
library_id: notsettable!(library_id, LibraryId::from_raw($lid) $(, $($skip),+)?),
directory: notsettable!(directory, Path::new(concat!("SS Directory ", $id, ",", $season)).to_owned().into() $(, $($skip),+)?),
relative_poster_path: notsettable!(relative_poster_path, Some(concat!("SS Poster ", $id, ",", $season).to_owned()) $(, $($skip),+)?),
}.insert($db).await
};
}
make_content_library!(&db, 1);
make_info_show!(&db, 1);
assert_season!(&db, 1, 1, 1, ForeignKeyViolation);
make_info_season!(&db, 1, 1);
assert_season!(&db, 1, 1, 1, Success);
assert_season!(&db, 1, 1, 1, UniqueViolation);
make_info_season!(&db, 1, 3);
make_info_season!(&db, 1, 4);
make_info_season!(&db, 1, 5);
make_info_season!(&db, 1, 6);
make_info_season!(&db, 1, 7);
make_info_season!(&db, 1, 8);
assert_season!(&db, 1, 3, 1, NotNullViolation; show_id);
assert_season!(&db, 1, 4, 1, NotNullViolation; season_number);
assert_season!(&db, 1, 5, 1, NotNullViolation; slug);
assert_season!(&db, 1, 6, 1, NotNullViolation; library_id);
assert_season!(&db, 1, 7, 1, NotNullViolation; directory);
assert_season!(&db, 1, 8, 1, Success; relative_poster_path);
}
#[tokio::test]
async fn test_round_trip_episodes() {
let db = new_initialized_memory_db().await;
macro_rules! assert_episode {
($db:expr, $id:literal, $season:literal, $episode:literal, $lid:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_episode!(@insert, $db, $id, $season, $episode, $lid $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.show_id, ShowId::from_raw($id));
assert_eq!(model.season_number, $season);
assert_eq!(model.episode_number, $episode);
assert_eq!(model.slug, concat!("SS Slug ", $id, ",", $season, $episode).to_string());
assert_eq!(model.library_id, LibraryId::from_raw($lid));
assert_eq!(model.directory, Path::new(concat!("SS Directory ", $id, ",", $season, $episode)).to_owned().into());
assert_eq!(model.relative_media_path, concat!("SS Media ", $id, ",", $season, $episode));
assert_eq!(model.relative_poster_path, noneable!(relative_poster_path, concat!("SS Poster ", $id, ",", $season, $episode).to_owned() $(, $($skip),+)?));
};
($db:expr, $id:literal, $season:literal, $episode:literal, $lid:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_episode!(@insert, $db, $id, $season, $episode, $lid $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
};
(@insert, $db:expr, $id:literal, $season:literal, $episode:literal, $lid:literal $(; $($skip:ident),+)?) => {
super::episodes::ActiveModel {
show_id: notsettable!(show_id, ShowId::from_raw($id) $(, $($skip),+)?),
season_number: notsettable!(season_number, $season $(, $($skip),+)?),
episode_number: notsettable!(episode_number, $episode $(, $($skip),+)?),
count: notsettable!(count, 0 $(, $($skip),+)?),
slug: notsettable!(slug, concat!("SS Slug ", $id, ",", $season, $episode).to_string() $(, $($skip),+)?),
library_id: notsettable!(library_id, LibraryId::from_raw($lid) $(, $($skip),+)?),
directory: notsettable!(directory, Path::new(concat!("SS Directory ", $id, ",", $season, $episode)).to_owned().into() $(, $($skip),+)?),
relative_media_path: notsettable!(relative_media_path, concat!("SS Media ", $id, ",", $season, $episode).to_owned() $(, $($skip),+)?),
relative_poster_path: notsettable!(relative_poster_path, Some(concat!("SS Poster ", $id, ",", $season, $episode).to_owned()) $(, $($skip),+)?),
}.insert($db).await
};
}
make_content_library!(&db, 1);
make_info_show!(&db, 1);
make_info_season!(&db, 1, 1);
assert_episode!(&db, 1, 1, 1, 1, ForeignKeyViolation);
make_info_episode!(&db, 1, 1, 1);
assert_episode!(&db, 1, 1, 1, 1, Success);
assert_episode!(&db, 1, 1, 1, 1, UniqueViolation);
make_info_episode!(&db, 1, 1, 3);
make_info_episode!(&db, 1, 1, 4);
make_info_episode!(&db, 1, 1, 5);
make_info_episode!(&db, 1, 1, 6);
make_info_episode!(&db, 1, 1, 7);
make_info_episode!(&db, 1, 1, 8);
make_info_episode!(&db, 1, 1, 9);
make_info_episode!(&db, 1, 1, 10);
assert_episode!(&db, 1, 1, 3, 1, NotNullViolation; show_id);
assert_episode!(&db, 1, 1, 4, 1, NotNullViolation; season_number);
assert_episode!(&db, 1, 1, 5, 1, NotNullViolation; episode_number);
assert_episode!(&db, 1, 1, 6, 1, NotNullViolation; slug);
assert_episode!(&db, 1, 1, 7, 1, NotNullViolation; library_id);
assert_episode!(&db, 1, 1, 8, 1, NotNullViolation; directory);
assert_episode!(&db, 1, 1, 9, 1, NotNullViolation; relative_media_path);
assert_episode!(&db, 1, 1, 10, 1, Success; relative_poster_path);
}
}
@@ -1,96 +0,0 @@
//! Collection entity
use flix_model::id::{CollectionId, LibraryId};
use seamantic::model::path::PathBytes;
use sea_orm::{
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
};
/// The database representation of a collection media folder
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_collections")]
pub struct Model {
/// The collection's ID
#[sea_orm(primary_key, auto_increment = false)]
pub id: CollectionId,
/// The collection's parent
pub parent: Option<CollectionId>,
/// The collection's slug
pub slug: String,
/// The collection's library ID
pub library: LibraryId,
/// The collection's directory
pub directory: PathBytes,
/// The collection's poster path
pub relative_poster_path: Option<String>,
}
impl ActiveModelBehavior for ActiveModel {}
/// Relation
#[derive(Debug, EnumIter, DeriveRelation)]
pub enum Relation {
/// The parent collection of this collection
#[sea_orm(
belongs_to = "super::collections::Entity",
from = "Column::Parent",
to = "super::collections::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
Parent,
/// The library this collection belongs to
#[sea_orm(
belongs_to = "super::libraries::Entity",
from = "Column::Library",
to = "super::libraries::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
Library,
/// The media info for this collection
#[sea_orm(
belongs_to = "super::super::info::collections::Entity",
from = "Column::Id",
to = "super::super::info::collections::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
MediaInfo,
/// The watched info for this collection
#[sea_orm(
belongs_to = "super::super::watched::collections::Entity",
from = "Column::Id",
to = "super::super::watched::collections::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
WatchInfo,
}
impl Related<super::collections::Entity> for Entity {
fn to() -> RelationDef {
Relation::Parent.def()
}
}
impl Related<super::libraries::Entity> for Entity {
fn to() -> RelationDef {
Relation::Library.def()
}
}
impl Related<super::super::info::collections::Entity> for Entity {
fn to() -> RelationDef {
Relation::MediaInfo.def()
}
}
impl Related<super::super::watched::collections::Entity> for Entity {
fn to() -> RelationDef {
Relation::WatchInfo.def()
}
}
-90
View File
@@ -1,90 +0,0 @@
//! Episode entity
use flix_model::id::{LibraryId, ShowId};
use seamantic::model::path::PathBytes;
use flix_model::numbers::{EpisodeNumber, SeasonNumber};
use sea_orm::{
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
};
/// The database representation of a episode media folder
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_episodes")]
pub struct Model {
/// The episode's show's ID
#[sea_orm(primary_key, auto_increment = false)]
pub show: ShowId,
/// The episode's season's number
#[sea_orm(primary_key, auto_increment = false)]
pub season: SeasonNumber,
/// The episode's number
#[sea_orm(primary_key, auto_increment = false)]
pub episode: EpisodeNumber,
/// The number of additional contained episodes
pub count: u8,
/// The episode's slug
pub slug: String,
/// The episode's library
pub library: LibraryId,
/// The episode's directory
pub directory: PathBytes,
/// The episode's media path
pub relative_media_path: String,
/// The episode's poster path
pub relative_poster_path: Option<String>,
}
impl ActiveModelBehavior for ActiveModel {}
/// Relation
#[derive(Debug, EnumIter, DeriveRelation)]
pub enum Relation {
/// The library this episode belongs to
#[sea_orm(
belongs_to = "super::libraries::Entity",
from = "Column::Library",
to = "super::libraries::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
Library,
/// The media info for this episode
#[sea_orm(
belongs_to = "super::super::info::episodes::Entity",
from = "(Column::Show, Column::Season, Column::Episode)",
to = "(super::super::info::episodes::Column::Show, super::super::info::episodes::Column::Season, super::super::info::episodes::Column::Episode)",
on_update = "Cascade",
on_delete = "Cascade"
)]
MediaInfo,
/// The watched info for this episode
#[sea_orm(
belongs_to = "super::super::watched::episodes::Entity",
from = "(Column::Show, Column::Season, Column::Episode)",
to = "(super::super::watched::episodes::Column::Show, super::super::watched::episodes::Column::Season, super::super::watched::episodes::Column::Episode)",
on_update = "Cascade",
on_delete = "Cascade"
)]
WatchInfo,
}
impl Related<super::libraries::Entity> for Entity {
fn to() -> RelationDef {
Relation::Library.def()
}
}
impl Related<super::super::info::episodes::Entity> for Entity {
fn to() -> RelationDef {
Relation::MediaInfo.def()
}
}
impl Related<super::super::watched::episodes::Entity> for Entity {
fn to() -> RelationDef {
Relation::WatchInfo.def()
}
}
-73
View File
@@ -1,73 +0,0 @@
//! Library entity
use flix_model::id::LibraryId;
use seamantic::model::path::PathBytes;
use sea_orm::{
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
};
/// The database representation of a library media folder
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_libraries")]
pub struct Model {
/// The library's ID
#[sea_orm(primary_key, auto_increment = false)]
pub id: LibraryId,
/// The library's directory
pub directory: PathBytes,
}
impl ActiveModelBehavior for ActiveModel {}
/// Relation
#[derive(Debug, EnumIter, DeriveRelation)]
pub enum Relation {
/// All collections in this library
#[sea_orm(has_many = "super::collections::Entity")]
Collections,
#[sea_orm(has_many = "super::movies::Entity")]
/// All movies in this library
Movies,
#[sea_orm(has_many = "super::shows::Entity")]
/// All shows in this library
Shows,
#[sea_orm(has_many = "super::seasons::Entity")]
/// All seasons in this library
Seasons,
#[sea_orm(has_many = "super::episodes::Entity")]
/// All episodes in this library
Episodes,
}
impl Related<super::collections::Entity> for Entity {
fn to() -> RelationDef {
Relation::Collections.def()
}
}
impl Related<super::movies::Entity> for Entity {
fn to() -> RelationDef {
Relation::Movies.def()
}
}
impl Related<super::shows::Entity> for Entity {
fn to() -> RelationDef {
Relation::Shows.def()
}
}
impl Related<super::seasons::Entity> for Entity {
fn to() -> RelationDef {
Relation::Seasons.def()
}
}
impl Related<super::episodes::Entity> for Entity {
fn to() -> RelationDef {
Relation::Episodes.def()
}
}
-342
View File
@@ -1,342 +0,0 @@
//! This module contains entities for storing media file information
pub mod libraries;
pub mod collections;
pub mod movies;
pub mod episodes;
pub mod seasons;
pub mod shows;
#[cfg(test)]
mod tests {
use std::path::Path;
use flix_model::id::{CollectionId, LibraryId, MovieId, ShowId};
use sea_orm::ActiveModelTrait;
use sea_orm::ActiveValue::{NotSet, Set};
use sea_orm::sqlx::error::ErrorKind;
use sea_orm_migration::MigratorTrait;
use crate::migration::Migrator;
use crate::tests::new_memory_db;
use super::super::tests::get_error_kind;
use super::super::tests::{
make_flix_collection, make_flix_episode, make_flix_movie, make_flix_season, make_flix_show,
};
use super::super::tests::{noneable, notsettable};
#[tokio::test]
async fn test_inserts() {
let db = new_memory_db().await;
Migrator::up(&db, None).await.expect("up");
// Libraries
macro_rules! assert_library {
($db:expr, $id:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_library!(@insert, $db, $id $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.id, LibraryId::from_raw($id));
assert_eq!(model.directory, Path::new(concat!("/L/", $id)).to_owned().into());
};
($db:expr, $id:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_library!(@insert, $db, $id $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
};
(@insert, $db:expr, $id:literal $(; $($skip:ident),+)?) => {
super::libraries::ActiveModel {
id: notsettable!(id, LibraryId::from_raw($id) $(, $($skip),+)?),
directory: notsettable!(directory, Path::new(concat!("/L/", $id)).to_owned().into() $(, $($skip),+)?),
}.insert($db).await
};
}
assert_library!(&db, 1, Success);
assert_library!(&db, 1, UniqueViolation);
assert_library!(&db, 2, Success);
assert_library!(&db, 3, Success; id);
assert_library!(&db, 4, NotNullViolation; directory);
// Collections
macro_rules! assert_collection {
($db:expr, $id:literal, $pid:expr, $lid:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_collection!(@insert, $db, $id, $pid, $lid $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.id, CollectionId::from_raw($id));
assert_eq!(model.parent, $pid);
assert_eq!(model.slug, concat!("C/", $id).to_string());
assert_eq!(model.library, LibraryId::from_raw($lid));
assert_eq!(model.directory, Path::new(concat!("/C/", $id)).to_owned().into());
assert_eq!(model.relative_poster_path, noneable!(relative_poster_path, concat!("C/Poster", $id).to_owned() $(, $($skip),+)?));
};
($db:expr, $id:literal, $pid:expr, $lid:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_collection!(@insert, $db, $id, $pid, $lid $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
};
(@insert, $db:expr, $id:literal, $pid:expr, $lid:literal $(; $($skip:ident),+)?) => {
super::collections::ActiveModel {
id: notsettable!(id, CollectionId::from_raw($id) $(, $($skip),+)?),
parent: notsettable!(parent, $pid $(, $($skip),+)?),
slug: notsettable!(slug, concat!("C/", $id).to_string() $(, $($skip),+)?),
library: notsettable!(library, LibraryId::from_raw($lid) $(, $($skip),+)?),
directory: notsettable!(directory, Path::new(concat!("/C/", $id)).to_owned().into() $(, $($skip),+)?),
relative_poster_path: notsettable!(relative_poster_path, Some(concat!("C/Poster", $id).to_owned()) $(, $($skip),+)?),
}.insert($db).await
};
}
assert_collection!(&db, 1, None, 0, ForeignKeyViolation);
assert_collection!(
&db,
1,
Some(CollectionId::from_raw(0)),
1,
ForeignKeyViolation
);
assert_collection!(&db, 1, None, 1, ForeignKeyViolation);
make_flix_collection!(&db, 1);
make_flix_collection!(&db, 2);
make_flix_collection!(&db, 3);
make_flix_collection!(&db, 4);
make_flix_collection!(&db, 8);
assert_collection!(&db, 1, None, 1, Success);
assert_collection!(&db, 1, None, 1, UniqueViolation);
assert_collection!(&db, 2, None, 1, Success);
assert_collection!(&db, 3, None, 1, Success; id);
assert_collection!(&db, 4, None, 1, Success; parent);
assert_collection!(&db, 5, None, 1, NotNullViolation; slug);
assert_collection!(&db, 6, None, 1, NotNullViolation; library);
assert_collection!(&db, 7, None, 1, NotNullViolation; directory);
assert_collection!(&db, 8, None, 1, Success; relative_poster_path);
// Movies
macro_rules! assert_movie {
($db:expr, $id:literal, $pid:expr, $lid:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_movie!(@insert, $db, $id, $pid, $lid $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.id, MovieId::from_raw($id));
assert_eq!(model.parent, $pid);
assert_eq!(model.slug, concat!("M/", $id).to_string());
assert_eq!(model.library, LibraryId::from_raw($lid));
assert_eq!(model.directory, Path::new(concat!("/M/", $id)).to_owned().into());
assert_eq!(model.relative_media_path, concat!("M/Media", $id));
assert_eq!(model.relative_poster_path, noneable!(relative_poster_path, concat!("M/Poster", $id).to_owned() $(, $($skip),+)?));
};
($db:expr, $id:literal, $pid:expr, $lid:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_movie!(@insert, $db, $id, $pid, $lid $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
};
(@insert, $db:expr, $id:literal, $pid:expr, $lid:literal $(; $($skip:ident),+)?) => {
super::movies::ActiveModel {
id: notsettable!(id, MovieId::from_raw($id) $(, $($skip),+)?),
parent: notsettable!(parent, $pid $(, $($skip),+)?),
slug: notsettable!(slug, concat!("M/", $id).to_string() $(, $($skip),+)?),
library: notsettable!(library, LibraryId::from_raw($lid) $(, $($skip),+)?),
directory: notsettable!(directory, Path::new(concat!("/M/", $id)).to_owned().into() $(, $($skip),+)?),
relative_media_path: notsettable!(relative_media_path, concat!("M/Media", $id).to_owned() $(, $($skip),+)?),
relative_poster_path: notsettable!(relative_poster_path, Some(concat!("M/Poster", $id).to_owned()) $(, $($skip),+)?),
}.insert($db).await
};
}
assert_movie!(&db, 1, None, 0, ForeignKeyViolation);
assert_movie!(
&db,
1,
Some(CollectionId::from_raw(0)),
1,
ForeignKeyViolation
);
assert_movie!(&db, 1, None, 1, ForeignKeyViolation);
make_flix_movie!(&db, 1);
make_flix_movie!(&db, 2);
make_flix_movie!(&db, 3);
make_flix_movie!(&db, 4);
make_flix_movie!(&db, 9);
assert_movie!(&db, 1, None, 1, Success);
assert_movie!(&db, 1, None, 1, UniqueViolation);
assert_movie!(&db, 2, None, 1, Success);
assert_movie!(&db, 3, None, 1, Success; id);
assert_movie!(&db, 4, None, 1, Success; parent);
assert_movie!(&db, 5, None, 1, NotNullViolation; slug);
assert_movie!(&db, 6, None, 1, NotNullViolation; library);
assert_movie!(&db, 7, None, 1, NotNullViolation; directory);
assert_movie!(&db, 8, None, 1, NotNullViolation; relative_media_path);
assert_movie!(&db, 9, None, 1, Success; relative_poster_path);
// Shows
macro_rules! assert_show {
($db:expr, $id:literal, $pid:expr, $lid:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_show!(@insert, $db, $id, $pid, $lid $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.id, ShowId::from_raw($id));
assert_eq!(model.parent, $pid);
assert_eq!(model.slug, concat!("S/", $id).to_string());
assert_eq!(model.library, LibraryId::from_raw($lid));
assert_eq!(model.directory, Path::new(concat!("/S/", $id)).to_owned().into());
assert_eq!(model.relative_poster_path, noneable!(relative_poster_path, concat!("S/Poster", $id).to_owned() $(, $($skip),+)?));
};
($db:expr, $id:literal, $pid:expr, $lid:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_show!(@insert, $db, $id, $pid, $lid $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
};
(@insert, $db:expr, $id:literal, $pid:expr, $lid:literal $(; $($skip:ident),+)?) => {
super::shows::ActiveModel {
id: notsettable!(id, ShowId::from_raw($id) $(, $($skip),+)?),
parent: notsettable!(parent, $pid $(, $($skip),+)?),
slug: notsettable!(slug, concat!("S/", $id).to_string() $(, $($skip),+)?),
library: notsettable!(library, LibraryId::from_raw($lid) $(, $($skip),+)?),
directory: notsettable!(directory, Path::new(concat!("/S/", $id)).to_owned().into() $(, $($skip),+)?),
relative_poster_path: notsettable!(relative_poster_path, Some(concat!("S/Poster", $id).to_owned()) $(, $($skip),+)?),
}.insert($db).await
};
}
assert_show!(&db, 1, None, 0, ForeignKeyViolation);
assert_show!(
&db,
1,
Some(CollectionId::from_raw(0)),
1,
ForeignKeyViolation
);
assert_show!(&db, 1, None, 1, ForeignKeyViolation);
make_flix_show!(&db, 1);
make_flix_show!(&db, 2);
make_flix_show!(&db, 3);
make_flix_show!(&db, 4);
make_flix_show!(&db, 8);
assert_show!(&db, 1, None, 1, Success);
assert_show!(&db, 1, None, 1, UniqueViolation);
assert_show!(&db, 2, None, 1, Success);
assert_show!(&db, 3, None, 1, Success; id);
assert_show!(&db, 4, None, 1, Success; parent);
assert_show!(&db, 5, None, 1, NotNullViolation; slug);
assert_show!(&db, 6, None, 1, NotNullViolation; library);
assert_show!(&db, 7, None, 1, NotNullViolation; directory);
assert_show!(&db, 8, None, 1, Success; relative_poster_path);
// Seasons
macro_rules! assert_season {
($db:expr, $id:literal, $season:literal, $lid:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_season!(@insert, $db, $id, $season, $lid $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.show, ShowId::from_raw($id));
assert_eq!(model.season, $season);
assert_eq!(model.slug, concat!("S/S", $id).to_string());
assert_eq!(model.library, LibraryId::from_raw($lid));
assert_eq!(model.directory, Path::new(concat!("/S/S", $id)).to_owned().into());
assert_eq!(model.relative_poster_path, noneable!(relative_poster_path, concat!("S/S/Poster", $id).to_owned() $(, $($skip),+)?));
};
($db:expr, $id:literal, $season:literal, $lid:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_season!(@insert, $db, $id, $season, $lid $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
};
(@insert, $db:expr, $id:literal, $season:literal, $lid:literal $(; $($skip:ident),+)?) => {
super::seasons::ActiveModel {
show: notsettable!(id, ShowId::from_raw($id) $(, $($skip),+)?),
season: notsettable!(season, $season $(, $($skip),+)?),
slug: notsettable!(slug, concat!("S/S", $id).to_string() $(, $($skip),+)?),
library: notsettable!(library, LibraryId::from_raw($lid) $(, $($skip),+)?),
directory: notsettable!(directory, Path::new(concat!("/S/S", $id)).to_owned().into() $(, $($skip),+)?),
relative_poster_path: notsettable!(relative_poster_path, Some(concat!("S/S/Poster", $id).to_owned()) $(, $($skip),+)?),
}.insert($db).await
};
}
assert_season!(&db, 1, 1, 0, ForeignKeyViolation);
assert_season!(&db, 1, 1, 1, ForeignKeyViolation);
make_flix_season!(&db, 1, 1);
make_flix_season!(&db, 1, 2);
make_flix_season!(&db, 2, 1);
make_flix_season!(&db, 3, 1);
make_flix_season!(&db, 8, 1);
assert_season!(&db, 1, 1, 1, Success);
assert_season!(&db, 1, 2, 1, Success);
assert_season!(&db, 1, 1, 1, UniqueViolation);
assert_season!(&db, 2, 1, 1, Success);
assert_season!(&db, 3, 1, 1, Success; show);
assert_season!(&db, 4, 1, 1, NotNullViolation; season);
assert_season!(&db, 5, 1, 1, NotNullViolation; slug);
assert_season!(&db, 6, 1, 1, NotNullViolation; library);
assert_season!(&db, 7, 1, 1, NotNullViolation; directory);
assert_season!(&db, 8, 1, 1, Success; relative_poster_path);
// Episodes
macro_rules! assert_episode {
($db:expr, $id:literal, $season:literal, $episode:literal, $lid:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_episode!(@insert, $db, $id, $season, $episode, $lid $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.show, ShowId::from_raw($id));
assert_eq!(model.season, $season);
assert_eq!(model.episode, $episode);
assert_eq!(model.slug, concat!("S/S/E", $id).to_string());
assert_eq!(model.library, LibraryId::from_raw($lid));
assert_eq!(model.directory, Path::new(concat!("/S/S/E", $id)).to_owned().into());
assert_eq!(model.relative_media_path, concat!("E/Media", $id));
assert_eq!(model.relative_poster_path, noneable!(relative_poster_path, concat!("S/S/E/Poster", $id).to_owned() $(, $($skip),+)?));
};
($db:expr, $id:literal, $season:literal, $episode:literal, $lid:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_episode!(@insert, $db, $id, $season, $episode, $lid $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
};
(@insert, $db:expr, $id:literal, $season:literal, $episode:literal, $lid:literal $(; $($skip:ident),+)?) => {
super::episodes::ActiveModel {
show: notsettable!(id, ShowId::from_raw($id) $(, $($skip),+)?),
season: notsettable!(season, $season $(, $($skip),+)?),
episode: notsettable!(episode, $episode $(, $($skip),+)?),
count: notsettable!(count, 0 $(, $($skip),+)?),
slug: notsettable!(slug, concat!("S/S/E", $id).to_string() $(, $($skip),+)?),
library: notsettable!(library, LibraryId::from_raw($lid) $(, $($skip),+)?),
directory: notsettable!(directory, Path::new(concat!("/S/S/E", $id)).to_owned().into() $(, $($skip),+)?),
relative_media_path: notsettable!(relative_media_path, concat!("E/Media", $id).to_owned() $(, $($skip),+)?),
relative_poster_path: notsettable!(relative_poster_path, Some(concat!("S/S/E/Poster", $id).to_owned()) $(, $($skip),+)?),
}.insert($db).await
};
}
assert_episode!(&db, 1, 1, 1, 0, ForeignKeyViolation);
assert_episode!(&db, 1, 1, 1, 1, ForeignKeyViolation);
make_flix_episode!(&db, 1, 1, 1);
make_flix_episode!(&db, 1, 1, 2);
make_flix_episode!(&db, 2, 1, 1);
make_flix_episode!(&db, 3, 1, 1);
make_flix_show!(&db, 11);
make_flix_season!(&db, 11, 1);
make_flix_episode!(&db, 11, 1, 1);
assert_episode!(&db, 1, 1, 1, 1, Success);
assert_episode!(&db, 1, 1, 2, 1, Success);
assert_episode!(&db, 1, 1, 1, 1, UniqueViolation);
assert_episode!(&db, 2, 1, 1, 1, Success);
assert_episode!(&db, 3, 1, 1, 1, Success; show);
assert_episode!(&db, 4, 1, 1, 1, NotNullViolation; season);
assert_episode!(&db, 5, 1, 1, 1, NotNullViolation; episode);
assert_episode!(&db, 6, 1, 1, 1, NotNullViolation; count);
assert_episode!(&db, 7, 1, 1, 1, NotNullViolation; slug);
assert_episode!(&db, 8, 1, 1, 1, NotNullViolation; library);
assert_episode!(&db, 9, 1, 1, 1, NotNullViolation; directory);
assert_episode!(&db, 10, 1, 1, 1, NotNullViolation; relative_media_path);
assert_episode!(&db, 11, 1, 1, 1, Success; relative_poster_path);
}
}
-98
View File
@@ -1,98 +0,0 @@
//! Movie entity
use flix_model::id::{CollectionId, LibraryId, MovieId};
use seamantic::model::path::PathBytes;
use sea_orm::{
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
};
/// The database representation of a movie media folder
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_movies")]
pub struct Model {
/// The movie's ID
#[sea_orm(primary_key, auto_increment = false)]
pub id: MovieId,
/// The movie's parent
pub parent: Option<CollectionId>,
/// The movie's slug
pub slug: String,
/// The movie's library
pub library: LibraryId,
/// The movie's directory
pub directory: PathBytes,
/// The movie's media path
pub relative_media_path: String,
/// The movie's poster path
pub relative_poster_path: Option<String>,
}
impl ActiveModelBehavior for ActiveModel {}
/// Relation
#[derive(Debug, EnumIter, DeriveRelation)]
pub enum Relation {
/// The parent collection of this collection
#[sea_orm(
belongs_to = "super::collections::Entity",
from = "Column::Parent",
to = "super::collections::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
Parent,
/// The library this movie belongs to
#[sea_orm(
belongs_to = "super::libraries::Entity",
from = "Column::Library",
to = "super::libraries::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
Library,
/// The media info for this movie
#[sea_orm(
belongs_to = "super::super::info::movies::Entity",
from = "Column::Id",
to = "super::super::info::movies::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
MediaInfo,
/// The watched info for this movie
#[sea_orm(
belongs_to = "super::super::watched::movies::Entity",
from = "Column::Id",
to = "super::super::watched::movies::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
WatchInfo,
}
impl Related<super::collections::Entity> for Entity {
fn to() -> RelationDef {
Relation::Parent.def()
}
}
impl Related<super::libraries::Entity> for Entity {
fn to() -> RelationDef {
Relation::Library.def()
}
}
impl Related<super::super::info::movies::Entity> for Entity {
fn to() -> RelationDef {
Relation::MediaInfo.def()
}
}
impl Related<super::super::watched::movies::Entity> for Entity {
fn to() -> RelationDef {
Relation::WatchInfo.def()
}
}
-83
View File
@@ -1,83 +0,0 @@
//! Season entity
use flix_model::id::{LibraryId, ShowId};
use seamantic::model::path::PathBytes;
use flix_model::numbers::SeasonNumber;
use sea_orm::{
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
};
/// The database representation of a season media folder
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_seasons")]
pub struct Model {
/// The season's show's ID
#[sea_orm(primary_key, auto_increment = false)]
pub show: ShowId,
/// The season's number
#[sea_orm(primary_key, auto_increment = false)]
pub season: SeasonNumber,
/// The season's slug
pub slug: String,
/// The season's library
pub library: LibraryId,
/// The season's directory
pub directory: PathBytes,
/// The season's poster path
pub relative_poster_path: Option<String>,
}
impl ActiveModelBehavior for ActiveModel {}
/// Relation
#[derive(Debug, EnumIter, DeriveRelation)]
pub enum Relation {
/// The library this season belongs to
#[sea_orm(
belongs_to = "super::libraries::Entity",
from = "Column::Library",
to = "super::libraries::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
Library,
/// The media info for this show
#[sea_orm(
belongs_to = "super::super::info::seasons::Entity",
from = "(Column::Show, Column::Season)",
to = "(super::super::info::seasons::Column::Show, super::super::info::seasons::Column::Season)",
on_update = "Cascade",
on_delete = "Cascade"
)]
MediaInfo,
/// The watched info for this show
#[sea_orm(
belongs_to = "super::super::watched::seasons::Entity",
from = "(Column::Show, Column::Season)",
to = "(super::super::watched::seasons::Column::Show, super::super::watched::seasons::Column::Season)",
on_update = "Cascade",
on_delete = "Cascade"
)]
WatchInfo,
}
impl Related<super::libraries::Entity> for Entity {
fn to() -> RelationDef {
Relation::Library.def()
}
}
impl Related<super::super::info::seasons::Entity> for Entity {
fn to() -> RelationDef {
Relation::MediaInfo.def()
}
}
impl Related<super::super::watched::seasons::Entity> for Entity {
fn to() -> RelationDef {
Relation::WatchInfo.def()
}
}
-96
View File
@@ -1,96 +0,0 @@
//! Show entity
use flix_model::id::{CollectionId, LibraryId, ShowId};
use seamantic::model::path::PathBytes;
use sea_orm::{
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
};
/// The database representation of a show media folder
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_shows")]
pub struct Model {
/// The show's ID
#[sea_orm(primary_key, auto_increment = false)]
pub id: ShowId,
/// The show's parent
pub parent: Option<CollectionId>,
/// The show's slug
pub slug: String,
/// The show's library
pub library: LibraryId,
/// The show's directory
pub directory: PathBytes,
/// The show's poster path
pub relative_poster_path: Option<String>,
}
impl ActiveModelBehavior for ActiveModel {}
/// Relation
#[derive(Debug, EnumIter, DeriveRelation)]
pub enum Relation {
/// The parent collection of this collection
#[sea_orm(
belongs_to = "super::collections::Entity",
from = "Column::Parent",
to = "super::collections::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
Parent,
/// The library this show belongs to
#[sea_orm(
belongs_to = "super::libraries::Entity",
from = "Column::Library",
to = "super::libraries::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
Library,
/// The media info for this show
#[sea_orm(
belongs_to = "super::super::info::shows::Entity",
from = "Column::Id",
to = "super::super::info::shows::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
MediaInfo,
/// The watched info for this show
#[sea_orm(
belongs_to = "super::super::watched::shows::Entity",
from = "Column::Id",
to = "super::super::watched::shows::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
WatchInfo,
}
impl Related<super::collections::Entity> for Entity {
fn to() -> RelationDef {
Relation::Parent.def()
}
}
impl Related<super::libraries::Entity> for Entity {
fn to() -> RelationDef {
Relation::Library.def()
}
}
impl Related<super::super::info::shows::Entity> for Entity {
fn to() -> RelationDef {
Relation::MediaInfo.def()
}
}
impl Related<super::super::watched::shows::Entity> for Entity {
fn to() -> RelationDef {
Relation::WatchInfo.def()
}
}
+524
View File
@@ -0,0 +1,524 @@
//! This module contains entities for storing media information such as
//! titles and overviews
/// Collection entity
pub mod collections {
use flix_model::id::CollectionId;
use sea_orm::entity::prelude::*;
/// The database representation of a flix collection
#[sea_orm::model]
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_info_collections")]
pub struct Model {
/// The collection's ID
#[sea_orm(column_type = "Integer", primary_key, nullable, auto_increment = false)]
pub id: CollectionId,
/// The collection's title
#[sea_orm(indexed)]
pub title: String,
/// The collection's overview
pub overview: String,
}
impl ActiveModelBehavior for ActiveModel {}
}
/// Movie entity
pub mod movies {
use flix_model::id::MovieId;
use chrono::NaiveDate;
use sea_orm::entity::prelude::*;
/// The database representation of a flix movie
#[sea_orm::model]
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_info_movies")]
pub struct Model {
/// The movie's ID
#[sea_orm(column_type = "Integer", primary_key, nullable, auto_increment = false)]
pub id: MovieId,
/// The movie's title
#[sea_orm(indexed)]
pub title: String,
/// The movie's tagline
pub tagline: String,
/// The movie's overview
pub overview: String,
/// The movie's release date
#[sea_orm(indexed)]
pub date: NaiveDate,
}
impl ActiveModelBehavior for ActiveModel {}
}
/// Show entity
pub mod shows {
use flix_model::id::ShowId;
use chrono::NaiveDate;
use sea_orm::entity::prelude::*;
/// The database representation of a flix show
#[sea_orm::model]
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_info_shows")]
pub struct Model {
/// The show's ID
#[sea_orm(column_type = "Integer", primary_key, nullable, auto_increment = false)]
pub id: ShowId,
/// The show's title
#[sea_orm(indexed)]
pub title: String,
/// The show's tagline
pub tagline: String,
/// The show's overview
pub overview: String,
/// The show's air date
#[sea_orm(indexed)]
pub date: NaiveDate,
/// Seasons that are part of this show
#[sea_orm(has_many, on_update = "Cascade", on_delete = "Cascade")]
pub seasons: HasMany<super::seasons::Entity>,
/// Episodes that are part of this show
#[sea_orm(has_many, on_update = "Cascade", on_delete = "Cascade")]
pub episodes: HasMany<super::episodes::Entity>,
}
impl ActiveModelBehavior for ActiveModel {}
}
/// Season entity
pub mod seasons {
use flix_model::id::ShowId;
use flix_model::numbers::SeasonNumber;
use chrono::NaiveDate;
use sea_orm::entity::prelude::*;
/// The database representation of a flix season
#[sea_orm::model]
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_info_seasons")]
pub struct Model {
/// The season's show's ID
#[sea_orm(primary_key, auto_increment = false)]
pub show_id: ShowId,
/// The season's number
#[sea_orm(primary_key, auto_increment = false)]
pub season_number: SeasonNumber,
/// The season's title
pub title: String,
/// The season's overview
pub overview: String,
/// The season's air date
#[sea_orm(indexed)]
pub date: NaiveDate,
/// The show this season belongs to
#[sea_orm(belongs_to, from = "show_id", to = "id")]
pub show: HasOne<super::shows::Entity>,
/// Episodes that are part of this season
#[sea_orm(has_many, on_update = "Cascade", on_delete = "Cascade")]
pub episodes: HasMany<super::episodes::Entity>,
}
impl ActiveModelBehavior for ActiveModel {}
}
/// Episode entity
pub mod episodes {
use flix_model::id::ShowId;
use flix_model::numbers::{EpisodeNumber, SeasonNumber};
use chrono::NaiveDate;
use sea_orm::entity::prelude::*;
/// The database representation of a flix episode
#[sea_orm::model]
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_info_episodes")]
pub struct Model {
/// The episode's show's ID
#[sea_orm(primary_key, auto_increment = false)]
pub show_id: ShowId,
/// The episode's season's number
#[sea_orm(primary_key, auto_increment = false)]
pub season_number: SeasonNumber,
/// The episode's number
#[sea_orm(primary_key, auto_increment = false)]
pub episode_number: EpisodeNumber,
/// The episode's title
pub title: String,
/// The episode's overview
pub overview: String,
/// The episode's air date
#[sea_orm(indexed)]
pub date: NaiveDate,
/// The show this episode belongs to
#[sea_orm(belongs_to, from = "show_id", to = "id")]
pub show: HasOne<super::shows::Entity>,
/// The season this episode belongs to
#[sea_orm(
belongs_to,
from = "(show_id, season_number)",
to = "(show_id, season_number)"
)]
pub season: HasOne<super::seasons::Entity>,
}
impl ActiveModelBehavior for ActiveModel {}
}
/// Macros for creating info entities
#[cfg(test)]
pub mod test {
macro_rules! make_info_collection {
($db:expr, $id:literal) => {
$crate::entity::info::collections::ActiveModel {
id: Set(::flix_model::id::CollectionId::from_raw($id)),
title: Set(::std::string::String::new()),
overview: Set(::std::string::String::new()),
}
.insert($db)
.await
.expect("insert");
};
}
pub(crate) use make_info_collection;
macro_rules! make_info_movie {
($db:expr, $id:literal) => {
$crate::entity::info::movies::ActiveModel {
id: Set(::flix_model::id::MovieId::from_raw($id)),
title: Set(::std::string::String::new()),
tagline: Set(::std::string::String::new()),
overview: Set(::std::string::String::new()),
date: Set(::chrono::NaiveDate::from_yo_opt(1, 1).expect("from_yo_opt")),
}
.insert($db)
.await
.expect("insert");
};
}
pub(crate) use make_info_movie;
macro_rules! make_info_show {
($db:expr, $id:literal) => {
$crate::entity::info::shows::ActiveModel {
id: Set(::flix_model::id::ShowId::from_raw($id)),
title: Set(::std::string::String::new()),
tagline: Set(::std::string::String::new()),
overview: Set(::std::string::String::new()),
date: Set(::chrono::NaiveDate::from_yo_opt(1, 1).expect("from_yo_opt")),
}
.insert($db)
.await
.expect("insert");
};
}
pub(crate) use make_info_show;
macro_rules! make_info_season {
($db:expr, $show:literal, $season:literal) => {
$crate::entity::info::seasons::ActiveModel {
show_id: Set(::flix_model::id::ShowId::from_raw($show)),
season_number: Set($season),
title: Set(::std::string::String::new()),
overview: Set(::std::string::String::new()),
date: Set(::chrono::NaiveDate::from_yo_opt(1, 1).expect("from_yo_opt")),
}
.insert($db)
.await
.expect("insert");
};
}
pub(crate) use make_info_season;
macro_rules! make_info_episode {
($db:expr, $show:literal, $season:literal, $episode:literal) => {
$crate::entity::info::episodes::ActiveModel {
show_id: Set(::flix_model::id::ShowId::from_raw($show)),
season_number: Set($season),
episode_number: Set($episode),
title: Set(::std::string::String::new()),
overview: Set(::std::string::String::new()),
date: Set(::chrono::NaiveDate::from_yo_opt(1, 1).expect("from_yo_opt")),
}
.insert($db)
.await
.expect("insert");
};
}
pub(crate) use make_info_episode;
}
#[cfg(test)]
mod tests {
use flix_model::id::{CollectionId, MovieId, ShowId};
use chrono::NaiveDate;
use sea_orm::ActiveValue::{NotSet, Set};
use sea_orm::entity::prelude::*;
use sea_orm::sqlx::error::ErrorKind;
use crate::tests::new_initialized_memory_db;
use super::super::tests::get_error_kind;
use super::super::tests::notsettable;
use super::test::{
make_info_collection, make_info_episode, make_info_movie, make_info_season, make_info_show,
};
#[tokio::test]
async fn use_test_macros() {
let db = new_initialized_memory_db().await;
make_info_collection!(&db, 1);
make_info_movie!(&db, 1);
make_info_show!(&db, 1);
make_info_season!(&db, 1, 1);
make_info_episode!(&db, 1, 1, 1);
}
#[tokio::test]
async fn test_round_trip_collections() {
let db = new_initialized_memory_db().await;
macro_rules! assert_collection {
($db:expr, $id:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_collection!(@insert, $db, $id $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.id, CollectionId::from_raw($id));
assert_eq!(model.title, concat!("C Title ", $id));
assert_eq!(model.overview, concat!("C Overview ", $id));
};
($db:expr, $id:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_collection!(@insert, $db, $id $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
};
(@insert, $db:expr, $id:literal $(; $($skip:ident),+)?) => {
super::collections::ActiveModel {
id: notsettable!(id, CollectionId::from_raw($id) $(, $($skip),+)?),
title: notsettable!(title, concat!("C Title ", $id).to_string() $(, $($skip),+)?),
overview: notsettable!(overview, concat!("C Overview ", $id).to_string() $(, $($skip),+)?),
}.insert($db).await
};
}
assert_collection!(&db, 1, Success);
assert_collection!(&db, 1, UniqueViolation);
assert_collection!(&db, 2, Success);
assert_collection!(&db, 3, Success; id);
assert_collection!(&db, 4, NotNullViolation; title);
assert_collection!(&db, 5, NotNullViolation; overview);
}
#[tokio::test]
async fn test_round_trip_movies() {
let db = new_initialized_memory_db().await;
macro_rules! assert_movie {
($db:expr, $id:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_movie!(@insert, $db, $id $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.id, MovieId::from_raw($id));
assert_eq!(model.title, concat!("M Title ", $id));
assert_eq!(model.tagline, concat!("M Tagline ", $id));
assert_eq!(model.overview, concat!("M Overview ", $id));
assert_eq!(model.date, NaiveDate::from_yo_opt($id, 1).expect("from_yo_opt"));
};
($db:expr, $id:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_movie!(@insert, $db, $id $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
};
(@insert, $db:expr, $id:literal $(; $($skip:ident),+)?) => {
super::movies::ActiveModel {
id: notsettable!(id, MovieId::from_raw($id) $(, $($skip),+)?),
title: notsettable!(title, concat!("M Title ", $id).to_string() $(, $($skip),+)?),
tagline: notsettable!(tagline, concat!("M Tagline ", $id).to_string() $(, $($skip),+)?),
overview: notsettable!(overview, concat!("M Overview ", $id).to_string() $(, $($skip),+)?),
date: notsettable!(date, NaiveDate::from_yo_opt($id, 1).expect("from_yo_opt") $(, $($skip),+)?),
}.insert($db).await
};
}
assert_movie!(&db, 1, Success);
assert_movie!(&db, 1, UniqueViolation);
assert_movie!(&db, 2, Success);
assert_movie!(&db, 3, Success; id);
assert_movie!(&db, 4, NotNullViolation; title);
assert_movie!(&db, 5, NotNullViolation; tagline);
assert_movie!(&db, 6, NotNullViolation; overview);
assert_movie!(&db, 7, NotNullViolation; date);
}
#[tokio::test]
async fn test_round_trip_shows() {
let db = new_initialized_memory_db().await;
macro_rules! assert_show {
($db:expr, $id:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_show!(@insert, $db, $id $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.id, ShowId::from_raw($id));
assert_eq!(model.title, concat!("S Title ", $id));
assert_eq!(model.tagline, concat!("S Tagline ", $id));
assert_eq!(model.overview, concat!("S Overview ", $id));
assert_eq!(model.date, NaiveDate::from_yo_opt($id, 1).expect("from_yo_opt"));
};
($db:expr, $id:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_show!(@insert, $db, $id $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(
get_error_kind(model).expect("get_error_kind"),
ErrorKind::$error
);
};
(@insert, $db:expr, $id:literal $(; $($skip:ident),+)?) => {
super::shows::ActiveModel {
id: notsettable!(id, ShowId::from_raw($id) $(, $($skip),+)?),
title: notsettable!(title, concat!("S Title ", $id).to_string() $(, $($skip),+)?),
tagline: notsettable!(tagline, concat!("S Tagline ", $id).to_string() $(, $($skip),+)?),
overview: notsettable!(overview, concat!("S Overview ", $id).to_string() $(, $($skip),+)?),
date: notsettable!(date, NaiveDate::from_yo_opt($id, 1).expect("from_yo_opt") $(, $($skip),+)?),
}.insert($db).await
};
}
assert_show!(&db, 1, Success);
assert_show!(&db, 1, UniqueViolation);
assert_show!(&db, 2, Success);
assert_show!(&db, 3, Success; id);
assert_show!(&db, 4, NotNullViolation; title);
assert_show!(&db, 5, NotNullViolation; tagline);
assert_show!(&db, 6, NotNullViolation; overview);
assert_show!(&db, 7, NotNullViolation; date);
}
#[tokio::test]
async fn test_round_trip_seasons() {
let db = new_initialized_memory_db().await;
macro_rules! assert_season {
($db:expr, $show:literal, $season:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_season!(@insert, $db, $show, $season $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.show_id, ShowId::from_raw($show));
assert_eq!(model.season_number, $season);
assert_eq!(model.title, concat!("SS Title ", $show, ",", $season));
assert_eq!(model.overview, concat!("SS Overview ", $show, ",", $season));
assert_eq!(model.date, NaiveDate::from_yo_opt($show + $season, 1).expect("from_yo_opt"));
};
($db:expr, $show:literal, $season:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_season!(@insert, $db, $show, $season $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(
get_error_kind(model).expect("get_error_kind"),
ErrorKind::$error
);
};
(@insert, $db:expr, $show:literal, $season:literal $(; $($skip:ident),+)?) => {
super::seasons::ActiveModel {
show_id: notsettable!(show_id, ShowId::from_raw($show) $(, $($skip),+)?),
season_number: notsettable!(season_number, $season $(, $($skip),+)?),
title: notsettable!(title, concat!("SS Title ", $show, ",", $season).to_string() $(, $($skip),+)?),
overview: notsettable!(overview, concat!("SS Overview ", $show, ",", $season).to_string() $(, $($skip),+)?),
date: notsettable!(date, NaiveDate::from_yo_opt($show + $season, 1).expect("from_yo_opt") $(, $($skip),+)?),
}.insert($db).await
};
}
assert_season!(&db, 1, 1, ForeignKeyViolation);
make_info_show!(&db, 1);
make_info_show!(&db, 2);
assert_season!(&db, 1, 1, Success);
assert_season!(&db, 1, 1, UniqueViolation);
assert_season!(&db, 2, 1, Success);
assert_season!(&db, 1, 2, Success);
assert_season!(&db, 1, 3, NotNullViolation; show_id);
assert_season!(&db, 1, 4, NotNullViolation; season_number);
assert_season!(&db, 1, 5, NotNullViolation; title);
assert_season!(&db, 1, 6, NotNullViolation; overview);
assert_season!(&db, 1, 7, NotNullViolation; date);
}
#[tokio::test]
async fn test_round_trip_episodes() {
let db = new_initialized_memory_db().await;
macro_rules! assert_episode {
($db:expr, $show:literal, $season:literal, $episode:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_episode!(@insert, $db, $show, $season, $episode $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.show_id, ShowId::from_raw($show));
assert_eq!(model.season_number, $season);
assert_eq!(model.episode_number, $episode);
assert_eq!(model.title, concat!("SSE Title ", $show, ",", $season, ",", $episode));
assert_eq!(model.overview, concat!("SSE Overview ", $show, ",", $season, ",", $episode));
assert_eq!(model.date, NaiveDate::from_yo_opt($show + $season, 1).expect("from_yo_opt"));
};
($db:expr, $show:literal, $season:literal, $episode:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_episode!(@insert, $db, $show, $season, $episode $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(
get_error_kind(model).expect("get_error_kind"),
ErrorKind::$error
);
};
(@insert, $db:expr, $show:literal, $season:literal, $episode:literal $(; $($skip:ident),+)?) => {
super::episodes::ActiveModel {
show_id: notsettable!(show_id, ShowId::from_raw($show) $(, $($skip),+)?),
season_number: notsettable!(season_number, $season $(, $($skip),+)?),
episode_number: notsettable!(episode_number, $episode $(, $($skip),+)?),
title: notsettable!(title, concat!("SSE Title ", $show, ",", $season, ",", $episode).to_string() $(, $($skip),+)?),
overview: notsettable!(overview, concat!("SSE Overview ", $show, ",", $season, ",", $episode).to_string() $(, $($skip),+)?),
date: notsettable!(date, NaiveDate::from_yo_opt($show + $season, 1).expect("from_yo_opt") $(, $($skip),+)?),
}.insert($db).await
};
}
assert_episode!(&db, 1, 1, 1, ForeignKeyViolation);
make_info_show!(&db, 1);
make_info_show!(&db, 2);
assert_episode!(&db, 1, 1, 1, ForeignKeyViolation);
make_info_season!(&db, 1, 1);
make_info_season!(&db, 1, 2);
make_info_season!(&db, 2, 1);
assert_episode!(&db, 1, 1, 1, Success);
assert_episode!(&db, 1, 1, 1, UniqueViolation);
assert_episode!(&db, 2, 1, 1, Success);
assert_episode!(&db, 1, 2, 1, Success);
assert_episode!(&db, 1, 1, 2, Success);
assert_episode!(&db, 1, 1, 3, NotNullViolation; show_id);
assert_episode!(&db, 1, 1, 4, NotNullViolation; season_number);
assert_episode!(&db, 1, 1, 4, NotNullViolation; episode_number);
assert_episode!(&db, 1, 1, 5, NotNullViolation; title);
assert_episode!(&db, 1, 1, 6, NotNullViolation; overview);
assert_episode!(&db, 1, 1, 7, NotNullViolation; date);
}
}
-27
View File
@@ -1,27 +0,0 @@
//! Collection entity
use flix_model::id::CollectionId;
use sea_orm::{
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
EnumIter, PrimaryKeyTrait,
};
/// The database representation of a flix collection
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_info_collections")]
pub struct Model {
/// The collection's ID
#[sea_orm(primary_key, auto_increment = false)]
pub id: CollectionId,
/// The collection's title
pub title: String,
/// The collection's overview
pub overview: String,
}
impl ActiveModelBehavior for ActiveModel {}
/// Relation
#[derive(Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
-53
View File
@@ -1,53 +0,0 @@
//! Episode entity
use flix_model::id::ShowId;
use chrono::NaiveDate;
use flix_model::numbers::{EpisodeNumber, SeasonNumber};
use sea_orm::{
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
};
/// The database representation of a flix episode
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_info_episodes")]
pub struct Model {
/// The episode's show's ID
#[sea_orm(primary_key, auto_increment = false)]
pub show: ShowId,
/// The episode's season's number
#[sea_orm(primary_key, auto_increment = false)]
pub season: SeasonNumber,
/// The episode's number
#[sea_orm(primary_key, auto_increment = false)]
pub episode: EpisodeNumber,
/// The episode's title
pub title: String,
/// The episode's overview
pub overview: String,
/// The episode's air date
pub date: NaiveDate,
}
impl ActiveModelBehavior for ActiveModel {}
/// Relation
#[derive(Debug, EnumIter, DeriveRelation)]
pub enum Relation {
/// The show this season belongs to
#[sea_orm(
belongs_to = "super::shows::Entity",
from = "Column::Show",
to = "super::shows::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
Show,
}
impl Related<super::shows::Entity> for Entity {
fn to() -> RelationDef {
Relation::Show.def()
}
}
-230
View File
@@ -1,230 +0,0 @@
//! This module contains entities for storing media information such as
//! titles and overviews
pub mod collections;
pub mod movies;
pub mod episodes;
pub mod seasons;
pub mod shows;
#[cfg(test)]
mod tests {
use flix_model::id::{CollectionId, MovieId, ShowId};
use chrono::NaiveDate;
use sea_orm::ActiveModelTrait;
use sea_orm::ActiveValue::{NotSet, Set};
use sea_orm::sqlx::error::ErrorKind;
use sea_orm_migration::MigratorTrait;
use crate::migration::Migrator;
use crate::tests::new_memory_db;
use super::super::tests::get_error_kind;
use super::super::tests::notsettable;
#[tokio::test]
async fn test_inserts() {
let db = new_memory_db().await;
Migrator::up(&db, None).await.expect("up");
// Collections
macro_rules! assert_collection {
($db:expr, $id:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_collection!(@insert, $db, $id $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.id, CollectionId::from_raw($id));
assert_eq!(model.title, concat!("C", $id));
assert_eq!(model.overview, concat!("Collection", " ", $id));
};
($db:expr, $id:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_collection!(@insert, $db, $id $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
};
(@insert, $db:expr, $id:literal $(; $($skip:ident),+)?) => {
super::collections::ActiveModel {
id: notsettable!(id, CollectionId::from_raw($id) $(, $($skip),+)?),
title: notsettable!(title, concat!("C", $id).to_string() $(, $($skip),+)?),
overview: notsettable!(overview, concat!("Collection", " ", $id).to_string() $(, $($skip),+)?),
}.insert($db).await
};
}
assert_collection!(&db, 1, Success);
assert_collection!(&db, 1, UniqueViolation);
assert_collection!(&db, 2, Success);
assert_collection!(&db, 3, Success; id);
assert_collection!(&db, 4, NotNullViolation; title);
assert_collection!(&db, 5, NotNullViolation; overview);
// Movies
macro_rules! assert_movie {
($db:expr, $id:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_movie!(@insert, $db, $id $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.id, MovieId::from_raw($id));
assert_eq!(model.title, concat!("M", $id));
assert_eq!(model.tagline, concat!("Watch Movie", " ", $id));
assert_eq!(model.overview, concat!("Movie", " ", $id));
assert_eq!(model.date, NaiveDate::from_yo_opt(2000, $id).expect("NaiveDate::from_yo_opt"));
};
($db:expr, $id:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_movie!(@insert, $db, $id $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
};
(@insert, $db:expr, $id:literal $(; $($skip:ident),+)?) => {
super::movies::ActiveModel {
id: notsettable!(id, MovieId::from_raw($id) $(, $($skip),+)?),
title: notsettable!(title, concat!("M", $id).to_string() $(, $($skip),+)?),
tagline: notsettable!(tagline, concat!("Watch Movie", " ", $id).to_string() $(, $($skip),+)?),
overview: notsettable!(overview, concat!("Movie", " ", $id).to_string() $(, $($skip),+)?),
date: notsettable!(date, NaiveDate::from_yo_opt(2000, $id).expect("NaiveDate::from_yo_opt") $(, $($skip),+)?),
}.insert($db).await
};
}
assert_movie!(&db, 1, Success);
assert_movie!(&db, 1, UniqueViolation);
assert_movie!(&db, 2, Success);
assert_movie!(&db, 3, Success; id);
assert_movie!(&db, 4, NotNullViolation; title);
assert_movie!(&db, 5, NotNullViolation; tagline);
assert_movie!(&db, 6, NotNullViolation; overview);
assert_movie!(&db, 7, NotNullViolation; date);
// Shows
macro_rules! assert_show {
($db:expr, $id:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_show!(@insert, $db, $id $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.id, ShowId::from_raw($id));
assert_eq!(model.title, concat!("S", $id));
assert_eq!(model.tagline, concat!("Watch Show", " ", $id));
assert_eq!(model.overview, concat!("Show", " ", $id));
assert_eq!(model.date, NaiveDate::from_yo_opt(2000, $id).expect("NaiveDate::from_yo_opt"));
};
($db:expr, $id:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_show!(@insert, $db, $id $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(
get_error_kind(model).expect("get_error_kind"),
ErrorKind::$error
);
};
(@insert, $db:expr, $id:literal $(; $($skip:ident),+)?) => {
super::shows::ActiveModel {
id: notsettable!(id, ShowId::from_raw($id) $(, $($skip),+)?),
title: notsettable!(title, concat!("S", $id).to_string() $(, $($skip),+)?),
tagline: notsettable!(tagline, concat!("Watch Show", " ", $id).to_string() $(, $($skip),+)?),
overview: notsettable!(overview, concat!("Show", " ", $id).to_string() $(, $($skip),+)?),
date: notsettable!(date, NaiveDate::from_yo_opt(2000, $id).expect("NaiveDate::from_yo_opt") $(, $($skip),+)?),
}.insert($db).await
};
}
assert_show!(&db, 1, Success);
assert_show!(&db, 1, UniqueViolation);
assert_show!(&db, 2, Success);
assert_show!(&db, 3, Success; id);
assert_show!(&db, 4, NotNullViolation; title);
assert_show!(&db, 5, NotNullViolation; tagline);
assert_show!(&db, 6, NotNullViolation; overview);
assert_show!(&db, 7, NotNullViolation; date);
// Seasons
macro_rules! assert_season {
($db:expr, $show:literal, $season:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_season!(@insert, $db, $show, $season $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.show, ShowId::from_raw($show));
assert_eq!(model.season, $season);
assert_eq!(model.title, concat!("S", $show, "S", $season));
assert_eq!(model.overview, concat!("Show", " ", $show, " ", "Season", " ", $season));
assert_eq!(model.date, NaiveDate::from_yo_opt(2000, $show + $season).expect("NaiveDate::from_yo_opt"));
};
($db:expr, $show:literal, $season:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_season!(@insert, $db, $show, $season $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(
get_error_kind(model).expect("get_error_kind"),
ErrorKind::$error
);
};
(@insert, $db:expr, $show:literal, $season:literal $(; $($skip:ident),+)?) => {
super::seasons::ActiveModel {
show: notsettable!(show, ShowId::from_raw($show) $(, $($skip),+)?),
season: notsettable!(season, $season $(, $($skip),+)?),
title: notsettable!(title, concat!("S", $show, "S", $season).to_string() $(, $($skip),+)?),
overview: notsettable!(overview, concat!("Show", " ", $show, " ", "Season", " ", $season).to_string() $(, $($skip),+)?),
date: notsettable!(date, NaiveDate::from_yo_opt(2000, $show + $season).expect("NaiveDate::from_yo_opt") $(, $($skip),+)?),
}.insert($db).await
};
}
assert_season!(&db, 1, 1, Success);
assert_season!(&db, 1, 1, UniqueViolation);
assert_season!(&db, 2, 1, Success);
assert_season!(&db, 0, 1, ForeignKeyViolation);
assert_season!(&db, 1, 2, Success);
assert_season!(&db, 1, 3, NotNullViolation; show);
assert_season!(&db, 1, 4, NotNullViolation; season);
assert_season!(&db, 1, 5, NotNullViolation; title);
assert_season!(&db, 1, 6, NotNullViolation; overview);
assert_season!(&db, 1, 7, NotNullViolation; date);
// Episodes
macro_rules! assert_episode {
($db:expr, $show:literal, $season:literal, $episode:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_episode!(@insert, $db, $show, $season, $episode $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.show, ShowId::from_raw($show));
assert_eq!(model.season, $season);
assert_eq!(model.episode, $episode);
assert_eq!(model.title, concat!("S", $show, "S", $season, "E", $episode));
assert_eq!(model.overview, concat!("Show", " ", $show, " ", "Season", " ", $season, " ", "Episode", " ", $episode));
assert_eq!(model.date, NaiveDate::from_yo_opt(2000, $show + $season + $episode).expect("NaiveDate::from_yo_opt"));
};
($db:expr, $show:literal, $season:literal, $episode:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_episode!(@insert, $db, $show, $season, $episode $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(
get_error_kind(model).expect("get_error_kind"),
ErrorKind::$error
);
};
(@insert, $db:expr, $show:literal, $season:literal, $episode:literal $(; $($skip:ident),+)?) => {
super::episodes::ActiveModel {
show: notsettable!(show, ShowId::from_raw($show) $(, $($skip),+)?),
season: notsettable!(season, $season $(, $($skip),+)?),
episode: notsettable!(episode, $episode $(, $($skip),+)?),
title: notsettable!(title, concat!("S", $show, "S", $season, "E", $episode).to_string() $(, $($skip),+)?),
overview: notsettable!(overview, concat!("Show", " ", $show, " ", "Season", " ", $season, " ", "Episode", " ", $episode).to_string() $(, $($skip),+)?),
date: notsettable!(date, NaiveDate::from_yo_opt(2000, $show + $season + $episode).expect("NaiveDate::from_yo_opt") $(, $($skip),+)?),
}.insert($db).await
};
}
assert_episode!(&db, 1, 1, 1, Success);
assert_episode!(&db, 1, 1, 1, UniqueViolation);
assert_episode!(&db, 1, 2, 1, Success);
assert_episode!(&db, 2, 1, 1, Success);
assert_episode!(&db, 1, 0, 1, ForeignKeyViolation);
assert_episode!(&db, 0, 1, 1, ForeignKeyViolation);
assert_episode!(&db, 1, 1, 2, Success);
assert_episode!(&db, 1, 1, 3, NotNullViolation; show);
assert_episode!(&db, 1, 1, 4, NotNullViolation; season);
assert_episode!(&db, 1, 1, 4, NotNullViolation; episode);
assert_episode!(&db, 1, 1, 5, NotNullViolation; title);
assert_episode!(&db, 1, 1, 6, NotNullViolation; overview);
assert_episode!(&db, 1, 1, 7, NotNullViolation; date);
}
}
-32
View File
@@ -1,32 +0,0 @@
//! Movie entity
use flix_model::id::MovieId;
use chrono::NaiveDate;
use sea_orm::{
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
EnumIter, PrimaryKeyTrait,
};
/// The database representation of a flix movie
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_info_movies")]
pub struct Model {
/// The movie's ID
#[sea_orm(primary_key, auto_increment = false)]
pub id: MovieId,
/// The movie's title
pub title: String,
/// The movie's tagline
pub tagline: String,
/// The movie's overview
pub overview: String,
/// The movie's release date
pub date: NaiveDate,
}
impl ActiveModelBehavior for ActiveModel {}
/// Relation
#[derive(Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
-50
View File
@@ -1,50 +0,0 @@
//! Season entity
use flix_model::id::ShowId;
use chrono::NaiveDate;
use flix_model::numbers::SeasonNumber;
use sea_orm::{
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
};
/// The database representation of a flix season
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_info_seasons")]
pub struct Model {
/// The season's show's ID
#[sea_orm(primary_key, auto_increment = false)]
pub show: ShowId,
/// The season's number
#[sea_orm(primary_key, auto_increment = false)]
pub season: SeasonNumber,
/// The season's title
pub title: String,
/// The season's overview
pub overview: String,
/// The season's air date
pub date: NaiveDate,
}
impl ActiveModelBehavior for ActiveModel {}
/// Relation
#[derive(Debug, EnumIter, DeriveRelation)]
pub enum Relation {
/// The show this season belongs to
#[sea_orm(
belongs_to = "super::shows::Entity",
from = "Column::Show",
to = "super::shows::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
Show,
}
impl Related<super::shows::Entity> for Entity {
fn to() -> RelationDef {
Relation::Show.def()
}
}
-51
View File
@@ -1,51 +0,0 @@
//! Show entity
use flix_model::id::ShowId;
use chrono::NaiveDate;
use sea_orm::{
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
};
/// The database representation of a flix show
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_info_shows")]
pub struct Model {
/// The show's ID
#[sea_orm(primary_key, auto_increment = false)]
pub id: ShowId,
/// The show's title
pub title: String,
/// The show's tagline
pub tagline: String,
/// The show's overview
pub overview: String,
/// The show's air date
pub date: NaiveDate,
}
impl ActiveModelBehavior for ActiveModel {}
/// Relation
#[derive(Debug, EnumIter, DeriveRelation)]
pub enum Relation {
/// The seasons that are part of this show
#[sea_orm(has_many = "super::seasons::Entity")]
Seasons,
/// The episodes that are part of this show
#[sea_orm(has_many = "super::episodes::Entity")]
Episodes,
}
impl Related<super::seasons::Entity> for Entity {
fn to() -> RelationDef {
Relation::Seasons.def()
}
}
impl Related<super::episodes::Entity> for Entity {
fn to() -> RelationDef {
Relation::Episodes.def()
}
}
+11 -210
View File
@@ -58,215 +58,16 @@ mod tests {
/// Helper macro for writing tests for `ActiveModel` structs where /// Helper macro for writing tests for `ActiveModel` structs where
/// toggling [sea_orm::ActiveValue] is needed /// toggling [sea_orm::ActiveValue] is needed
macro_rules! noneable { macro_rules! noneable {
($field:ident, $value:expr $(, $($skip:ident),+)?) => { ($field:ident, $value:expr $(, $($skip:ident),+)?) => {
if noneable!(@skip, $field $(, $($skip),+)?) { if noneable!(@skip, $field $(, $($skip),+)?) {
None None
} else { } else {
Some($value) Some($value)
} }
}; };
(@skip, $field:ident $(, $skip:ident),*) => { (@skip, $field:ident $(, $skip:ident),*) => {
false $(|| stringify!($field) == stringify!($skip))* false $(|| stringify!($field) == stringify!($skip))*
}; };
} }
pub(super) use noneable; pub(super) use noneable;
/// Helper macro for creating a flix library
macro_rules! have_library {
($db:expr, $id:literal) => {
$crate::entity::content::libraries::ActiveModel {
id: Set(::flix_model::id::LibraryId::from_raw($id)),
directory: Set(::std::path::PathBuf::new().into()),
}
.insert($db)
.await
.expect("insert");
};
}
pub(super) use have_library;
/// Helper macro for creating a flix collection
macro_rules! make_flix_collection {
($db:expr, $id:literal) => {
$crate::entity::info::collections::ActiveModel {
id: Set(::flix_model::id::CollectionId::from_raw($id)),
title: Set(::std::string::String::new()),
overview: Set(::std::string::String::new()),
}
.insert($db)
.await
.expect("insert");
};
}
pub(super) use make_flix_collection;
macro_rules! have_collection {
($db:expr, $lid:literal, $id:literal, $pid:expr) => {
$crate::entity::tests::make_flix_collection!($db, $id);
$crate::entity::content::collections::ActiveModel {
id: Set(::flix_model::id::CollectionId::from_raw($id)),
parent: Set($pid.map(::flix_model::id::CollectionId::from_raw)),
slug: Set(::std::string::String::new()),
library: Set(::flix_model::id::LibraryId::from_raw($lid)),
directory: Set(::std::path::PathBuf::new().into()),
relative_poster_path: Set(::core::option::Option::None),
}
.insert($db)
.await
.expect("insert");
};
}
pub(super) use have_collection;
/// Helper macro for creating a flix movie
macro_rules! make_flix_movie {
($db:expr, $id:literal) => {
$crate::entity::info::movies::ActiveModel {
id: Set(::flix_model::id::MovieId::from_raw($id)),
title: Set(::std::string::String::new()),
tagline: Set(::std::string::String::new()),
overview: Set(::std::string::String::new()),
date: Set(
::chrono::NaiveDate::from_yo_opt(2000, $id).expect("NaiveDate::from_yo_opt")
),
}
.insert($db)
.await
.expect("insert");
};
}
pub(super) use make_flix_movie;
macro_rules! have_movie {
($db:expr, $lid:literal, $id:literal, $pid:expr) => {
$crate::entity::tests::make_flix_movie!($db, $id);
$crate::entity::content::movies::ActiveModel {
id: Set(::flix_model::id::MovieId::from_raw($id)),
parent: Set($pid.map(::flix_model::id::CollectionId::from_raw)),
slug: Set(::std::string::String::new()),
library: Set(::flix_model::id::LibraryId::from_raw($lid)),
directory: Set(::std::path::PathBuf::new().into()),
relative_media_path: Set(::std::string::String::new()),
relative_poster_path: Set(::core::option::Option::None),
}
.insert($db)
.await
.expect("insert");
};
}
pub(super) use have_movie;
/// Helper macro for creating a flix show
macro_rules! make_flix_show {
($db:expr, $id:literal) => {
$crate::entity::info::shows::ActiveModel {
id: Set(::flix_model::id::ShowId::from_raw($id)),
title: Set(::std::string::String::new()),
tagline: Set(::std::string::String::new()),
overview: Set(::std::string::String::new()),
date: Set(
::chrono::NaiveDate::from_yo_opt(2000, $id).expect("NaiveDate::from_yo_opt")
),
}
.insert($db)
.await
.expect("insert");
};
}
pub(super) use make_flix_show;
macro_rules! have_show {
($db:expr, $lid:literal, $id:literal, $pid:expr) => {
$crate::entity::tests::make_flix_show!($db, $id);
$crate::entity::content::shows::ActiveModel {
id: Set(::flix_model::id::ShowId::from_raw($id)),
parent: Set($pid.map(::flix_model::id::CollectionId::from_raw)),
slug: Set(::std::string::String::new()),
library: Set(::flix_model::id::LibraryId::from_raw($lid)),
directory: Set(::std::path::PathBuf::new().into()),
relative_poster_path: Set(::core::option::Option::None),
}
.insert($db)
.await
.expect("insert");
};
}
pub(super) use have_show;
/// Helper macro for creating a flix season
macro_rules! make_flix_season {
($db:expr, $show:literal, $season:literal) => {
$crate::entity::info::seasons::ActiveModel {
show: Set(::flix_model::id::ShowId::from_raw($show)),
season: Set($season),
title: Set(::std::string::String::new()),
overview: Set(::std::string::String::new()),
date: Set(::chrono::NaiveDate::from_yo_opt(2000, $show + $season)
.expect("NaiveDate::from_yo_opt")),
}
.insert($db)
.await
.expect("insert");
};
}
pub(super) use make_flix_season;
macro_rules! have_season {
($db:expr, $lid:literal, $show:literal, $season:literal) => {
$crate::entity::tests::make_flix_season!($db, $show, $season);
$crate::entity::content::seasons::ActiveModel {
show: Set(::flix_model::id::ShowId::from_raw($show)),
season: Set($season),
slug: Set(::std::string::String::new()),
library: Set(::flix_model::id::LibraryId::from_raw($lid)),
directory: Set(::std::path::PathBuf::new().into()),
relative_poster_path: Set(::core::option::Option::None),
}
.insert($db)
.await
.expect("insert");
};
}
pub(super) use have_season;
/// Helper macro for creating a flix episode
macro_rules! make_flix_episode {
($db:expr, $show:literal, $season:literal, $episode:literal) => {
$crate::entity::info::episodes::ActiveModel {
show: Set(::flix_model::id::ShowId::from_raw($show)),
season: Set($season),
episode: Set($episode),
title: Set(::std::string::String::new()),
overview: Set(::std::string::String::new()),
date: Set(::chrono::NaiveDate::from_yo_opt(2000, $show + $season)
.expect("NaiveDate::from_yo_opt")),
}
.insert($db)
.await
.expect("insert");
};
}
pub(super) use make_flix_episode;
macro_rules! have_episode {
($db:expr, $lid:literal, $show:literal, $season:literal, $episode:literal) => {
have_episode!(@make, $db, $lid, $show, $season, $episode, 0);
};
($db:expr, $lid:literal, $show:literal, $season:literal, $episode:literal, >1) => {
have_episode!(@make, $db, $lid, $show, $season, $episode, 1);
};
(@make, $db:expr, $lid:literal, $show:literal, $season:literal, $episode:literal, $count:literal) => {
$crate::entity::tests::make_flix_episode!($db, $show, $season, $episode);
$crate::entity::content::episodes::ActiveModel {
show: Set(::flix_model::id::ShowId::from_raw($show)),
season: Set($season),
episode: Set($episode),
count: Set($count),
slug: Set(::std::string::String::new()),
library: Set(::flix_model::id::LibraryId::from_raw($lid)),
directory: Set(::std::path::PathBuf::new().into()),
relative_media_path: Set(::std::string::String::new()),
relative_poster_path: Set(::core::option::Option::None),
}
.insert($db)
.await
.expect("insert");
};
}
pub(super) use have_episode;
} }
+629
View File
@@ -0,0 +1,629 @@
//! This module contains entities for storing dynamic data from TMDB
/// Collection entity
pub mod collections {
use flix_model::id::CollectionId as FlixId;
use flix_tmdb::model::id::CollectionId;
use chrono::NaiveDate;
use sea_orm::entity::prelude::*;
use crate::entity;
/// The database representation of a tmdb collection
#[sea_orm::model]
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_tmdb_collections")]
pub struct Model {
/// The collection's TMDB ID
#[sea_orm(column_type = "Integer", primary_key, nullable, auto_increment = false)]
pub tmdb_id: CollectionId,
/// The collection's ID
#[sea_orm(unique)]
pub flix_id: FlixId,
/// The date of the last update
pub last_update: NaiveDate,
/// The number of movies in the collection
pub movie_count: u16,
/// Movies that are in this collection
#[sea_orm(has_many, on_update = "Cascade", on_delete = "Cascade")]
pub movies: HasMany<super::movies::Entity>,
/// The info for this collection
#[sea_orm(belongs_to, from = "flix_id", to = "id")]
pub info: HasOne<entity::info::collections::Entity>,
}
impl ActiveModelBehavior for ActiveModel {}
}
/// Movie entity
pub mod movies {
use flix_model::id::MovieId as FlixId;
use flix_tmdb::model::id::{CollectionId, MovieId};
use seamantic::model::duration::Seconds;
use chrono::NaiveDate;
use sea_orm::entity::prelude::*;
use crate::entity;
/// The database representation of a tmdb movie
#[sea_orm::model]
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_tmdb_movies")]
pub struct Model {
/// The movie's TMDB ID
#[sea_orm(column_type = "Integer", primary_key, nullable, auto_increment = false)]
pub tmdb_id: MovieId,
/// The movie's ID
#[sea_orm(unique)]
pub flix_id: FlixId,
/// The date of the last update
pub last_update: NaiveDate,
/// The movie's runtime in seconds
pub runtime: Seconds,
/// The TMDB ID of the collection this movie belongs to
#[sea_orm(indexed)]
pub collection_id: Option<CollectionId>,
/// The info for this collection
#[sea_orm(belongs_to, from = "collection_id", to = "tmdb_id")]
pub collection: HasOne<super::collections::Entity>,
/// The info for this movie
#[sea_orm(belongs_to, from = "flix_id", to = "id")]
pub info: HasOne<entity::info::movies::Entity>,
}
impl ActiveModelBehavior for ActiveModel {}
}
/// Show entity
pub mod shows {
use flix_model::id::ShowId as FlixId;
use flix_tmdb::model::id::ShowId;
use chrono::NaiveDate;
use sea_orm::entity::prelude::*;
use crate::entity;
/// The database representation of a tmdb show
#[sea_orm::model]
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_tmdb_shows")]
pub struct Model {
/// The show's TMDB ID
#[sea_orm(column_type = "Integer", primary_key, nullable, auto_increment = false)]
pub tmdb_id: ShowId,
/// The show's ID
#[sea_orm(unique)]
pub flix_id: FlixId,
/// The movie's runtime in seconds
pub last_update: NaiveDate,
/// The number of seasons the show has
pub number_of_seasons: u32,
/// Seasons that are part of this show
#[sea_orm(has_many, on_update = "Cascade", on_delete = "Cascade")]
pub seasons: HasMany<super::seasons::Entity>,
/// Episodes that are part of this show
#[sea_orm(has_many, on_update = "Cascade", on_delete = "Cascade")]
pub episodes: HasMany<super::episodes::Entity>,
/// The info for this show
#[sea_orm(belongs_to, from = "flix_id", to = "id")]
pub info: HasOne<entity::info::shows::Entity>,
}
impl ActiveModelBehavior for ActiveModel {}
}
/// Season entity
pub mod seasons {
use flix_model::id::ShowId as FlixId;
use flix_model::numbers::SeasonNumber;
use flix_tmdb::model::id::ShowId;
use chrono::NaiveDate;
use sea_orm::entity::prelude::*;
use crate::entity;
/// The database representation of a tmdb season
#[sea_orm::model]
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_tmdb_seasons")]
pub struct Model {
/// The season's show's TMDB ID
#[sea_orm(primary_key, auto_increment = false)]
pub tmdb_show: ShowId,
/// The season's TMDB season number
#[sea_orm(primary_key, auto_increment = false)]
pub tmdb_season: SeasonNumber,
/// The season's show's ID
#[sea_orm(unique_key = "flix")]
pub flix_show: FlixId,
/// The season's number
#[sea_orm(unique_key = "flix")]
pub flix_season: SeasonNumber,
/// The date of the last update
pub last_update: NaiveDate,
/// The show this season belongs to
#[sea_orm(belongs_to, from = "tmdb_show", to = "tmdb_id")]
pub show: HasOne<super::shows::Entity>,
/// The info for this season
#[sea_orm(
belongs_to,
from = "(flix_show, flix_season)",
to = "(show_id, season_number)"
)]
pub info: HasOne<entity::info::seasons::Entity>,
}
impl ActiveModelBehavior for ActiveModel {}
}
/// Season entity
pub mod episodes {
use flix_model::id::ShowId as FlixId;
use flix_model::numbers::{EpisodeNumber, SeasonNumber};
use flix_tmdb::model::id::ShowId;
use seamantic::model::duration::Seconds;
use chrono::NaiveDate;
use sea_orm::entity::prelude::*;
use crate::entity;
/// The database representation of a tmdb episode
#[sea_orm::model]
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_tmdb_episodes")]
pub struct Model {
/// The episode's show's TMDB ID
#[sea_orm(primary_key, auto_increment = false)]
pub tmdb_show: ShowId,
/// The episode's season's TMDB season number
#[sea_orm(primary_key, auto_increment = false)]
pub tmdb_season: SeasonNumber,
/// The episode's TMDB episode number
#[sea_orm(primary_key, auto_increment = false)]
pub tmdb_episode: EpisodeNumber,
/// The episode's show's ID
#[sea_orm(unique_key = "flix")]
pub flix_show: FlixId,
/// The episode's season's number
#[sea_orm(unique_key = "flix")]
pub flix_season: SeasonNumber,
/// The episode's number
#[sea_orm(unique_key = "flix")]
pub flix_episode: EpisodeNumber,
/// The date of the last update
pub last_update: NaiveDate,
/// The episode's runtime in seconds
pub runtime: Seconds,
/// The show this episode belongs to
#[sea_orm(belongs_to, from = "tmdb_show", to = "tmdb_id")]
pub show: HasOne<super::shows::Entity>,
/// The season this episode belongs to
#[sea_orm(
belongs_to,
from = "(tmdb_show, tmdb_season)",
to = "(tmdb_show, tmdb_season)"
)]
pub season: HasOne<super::seasons::Entity>,
/// The info for this episode
#[sea_orm(
belongs_to,
from = "(flix_show, flix_season, flix_episode)",
to = "(show_id, season_number, episode_number)"
)]
pub info: HasOne<entity::info::episodes::Entity>,
}
impl ActiveModelBehavior for ActiveModel {}
}
/// Macros for creating tmdb entities
#[cfg(test)]
pub mod test {
macro_rules! make_tmdb_collection {
($db:expr, $id:literal, $flix_id:literal) => {
$crate::entity::tmdb::collections::ActiveModel {
tmdb_id: Set(::flix_tmdb::model::id::CollectionId::from_raw($id)),
flix_id: Set(::flix_model::id::CollectionId::from_raw($flix_id)),
last_update: Set(::chrono::NaiveDate::from_yo_opt(1, 1).expect("from_yo_opt")),
movie_count: Set(::core::default::Default::default()),
}
.insert($db)
.await
.expect("insert");
};
}
pub(crate) use make_tmdb_collection;
macro_rules! make_tmdb_movie {
($db:expr, $id:literal, $flix_id:literal) => {
$crate::entity::tmdb::movies::ActiveModel {
tmdb_id: Set(::flix_tmdb::model::id::MovieId::from_raw($id)),
flix_id: Set(::flix_model::id::MovieId::from_raw($flix_id)),
last_update: Set(::chrono::NaiveDate::from_yo_opt(1, 1).expect("from_yo_opt")),
runtime: Set(::core::default::Default::default()),
collection_id: Set(None),
}
.insert($db)
.await
.expect("insert");
};
}
pub(crate) use make_tmdb_movie;
macro_rules! make_tmdb_show {
($db:expr, $id:literal, $flix_id:literal) => {
$crate::entity::tmdb::shows::ActiveModel {
tmdb_id: Set(::flix_tmdb::model::id::ShowId::from_raw($id)),
flix_id: Set(::flix_model::id::ShowId::from_raw($flix_id)),
last_update: Set(::chrono::NaiveDate::from_yo_opt(1, 1).expect("from_yo_opt")),
number_of_seasons: Set(::core::default::Default::default()),
}
.insert($db)
.await
.expect("insert");
};
}
pub(crate) use make_tmdb_show;
macro_rules! make_tmdb_season {
($db:expr, $show:literal, $season:literal, $flix_show:literal, $flix_season:literal) => {
$crate::entity::tmdb::seasons::ActiveModel {
tmdb_show: Set(::flix_tmdb::model::id::ShowId::from_raw($show)),
tmdb_season: Set($season),
flix_show: Set(::flix_model::id::ShowId::from_raw($flix_show)),
flix_season: Set($flix_season),
last_update: Set(::chrono::NaiveDate::from_yo_opt(1, 1).expect("from_yo_opt")),
}
.insert($db)
.await
.expect("insert");
};
}
pub(crate) use make_tmdb_season;
macro_rules! make_tmdb_episode {
($db:expr, $show:literal, $season:literal, $episode:literal, $flix_show:literal, $flix_season:literal, $flix_episode:literal) => {
$crate::entity::tmdb::episodes::ActiveModel {
tmdb_show: Set(::flix_tmdb::model::id::ShowId::from_raw($show)),
tmdb_season: Set($season),
tmdb_episode: Set($episode),
flix_show: Set(::flix_model::id::ShowId::from_raw($flix_show)),
flix_season: Set($flix_season),
flix_episode: Set($flix_episode),
last_update: Set(::chrono::NaiveDate::from_yo_opt(1, 1).expect("from_yo_opt")),
runtime: Set(::core::default::Default::default()),
}
.insert($db)
.await
.expect("insert");
};
}
pub(crate) use make_tmdb_episode;
}
#[cfg(test)]
mod tests {
use core::time::Duration;
use flix_model::id::{CollectionId, MovieId, ShowId};
use flix_tmdb::model::id::{
CollectionId as TmdbCollectionId, MovieId as TmdbMovieId, ShowId as TmdbShowId,
};
use chrono::NaiveDate;
use sea_orm::ActiveValue::{NotSet, Set};
use sea_orm::entity::prelude::*;
use sea_orm::sqlx::error::ErrorKind;
use crate::entity::info::test::{
make_info_collection, make_info_episode, make_info_movie, make_info_season, make_info_show,
};
use crate::tests::new_initialized_memory_db;
use super::super::tests::get_error_kind;
use super::super::tests::notsettable;
use super::test::{
make_tmdb_collection, make_tmdb_episode, make_tmdb_movie, make_tmdb_season, make_tmdb_show,
};
#[tokio::test]
async fn use_test_macros() {
let db = new_initialized_memory_db().await;
make_info_collection!(&db, 1);
make_info_movie!(&db, 1);
make_info_show!(&db, 1);
make_info_season!(&db, 1, 1);
make_info_episode!(&db, 1, 1, 1);
make_tmdb_collection!(&db, 1, 1);
make_tmdb_movie!(&db, 1, 1);
make_tmdb_show!(&db, 1, 1);
make_tmdb_season!(&db, 1, 1, 1, 1);
make_tmdb_episode!(&db, 1, 1, 1, 1, 1, 1);
}
#[tokio::test]
async fn test_round_trip_collections() {
let db = new_initialized_memory_db().await;
macro_rules! assert_collection {
($db:expr, $id:literal, $tid:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_collection!(@insert, $db, $id, $tid $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.tmdb_id, TmdbCollectionId::from_raw($tid));
assert_eq!(model.flix_id, CollectionId::from_raw($id));
assert_eq!(model.last_update, NaiveDate::from_yo_opt($id, 1).expect("from_yo_opt"));
assert_eq!(model.movie_count, $id);
};
($db:expr, $id:literal, $tid:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_collection!(@insert, $db, $id, $tid $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
};
(@insert, $db:expr, $id:literal, $tid:literal $(; $($skip:ident),+)?) => {
super::collections::ActiveModel {
tmdb_id: notsettable!(tmdb_id, TmdbCollectionId::from_raw($tid) $(, $($skip),+)?),
flix_id: notsettable!(flix_id, CollectionId::from_raw($id) $(, $($skip),+)?),
last_update: notsettable!(last_update, NaiveDate::from_yo_opt($id, 1).expect("from_yo_opt") $(, $($skip),+)?),
movie_count: notsettable!(movie_count, $id $(, $($skip),+)?),
}.insert($db).await
};
}
assert_collection!(&db, 1, 1, ForeignKeyViolation);
make_info_collection!(&db, 1);
assert_collection!(&db, 1, 1, Success);
assert_collection!(&db, 1, 1, UniqueViolation);
assert_collection!(&db, 1, 2, UniqueViolation);
assert_collection!(&db, 2, 1, UniqueViolation);
make_info_collection!(&db, 2);
assert_collection!(&db, 2, 2, Success);
make_info_collection!(&db, 3);
assert_collection!(&db, 3, 3, Success; tmdb_id);
assert_collection!(&db, 4, 4, NotNullViolation; flix_id);
assert_collection!(&db, 5, 5, NotNullViolation; last_update);
assert_collection!(&db, 6, 6, NotNullViolation; movie_count);
}
#[tokio::test]
async fn test_round_trip_movies() {
let db = new_initialized_memory_db().await;
macro_rules! assert_movie {
($db:expr, $id:literal, $tid:literal, $cid:expr, Success $(; $($skip:ident),+)?) => {
let model = assert_movie!(@insert, $db, $id, $tid, $cid $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.tmdb_id, TmdbMovieId::from_raw($tid));
assert_eq!(model.flix_id, MovieId::from_raw($id));
assert_eq!(model.last_update, NaiveDate::from_yo_opt($id, 1).expect("from_yo_opt"));
assert_eq!(model.runtime, Duration::from_secs($tid).into());
assert_eq!(model.collection_id, $cid.map(TmdbCollectionId::from_raw));
};
($db:expr, $id:literal, $tid:literal, $cid:expr, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_movie!(@insert, $db, $id, $tid, $cid $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
};
(@insert, $db:expr, $id:literal, $tid:literal, $cid:expr $(; $($skip:ident),+)?) => {
super::movies::ActiveModel {
tmdb_id: notsettable!(tmdb_id, TmdbMovieId::from_raw($tid) $(, $($skip),+)?),
flix_id: notsettable!(flix_id, MovieId::from_raw($id) $(, $($skip),+)?),
last_update: notsettable!(last_update, NaiveDate::from_yo_opt($id, 1).expect("from_yo_opt") $(, $($skip),+)?),
runtime: notsettable!(runtime, Duration::from_secs($tid).into() $(, $($skip),+)?),
collection_id: notsettable!(collection_id, $cid.map(TmdbCollectionId::from_raw) $(, $($skip),+)?),
}.insert($db).await
};
}
assert_movie!(&db, 1, 1, None, ForeignKeyViolation);
make_info_movie!(&db, 1);
assert_movie!(&db, 1, 1, None, Success);
assert_movie!(&db, 1, 1, None, UniqueViolation);
make_info_movie!(&db, 2);
assert_movie!(&db, 2, 2, Some(2), ForeignKeyViolation);
make_info_collection!(&db, 2);
make_tmdb_collection!(&db, 2, 2);
assert_movie!(&db, 2, 2, Some(2), Success);
assert_movie!(&db, 1, 2, None, UniqueViolation);
assert_movie!(&db, 2, 1, None, UniqueViolation);
make_info_movie!(&db, 3);
assert_movie!(&db, 3, 3, None, Success; tmdb_id);
assert_movie!(&db, 4, 4, None, NotNullViolation; flix_id);
assert_movie!(&db, 5, 5, None, NotNullViolation; last_update);
assert_movie!(&db, 6, 6, None, NotNullViolation; runtime);
assert_movie!(&db, 7, 7, None, ForeignKeyViolation; collection_id);
}
#[tokio::test]
async fn test_round_trip_shows() {
let db = new_initialized_memory_db().await;
macro_rules! assert_show {
($db:expr, $id:literal, $tid:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_show!(@insert, $db, $id, $tid $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.tmdb_id, TmdbShowId::from_raw($tid));
assert_eq!(model.flix_id, ShowId::from_raw($id));
assert_eq!(model.last_update, NaiveDate::from_yo_opt(2000, $tid).expect("NaiveDate::from_yo_opt"));
assert_eq!(model.number_of_seasons, $id);
};
($db:expr, $id:literal, $tid:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_show!(@insert, $db, $id, $tid $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(
get_error_kind(model).expect("get_error_kind"),
ErrorKind::$error
);
};
(@insert, $db:expr, $id:literal, $tid:literal $(; $($skip:ident),+)?) => {
super::shows::ActiveModel {
tmdb_id: notsettable!(tmdb_id, TmdbShowId::from_raw($tid) $(, $($skip),+)?),
flix_id: notsettable!(flix_id, ShowId::from_raw($id) $(, $($skip),+)?),
last_update: notsettable!(last_update, NaiveDate::from_yo_opt(2000, $tid).expect("NaiveDate::from_yo_opt") $(, $($skip),+)?),
number_of_seasons: notsettable!(number_of_seasons, $id $(, $($skip),+)?),
}.insert($db).await
};
}
assert_show!(&db, 1, 1, ForeignKeyViolation);
make_info_show!(&db, 1);
assert_show!(&db, 1, 1, Success);
assert_show!(&db, 1, 1, UniqueViolation);
assert_show!(&db, 1, 2, UniqueViolation);
assert_show!(&db, 2, 1, UniqueViolation);
make_info_show!(&db, 2);
assert_show!(&db, 2, 2, Success);
make_info_show!(&db, 3);
assert_show!(&db, 3, 3, Success; tmdb_id);
assert_show!(&db, 4, 4, NotNullViolation; flix_id);
assert_show!(&db, 5, 5, NotNullViolation; last_update);
assert_show!(&db, 6, 6, NotNullViolation; number_of_seasons);
}
#[tokio::test]
async fn test_round_trip_seasons() {
let db = new_initialized_memory_db().await;
macro_rules! assert_season {
($db:expr, $show:literal, $season:literal, $tshow:literal, $tseason:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_season!(@insert, $db, $show, $season, $tshow, $tseason $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.tmdb_show, TmdbShowId::from_raw($tshow));
assert_eq!(model.tmdb_season, $tseason);
assert_eq!(model.flix_show, ShowId::from_raw($show));
assert_eq!(model.flix_season, $season);
assert_eq!(model.last_update, NaiveDate::from_yo_opt(2000, $tshow).expect("NaiveDate::from_yo_opt"));
};
($db:expr, $show:literal, $season:literal, $tshow:literal, $tseason:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_season!(@insert, $db, $show, $season, $tshow, $tseason $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(
get_error_kind(model).expect("get_error_kind"),
ErrorKind::$error
);
};
(@insert, $db:expr, $show:literal, $season:literal, $tshow:literal, $tseason:literal $(; $($skip:ident),+)?) => {
super::seasons::ActiveModel {
tmdb_show: notsettable!(tmdb_show, TmdbShowId::from_raw($tshow) $(, $($skip),+)?),
tmdb_season: notsettable!(tmdb_season, $tseason $(, $($skip),+)?),
flix_show: notsettable!(flix_show, ShowId::from_raw($show) $(, $($skip),+)?),
flix_season: notsettable!(flix_season, $season $(, $($skip),+)?),
last_update: notsettable!(last_update, NaiveDate::from_yo_opt(2000, $tshow).expect("NaiveDate::from_yo_opt") $(, $($skip),+)?),
}.insert($db).await
};
}
make_info_show!(&db, 1);
make_tmdb_show!(&db, 1, 1);
assert_season!(&db, 1, 1, 1, 1, ForeignKeyViolation);
make_info_season!(&db, 1, 1);
assert_season!(&db, 1, 1, 1, 1, Success);
assert_season!(&db, 1, 1, 1, 1, UniqueViolation);
assert_season!(&db, 1, 1, 2, 1, UniqueViolation);
assert_season!(&db, 2, 1, 1, 1, UniqueViolation);
make_info_season!(&db, 1, 2);
assert_season!(&db, 1, 2, 1, 2, Success);
assert_season!(&db, 1, 3, 1, 3, NotNullViolation; tmdb_show);
assert_season!(&db, 1, 4, 1, 4, NotNullViolation; tmdb_season);
assert_season!(&db, 1, 5, 1, 5, NotNullViolation; flix_show);
assert_season!(&db, 1, 6, 1, 6, NotNullViolation; flix_season);
assert_season!(&db, 1, 7, 1, 7, NotNullViolation; last_update);
}
#[tokio::test]
async fn test_round_trip_episodes() {
let db = new_initialized_memory_db().await;
macro_rules! assert_episode {
($db:expr, $show:literal, $season:literal, $episode:literal, $tshow:literal, $tseason:literal, $tepisode:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_episode!(@insert, $db, $show, $season, $episode, $tshow, $tseason, $tepisode $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.tmdb_show, TmdbShowId::from_raw($tshow));
assert_eq!(model.tmdb_season, $tseason);
assert_eq!(model.tmdb_episode, $tepisode);
assert_eq!(model.flix_show, ShowId::from_raw($show));
assert_eq!(model.flix_season, $season);
assert_eq!(model.flix_episode, $episode);
assert_eq!(model.last_update, NaiveDate::from_yo_opt(2000, $tshow).expect("NaiveDate::from_yo_opt"));
assert_eq!(model.runtime, Duration::from_secs($tshow).into());
};
($db:expr, $show:literal, $season:literal, $episode:literal, $tshow:literal, $tseason:literal, $tepisode:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_episode!(@insert, $db, $show, $season, $episode, $tshow, $tseason, $tepisode $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(
get_error_kind(model).expect("get_error_kind"),
ErrorKind::$error
);
};
(@insert, $db:expr, $show:literal, $season:literal, $episode:literal, $tshow:literal, $tseason:literal, $tepisode:literal $(; $($skip:ident),+)?) => {
super::episodes::ActiveModel {
tmdb_show: notsettable!(tmdb_show, TmdbShowId::from_raw($tshow) $(, $($skip),+)?),
tmdb_season: notsettable!(tmdb_season, $tseason $(, $($skip),+)?),
tmdb_episode: notsettable!(tmdb_episode, $tepisode $(, $($skip),+)?),
flix_show: notsettable!(flix_show, ShowId::from_raw($show) $(, $($skip),+)?),
flix_season: notsettable!(flix_season, $season $(, $($skip),+)?),
flix_episode: notsettable!(flix_episode, $episode $(, $($skip),+)?),
last_update: notsettable!(last_update, NaiveDate::from_yo_opt(2000, $tshow).expect("NaiveDate::from_yo_opt") $(, $($skip),+)?),
runtime: notsettable!(runtime, Duration::from_secs($tshow).into() $(, $($skip),+)?),
}.insert($db).await
};
}
make_info_show!(&db, 1);
make_info_season!(&db, 1, 1);
make_tmdb_show!(&db, 1, 1);
make_tmdb_season!(&db, 1, 1, 1, 1);
assert_episode!(&db, 1, 1, 1, 1, 1, 1, ForeignKeyViolation);
make_info_episode!(&db, 1, 1, 1);
assert_episode!(&db, 1, 1, 1, 1, 1, 1, Success);
assert_episode!(&db, 1, 1, 1, 1, 1, 1, UniqueViolation);
assert_episode!(&db, 1, 1, 1, 1, 2, 1, UniqueViolation);
assert_episode!(&db, 1, 1, 1, 2, 1, 1, UniqueViolation);
assert_episode!(&db, 1, 2, 1, 1, 1, 1, UniqueViolation);
assert_episode!(&db, 2, 1, 1, 1, 1, 1, UniqueViolation);
make_info_episode!(&db, 1, 1, 2);
assert_episode!(&db, 1, 1, 2, 1, 1, 2, Success);
assert_episode!(&db, 1, 1, 3, 1, 1, 3, NotNullViolation; tmdb_show);
assert_episode!(&db, 1, 1, 3, 1, 1, 4, NotNullViolation; tmdb_season);
assert_episode!(&db, 1, 1, 3, 1, 1, 5, NotNullViolation; tmdb_episode);
assert_episode!(&db, 1, 1, 3, 1, 1, 6, NotNullViolation; flix_show);
assert_episode!(&db, 1, 1, 3, 1, 1, 7, NotNullViolation; flix_season);
assert_episode!(&db, 1, 1, 3, 1, 1, 8, NotNullViolation; flix_episode);
assert_episode!(&db, 1, 1, 3, 1, 1, 9, NotNullViolation; last_update);
assert_episode!(&db, 1, 1, 3, 1, 1, 10, NotNullViolation; runtime);
}
}
-41
View File
@@ -1,41 +0,0 @@
//! Collection entity
use flix_model::id::CollectionId as FlixId;
use flix_tmdb::model::id::CollectionId;
use chrono::NaiveDate;
use sea_orm::{
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
};
/// The database representation of a tmdb collection
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_tmdb_collections")]
pub struct Model {
/// The collection's TMDB ID
#[sea_orm(primary_key, auto_increment = false)]
pub tmdb_id: CollectionId,
/// The collection's ID
pub flix_id: FlixId,
/// The date of the last update
pub last_update: NaiveDate,
/// The number of movies in the collection
pub movie_count: u16,
}
impl ActiveModelBehavior for ActiveModel {}
/// Relation
#[derive(Debug, EnumIter, DeriveRelation)]
pub enum Relation {
/// The movies that are part of this collection
#[sea_orm(has_many = "super::movies::Entity")]
Movies,
}
impl Related<super::movies::Entity> for Entity {
fn to() -> RelationDef {
Relation::Movies.def()
}
}
-43
View File
@@ -1,43 +0,0 @@
//! Season entity
use flix_model::id::ShowId as FlixId;
use flix_model::numbers::{EpisodeNumber, SeasonNumber};
use flix_tmdb::model::id::ShowId;
use seamantic::model::duration::Seconds;
use chrono::NaiveDate;
use sea_orm::{
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
EnumIter, PrimaryKeyTrait,
};
/// The database representation of a tmdb episode
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_tmdb_episodes")]
pub struct Model {
/// The episode's show's TMDB ID
#[sea_orm(primary_key, auto_increment = false)]
pub tmdb_show: ShowId,
/// The episode's season's TMDB season number
#[sea_orm(primary_key, auto_increment = false)]
pub tmdb_season: SeasonNumber,
/// The episode's TMDB episode number
#[sea_orm(primary_key, auto_increment = false)]
pub tmdb_episode: EpisodeNumber,
/// The episode's show's ID
pub flix_show: FlixId,
/// The episode's season's number
pub flix_season: SeasonNumber,
/// The episode's number
pub flix_episode: EpisodeNumber,
/// The date of the last update
pub last_update: NaiveDate,
/// The episode's runtime in seconds
pub runtime: Seconds,
}
impl ActiveModelBehavior for ActiveModel {}
/// Relation
#[derive(Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
-278
View File
@@ -1,278 +0,0 @@
//! This module contains entities for storing dynamic data from TMDB
pub mod collections;
pub mod movies;
pub mod episodes;
pub mod seasons;
pub mod shows;
#[cfg(test)]
mod tests {
use core::time::Duration;
use flix_model::id::{CollectionId, MovieId, ShowId};
use flix_tmdb::model::id::{
CollectionId as TmdbCollectionId, MovieId as TmdbMovieId, ShowId as TmdbShowId,
};
use chrono::NaiveDate;
use sea_orm::ActiveModelTrait;
use sea_orm::ActiveValue::{NotSet, Set};
use sea_orm::sqlx::error::ErrorKind;
use sea_orm_migration::MigratorTrait;
use crate::migration::Migrator;
use crate::tests::new_memory_db;
use super::super::tests::get_error_kind;
use super::super::tests::notsettable;
use super::super::tests::{
make_flix_collection, make_flix_episode, make_flix_movie, make_flix_season, make_flix_show,
};
#[tokio::test]
async fn test_inserts() {
let db = new_memory_db().await;
Migrator::up(&db, None).await.expect("up");
// Collections
macro_rules! assert_collection {
($db:expr, $id:literal, $tid:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_collection!(@insert, $db, $id, $tid $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.tmdb_id, TmdbCollectionId::from_raw($tid));
assert_eq!(model.flix_id, CollectionId::from_raw($id));
assert_eq!(model.last_update, NaiveDate::from_yo_opt(2000, $tid).expect("NaiveDate::from_yo_opt"));
assert_eq!(model.movie_count, $id);
};
($db:expr, $id:literal, $tid:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_collection!(@insert, $db, $id, $tid $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
};
(@insert, $db:expr, $id:literal, $tid:literal $(; $($skip:ident),+)?) => {
super::collections::ActiveModel {
tmdb_id: notsettable!(tmdb_id, TmdbCollectionId::from_raw($tid) $(, $($skip),+)?),
flix_id: notsettable!(flix_id, CollectionId::from_raw($id) $(, $($skip),+)?),
last_update: notsettable!(last_update, NaiveDate::from_yo_opt(2000, $tid).expect("NaiveDate::from_yo_opt") $(, $($skip),+)?),
movie_count: notsettable!(movie_count, $id $(, $($skip),+)?),
}.insert($db).await
};
}
assert_collection!(&db, 1, 1, ForeignKeyViolation);
make_flix_collection!(&db, 1);
make_flix_collection!(&db, 2);
make_flix_collection!(&db, 3);
assert_collection!(&db, 1, 1, Success);
assert_collection!(&db, 1, 1, UniqueViolation);
assert_collection!(&db, 1, 2, UniqueViolation);
assert_collection!(&db, 2, 1, UniqueViolation);
assert_collection!(&db, 2, 2, Success);
assert_collection!(&db, 3, 3, Success; tmdb_id);
assert_collection!(&db, 4, 4, NotNullViolation; flix_id);
assert_collection!(&db, 5, 5, NotNullViolation; last_update);
assert_collection!(&db, 6, 6, NotNullViolation; movie_count);
// Movies
macro_rules! assert_movie {
($db:expr, $id:literal, $tid:literal, $cid:expr, Success $(; $($skip:ident),+)?) => {
let model = assert_movie!(@insert, $db, $id, $tid, $cid $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.tmdb_id, TmdbMovieId::from_raw($tid));
assert_eq!(model.flix_id, MovieId::from_raw($id));
assert_eq!(model.last_update, NaiveDate::from_yo_opt(2000, $tid).expect("NaiveDate::from_yo_opt"));
assert_eq!(model.runtime, Duration::from_secs($tid).into());
assert_eq!(model.collection, $cid);
};
($db:expr, $id:literal, $tid:literal, $cid:expr, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_movie!(@insert, $db, $id, $tid, $cid $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
};
(@insert, $db:expr, $id:literal, $tid:literal, $cid:expr $(; $($skip:ident),+)?) => {
super::movies::ActiveModel {
tmdb_id: notsettable!(tmdb_id, TmdbMovieId::from_raw($tid) $(, $($skip),+)?),
flix_id: notsettable!(flix_id, MovieId::from_raw($id) $(, $($skip),+)?),
last_update: notsettable!(last_update, NaiveDate::from_yo_opt(2000, $tid).expect("NaiveDate::from_yo_opt") $(, $($skip),+)?),
runtime: notsettable!(runtime, Duration::from_secs($tid).into() $(, $($skip),+)?),
collection: notsettable!(collection, $cid $(, $($skip),+)?),
}.insert($db).await
};
}
assert_movie!(
&db,
1,
1,
Some(TmdbCollectionId::from_raw(1)),
ForeignKeyViolation
);
make_flix_movie!(&db, 1);
make_flix_movie!(&db, 2);
make_flix_movie!(&db, 3);
assert_movie!(&db, 1, 1, Some(TmdbCollectionId::from_raw(1)), Success);
assert_movie!(&db, 1, 1, None, UniqueViolation);
assert_movie!(&db, 1, 2, None, UniqueViolation);
assert_movie!(&db, 2, 1, None, UniqueViolation);
assert_movie!(&db, 2, 2, Some(TmdbCollectionId::from_raw(1)), Success);
assert_movie!(&db, 3, 3, None, Success; tmdb_id);
assert_movie!(&db, 4, 4, None, NotNullViolation; flix_id);
assert_movie!(&db, 5, 5, None, NotNullViolation; last_update);
assert_movie!(&db, 6, 6, None, NotNullViolation; runtime);
assert_movie!(&db, 7, 7, None, ForeignKeyViolation; collection); // Must be `Set(None)`
// Shows
macro_rules! assert_show {
($db:expr, $id:literal, $tid:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_show!(@insert, $db, $id, $tid $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.tmdb_id, TmdbShowId::from_raw($tid));
assert_eq!(model.flix_id, ShowId::from_raw($id));
assert_eq!(model.last_update, NaiveDate::from_yo_opt(2000, $tid).expect("NaiveDate::from_yo_opt"));
assert_eq!(model.number_of_seasons, $id);
};
($db:expr, $id:literal, $tid:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_show!(@insert, $db, $id, $tid $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(
get_error_kind(model).expect("get_error_kind"),
ErrorKind::$error
);
};
(@insert, $db:expr, $id:literal, $tid:literal $(; $($skip:ident),+)?) => {
super::shows::ActiveModel {
tmdb_id: notsettable!(tmdb_id, TmdbShowId::from_raw($tid) $(, $($skip),+)?),
flix_id: notsettable!(flix_id, ShowId::from_raw($id) $(, $($skip),+)?),
last_update: notsettable!(last_update, NaiveDate::from_yo_opt(2000, $tid).expect("NaiveDate::from_yo_opt") $(, $($skip),+)?),
number_of_seasons: notsettable!(number_of_seasons, $id $(, $($skip),+)?),
}.insert($db).await
};
}
assert_show!(&db, 1, 1, ForeignKeyViolation);
make_flix_show!(&db, 1);
make_flix_show!(&db, 2);
make_flix_show!(&db, 3);
assert_show!(&db, 1, 1, Success);
assert_show!(&db, 1, 1, UniqueViolation);
assert_show!(&db, 1, 2, UniqueViolation);
assert_show!(&db, 2, 1, UniqueViolation);
assert_show!(&db, 2, 2, Success);
assert_show!(&db, 3, 3, Success; tmdb_id);
assert_show!(&db, 4, 4, NotNullViolation; flix_id);
assert_show!(&db, 5, 5, NotNullViolation; last_update);
assert_show!(&db, 6, 6, NotNullViolation; number_of_seasons);
// Seasons
macro_rules! assert_season {
($db:expr, $show:literal, $season:literal, $tshow:literal, $tseason:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_season!(@insert, $db, $show, $season, $tshow, $tseason $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.tmdb_show, TmdbShowId::from_raw($tshow));
assert_eq!(model.tmdb_season, $tseason);
assert_eq!(model.flix_show, ShowId::from_raw($show));
assert_eq!(model.flix_season, $season);
assert_eq!(model.last_update, NaiveDate::from_yo_opt(2000, $tshow).expect("NaiveDate::from_yo_opt"));
};
($db:expr, $show:literal, $season:literal, $tshow:literal, $tseason:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_season!(@insert, $db, $show, $season, $tshow, $tseason $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(
get_error_kind(model).expect("get_error_kind"),
ErrorKind::$error
);
};
(@insert, $db:expr, $show:literal, $season:literal, $tshow:literal, $tseason:literal $(; $($skip:ident),+)?) => {
super::seasons::ActiveModel {
tmdb_show: notsettable!(tmdb_show, TmdbShowId::from_raw($tshow) $(, $($skip),+)?),
tmdb_season: notsettable!(tmdb_season, $tseason $(, $($skip),+)?),
flix_show: notsettable!(flix_show, ShowId::from_raw($show) $(, $($skip),+)?),
flix_season: notsettable!(flix_season, $season $(, $($skip),+)?),
last_update: notsettable!(last_update, NaiveDate::from_yo_opt(2000, $tshow).expect("NaiveDate::from_yo_opt") $(, $($skip),+)?),
}.insert($db).await
};
}
assert_season!(&db, 1, 1, 1, 1, ForeignKeyViolation);
make_flix_season!(&db, 1, 1);
make_flix_season!(&db, 1, 2);
assert_season!(&db, 1, 1, 1, 1, Success);
assert_season!(&db, 1, 1, 1, 1, UniqueViolation);
assert_season!(&db, 1, 1, 2, 1, UniqueViolation);
assert_season!(&db, 2, 1, 1, 1, UniqueViolation);
assert_season!(&db, 1, 2, 1, 2, Success);
assert_season!(&db, 1, 3, 1, 3, NotNullViolation; tmdb_show);
assert_season!(&db, 1, 4, 1, 4, NotNullViolation; tmdb_season);
assert_season!(&db, 1, 5, 1, 5, NotNullViolation; flix_show);
assert_season!(&db, 1, 6, 1, 6, NotNullViolation; flix_season);
assert_season!(&db, 1, 7, 1, 7, NotNullViolation; last_update);
// Episodes
macro_rules! assert_episode {
($db:expr, $show:literal, $season:literal, $episode:literal, $tshow:literal, $tseason:literal, $tepisode:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_episode!(@insert, $db, $show, $season, $episode, $tshow, $tseason, $tepisode $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.tmdb_show, TmdbShowId::from_raw($tshow));
assert_eq!(model.tmdb_season, $tseason);
assert_eq!(model.tmdb_episode, $tepisode);
assert_eq!(model.flix_show, ShowId::from_raw($show));
assert_eq!(model.flix_season, $season);
assert_eq!(model.flix_episode, $episode);
assert_eq!(model.last_update, NaiveDate::from_yo_opt(2000, $tshow).expect("NaiveDate::from_yo_opt"));
assert_eq!(model.runtime, Duration::from_secs($tshow).into());
};
($db:expr, $show:literal, $season:literal, $episode:literal, $tshow:literal, $tseason:literal, $tepisode:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_episode!(@insert, $db, $show, $season, $episode, $tshow, $tseason, $tepisode $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(
get_error_kind(model).expect("get_error_kind"),
ErrorKind::$error
);
};
(@insert, $db:expr, $show:literal, $season:literal, $episode:literal, $tshow:literal, $tseason:literal, $tepisode:literal $(; $($skip:ident),+)?) => {
super::episodes::ActiveModel {
tmdb_show: notsettable!(tmdb_show, TmdbShowId::from_raw($tshow) $(, $($skip),+)?),
tmdb_season: notsettable!(tmdb_season, $tseason $(, $($skip),+)?),
tmdb_episode: notsettable!(tmdb_episode, $tepisode $(, $($skip),+)?),
flix_show: notsettable!(flix_show, ShowId::from_raw($show) $(, $($skip),+)?),
flix_season: notsettable!(flix_season, $season $(, $($skip),+)?),
flix_episode: notsettable!(flix_episode, $episode $(, $($skip),+)?),
last_update: notsettable!(last_update, NaiveDate::from_yo_opt(2000, $tshow).expect("NaiveDate::from_yo_opt") $(, $($skip),+)?),
runtime: notsettable!(runtime, Duration::from_secs($tshow).into() $(, $($skip),+)?),
}.insert($db).await
};
}
assert_episode!(&db, 1, 1, 1, 1, 1, 1, ForeignKeyViolation);
make_flix_episode!(&db, 1, 1, 1);
make_flix_episode!(&db, 1, 1, 2);
assert_episode!(&db, 1, 1, 1, 1, 1, 1, Success);
assert_episode!(&db, 1, 1, 1, 1, 1, 1, UniqueViolation);
assert_episode!(&db, 1, 1, 1, 1, 2, 1, UniqueViolation);
assert_episode!(&db, 1, 1, 1, 2, 1, 1, UniqueViolation);
assert_episode!(&db, 1, 2, 1, 1, 1, 1, UniqueViolation);
assert_episode!(&db, 2, 1, 1, 1, 1, 1, UniqueViolation);
assert_episode!(&db, 1, 1, 2, 1, 1, 2, Success);
assert_episode!(&db, 1, 1, 3, 1, 1, 3, NotNullViolation; tmdb_show);
assert_episode!(&db, 1, 1, 3, 1, 1, 4, NotNullViolation; tmdb_season);
assert_episode!(&db, 1, 1, 3, 1, 1, 5, NotNullViolation; tmdb_episode);
assert_episode!(&db, 1, 1, 3, 1, 1, 6, NotNullViolation; flix_show);
assert_episode!(&db, 1, 1, 3, 1, 1, 7, NotNullViolation; flix_season);
assert_episode!(&db, 1, 1, 3, 1, 1, 8, NotNullViolation; flix_episode);
assert_episode!(&db, 1, 1, 3, 1, 1, 9, NotNullViolation; last_update);
assert_episode!(&db, 1, 1, 3, 1, 1, 10, NotNullViolation; runtime);
}
}
-51
View File
@@ -1,51 +0,0 @@
//! Movie entity
use flix_model::id::MovieId as FlixId;
use flix_tmdb::model::id::{CollectionId, MovieId};
use seamantic::model::duration::Seconds;
use chrono::NaiveDate;
use sea_orm::{
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
};
/// The database representation of a tmdb movie
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_tmdb_movies")]
pub struct Model {
/// The movie's TMDB ID
#[sea_orm(primary_key, auto_increment = false)]
pub tmdb_id: MovieId,
/// The movie's ID
pub flix_id: FlixId,
/// The date of the last update
pub last_update: NaiveDate,
/// The movie's runtime in seconds
pub runtime: Seconds,
/// The TMDB ID of the collection this movie belongs to
pub collection: Option<CollectionId>,
}
impl ActiveModelBehavior for ActiveModel {}
/// Relation
#[derive(Debug, EnumIter, DeriveRelation)]
pub enum Relation {
/// The collection this movie belongs to
#[sea_orm(
belongs_to = "super::collections::Entity",
from = "Column::Collection",
to = "super::collections::Column::TmdbId",
on_update = "Cascade",
on_delete = "Cascade"
)]
Collection,
}
impl Related<super::collections::Entity> for Entity {
fn to() -> RelationDef {
Relation::Collection.def()
}
}
-51
View File
@@ -1,51 +0,0 @@
//! Season entity
use flix_model::id::ShowId as FlixId;
use flix_model::numbers::SeasonNumber;
use flix_tmdb::model::id::ShowId;
use chrono::NaiveDate;
use sea_orm::{
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
};
/// The database representation of a tmdb season
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_tmdb_seasons")]
pub struct Model {
/// The season's show's TMDB ID
#[sea_orm(primary_key, auto_increment = false)]
pub tmdb_show: ShowId,
/// The season's TMDB season number
#[sea_orm(primary_key, auto_increment = false)]
pub tmdb_season: SeasonNumber,
/// The season's show's ID
pub flix_show: FlixId,
/// The season's number
pub flix_season: SeasonNumber,
/// The date of the last update
pub last_update: NaiveDate,
}
impl ActiveModelBehavior for ActiveModel {}
/// Relation
#[derive(Debug, EnumIter, DeriveRelation)]
pub enum Relation {
/// The show this season belongs to
#[sea_orm(
belongs_to = "super::shows::Entity",
from = "Column::TmdbShow",
to = "super::shows::Column::TmdbId",
on_update = "Cascade",
on_delete = "Cascade"
)]
Show,
}
impl Related<super::shows::Entity> for Entity {
fn to() -> RelationDef {
Relation::Show.def()
}
}
-41
View File
@@ -1,41 +0,0 @@
//! Show entity
use flix_model::id::ShowId as FlixId;
use flix_tmdb::model::id::ShowId;
use chrono::NaiveDate;
use sea_orm::{
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
};
/// The database representation of a tmdb show
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_tmdb_shows")]
pub struct Model {
/// The show's TMDB ID
#[sea_orm(primary_key, auto_increment = false)]
pub tmdb_id: ShowId,
/// The show's ID
pub flix_id: FlixId,
/// The movie's runtime in seconds
pub last_update: NaiveDate,
/// The number of seasons the show has
pub number_of_seasons: u32,
}
impl ActiveModelBehavior for ActiveModel {}
/// Relation
#[derive(Debug, EnumIter, DeriveRelation)]
pub enum Relation {
/// The seasons that are part of this show
#[sea_orm(has_many = "super::seasons::Entity")]
Seasons,
}
impl Related<super::seasons::Entity> for Entity {
fn to() -> RelationDef {
Relation::Seasons.def()
}
}
+555
View File
@@ -0,0 +1,555 @@
//! This module contains entities for storing watched information
/// Collection entity
pub mod collections {
use flix_model::id::{CollectionId, RawId};
use chrono::NaiveDate;
use sea_orm::entity::prelude::*;
use crate::entity;
/// The database representation of a watched movie
#[sea_orm::model]
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_watched_collections")]
pub struct Model {
/// The collection's ID
#[sea_orm(primary_key, auto_increment = false)]
pub id: CollectionId,
/// The user's ID
#[sea_orm(primary_key, auto_increment = false)]
pub user_id: RawId,
/// The date this collection was watched
pub watched_date: NaiveDate,
/// The info for this collection
#[sea_orm(belongs_to, relation_enum = "Info", from = "id", to = "id")]
pub info: HasOne<entity::info::collections::Entity>,
/// The content for this collection
#[sea_orm(belongs_to, relation_enum = "Content", from = "id", to = "id", skip_fk)]
pub content: HasOne<entity::content::collections::Entity>,
}
impl ActiveModelBehavior for ActiveModel {}
}
/// Movie entity
pub mod movies {
use flix_model::id::{MovieId, RawId};
use chrono::NaiveDate;
use sea_orm::entity::prelude::*;
use crate::entity;
/// The database representation of a watched movie
#[sea_orm::model]
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_watched_movies")]
pub struct Model {
/// The movie's ID
#[sea_orm(primary_key, auto_increment = false)]
pub id: MovieId,
/// The user's ID
#[sea_orm(primary_key, auto_increment = false)]
pub user_id: RawId,
/// The date this movie was watched
pub watched_date: NaiveDate,
/// The info for this movie
#[sea_orm(belongs_to, from = "id", to = "id")]
pub info: HasOne<entity::info::movies::Entity>,
/// The content for this movie
#[sea_orm(belongs_to, relation_enum = "Content", from = "id", to = "id", skip_fk)]
pub content: HasOne<entity::content::movies::Entity>,
}
impl ActiveModelBehavior for ActiveModel {}
}
/// Show entity
pub mod shows {
use flix_model::id::{RawId, ShowId};
use chrono::NaiveDate;
use sea_orm::entity::prelude::*;
use crate::entity;
/// The database representation of a watched movie
#[sea_orm::model]
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_watched_shows")]
pub struct Model {
/// The show's ID
#[sea_orm(primary_key, auto_increment = false)]
pub id: ShowId,
/// The user's ID
#[sea_orm(primary_key, auto_increment = false)]
pub user_id: RawId,
/// The date this show was watched
pub watched_date: NaiveDate,
/// The info for this show
#[sea_orm(belongs_to, relation_enum = "Info", from = "id", to = "id")]
pub info: HasOne<entity::info::shows::Entity>,
/// The content for this show
#[sea_orm(belongs_to, relation_enum = "Content", from = "id", to = "id", skip_fk)]
pub content: HasOne<entity::content::shows::Entity>,
}
impl ActiveModelBehavior for ActiveModel {}
}
/// Season entity
pub mod seasons {
use flix_model::id::{RawId, ShowId};
use flix_model::numbers::SeasonNumber;
use chrono::NaiveDate;
use sea_orm::entity::prelude::*;
use crate::entity;
/// The database representation of a watched movie
#[sea_orm::model]
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_watched_seasons")]
pub struct Model {
/// The season's show's ID
#[sea_orm(primary_key, auto_increment = false)]
pub show_id: ShowId,
/// The season's number
#[sea_orm(primary_key, auto_increment = false)]
pub season_number: SeasonNumber,
/// The user's ID
#[sea_orm(primary_key, auto_increment = false)]
pub user_id: RawId,
/// The date this season was watched
pub watched_date: NaiveDate,
/// The info for this season
#[sea_orm(
belongs_to,
relation_enum = "Info",
from = "(show_id, season_number)",
to = "(show_id, season_number)"
)]
pub info: HasOne<entity::info::seasons::Entity>,
/// The content for this season
#[sea_orm(
belongs_to,
relation_enum = "Content",
from = "(show_id, season_number)",
to = "(show_id, season_number)",
skip_fk
)]
pub content: HasOne<entity::content::seasons::Entity>,
}
impl ActiveModelBehavior for ActiveModel {}
}
/// Episode entity
pub mod episodes {
use flix_model::id::{RawId, ShowId};
use flix_model::numbers::{EpisodeNumber, SeasonNumber};
use chrono::NaiveDate;
use sea_orm::entity::prelude::*;
use crate::entity;
/// The database representation of a watched movie
#[sea_orm::model]
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_watched_episodes")]
pub struct Model {
/// The episode's show's ID
#[sea_orm(primary_key, auto_increment = false)]
pub show_id: ShowId,
/// The episode's season's number
#[sea_orm(primary_key, auto_increment = false)]
pub season_number: SeasonNumber,
/// The episode's number
#[sea_orm(primary_key, auto_increment = false)]
pub episode_number: EpisodeNumber,
/// The user's ID
#[sea_orm(primary_key, auto_increment = false)]
pub user_id: RawId,
/// The date this episode was watched
pub watched_date: NaiveDate,
/// The info for this episode
#[sea_orm(
belongs_to,
relation_enum = "Info",
from = "(show_id, season_number, episode_number)",
to = "(show_id, season_number, episode_number)"
)]
pub info: HasOne<entity::info::episodes::Entity>,
/// The content for this episode
#[sea_orm(
belongs_to,
relation_enum = "Content",
from = "(show_id, season_number, episode_number)",
to = "(show_id, season_number, episode_number)",
skip_fk
)]
pub content: HasOne<entity::content::episodes::Entity>,
}
impl ActiveModelBehavior for ActiveModel {}
}
/// Macros for creating watched entities
#[cfg(test)]
pub mod test {
macro_rules! make_watched_movie {
($db:expr, $id:literal, $user:literal) => {
$crate::entity::watched::movies::ActiveModel {
id: Set(::flix_model::id::MovieId::from_raw($id)),
user_id: Set($user),
watched_date: Set(::chrono::NaiveDate::from_yo_opt(1, 1).expect("from_yo_opt")),
}
.insert($db)
.await
.expect("insert");
};
}
pub(crate) use make_watched_movie;
macro_rules! make_watched_episode {
($db:expr, $show:literal, $season:literal, $episode:literal, $user:literal) => {
$crate::entity::watched::episodes::ActiveModel {
show_id: Set(::flix_model::id::ShowId::from_raw($show)),
season_number: Set($season),
episode_number: Set($episode),
user_id: Set($user),
watched_date: Set(::chrono::NaiveDate::from_yo_opt(1, 1).expect("from_yo_opt")),
}
.insert($db)
.await
.expect("insert");
};
}
pub(crate) use make_watched_episode;
}
#[cfg(test)]
mod tests {
use flix_model::id::{MovieId, ShowId};
use chrono::NaiveDate;
use sea_orm::ActiveValue::{NotSet, Set};
use sea_orm::Condition;
use sea_orm::entity::prelude::*;
use sea_orm::sqlx::error::ErrorKind;
use crate::entity::content::test::{
make_content_collection, make_content_episode, make_content_library, make_content_movie,
make_content_season, make_content_show,
};
use crate::entity::info::test::{
make_info_episode, make_info_movie, make_info_season, make_info_show,
};
use crate::tests::new_initialized_memory_db;
use super::super::tests::get_error_kind;
use super::super::tests::notsettable;
use super::test::{make_watched_episode, make_watched_movie};
#[tokio::test]
async fn use_test_macros() {
let db = new_initialized_memory_db().await;
make_info_movie!(&db, 1);
make_info_show!(&db, 1);
make_info_season!(&db, 1, 1);
make_info_episode!(&db, 1, 1, 1);
make_watched_movie!(&db, 1, 1);
make_watched_episode!(&db, 1, 1, 1, 1);
}
#[tokio::test]
async fn test_round_trip_movies() {
let db = new_initialized_memory_db().await;
macro_rules! assert_movie {
($db:expr, $id:literal, $uid:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_movie!(@insert, $db, $id, $uid $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.id, MovieId::from_raw($id));
assert_eq!(model.user_id, $uid);
assert_eq!(model.watched_date, NaiveDate::from_yo_opt($uid, 1).expect("from_yo_opt"));
};
($db:expr, $id:literal, $uid:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_movie!(@insert, $db, $id, $uid $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
};
(@insert, $db:expr, $id:literal, $uid:literal $(; $($skip:ident),+)?) => {
super::movies::ActiveModel {
id: notsettable!(id, MovieId::from_raw($id) $(, $($skip),+)?),
user_id: notsettable!(user_id, $uid $(, $($skip),+)?),
watched_date: notsettable!(watched_date, NaiveDate::from_yo_opt($uid, 1).expect("from_yo_opt") $(, $($skip),+)?),
}.insert($db).await
};
}
assert_movie!(&db, 1, 1, ForeignKeyViolation);
make_info_movie!(&db, 1);
assert_movie!(&db, 1, 1, Success);
assert_movie!(&db, 1, 2, Success);
assert_movie!(&db, 1, 1, UniqueViolation);
make_info_movie!(&db, 2);
assert_movie!(&db, 2, 1, Success);
assert_movie!(&db, 2, 2, Success);
assert_movie!(&db, 3, 1, NotNullViolation; id);
assert_movie!(&db, 4, 1, NotNullViolation; user_id);
assert_movie!(&db, 5, 1, NotNullViolation; watched_date);
}
#[tokio::test]
async fn test_round_trip_episodes() {
let db = new_initialized_memory_db().await;
macro_rules! assert_episode {
($db:expr, $show:literal, $season:literal, $episode:literal, $uid:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_episode!(@insert, $db, $show, $season, $episode, $uid $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.show_id, ShowId::from_raw($show));
assert_eq!(model.season_number, $season);
assert_eq!(model.episode_number, $episode);
assert_eq!(model.user_id, $uid);
assert_eq!(model.watched_date, NaiveDate::from_yo_opt($uid, 1).expect("from_yo_opt"));
};
($db:expr, $show:literal, $season:literal, $episode:literal, $uid:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_episode!(@insert, $db, $show, $season, $episode, $uid $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
};
(@insert, $db:expr, $show:literal, $season:literal, $episode:literal, $uid:literal $(; $($skip:ident),+)?) => {
super::episodes::ActiveModel {
show_id: notsettable!(show_id, ShowId::from_raw($show) $(, $($skip),+)?),
season_number: notsettable!(season_number, $season $(, $($skip),+)?),
episode_number: notsettable!(episode_number, $episode $(, $($skip),+)?),
user_id: notsettable!(user_id, $uid $(, $($skip),+)?),
watched_date: notsettable!(watched_date, NaiveDate::from_yo_opt($uid, 1).expect("from_yo_opt") $(, $($skip),+)?),
}.insert($db).await
};
}
make_info_show!(&db, 1);
make_info_season!(&db, 1, 1);
make_info_show!(&db, 2);
make_info_season!(&db, 2, 1);
assert_episode!(&db, 1, 1, 1, 1, ForeignKeyViolation);
assert_episode!(&db, 2, 1, 1, 1, ForeignKeyViolation);
make_info_episode!(&db, 1, 1, 1);
make_info_episode!(&db, 2, 1, 1);
assert_episode!(&db, 1, 1, 1, 1, Success);
assert_episode!(&db, 1, 1, 1, 2, Success);
assert_episode!(&db, 2, 1, 1, 1, Success);
assert_episode!(&db, 1, 1, 1, 1, UniqueViolation);
assert_episode!(&db, 3, 1, 1, 1, NotNullViolation; show_id);
assert_episode!(&db, 4, 1, 1, 1, NotNullViolation; season_number);
assert_episode!(&db, 5, 1, 1, 1, NotNullViolation; episode_number);
assert_episode!(&db, 6, 1, 1, 1, NotNullViolation; user_id);
assert_episode!(&db, 7, 1, 1, 1, NotNullViolation; watched_date);
}
#[tokio::test]
async fn test_query_seasons() {
let db = new_initialized_memory_db().await;
macro_rules! assert_season {
($db:expr, $show:literal, $season:literal, $uid:literal, Watched) => {
assert_season!(@find, $db, $show, $season, $uid)
.ok_or(())
.expect("is none");
};
($db:expr, $show:literal, $season:literal, $uid:literal, Unwatched) => {
assert_season!(@find, $db, $show, $season, $uid)
.ok_or(())
.expect_err("is some");
};
(@find, $db:expr, $show:literal, $season:literal, $uid:literal) => {
super::seasons::Entity::find()
.filter(
Condition::all()
.add(super::seasons::Column::ShowId.eq($show))
.add(super::seasons::Column::SeasonNumber.eq($season))
.add(super::seasons::Column::UserId.eq($uid)),
)
.one(&db)
.await
.expect("find.filter.one")
};
}
make_content_library!(&db, 1);
make_content_show!(&db, 1, 1, None);
make_content_season!(&db, 1, 1, 1);
assert_season!(&db, 1, 1, 1, Unwatched);
make_content_episode!(&db, 1, 1, 1, 1);
assert_season!(&db, 1, 1, 1, Unwatched);
make_watched_episode!(&db, 1, 1, 1, 1);
assert_season!(&db, 1, 1, 1, Watched);
assert_season!(&db, 1, 1, 2, Unwatched);
make_content_episode!(&db, 1, 1, 1, 2);
assert_season!(&db, 1, 1, 1, Unwatched);
make_content_season!(&db, 1, 1, 2);
make_content_episode!(&db, 1, 1, 2, 1);
make_content_episode!(&db, 1, 1, 2, 2, >1);
make_info_episode!(&db, 1, 2, 3);
make_content_episode!(&db, 1, 1, 2, 4);
assert_season!(&db, 1, 2, 1, Unwatched);
assert_season!(&db, 1, 2, 2, Unwatched);
assert_season!(&db, 1, 2, 3, Unwatched);
make_watched_episode!(&db, 1, 2, 1, 1);
make_watched_episode!(&db, 1, 2, 1, 2);
make_watched_episode!(&db, 1, 2, 2, 3);
assert_season!(&db, 1, 2, 1, Unwatched);
assert_season!(&db, 1, 2, 2, Unwatched);
assert_season!(&db, 1, 2, 3, Unwatched);
make_watched_episode!(&db, 1, 2, 2, 1);
make_watched_episode!(&db, 1, 2, 2, 2);
make_watched_episode!(&db, 1, 2, 1, 3);
assert_season!(&db, 1, 2, 1, Unwatched);
assert_season!(&db, 1, 2, 2, Unwatched);
assert_season!(&db, 1, 2, 3, Unwatched);
make_watched_episode!(&db, 1, 2, 4, 1);
assert_season!(&db, 1, 2, 1, Watched);
assert_season!(&db, 1, 2, 2, Unwatched);
assert_season!(&db, 1, 2, 3, Unwatched);
}
#[tokio::test]
async fn test_query_shows() {
let db = new_initialized_memory_db().await;
macro_rules! assert_show {
($db:expr, $show:literal, $uid:literal, Watched) => {
assert_show!(@find, $db, $show, $uid)
.ok_or(())
.expect("is none");
};
($db:expr, $show:literal, $uid:literal, Unwatched) => {
assert_show!(@find, $db, $show, $uid)
.ok_or(())
.expect_err("is some");
};
(@find, $db:expr, $show:literal, $uid:literal) => {
super::shows::Entity::find()
.filter(
Condition::all()
.add(super::shows::Column::Id.eq($show))
.add(super::shows::Column::UserId.eq($uid)),
)
.one(&db)
.await
.expect("find.filter.one")
};
}
make_content_library!(&db, 1);
make_content_show!(&db, 1, 1, None);
assert_show!(&db, 1, 1, Unwatched);
make_content_season!(&db, 1, 1, 1);
assert_show!(&db, 1, 1, Unwatched);
make_content_episode!(&db, 1, 1, 1, 1);
assert_show!(&db, 1, 1, Unwatched);
make_watched_episode!(&db, 1, 1, 1, 1);
assert_show!(&db, 1, 1, Watched);
assert_show!(&db, 1, 2, Unwatched);
make_content_episode!(&db, 1, 1, 1, 2);
assert_show!(&db, 1, 1, Unwatched);
assert_show!(&db, 1, 2, Unwatched);
make_watched_episode!(&db, 1, 1, 2, 1);
make_content_season!(&db, 1, 1, 2);
assert_show!(&db, 1, 1, Unwatched);
assert_show!(&db, 1, 2, Unwatched);
make_content_episode!(&db, 1, 1, 2, 1);
assert_show!(&db, 1, 1, Unwatched);
assert_show!(&db, 1, 2, Unwatched);
make_watched_episode!(&db, 1, 2, 1, 1);
assert_show!(&db, 1, 1, Watched);
assert_show!(&db, 1, 2, Unwatched);
}
#[tokio::test]
async fn test_query_collections() {
let db = new_initialized_memory_db().await;
macro_rules! assert_collection {
($db:expr, $id:literal, $uid:literal, Watched) => {
assert_collection!(@find, $db, $id, $uid)
.ok_or(())
.expect("is none");
};
($db:expr, $id:literal, $uid:literal, Unwatched) => {
assert_collection!(@find, $db, $id, $uid)
.ok_or(())
.expect_err("is some");
};
(@find, $db:expr, $id:literal, $uid:literal) => {
super::collections::Entity::find()
.filter(
Condition::all()
.add(super::collections::Column::Id.eq($id))
.add(super::collections::Column::UserId.eq($uid)),
)
.one(&db)
.await
.expect("find.filter.one")
};
}
make_content_library!(&db, 1);
make_content_collection!(&db, 1, 1, None);
assert_collection!(&db, 1, 1, Unwatched);
make_content_movie!(&db, 1, 1, Some(1));
assert_collection!(&db, 1, 1, Unwatched);
make_info_movie!(&db, 9999);
make_watched_movie!(&db, 9999, 1);
assert_collection!(&db, 1, 1, Unwatched);
make_watched_movie!(&db, 1, 1);
assert_collection!(&db, 1, 1, Watched);
make_content_collection!(&db, 1, 2, Some(1));
assert_collection!(&db, 1, 1, Watched);
assert_collection!(&db, 2, 1, Unwatched);
make_content_movie!(&db, 1, 2, Some(2));
assert_collection!(&db, 1, 1, Unwatched);
assert_collection!(&db, 2, 1, Unwatched);
make_watched_movie!(&db, 2, 1);
assert_collection!(&db, 1, 1, Watched);
assert_collection!(&db, 2, 1, Watched);
make_content_show!(&db, 1, 1, Some(2));
assert_collection!(&db, 1, 1, Unwatched);
assert_collection!(&db, 2, 1, Unwatched);
make_content_season!(&db, 1, 1, 1);
make_content_episode!(&db, 1, 1, 1, 1);
make_watched_episode!(&db, 1, 1, 1, 1);
assert_collection!(&db, 1, 1, Watched);
assert_collection!(&db, 2, 1, Watched);
}
}
@@ -1,26 +0,0 @@
//! Collection entity
use flix_model::id::{CollectionId, RawId};
use sea_orm::{
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
EnumIter, PrimaryKeyTrait,
};
/// The database representation of a watched movie
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_watched_collections")]
pub struct Model {
/// The collection's ID
#[sea_orm(primary_key, auto_increment = false)]
pub id: CollectionId,
/// The user's ID
#[sea_orm(primary_key, auto_increment = false)]
pub user_id: RawId,
}
impl ActiveModelBehavior for ActiveModel {}
/// Relation
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
-36
View File
@@ -1,36 +0,0 @@
//! Episode entity
use flix_model::id::{RawId, ShowId};
use flix_model::numbers::{EpisodeNumber, SeasonNumber};
use chrono::NaiveDate;
use sea_orm::{
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
EnumIter, PrimaryKeyTrait,
};
/// The database representation of a watched movie
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_watched_episodes")]
pub struct Model {
/// The episode's show's ID
#[sea_orm(primary_key, auto_increment = false)]
pub show: ShowId,
/// The episode's season's number
#[sea_orm(primary_key, auto_increment = false)]
pub season: SeasonNumber,
/// The episode's number
#[sea_orm(primary_key, auto_increment = false)]
pub episode: EpisodeNumber,
/// The user's ID
#[sea_orm(primary_key, auto_increment = false)]
pub user_id: RawId,
/// The date this episode was watched
pub watched_date: NaiveDate,
}
impl ActiveModelBehavior for ActiveModel {}
/// Relation
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
-289
View File
@@ -1,289 +0,0 @@
//! This module contains entities for storing watched information
pub mod collections;
pub mod movies;
pub mod episodes;
pub mod seasons;
pub mod shows;
#[cfg(test)]
mod tests {
use flix_model::id::{MovieId, ShowId};
use chrono::NaiveDate;
use sea_orm::ActiveValue::{NotSet, Set};
use sea_orm::sqlx::error::ErrorKind;
use sea_orm::{ActiveModelTrait, ColumnTrait, Condition, EntityTrait, QueryFilter};
use sea_orm_migration::MigratorTrait;
use crate::entity::tests::{have_collection, have_library, have_movie, have_season, have_show};
use crate::migration::Migrator;
use crate::tests::new_memory_db;
use super::super::tests::get_error_kind;
use super::super::tests::notsettable;
use super::super::tests::{
have_episode, make_flix_episode, make_flix_movie, make_flix_season, make_flix_show,
};
macro_rules! assert_movie {
($db:expr, $id:literal, $uid:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_movie!(@insert, $db, $id, $uid $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.id, MovieId::from_raw($id));
assert_eq!(model.user_id, $uid);
assert_eq!(model.watched_date, NaiveDate::from_yo_opt(2000, $uid).expect("NaiveDate::from_yo_opt"));
};
($db:expr, $id:literal, $uid:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_movie!(@insert, $db, $id, $uid $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
};
(@insert, $db:expr, $id:literal, $uid:literal $(; $($skip:ident),+)?) => {
super::movies::ActiveModel {
id: notsettable!(id, MovieId::from_raw($id) $(, $($skip),+)?),
user_id: notsettable!(user_id, $uid $(, $($skip),+)?),
watched_date: notsettable!(watched_date, NaiveDate::from_yo_opt(2000, $uid).expect("NaiveDate::from_yo_opt") $(, $($skip),+)?),
}.insert($db).await
};
}
macro_rules! assert_episode {
($db:expr, $show:literal, $season:literal, $episode:literal, $uid:literal, Success $(; $($skip:ident),+)?) => {
let model = assert_episode!(@insert, $db, $show, $season, $episode, $uid $(; $($skip),+)?)
.expect("insert");
assert_eq!(model.show, ShowId::from_raw($show));
assert_eq!(model.season, $season);
assert_eq!(model.episode, $episode);
assert_eq!(model.user_id, $uid);
assert_eq!(model.watched_date, NaiveDate::from_yo_opt(2000, $uid).expect("NaiveDate::from_yo_opt"));
};
($db:expr, $show:literal, $season:literal, $episode:literal, $uid:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_episode!(@insert, $db, $show, $season, $episode, $uid $(; $($skip),+)?)
.expect_err("insert");
assert_eq!(get_error_kind(model).expect("get_error_kind"), ErrorKind::$error);
};
(@insert, $db:expr, $show:literal, $season:literal, $episode:literal, $uid:literal $(; $($skip:ident),+)?) => {
super::episodes::ActiveModel {
show: notsettable!(show, ShowId::from_raw($show) $(, $($skip),+)?),
season: notsettable!(season, $season $(, $($skip),+)?),
episode: notsettable!(episode, $episode $(, $($skip),+)?),
user_id: notsettable!(user_id, $uid $(, $($skip),+)?),
watched_date: notsettable!(watched_date, NaiveDate::from_yo_opt(2000, $uid).expect("NaiveDate::from_yo_opt") $(, $($skip),+)?),
}.insert($db).await
};
}
#[tokio::test]
async fn test_inserts() {
let db = new_memory_db().await;
Migrator::up(&db, None).await.expect("up");
// Movies
assert_movie!(&db, 1, 1, ForeignKeyViolation);
make_flix_movie!(&db, 1);
make_flix_movie!(&db, 2);
assert_movie!(&db, 1, 1, Success);
assert_movie!(&db, 1, 1, UniqueViolation);
assert_movie!(&db, 2, 1, Success);
assert_movie!(&db, 3, 1, NotNullViolation; id);
assert_movie!(&db, 4, 1, NotNullViolation; user_id);
assert_movie!(&db, 5, 1, NotNullViolation; watched_date);
// Episodes
make_flix_show!(&db, 1);
make_flix_season!(&db, 1, 1);
make_flix_show!(&db, 2);
make_flix_season!(&db, 2, 1);
assert_episode!(&db, 1, 1, 1, 1, ForeignKeyViolation);
make_flix_episode!(&db, 1, 1, 1);
make_flix_episode!(&db, 1, 1, 2);
make_flix_episode!(&db, 2, 1, 1);
assert_episode!(&db, 1, 1, 1, 1, Success);
assert_episode!(&db, 1, 1, 1, 1, UniqueViolation);
assert_episode!(&db, 1, 1, 2, 1, Success);
assert_episode!(&db, 2, 1, 1, 1, Success);
assert_episode!(&db, 3, 1, 1, 1, NotNullViolation; show);
assert_episode!(&db, 4, 1, 1, 1, NotNullViolation; season);
assert_episode!(&db, 5, 1, 1, 1, NotNullViolation; episode);
assert_episode!(&db, 6, 1, 1, 1, NotNullViolation; user_id);
assert_episode!(&db, 7, 1, 1, 1, NotNullViolation; watched_date);
}
#[tokio::test]
async fn test_queries() {
let db = new_memory_db().await;
Migrator::up(&db, None).await.expect("up");
have_library!(&db, 1);
// Season + Show
macro_rules! assert_season {
($db:expr, $show:literal, $season:literal, $uid:literal, Watched) => {
assert_season!(@find, $db, $show, $season, $uid)
.ok_or(())
.expect("is none");
};
($db:expr, $show:literal, $season:literal, $uid:literal, Unwatched) => {
assert_season!(@find, $db, $show, $season, $uid)
.ok_or(())
.expect_err("is some");
};
(@find, $db:expr, $show:literal, $season:literal, $uid:literal) => {
super::seasons::Entity::find()
.filter(
Condition::all()
.add(super::seasons::Column::Show.eq($show))
.add(super::seasons::Column::Season.eq($season))
.add(super::seasons::Column::UserId.eq($uid)),
)
.one(&db)
.await
.expect("find.filter.one")
};
}
macro_rules! assert_show {
($db:expr, $show:literal, $uid:literal, Watched) => {
assert_show!(@find, $db, $show, $uid)
.ok_or(())
.expect("is none");
};
($db:expr, $show:literal, $uid:literal, Unwatched) => {
assert_show!(@find, $db, $show, $uid)
.ok_or(())
.expect_err("is some");
};
(@find, $db:expr, $show:literal, $uid:literal) => {
super::shows::Entity::find()
.filter(
Condition::all()
.add(super::shows::Column::Id.eq($show))
.add(super::shows::Column::UserId.eq($uid)),
)
.one(&db)
.await
.expect("find.filter.one")
};
}
have_show!(&db, 1, 1, None);
have_season!(&db, 1, 1, 1);
have_episode!(&db, 1, 1, 1, 1);
assert_episode!(&db, 1, 1, 1, 1, Success);
assert_episode!(&db, 1, 1, 1, 2, Success);
have_episode!(&db, 1, 1, 1, 2, >1); // Covers 2 and 3
make_flix_episode!(&db, 1, 1, 3);
assert_episode!(&db, 1, 1, 2, 1, Success);
assert_episode!(&db, 1, 1, 2, 2, Success);
have_season!(&db, 1, 1, 2);
have_episode!(&db, 1, 1, 2, 1);
assert_episode!(&db, 1, 2, 1, 1, Success);
assert_episode!(&db, 1, 2, 1, 2, Success);
have_episode!(&db, 1, 1, 2, 2);
assert_episode!(&db, 1, 2, 2, 1, Success);
have_episode!(&db, 1, 1, 2, 3);
assert_episode!(&db, 1, 2, 3, 1, Success);
// Add watched episodes that we do not have
make_flix_episode!(&db, 1, 1, 4);
assert_episode!(&db, 1, 1, 4, 1, Success);
make_flix_episode!(&db, 1, 2, 4);
assert_episode!(&db, 1, 2, 4, 2, Success);
make_flix_episode!(&db, 1, 2, 5);
assert_episode!(&db, 1, 2, 5, 2, Success);
assert_season!(&db, 1, 1, 1, Watched);
assert_season!(&db, 1, 1, 2, Watched);
assert_season!(&db, 1, 1, 3, Unwatched);
assert_season!(&db, 1, 2, 1, Watched);
assert_season!(&db, 1, 2, 2, Unwatched);
assert_season!(&db, 1, 2, 3, Unwatched);
assert_season!(&db, 1, 3, 1, Unwatched);
assert_season!(&db, 1, 3, 2, Unwatched);
assert_season!(&db, 1, 3, 3, Unwatched);
assert_show!(&db, 1, 1, Watched);
assert_show!(&db, 1, 2, Unwatched);
assert_show!(&db, 1, 3, Unwatched);
assert_show!(&db, 2, 1, Unwatched);
assert_show!(&db, 2, 2, Unwatched);
assert_show!(&db, 2, 3, Unwatched);
// Collection
macro_rules! assert_collection {
($db:expr, $id:literal, $uid:literal, Watched) => {
assert_collection!(@find, $db, $id, $uid)
.ok_or(())
.expect("is none");
};
($db:expr, $id:literal, $uid:literal, Unwatched) => {
assert_collection!(@find, $db, $id, $uid)
.ok_or(())
.expect_err("is some");
};
(@find, $db:expr, $id:literal, $uid:literal) => {
super::collections::Entity::find()
.filter(
Condition::all()
.add(super::collections::Column::Id.eq($id))
.add(super::collections::Column::UserId.eq($uid)),
)
.one(&db)
.await
.expect("find.filter.one")
};
}
have_collection!(&db, 1, 1, None);
have_movie!(&db, 1, 1, Some(1));
assert_movie!(&db, 1, 1, Success);
assert_movie!(&db, 1, 2, Success);
have_movie!(&db, 1, 2, Some(1));
assert_movie!(&db, 2, 1, Success);
assert_movie!(&db, 2, 2, Success);
have_collection!(&db, 1, 2, Some(1));
have_movie!(&db, 1, 3, Some(2));
have_show!(&db, 1, 2, Some(2));
have_season!(&db, 1, 2, 1);
have_episode!(&db, 1, 2, 1, 1);
assert_episode!(&db, 2, 1, 1, 1, Success);
assert_movie!(&db, 3, 1, Success);
have_movie!(&db, 1, 4, Some(2));
assert_movie!(&db, 4, 1, Success);
have_collection!(&db, 1, 3, Some(2));
have_movie!(&db, 1, 5, Some(3));
assert_movie!(&db, 5, 1, Success);
have_movie!(&db, 1, 6, Some(3));
assert_movie!(&db, 6, 1, Success);
assert_movie!(&db, 6, 2, Success);
have_collection!(&db, 1, 4, Some(3));
have_movie!(&db, 1, 7, Some(4));
assert_movie!(&db, 7, 1, Success);
assert_movie!(&db, 7, 2, Success);
have_movie!(&db, 1, 8, Some(4));
assert_movie!(&db, 8, 1, Success);
assert_movie!(&db, 8, 2, Success);
assert_collection!(&db, 1, 1, Watched);
assert_collection!(&db, 1, 2, Unwatched);
assert_collection!(&db, 2, 1, Watched);
assert_collection!(&db, 2, 2, Unwatched);
assert_collection!(&db, 3, 1, Watched);
assert_collection!(&db, 3, 2, Unwatched);
assert_collection!(&db, 4, 1, Watched);
assert_collection!(&db, 4, 2, Watched);
}
}
-29
View File
@@ -1,29 +0,0 @@
//! Movie entity
use flix_model::id::{MovieId, RawId};
use chrono::NaiveDate;
use sea_orm::{
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
EnumIter, PrimaryKeyTrait,
};
/// The database representation of a watched movie
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_watched_movies")]
pub struct Model {
/// The movie's ID
#[sea_orm(primary_key, auto_increment = false)]
pub id: MovieId,
/// The user's ID
#[sea_orm(primary_key, auto_increment = false)]
pub user_id: RawId,
/// The date this movie was watched
pub watched_date: NaiveDate,
}
impl ActiveModelBehavior for ActiveModel {}
/// Relation
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
-33
View File
@@ -1,33 +0,0 @@
//! Episode entity
use flix_model::id::{RawId, ShowId};
use flix_model::numbers::SeasonNumber;
use chrono::NaiveDate;
use sea_orm::{
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
EnumIter, PrimaryKeyTrait,
};
/// The database representation of a watched movie
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_watched_seasons")]
pub struct Model {
/// The season's show's ID
#[sea_orm(primary_key, auto_increment = false)]
pub show: ShowId,
/// The season's number
#[sea_orm(primary_key, auto_increment = false)]
pub season: SeasonNumber,
/// The user's ID
#[sea_orm(primary_key, auto_increment = false)]
pub user_id: RawId,
/// The date this season was watched
pub watched_date: NaiveDate,
}
impl ActiveModelBehavior for ActiveModel {}
/// Relation
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
-29
View File
@@ -1,29 +0,0 @@
//! Show entity
use flix_model::id::{RawId, ShowId};
use chrono::NaiveDate;
use sea_orm::{
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
EnumIter, PrimaryKeyTrait,
};
/// The database representation of a watched movie
#[derive(Debug, Clone, DeriveEntityModel)]
#[sea_orm(table_name = "flix_watched_shows")]
pub struct Model {
/// The show's ID
#[sea_orm(primary_key, auto_increment = false)]
pub id: ShowId,
/// The user's ID
#[sea_orm(primary_key, auto_increment = false)]
pub user_id: RawId,
/// The date this show was watched
pub watched_date: NaiveDate,
}
impl ActiveModelBehavior for ActiveModel {}
/// Relation
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
+12 -3
View File
@@ -10,8 +10,17 @@ pub mod migration;
mod tests { mod tests {
use sea_orm::{ConnectOptions, Database, DatabaseConnection}; use sea_orm::{ConnectOptions, Database, DatabaseConnection};
pub async fn new_memory_db() -> DatabaseConnection { use crate::connection::Connection;
let options = ConnectOptions::new("sqlite:/tmp/db?mode=memory");
Database::connect(options).await.expect("Database::connect") pub async fn new_initialized_memory_db() -> DatabaseConnection {
let options = ConnectOptions::new("sqlite::memory:");
let db = Database::connect(options)
.await
.expect("Database::connect()");
let connection = Connection::try_from(db)
.await
.expect("Connection::try_from");
connection.take()
} }
} }
+5 -24
View File
@@ -1,52 +1,33 @@
//! Adds entity/info tables: //! Adds watched views:
//! - Collections //! - Collections
//! - Movies
//! - Shows //! - Shows
//! - Seasons //! - Seasons
//! - Episodes
use sea_orm::{DbErr, DeriveMigrationName}; use sea_orm::{DbErr, DeriveMigrationName};
use sea_orm_migration::async_trait; use sea_orm_migration::async_trait;
use sea_orm_migration::{MigrationTrait, SchemaManager}; use sea_orm_migration::{MigrationTrait, SchemaManager};
mod collections; mod collections;
mod episodes;
mod movies;
mod seasons; mod seasons;
mod shows; mod shows;
#[allow(unused_imports)]
pub use collections::FlixInfoCollections;
#[allow(unused_imports)]
pub use episodes::FlixInfoEpisodes;
#[allow(unused_imports)]
pub use movies::FlixInfoMovies;
#[allow(unused_imports)]
pub use seasons::FlixInfoSeasons;
#[allow(unused_imports)]
pub use shows::FlixInfoShows;
#[derive(DeriveMigrationName)] #[derive(DeriveMigrationName)]
pub(super) struct Migration; pub(super) struct Migration;
#[async_trait::async_trait] #[async_trait::async_trait]
impl MigrationTrait for Migration { impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
collections::up(manager).await?;
movies::up(manager).await?;
shows::up(manager).await?;
seasons::up(manager).await?; seasons::up(manager).await?;
episodes::up(manager).await?; shows::up(manager).await?;
collections::up(manager).await?;
Ok(()) Ok(())
} }
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
episodes::down(manager).await?;
seasons::down(manager).await?;
shows::down(manager).await?;
movies::down(manager).await?;
collections::down(manager).await?; collections::down(manager).await?;
shows::down(manager).await?;
seasons::down(manager).await?;
Ok(()) Ok(())
} }
+90 -32
View File
@@ -1,39 +1,88 @@
use seamantic::schema::sqlite_rowid_alias; use sea_orm::prelude::*;
use sea_orm::sea_query::Table;
use sea_orm::sea_query; use sea_orm::{ConnectionTrait, DbBackend, Statement};
use sea_orm::sea_query::{Index, Table}; use sea_orm_migration::prelude::*;
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::string;
#[derive(Iden)]
pub enum FlixInfoCollections {
Table,
Id,
Title,
Overview,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> { pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager manager
.create_table( .drop_table(Table::drop().table("flix_watched_collections").to_owned())
Table::create()
.table(FlixInfoCollections::Table)
.col(sqlite_rowid_alias(FlixInfoCollections::Id))
.col(string(FlixInfoCollections::Title))
.col(string(FlixInfoCollections::Overview))
.to_owned(),
)
.await?; .await?;
manager manager
.create_index( .get_connection()
Index::create() .execute_raw(Statement::from_string(
.name("idx-flix_info_collections-title") DbBackend::Sqlite,
.table(FlixInfoCollections::Table) r#"
.col(FlixInfoCollections::Title) CREATE VIEW flix_watched_collections AS
.to_owned(), WITH RECURSIVE
) watched_items AS (
SELECT
w.id,
w.user_id,
w.watched_date,
'movie' AS type
FROM flix_watched_movies w
UNION ALL
SELECT
w.id,
w.user_id,
w.watched_date,
'show' AS type
FROM flix_watched_shows w
),
collection_items AS (
SELECT
m.parent_id,
m.id,
'movie' AS type
FROM flix_movies m
WHERE m.parent_id IS NOT NULL
UNION ALL
SELECT
s.parent_id,
s.id,
'show' AS type
FROM flix_shows s
WHERE s.parent_id IS NOT NULL
UNION ALL
SELECT
c.parent_id,
ci.id,
ci.type
FROM collection_items ci
JOIN flix_collections c
ON c.id = ci.parent_id
)
SELECT
ci.parent_id AS id,
wi.user_id,
MAX(wi.watched_date) AS watched_date
FROM collection_items ci
JOIN watched_items wi
ON wi.id = ci.id
AND wi.type = ci.type
WHERE NOT EXISTS (
SELECT 1
FROM collection_items ci2
WHERE ci2.parent_id = ci.parent_id
AND NOT EXISTS (
SELECT 1
FROM watched_items wi2
WHERE wi2.id = ci2.id
AND wi2.type = ci2.type
AND wi2.user_id = wi.user_id
)
)
GROUP BY ci.parent_id, wi.user_id
;
"#,
))
.await?; .await?;
Ok(()) Ok(())
@@ -41,6 +90,15 @@ pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> { pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager manager
.drop_table(Table::drop().table(FlixInfoCollections::Table).to_owned()) .get_connection()
.await .execute_raw(Statement::from_string(
DbBackend::Sqlite,
r#"
DROP VIEW flix_watched_collections
;
"#,
))
.await?;
Ok(())
} }
@@ -1,68 +0,0 @@
use sea_orm::sea_query;
use sea_orm::sea_query::{ForeignKeyCreateStatement, Index, Table};
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::{date, integer, string};
use crate::migration::m_000001::FlixInfoShows;
use super::FlixInfoSeasons;
#[derive(Iden)]
pub enum FlixInfoEpisodes {
Table,
Show,
Season,
Episode,
Title,
Overview,
Date,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(FlixInfoEpisodes::Table)
.col(integer(FlixInfoEpisodes::Show))
.col(integer(FlixInfoEpisodes::Season))
.col(integer(FlixInfoEpisodes::Episode))
.col(string(FlixInfoEpisodes::Title))
.col(string(FlixInfoEpisodes::Overview))
.col(date(FlixInfoEpisodes::Date))
.primary_key(
Index::create()
.col(FlixInfoEpisodes::Show)
.col(FlixInfoEpisodes::Season)
.col(FlixInfoEpisodes::Episode),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_info_episodes-show")
.from_tbl(FlixInfoEpisodes::Table)
.from_col(FlixInfoEpisodes::Show)
.to_tbl(FlixInfoShows::Table)
.to_col(FlixInfoShows::Id),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_info_episodes-show_season")
.from_tbl(FlixInfoEpisodes::Table)
.from_col(FlixInfoEpisodes::Show)
.from_col(FlixInfoEpisodes::Season)
.to_tbl(FlixInfoSeasons::Table)
.to_col(FlixInfoSeasons::Show)
.to_col(FlixInfoSeasons::Season),
)
.to_owned(),
)
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(FlixInfoEpisodes::Table).to_owned())
.await
}
@@ -1,60 +0,0 @@
use seamantic::schema::sqlite_rowid_alias;
use sea_orm::sea_query;
use sea_orm::sea_query::{Index, Table};
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::{date, string};
#[derive(Iden)]
pub enum FlixInfoMovies {
Table,
Id,
Title,
Tagline,
Overview,
Date,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(FlixInfoMovies::Table)
.col(sqlite_rowid_alias(FlixInfoMovies::Id))
.col(string(FlixInfoMovies::Title))
.col(string(FlixInfoMovies::Tagline))
.col(string(FlixInfoMovies::Overview))
.col(date(FlixInfoMovies::Date))
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx-flix_info_movies-title")
.table(FlixInfoMovies::Table)
.col(FlixInfoMovies::Title)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx-flix_info_movies-date")
.table(FlixInfoMovies::Table)
.col(FlixInfoMovies::Date)
.to_owned(),
)
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(FlixInfoMovies::Table).to_owned())
.await
}
+47 -41
View File
@@ -1,46 +1,43 @@
use sea_orm::sea_query; use sea_orm::prelude::*;
use sea_orm::sea_query::{ForeignKeyCreateStatement, Index, Table}; use sea_orm::sea_query::Table;
use sea_orm::{DbErr, Iden}; use sea_orm::{ConnectionTrait, DbBackend, Statement};
use sea_orm_migration::SchemaManager; use sea_orm_migration::prelude::*;
use sea_orm_migration::schema::{date, integer, string};
use super::FlixInfoShows;
#[derive(Iden)]
pub enum FlixInfoSeasons {
Table,
Show,
Season,
Title,
Overview,
Date,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> { pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager manager
.create_table( .drop_table(Table::drop().table("flix_watched_seasons").to_owned())
Table::create() .await?;
.table(FlixInfoSeasons::Table)
.col(integer(FlixInfoSeasons::Show)) manager
.col(integer(FlixInfoSeasons::Season)) .get_connection()
.col(string(FlixInfoSeasons::Title)) .execute_raw(Statement::from_string(
.col(string(FlixInfoSeasons::Overview)) DbBackend::Sqlite,
.col(date(FlixInfoSeasons::Date)) r#"
.primary_key( CREATE VIEW flix_watched_seasons AS
Index::create() SELECT
.col(FlixInfoSeasons::Show) w.show_id,
.col(FlixInfoSeasons::Season), w.season_number,
w.user_id,
MAX(w.watched_date) AS watched_date
FROM flix_watched_episodes w
WHERE NOT EXISTS (
SELECT 1
FROM flix_episodes e
WHERE e.show_id = w.show_id
AND e.season_number = w.season_number
AND NOT EXISTS (
SELECT 1
FROM flix_watched_episodes wc
WHERE wc.show_id = e.show_id
AND wc.season_number = e.season_number
AND wc.episode_number = e.episode_number
AND wc.user_id = w.user_id
)
) )
.foreign_key( GROUP BY w.show_id, w.season_number, w.user_id
ForeignKeyCreateStatement::new() ;
.name("fk-flix_info_seasons-show") "#,
.from_tbl(FlixInfoSeasons::Table) ))
.from_col(FlixInfoSeasons::Show)
.to_tbl(FlixInfoShows::Table)
.to_col(FlixInfoShows::Id),
)
.to_owned(),
)
.await?; .await?;
Ok(()) Ok(())
@@ -48,6 +45,15 @@ pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> { pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager manager
.drop_table(Table::drop().table(FlixInfoSeasons::Table).to_owned()) .get_connection()
.await .execute_raw(Statement::from_string(
DbBackend::Sqlite,
r#"
DROP VIEW flix_watched_seasons
;
"#,
))
.await?;
Ok(())
} }
+42 -46
View File
@@ -1,53 +1,40 @@
use seamantic::schema::sqlite_rowid_alias; use sea_orm::prelude::*;
use sea_orm::sea_query::Table;
use sea_orm::sea_query; use sea_orm::{ConnectionTrait, DbBackend, Statement};
use sea_orm::sea_query::{Index, Table}; use sea_orm_migration::prelude::*;
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::{date, string};
#[derive(Iden)]
pub enum FlixInfoShows {
Table,
Id,
Title,
Tagline,
Overview,
Date,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> { pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager manager
.create_table( .drop_table(Table::drop().table("flix_watched_shows").to_owned())
Table::create()
.table(FlixInfoShows::Table)
.col(sqlite_rowid_alias(FlixInfoShows::Id))
.col(string(FlixInfoShows::Title))
.col(string(FlixInfoShows::Tagline))
.col(string(FlixInfoShows::Overview))
.col(date(FlixInfoShows::Date))
.to_owned(),
)
.await?; .await?;
manager manager
.create_index( .get_connection()
Index::create() .execute_raw(Statement::from_string(
.name("idx-flix_info_shows-title") DbBackend::Sqlite,
.table(FlixInfoShows::Table) r#"
.col(FlixInfoShows::Title) CREATE VIEW flix_watched_shows AS
.to_owned(), SELECT
) w.show_id as id,
.await?; w.user_id,
MAX(w.watched_date) AS watched_date
manager FROM flix_watched_seasons w
.create_index( WHERE NOT EXISTS (
Index::create() SELECT 1
.name("idx-flix_info_shows-date") FROM flix_seasons s
.table(FlixInfoShows::Table) WHERE s.show_id = w.show_id
.col(FlixInfoShows::Date) AND NOT EXISTS (
.to_owned(), SELECT 1
) FROM flix_watched_seasons wc
WHERE wc.show_id = s.show_id
AND wc.season_number = s.season_number
AND wc.user_id = w.user_id
)
)
GROUP BY w.show_id, w.user_id
;
"#,
))
.await?; .await?;
Ok(()) Ok(())
@@ -55,6 +42,15 @@ pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> { pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager manager
.drop_table(Table::drop().table(FlixInfoShows::Table).to_owned()) .get_connection()
.await .execute_raw(Statement::from_string(
DbBackend::Sqlite,
r#"
DROP VIEW flix_watched_shows
;
"#,
))
.await?;
Ok(())
} }
-53
View File
@@ -1,53 +0,0 @@
//! Adds entity/tmdb tables:
//! - Collections
//! - Movies
//! - Shows
//! - Seasons
//! - Episodes
use sea_orm::{DbErr, DeriveMigrationName};
use sea_orm_migration::async_trait;
use sea_orm_migration::{MigrationTrait, SchemaManager};
mod collections;
mod episodes;
mod movies;
mod seasons;
mod shows;
#[allow(unused_imports)]
pub use collections::FlixTmdbCollections;
#[allow(unused_imports)]
pub use episodes::FlixTmdbEpisodes;
#[allow(unused_imports)]
pub use movies::FlixTmdbMovies;
#[allow(unused_imports)]
pub use seasons::FlixTmdbSeasons;
#[allow(unused_imports)]
pub use shows::FlixTmdbShows;
#[derive(DeriveMigrationName)]
pub(super) struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
collections::up(manager).await?;
movies::up(manager).await?;
shows::up(manager).await?;
seasons::up(manager).await?;
episodes::up(manager).await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
episodes::down(manager).await?;
seasons::down(manager).await?;
shows::down(manager).await?;
movies::down(manager).await?;
collections::down(manager).await?;
Ok(())
}
}
@@ -1,58 +0,0 @@
use seamantic::schema::sqlite_rowid_alias;
use sea_orm::sea_query;
use sea_orm::sea_query::{ForeignKeyCreateStatement, Index, Table};
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::{date, integer};
use super::super::m_000001::FlixInfoCollections;
#[derive(Iden)]
pub enum FlixTmdbCollections {
Table,
TmdbId,
FlixId,
LastUpdate,
MovieCount,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(FlixTmdbCollections::Table)
.col(sqlite_rowid_alias(FlixTmdbCollections::TmdbId))
.col(integer(FlixTmdbCollections::FlixId).unique_key())
.col(date(FlixTmdbCollections::LastUpdate))
.col(integer(FlixTmdbCollections::MovieCount))
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_tmdb_collections-flixid")
.from_tbl(FlixTmdbCollections::Table)
.from_col(FlixTmdbCollections::FlixId)
.to_tbl(FlixInfoCollections::Table)
.to_col(FlixInfoCollections::Id),
)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx-flix_tmdb_collections-flixid")
.table(FlixTmdbCollections::Table)
.col(FlixTmdbCollections::FlixId)
.to_owned(),
)
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(FlixTmdbCollections::Table).to_owned())
.await
}
@@ -1,94 +0,0 @@
use sea_orm::sea_query;
use sea_orm::sea_query::{ForeignKeyCreateStatement, Index, Table};
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::{date, integer};
use super::super::m_000001::{FlixInfoEpisodes, FlixInfoSeasons};
use super::FlixTmdbSeasons;
#[derive(Iden)]
pub enum FlixTmdbEpisodes {
Table,
TmdbShow,
TmdbSeason,
TmdbEpisode,
FlixShow,
FlixSeason,
FlixEpisode,
LastUpdate,
Runtime,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(FlixTmdbEpisodes::Table)
.col(integer(FlixTmdbEpisodes::TmdbShow))
.col(integer(FlixTmdbEpisodes::TmdbSeason))
.col(integer(FlixTmdbEpisodes::TmdbEpisode))
.col(integer(FlixTmdbEpisodes::FlixShow))
.col(integer(FlixTmdbEpisodes::FlixSeason))
.col(integer(FlixTmdbEpisodes::FlixEpisode))
.col(date(FlixTmdbEpisodes::LastUpdate))
.col(integer(FlixTmdbEpisodes::Runtime))
.primary_key(
Index::create()
.col(FlixTmdbEpisodes::TmdbShow)
.col(FlixTmdbEpisodes::TmdbSeason)
.col(FlixTmdbEpisodes::TmdbEpisode),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_tmdb_episodes-tmdb_show_season")
.from_tbl(FlixTmdbEpisodes::Table)
.from_col(FlixTmdbEpisodes::TmdbShow)
.from_col(FlixTmdbEpisodes::TmdbSeason)
.to_tbl(FlixTmdbSeasons::Table)
.to_col(FlixTmdbSeasons::TmdbShow)
.to_col(FlixTmdbSeasons::TmdbSeason),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_tmdb_episodes-flix_show_season")
.from_tbl(FlixTmdbEpisodes::Table)
.from_col(FlixTmdbEpisodes::FlixShow)
.from_col(FlixTmdbEpisodes::FlixSeason)
.to_tbl(FlixInfoSeasons::Table)
.to_col(FlixInfoSeasons::Show)
.to_col(FlixInfoSeasons::Season),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_tmdb_episodes-flix_show_season_episode")
.from_tbl(FlixTmdbEpisodes::Table)
.from_col(FlixTmdbEpisodes::FlixShow)
.from_col(FlixTmdbEpisodes::FlixSeason)
.from_col(FlixTmdbEpisodes::FlixEpisode)
.to_tbl(FlixInfoEpisodes::Table)
.to_col(FlixInfoEpisodes::Show)
.to_col(FlixInfoEpisodes::Season)
.to_col(FlixInfoEpisodes::Episode),
)
.index(
Index::create()
.unique()
.name("idx-flix_tmdb_episodes-flix_show_season_episode")
.col(FlixTmdbEpisodes::FlixShow)
.col(FlixTmdbEpisodes::FlixSeason)
.col(FlixTmdbEpisodes::FlixEpisode),
)
.to_owned(),
)
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(FlixTmdbEpisodes::Table).to_owned())
.await
}
@@ -1,70 +0,0 @@
use seamantic::schema::sqlite_rowid_alias;
use sea_orm::sea_query;
use sea_orm::sea_query::{ForeignKeyCreateStatement, Index, Table};
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::{date, integer, integer_null};
use crate::migration::m_000002::FlixTmdbCollections;
use super::super::m_000001::FlixInfoMovies;
#[derive(Iden)]
pub enum FlixTmdbMovies {
Table,
TmdbId,
FlixId,
LastUpdate,
Runtime,
Collection,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(FlixTmdbMovies::Table)
.col(sqlite_rowid_alias(FlixTmdbMovies::TmdbId))
.col(integer(FlixTmdbMovies::FlixId).unique_key())
.col(date(FlixTmdbMovies::LastUpdate))
.col(integer(FlixTmdbMovies::Runtime))
.col(integer_null(FlixTmdbMovies::Collection))
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_tmdb_movies-flixid")
.from_tbl(FlixTmdbMovies::Table)
.from_col(FlixTmdbMovies::FlixId)
.to_tbl(FlixInfoMovies::Table)
.to_col(FlixInfoMovies::Id),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_tmdb_movies-collectionid")
.from_tbl(FlixTmdbMovies::Table)
.from_col(FlixTmdbMovies::Collection)
.to_tbl(FlixTmdbCollections::Table)
.to_col(FlixTmdbCollections::TmdbId),
)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx-flix_tmdb_movies-flixid")
.table(FlixTmdbMovies::Table)
.col(FlixTmdbMovies::FlixId)
.to_owned(),
)
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(FlixTmdbMovies::Table).to_owned())
.await
}
@@ -1,82 +0,0 @@
use sea_orm::sea_query;
use sea_orm::sea_query::{ForeignKeyCreateStatement, Index, Table};
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::{date, integer};
use crate::migration::m_000001::FlixInfoShows;
use super::super::m_000001::FlixInfoSeasons;
use super::FlixTmdbShows;
#[derive(Iden)]
pub enum FlixTmdbSeasons {
Table,
TmdbShow,
TmdbSeason,
FlixShow,
FlixSeason,
LastUpdate,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(FlixTmdbSeasons::Table)
.col(integer(FlixTmdbSeasons::TmdbShow))
.col(integer(FlixTmdbSeasons::TmdbSeason))
.col(integer(FlixTmdbSeasons::FlixShow))
.col(integer(FlixTmdbSeasons::FlixSeason))
.col(date(FlixTmdbSeasons::LastUpdate))
.primary_key(
Index::create()
.col(FlixTmdbSeasons::TmdbShow)
.col(FlixTmdbSeasons::TmdbSeason),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_tmdb_seasons-tmdb_show")
.from_tbl(FlixTmdbSeasons::Table)
.from_col(FlixTmdbSeasons::FlixShow)
.to_tbl(FlixTmdbShows::Table)
.to_col(FlixTmdbShows::FlixId),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_tmdb_seasons-flix_show")
.from_tbl(FlixTmdbSeasons::Table)
.from_col(FlixTmdbSeasons::FlixShow)
.to_tbl(FlixInfoShows::Table)
.to_col(FlixInfoShows::Id),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_tmdb_seasons-flix_show_season")
.from_tbl(FlixTmdbSeasons::Table)
.from_col(FlixTmdbSeasons::FlixShow)
.from_col(FlixTmdbSeasons::FlixSeason)
.to_tbl(FlixInfoSeasons::Table)
.to_col(FlixInfoSeasons::Show)
.to_col(FlixInfoSeasons::Season),
)
.index(
Index::create()
.unique()
.name("idx-flix_tmdb_seasons-flix_show_season")
.col(FlixTmdbSeasons::FlixShow)
.col(FlixTmdbSeasons::FlixSeason),
)
.to_owned(),
)
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(FlixTmdbSeasons::Table).to_owned())
.await
}
-58
View File
@@ -1,58 +0,0 @@
use seamantic::schema::sqlite_rowid_alias;
use sea_orm::sea_query;
use sea_orm::sea_query::{ForeignKeyCreateStatement, Index, Table};
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::{date, integer};
use super::super::m_000001::FlixInfoShows;
#[derive(Iden)]
pub enum FlixTmdbShows {
Table,
TmdbId,
FlixId,
LastUpdate,
NumberOfSeasons,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(FlixTmdbShows::Table)
.col(sqlite_rowid_alias(FlixTmdbShows::TmdbId))
.col(integer(FlixTmdbShows::FlixId).unique_key())
.col(date(FlixTmdbShows::LastUpdate))
.col(integer(FlixTmdbShows::NumberOfSeasons))
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_tmdb_shows-flixid")
.from_tbl(FlixTmdbShows::Table)
.from_col(FlixTmdbShows::FlixId)
.to_tbl(FlixInfoShows::Table)
.to_col(FlixInfoShows::Id),
)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx-flix_tmdb_shows-flixid")
.table(FlixTmdbShows::Table)
.col(FlixTmdbShows::FlixId)
.to_owned(),
)
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(FlixTmdbShows::Table).to_owned())
.await
}
-59
View File
@@ -1,59 +0,0 @@
//! Adds entity/content tables:
//! - Libraries
//! - Collections
//! - Movies
//! - Shows
//! - Seasons
//! - Episodes
use sea_orm::{DbErr, DeriveMigrationName};
use sea_orm_migration::async_trait;
use sea_orm_migration::{MigrationTrait, SchemaManager};
mod collections;
mod episodes;
mod libraries;
mod movies;
mod seasons;
mod shows;
#[allow(unused_imports)]
pub use collections::FlixCollections;
#[allow(unused_imports)]
pub use episodes::FlixEpisodes;
#[allow(unused_imports)]
pub use libraries::FlixLibraries;
#[allow(unused_imports)]
pub use movies::FlixMovies;
#[allow(unused_imports)]
pub use seasons::FlixSeasons;
#[allow(unused_imports)]
pub use shows::FlixShows;
#[derive(DeriveMigrationName)]
pub(super) struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
libraries::up(manager).await?;
collections::up(manager).await?;
movies::up(manager).await?;
shows::up(manager).await?;
seasons::up(manager).await?;
episodes::up(manager).await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
episodes::down(manager).await?;
seasons::down(manager).await?;
shows::down(manager).await?;
movies::down(manager).await?;
collections::down(manager).await?;
libraries::down(manager).await?;
Ok(())
}
}
@@ -1,69 +0,0 @@
use seamantic::schema::sqlite_rowid_alias;
use sea_orm::sea_query;
use sea_orm::sea_query::{ForeignKeyCreateStatement, Table};
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::{binary, integer, integer_null, string, string_null};
use crate::migration::m_000001::FlixInfoCollections;
use crate::migration::m_000003::FlixLibraries;
#[derive(Iden)]
pub enum FlixCollections {
Table,
Id,
Parent,
Slug,
Library,
Directory,
RelativePosterPath,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(FlixCollections::Table)
.col(sqlite_rowid_alias(FlixCollections::Id))
.col(integer_null(FlixCollections::Parent))
.col(string(FlixCollections::Slug))
.col(integer(FlixCollections::Library))
.col(binary(FlixCollections::Directory))
.col(string_null(FlixCollections::RelativePosterPath))
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_collections-id")
.from_tbl(FlixCollections::Table)
.from_col(FlixCollections::Id)
.to_tbl(FlixInfoCollections::Table)
.to_col(FlixInfoCollections::Id),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_collections-parent")
.from_tbl(FlixCollections::Table)
.from_col(FlixCollections::Parent)
.to_tbl(FlixCollections::Table)
.to_col(FlixCollections::Id),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_collections-library")
.from_tbl(FlixCollections::Table)
.from_col(FlixCollections::Library)
.to_tbl(FlixLibraries::Table)
.to_col(FlixLibraries::Id),
)
.to_owned(),
)
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(FlixCollections::Table).to_owned())
.await
}
@@ -1,75 +0,0 @@
use sea_orm::sea_query;
use sea_orm::sea_query::{ForeignKeyCreateStatement, Index, Table};
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::{binary, integer, string, string_null};
use crate::migration::m_000001::FlixInfoEpisodes;
use crate::migration::m_000003::FlixLibraries;
#[derive(Iden)]
pub enum FlixEpisodes {
Table,
Show,
Season,
Episode,
Count,
Slug,
Library,
Directory,
RelativeMediaPath,
RelativePosterPath,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(FlixEpisodes::Table)
.col(integer(FlixEpisodes::Show))
.col(integer(FlixEpisodes::Season))
.col(integer(FlixEpisodes::Episode))
.col(integer(FlixEpisodes::Count))
.col(string(FlixEpisodes::Slug))
.col(integer(FlixEpisodes::Library))
.col(binary(FlixEpisodes::Directory))
.col(string(FlixEpisodes::RelativeMediaPath))
.col(string_null(FlixEpisodes::RelativePosterPath))
.primary_key(
Index::create()
.col(FlixEpisodes::Show)
.col(FlixEpisodes::Season)
.col(FlixEpisodes::Episode),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_episodes-show_season_episode")
.from_tbl(FlixEpisodes::Table)
.from_col(FlixEpisodes::Show)
.from_col(FlixEpisodes::Season)
.from_col(FlixEpisodes::Episode)
.to_tbl(FlixInfoEpisodes::Table)
.to_col(FlixInfoEpisodes::Show)
.to_col(FlixInfoEpisodes::Season)
.to_col(FlixInfoEpisodes::Episode),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_episodes-library")
.from_tbl(FlixEpisodes::Table)
.from_col(FlixEpisodes::Library)
.to_tbl(FlixLibraries::Table)
.to_col(FlixLibraries::Id),
)
.to_owned(),
)
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(FlixEpisodes::Table).to_owned())
.await
}
@@ -1,34 +0,0 @@
use seamantic::schema::sqlite_rowid_alias;
use sea_orm::sea_query;
use sea_orm::sea_query::Table;
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::binary;
#[derive(Iden)]
pub enum FlixLibraries {
Table,
Id,
Directory,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(FlixLibraries::Table)
.col(sqlite_rowid_alias(FlixLibraries::Id))
.col(binary(FlixLibraries::Directory))
.to_owned(),
)
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(FlixLibraries::Table).to_owned())
.await
}
@@ -1,71 +0,0 @@
use seamantic::schema::sqlite_rowid_alias;
use sea_orm::sea_query;
use sea_orm::sea_query::{ForeignKeyCreateStatement, Table};
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::{binary, integer, integer_null, string, string_null};
use crate::migration::m_000001::FlixInfoMovies;
use crate::migration::m_000003::{FlixCollections, FlixLibraries};
#[derive(Iden)]
pub enum FlixMovies {
Table,
Id,
Parent,
Slug,
Library,
Directory,
RelativeMediaPath,
RelativePosterPath,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(FlixMovies::Table)
.col(sqlite_rowid_alias(FlixMovies::Id))
.col(integer_null(FlixMovies::Parent))
.col(string(FlixMovies::Slug))
.col(integer(FlixMovies::Library))
.col(binary(FlixMovies::Directory))
.col(string(FlixMovies::RelativeMediaPath))
.col(string_null(FlixMovies::RelativePosterPath))
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_movies-id")
.from_tbl(FlixMovies::Table)
.from_col(FlixMovies::Id)
.to_tbl(FlixInfoMovies::Table)
.to_col(FlixInfoMovies::Id),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_movies-parent")
.from_tbl(FlixMovies::Table)
.from_col(FlixMovies::Parent)
.to_tbl(FlixCollections::Table)
.to_col(FlixCollections::Id),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_movies-library")
.from_tbl(FlixMovies::Table)
.from_col(FlixMovies::Library)
.to_tbl(FlixLibraries::Table)
.to_col(FlixLibraries::Id),
)
.to_owned(),
)
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(FlixMovies::Table).to_owned())
.await
}
@@ -1,66 +0,0 @@
use sea_orm::sea_query;
use sea_orm::sea_query::{ForeignKeyCreateStatement, Index, Table};
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::{binary, integer, string, string_null};
use crate::migration::m_000001::FlixInfoSeasons;
use crate::migration::m_000003::FlixLibraries;
#[derive(Iden)]
pub enum FlixSeasons {
Table,
Show,
Season,
Slug,
Library,
Directory,
RelativePosterPath,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(FlixSeasons::Table)
.col(integer(FlixSeasons::Show))
.col(integer(FlixSeasons::Season))
.col(string(FlixSeasons::Slug))
.col(integer(FlixSeasons::Library))
.col(binary(FlixSeasons::Directory))
.col(string_null(FlixSeasons::RelativePosterPath))
.primary_key(
Index::create()
.col(FlixSeasons::Show)
.col(FlixSeasons::Season),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_seasons-show_season")
.from_tbl(FlixSeasons::Table)
.from_col(FlixSeasons::Show)
.from_col(FlixSeasons::Season)
.to_tbl(FlixInfoSeasons::Table)
.to_col(FlixInfoSeasons::Show)
.to_col(FlixInfoSeasons::Season),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_seasons-library")
.from_tbl(FlixSeasons::Table)
.from_col(FlixSeasons::Library)
.to_tbl(FlixLibraries::Table)
.to_col(FlixLibraries::Id),
)
.to_owned(),
)
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(FlixSeasons::Table).to_owned())
.await
}
-69
View File
@@ -1,69 +0,0 @@
use seamantic::schema::sqlite_rowid_alias;
use sea_orm::sea_query;
use sea_orm::sea_query::{ForeignKeyCreateStatement, Table};
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::{binary, integer, integer_null, string, string_null};
use crate::migration::m_000001::FlixInfoShows;
use crate::migration::m_000003::{FlixCollections, FlixLibraries};
#[derive(Iden)]
pub enum FlixShows {
Table,
Id,
Parent,
Slug,
Library,
Directory,
RelativePosterPath,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(FlixShows::Table)
.col(sqlite_rowid_alias(FlixShows::Id))
.col(integer_null(FlixShows::Parent))
.col(string(FlixShows::Slug))
.col(integer(FlixShows::Library))
.col(binary(FlixShows::Directory))
.col(string_null(FlixShows::RelativePosterPath))
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_shows-id")
.from_tbl(FlixShows::Table)
.from_col(FlixShows::Id)
.to_tbl(FlixInfoShows::Table)
.to_col(FlixInfoShows::Id),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_shows-parent")
.from_tbl(FlixShows::Table)
.from_col(FlixShows::Parent)
.to_tbl(FlixCollections::Table)
.to_col(FlixCollections::Id),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_shows-library")
.from_tbl(FlixShows::Table)
.from_col(FlixShows::Library)
.to_tbl(FlixLibraries::Table)
.to_col(FlixLibraries::Id),
)
.to_owned(),
)
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(FlixShows::Table).to_owned())
.await
}
-47
View File
@@ -1,47 +0,0 @@
//! Adds entity/watched tables:
//! - Collections
//! - Movies
//! - Shows
//! - Seasons
//! - Episodes
use sea_orm::{DbErr, DeriveMigrationName};
use sea_orm_migration::async_trait;
use sea_orm_migration::{MigrationTrait, SchemaManager};
mod collections;
mod episodes;
mod movies;
mod seasons;
mod shows;
#[allow(unused_imports)]
pub use episodes::FlixWatchedEpisodes;
#[allow(unused_imports)]
pub use movies::FlixWatchedMovies;
#[derive(DeriveMigrationName)]
pub(super) struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
episodes::up(manager).await?;
seasons::up(manager).await?;
shows::up(manager).await?;
movies::up(manager).await?;
collections::up(manager).await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
collections::down(manager).await?;
movies::down(manager).await?;
shows::down(manager).await?;
seasons::down(manager).await?;
episodes::down(manager).await?;
Ok(())
}
}
@@ -1,98 +0,0 @@
use sea_orm::DbErr;
use sea_orm::{ConnectionTrait, DbBackend, Statement};
use sea_orm_migration::SchemaManager;
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.get_connection()
.execute_raw(Statement::from_string(
DbBackend::Sqlite,
r#"
CREATE VIEW flix_watched_collections AS
WITH RECURSIVE
watched_items AS (
SELECT
w.id,
w.user_id,
w.watched_date,
'movie' AS type
FROM flix_watched_movies w
UNION ALL
SELECT
w.id,
w.user_id,
w.watched_date,
'show' AS type
FROM flix_watched_shows w
),
collection_items AS (
SELECT
m.parent,
m.id,
'movie' AS type
FROM flix_movies m
WHERE m.parent IS NOT NULL
UNION ALL
SELECT
s.parent,
s.id,
'show' AS type
FROM flix_shows s
WHERE s.parent IS NOT NULL
UNION ALL
SELECT
c.parent,
ci.id,
ci.type
FROM collection_items ci
JOIN flix_collections c
ON c.id = ci.parent
)
SELECT
ci.parent AS id,
wi.user_id,
MAX(wi.watched_date) AS watched_date
FROM collection_items ci
JOIN watched_items wi
ON wi.id = ci.id
AND wi.type = ci.type
WHERE NOT EXISTS (
SELECT 1
FROM collection_items ci2
WHERE ci2.parent = ci.parent
AND NOT EXISTS (
SELECT 1
FROM watched_items wi2
WHERE wi2.id = ci2.id
AND wi2.type = ci2.type
AND wi2.user_id = wi.user_id
)
)
GROUP BY ci.parent, wi.user_id;
"#,
))
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.get_connection()
.execute_raw(Statement::from_string(
DbBackend::Sqlite,
r#"
DROP VIEW flix_watched_collections
;
"#,
))
.await?;
Ok(())
}
@@ -1,60 +0,0 @@
use sea_orm::sea_query;
use sea_orm::sea_query::{ForeignKeyCreateStatement, Index, Table};
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::{date, integer};
use crate::migration::m_000001::FlixInfoEpisodes;
#[derive(Iden)]
pub enum FlixWatchedEpisodes {
Table,
Show,
Season,
Episode,
UserId,
WatchedDate,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(FlixWatchedEpisodes::Table)
.col(integer(FlixWatchedEpisodes::Show))
.col(integer(FlixWatchedEpisodes::Season))
.col(integer(FlixWatchedEpisodes::Episode))
.col(integer(FlixWatchedEpisodes::UserId))
.col(date(FlixWatchedEpisodes::WatchedDate))
.primary_key(
Index::create()
.col(FlixWatchedEpisodes::Show)
.col(FlixWatchedEpisodes::Season)
.col(FlixWatchedEpisodes::Episode)
.col(FlixWatchedEpisodes::UserId),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_watched_episodes-show_season_episode")
.from_tbl(FlixWatchedEpisodes::Table)
.from_tbl(FlixWatchedEpisodes::Table)
.from_col(FlixWatchedEpisodes::Show)
.from_col(FlixWatchedEpisodes::Season)
.from_col(FlixWatchedEpisodes::Episode)
.to_tbl(FlixInfoEpisodes::Table)
.to_col(FlixInfoEpisodes::Show)
.to_col(FlixInfoEpisodes::Season)
.to_col(FlixInfoEpisodes::Episode),
)
.to_owned(),
)
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(FlixWatchedEpisodes::Table).to_owned())
.await
}
@@ -1,49 +0,0 @@
use sea_orm::sea_query;
use sea_orm::sea_query::{ForeignKeyCreateStatement, Index, Table};
use sea_orm::{DbErr, Iden};
use sea_orm_migration::SchemaManager;
use sea_orm_migration::schema::{date, integer};
use crate::migration::m_000001::FlixInfoMovies;
#[derive(Iden)]
pub enum FlixWatchedMovies {
Table,
Id,
UserId,
WatchedDate,
}
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(FlixWatchedMovies::Table)
.col(integer(FlixWatchedMovies::Id))
.col(integer(FlixWatchedMovies::UserId))
.col(date(FlixWatchedMovies::WatchedDate))
.primary_key(
Index::create()
.col(FlixWatchedMovies::Id)
.col(FlixWatchedMovies::UserId),
)
.foreign_key(
ForeignKeyCreateStatement::new()
.name("fk-flix_watched_movies-id")
.from_tbl(FlixWatchedMovies::Table)
.from_col(FlixWatchedMovies::Id)
.to_tbl(FlixInfoMovies::Table)
.to_col(FlixInfoMovies::Id),
)
.to_owned(),
)
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(FlixWatchedMovies::Table).to_owned())
.await
}
@@ -1,54 +0,0 @@
use sea_orm::DbErr;
use sea_orm::{ConnectionTrait, DbBackend, Statement};
use sea_orm_migration::SchemaManager;
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.get_connection()
.execute_raw(Statement::from_string(
DbBackend::Sqlite,
r#"
CREATE VIEW flix_watched_seasons AS
SELECT
w.show,
w.season,
w.user_id,
MAX(w.watched_date) AS watched_date
FROM flix_watched_episodes w
WHERE NOT EXISTS (
SELECT 1
FROM flix_episodes e
WHERE e.show = w.show
AND e.season = w.season
AND NOT EXISTS (
SELECT 1
FROM flix_watched_episodes wc
WHERE wc.show = e.show
AND wc.season = e.season
AND wc.episode = e.episode
AND wc.user_id = w.user_id
)
)
GROUP BY w.show, w.season, w.user_id
;
"#,
))
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.get_connection()
.execute_raw(Statement::from_string(
DbBackend::Sqlite,
r#"
DROP VIEW flix_watched_seasons
;
"#,
))
.await?;
Ok(())
}
-51
View File
@@ -1,51 +0,0 @@
use sea_orm::DbErr;
use sea_orm::{ConnectionTrait, DbBackend, Statement};
use sea_orm_migration::SchemaManager;
pub async fn up(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.get_connection()
.execute_raw(Statement::from_string(
DbBackend::Sqlite,
r#"
CREATE VIEW flix_watched_shows AS
SELECT
w.show as id,
w.user_id,
MAX(w.watched_date) AS watched_date
FROM flix_watched_seasons w
WHERE NOT EXISTS (
SELECT 1
FROM flix_seasons s
WHERE s.show = w.show
AND NOT EXISTS (
SELECT 1
FROM flix_watched_seasons wc
WHERE wc.show = s.show
AND wc.season = s.season
AND wc.user_id = w.user_id
)
)
GROUP BY w.show, w.user_id
;
"#,
))
.await?;
Ok(())
}
pub async fn down(manager: &SchemaManager<'_>) -> Result<(), DbErr> {
manager
.get_connection()
.execute_raw(Statement::from_string(
DbBackend::Sqlite,
r#"
DROP VIEW flix_watched_shows
;
"#,
))
.await?;
Ok(())
}
-3
View File
@@ -3,7 +3,4 @@
seamantic::migrations! { seamantic::migrations! {
"seaql_migrations_flix"; "seaql_migrations_flix";
m_000001, m_000001,
m_000002,
m_000003,
m_000004,
} }
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "flix" name = "flix"
version = "0.0.11" version = "0.0.13"
categories = [] categories = []
description = "Mechanisms for interacting with flix media" description = "Mechanisms for interacting with flix media"
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "flix-fs" name = "flix-fs"
version = "0.0.11" version = "0.0.13"
categories = [] categories = []
description = "Filesystem scanner for flix media" description = "Filesystem scanner for flix media"
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "flix-model" name = "flix-model"
version = "0.0.11" version = "0.0.13"
categories = [] categories = []
description = "Core types for flix data" description = "Core types for flix data"
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "flix-tmdb" name = "flix-tmdb"
version = "0.0.11" version = "0.0.13"
categories = [] categories = []
description = "Clients and models for fetching data from TMDB" description = "Clients and models for fetching data from TMDB"