From 3e345c0b815c128b9f9f2318cf169a80e4f04bde Mon Sep 17 00:00:00 2001 From: Aaron Leopold <36278431+aaronleopold@users.noreply.github.com> Date: Thu, 26 May 2022 15:57:39 -0700 Subject: [PATCH] Develop changes (#15) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * bump prisma 🎉 * save progress --- .gitattributes | 6 +- .gitignore | 3 +- Cargo.lock | 125 +++++++++++++++--- packages/core/package.json | 2 +- packages/core/server/Cargo.toml | 2 +- packages/core/server/prisma-cli/Cargo.toml | 2 +- .../migration.sql | 38 +++++- packages/core/server/src/db/migration.rs | 80 +++++++++-- packages/core/server/src/main.rs | 16 +-- packages/core/server/src/routes/api/media.rs | 26 ++-- packages/core/server/src/routes/mod.rs | 1 - packages/core/server/src/routes/openapi.rs | 2 +- packages/core/server/src/types/errors.rs | 14 +- packages/website/src/components/Footer.tsx | 2 +- packages/website/src/components/Layout.tsx | 5 +- packages/website/src/pages/index.tsx | 2 +- 16 files changed, 252 insertions(+), 74 deletions(-) rename packages/core/server/prisma/migrations/{20220525133313_initial_migration => 20220526164945_}/migration.sql (76%) diff --git a/.gitattributes b/.gitattributes index cb670d4d2..9a6e233e4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,6 @@ # ignore markdown files, there's just gonna be so many of them lol -*.md linguist-detectable=false \ No newline at end of file +*.md linguist-detectable=false +*.sql linguist-detectable=false + +# I don't want website to be included in language stats +packages/website/* linguist-vendored \ No newline at end of file diff --git a/.gitignore b/.gitignore index 1e37984b4..ee9f0f072 100644 --- a/.gitignore +++ b/.gitignore @@ -37,4 +37,5 @@ target _next -docker-compose.yaml \ No newline at end of file +docker-compose.yaml +openapi-example* \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 3c36bb25d..0effc5fbb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -99,6 +99,12 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +[[package]] +name = "ascii" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eab1c04a571841102f5345a8fc0f6bb3d31c315dec879b5c6e42e40ce7ffa34e" + [[package]] name = "async-native-tls" version = "0.4.0" @@ -556,6 +562,19 @@ dependencies = [ "winapi", ] +[[package]] +name = "combine" +version = "3.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da3da6baa321ec19e1cc41d31bf599f00c783d0517095cdaf0332e3fe8d20680" +dependencies = [ + "ascii", + "byteorder", + "either", + "memchr", + "unreachable", +] + [[package]] name = "connection-string" version = "0.1.14" @@ -800,7 +819,7 @@ checksum = "3ee2393c4a91429dffb4bedf19f4d6abf27d8a732c8ce4980305d782e5426d57" [[package]] name = "datamodel" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines?rev=8b94a80a2d8f12a2916fe28e3218162aa71e8539#8b94a80a2d8f12a2916fe28e3218162aa71e8539" +source = "git+https://github.com/Brendonovich/prisma-engines?rev=5d34c9a567aaec4065a48d8cf6c2ee885e6ca281#5d34c9a567aaec4065a48d8cf6c2ee885e6ca281" dependencies = [ "bigdecimal 0.2.2", "chrono", @@ -823,7 +842,7 @@ dependencies = [ [[package]] name = "datamodel-connector" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines?rev=8b94a80a2d8f12a2916fe28e3218162aa71e8539#8b94a80a2d8f12a2916fe28e3218162aa71e8539" +source = "git+https://github.com/Brendonovich/prisma-engines?rev=5d34c9a567aaec4065a48d8cf6c2ee885e6ca281#5d34c9a567aaec4065a48d8cf6c2ee885e6ca281" dependencies = [ "diagnostics", "enumflags2", @@ -888,7 +907,7 @@ dependencies = [ [[package]] name = "diagnostics" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines?rev=8b94a80a2d8f12a2916fe28e3218162aa71e8539#8b94a80a2d8f12a2916fe28e3218162aa71e8539" +source = "git+https://github.com/Brendonovich/prisma-engines?rev=5d34c9a567aaec4065a48d8cf6c2ee885e6ca281#5d34c9a567aaec4065a48d8cf6c2ee885e6ca281" dependencies = [ "colored", "pest", @@ -947,7 +966,7 @@ dependencies = [ [[package]] name = "dml" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines?rev=8b94a80a2d8f12a2916fe28e3218162aa71e8539#8b94a80a2d8f12a2916fe28e3218162aa71e8539" +source = "git+https://github.com/Brendonovich/prisma-engines?rev=5d34c9a567aaec4065a48d8cf6c2ee885e6ca281#5d34c9a567aaec4065a48d8cf6c2ee885e6ca281" dependencies = [ "chrono", "cuid 0.1.0", @@ -960,6 +979,17 @@ dependencies = [ "uuid", ] +[[package]] +name = "dmmf" +version = "0.1.0" +source = "git+https://github.com/Brendonovich/prisma-engines?rev=5d34c9a567aaec4065a48d8cf6c2ee885e6ca281#5d34c9a567aaec4065a48d8cf6c2ee885e6ca281" +dependencies = [ + "bigdecimal 0.2.2", + "datamodel", + "serde", + "serde_json", +] + [[package]] name = "dotenv" version = "0.15.0" @@ -1478,6 +1508,16 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" +[[package]] +name = "graphql-parser" +version = "0.3.0" +source = "git+https://github.com/prisma/graphql-parser?rev=6a3f58bd879065588e710cb02b5bd30c1ce182c3#6a3f58bd879065588e710cb02b5bd30c1ce182c3" +dependencies = [ + "combine", + "indexmap", + "thiserror", +] + [[package]] name = "h2" version = "0.3.13" @@ -2210,7 +2250,7 @@ dependencies = [ [[package]] name = "mongodb-client" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines?rev=8b94a80a2d8f12a2916fe28e3218162aa71e8539#8b94a80a2d8f12a2916fe28e3218162aa71e8539" +source = "git+https://github.com/Brendonovich/prisma-engines?rev=5d34c9a567aaec4065a48d8cf6c2ee885e6ca281#5d34c9a567aaec4065a48d8cf6c2ee885e6ca281" dependencies = [ "mongodb", "once_cell", @@ -2221,7 +2261,7 @@ dependencies = [ [[package]] name = "mongodb-datamodel-connector" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines?rev=8b94a80a2d8f12a2916fe28e3218162aa71e8539#8b94a80a2d8f12a2916fe28e3218162aa71e8539" +source = "git+https://github.com/Brendonovich/prisma-engines?rev=5d34c9a567aaec4065a48d8cf6c2ee885e6ca281#5d34c9a567aaec4065a48d8cf6c2ee885e6ca281" dependencies = [ "datamodel-connector", "enumflags2", @@ -2233,7 +2273,7 @@ dependencies = [ [[package]] name = "mongodb-query-connector" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines?rev=8b94a80a2d8f12a2916fe28e3218162aa71e8539#8b94a80a2d8f12a2916fe28e3218162aa71e8539" +source = "git+https://github.com/Brendonovich/prisma-engines?rev=5d34c9a567aaec4065a48d8cf6c2ee885e6ca281#5d34c9a567aaec4065a48d8cf6c2ee885e6ca281" dependencies = [ "anyhow", "async-trait", @@ -2381,7 +2421,7 @@ dependencies = [ [[package]] name = "native-types" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines?rev=8b94a80a2d8f12a2916fe28e3218162aa71e8539#8b94a80a2d8f12a2916fe28e3218162aa71e8539" +source = "git+https://github.com/Brendonovich/prisma-engines?rev=5d34c9a567aaec4065a48d8cf6c2ee885e6ca281#5d34c9a567aaec4065a48d8cf6c2ee885e6ca281" dependencies = [ "serde", "serde_json", @@ -2712,7 +2752,7 @@ dependencies = [ [[package]] name = "parser-database" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines?rev=8b94a80a2d8f12a2916fe28e3218162aa71e8539#8b94a80a2d8f12a2916fe28e3218162aa71e8539" +source = "git+https://github.com/Brendonovich/prisma-engines?rev=5d34c9a567aaec4065a48d8cf6c2ee885e6ca281#5d34c9a567aaec4065a48d8cf6c2ee885e6ca281" dependencies = [ "diagnostics", "enumflags2", @@ -2972,8 +3012,9 @@ dependencies = [ [[package]] name = "prisma-client-rust" version = "0.4.1" -source = "git+https://github.com/Brendonovich/prisma-client-rust?tag=0.4.1#72326a946fa9fad4872eeeb9fa826f7acd5a0bed" +source = "git+https://github.com/Brendonovich/prisma-client-rust?tag=0.5.0#31a864ae09e835ff046469345bf6e413ae54a30f" dependencies = [ + "bigdecimal 0.2.2", "chrono", "datamodel", "prisma-models", @@ -2982,19 +3023,24 @@ dependencies = [ "serde", "serde_json", "thiserror", + "user-facing-errors", ] [[package]] name = "prisma-client-rust-cli" version = "0.4.1" -source = "git+https://github.com/Brendonovich/prisma-client-rust?tag=0.4.1#72326a946fa9fad4872eeeb9fa826f7acd5a0bed" +source = "git+https://github.com/Brendonovich/prisma-client-rust?tag=0.5.0#31a864ae09e835ff046469345bf6e413ae54a30f" dependencies = [ "convert_case", + "datamodel", "directories", "flate2", "http", + "prisma-models", + "query-core", "quote", "regex", + "request-handlers", "reqwest", "serde", "serde_json", @@ -3005,7 +3051,7 @@ dependencies = [ [[package]] name = "prisma-inflector" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines?rev=8b94a80a2d8f12a2916fe28e3218162aa71e8539#8b94a80a2d8f12a2916fe28e3218162aa71e8539" +source = "git+https://github.com/Brendonovich/prisma-engines?rev=5d34c9a567aaec4065a48d8cf6c2ee885e6ca281#5d34c9a567aaec4065a48d8cf6c2ee885e6ca281" dependencies = [ "once_cell", "regex", @@ -3015,7 +3061,7 @@ dependencies = [ [[package]] name = "prisma-models" version = "0.0.0" -source = "git+https://github.com/Brendonovich/prisma-engines?rev=8b94a80a2d8f12a2916fe28e3218162aa71e8539#8b94a80a2d8f12a2916fe28e3218162aa71e8539" +source = "git+https://github.com/Brendonovich/prisma-engines?rev=5d34c9a567aaec4065a48d8cf6c2ee885e6ca281#5d34c9a567aaec4065a48d8cf6c2ee885e6ca281" dependencies = [ "bigdecimal 0.2.2", "chrono", @@ -3036,7 +3082,7 @@ dependencies = [ [[package]] name = "prisma-value" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines?rev=8b94a80a2d8f12a2916fe28e3218162aa71e8539#8b94a80a2d8f12a2916fe28e3218162aa71e8539" +source = "git+https://github.com/Brendonovich/prisma-engines?rev=5d34c9a567aaec4065a48d8cf6c2ee885e6ca281#5d34c9a567aaec4065a48d8cf6c2ee885e6ca281" dependencies = [ "base64 0.12.3", "bigdecimal 0.2.2", @@ -3144,7 +3190,7 @@ dependencies = [ [[package]] name = "query-connector" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines?rev=8b94a80a2d8f12a2916fe28e3218162aa71e8539#8b94a80a2d8f12a2916fe28e3218162aa71e8539" +source = "git+https://github.com/Brendonovich/prisma-engines?rev=5d34c9a567aaec4065a48d8cf6c2ee885e6ca281#5d34c9a567aaec4065a48d8cf6c2ee885e6ca281" dependencies = [ "anyhow", "async-trait", @@ -3164,7 +3210,7 @@ dependencies = [ [[package]] name = "query-core" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines?rev=8b94a80a2d8f12a2916fe28e3218162aa71e8539#8b94a80a2d8f12a2916fe28e3218162aa71e8539" +source = "git+https://github.com/Brendonovich/prisma-engines?rev=5d34c9a567aaec4065a48d8cf6c2ee885e6ca281#5d34c9a567aaec4065a48d8cf6c2ee885e6ca281" dependencies = [ "async-trait", "base64 0.12.3", @@ -3435,6 +3481,28 @@ dependencies = [ "winapi", ] +[[package]] +name = "request-handlers" +version = "0.1.0" +source = "git+https://github.com/Brendonovich/prisma-engines?rev=5d34c9a567aaec4065a48d8cf6c2ee885e6ca281#5d34c9a567aaec4065a48d8cf6c2ee885e6ca281" +dependencies = [ + "bigdecimal 0.2.2", + "connection-string", + "datamodel", + "dmmf", + "futures", + "graphql-parser", + "indexmap", + "itertools", + "query-core", + "serde", + "serde_json", + "thiserror", + "tracing", + "url", + "user-facing-errors", +] + [[package]] name = "reqwest" version = "0.11.10" @@ -3732,7 +3800,7 @@ dependencies = [ [[package]] name = "schema-ast" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines?rev=8b94a80a2d8f12a2916fe28e3218162aa71e8539#8b94a80a2d8f12a2916fe28e3218162aa71e8539" +source = "git+https://github.com/Brendonovich/prisma-engines?rev=5d34c9a567aaec4065a48d8cf6c2ee885e6ca281#5d34c9a567aaec4065a48d8cf6c2ee885e6ca281" dependencies = [ "diagnostics", "pest", @@ -4015,7 +4083,7 @@ dependencies = [ [[package]] name = "sql-datamodel-connector" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines?rev=8b94a80a2d8f12a2916fe28e3218162aa71e8539#8b94a80a2d8f12a2916fe28e3218162aa71e8539" +source = "git+https://github.com/Brendonovich/prisma-engines?rev=5d34c9a567aaec4065a48d8cf6c2ee885e6ca281#5d34c9a567aaec4065a48d8cf6c2ee885e6ca281" dependencies = [ "datamodel-connector", "enumflags2", @@ -4028,7 +4096,7 @@ dependencies = [ [[package]] name = "sql-query-connector" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines?rev=8b94a80a2d8f12a2916fe28e3218162aa71e8539#8b94a80a2d8f12a2916fe28e3218162aa71e8539" +source = "git+https://github.com/Brendonovich/prisma-engines?rev=5d34c9a567aaec4065a48d8cf6c2ee885e6ca281#5d34c9a567aaec4065a48d8cf6c2ee885e6ca281" dependencies = [ "anyhow", "async-trait", @@ -4730,6 +4798,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "unreachable" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" +dependencies = [ + "void", +] + [[package]] name = "untrusted" version = "0.7.1" @@ -4757,7 +4834,7 @@ checksum = "68b90931029ab9b034b300b797048cf23723400aa757e8a2bfb9d748102f9821" [[package]] name = "user-facing-error-macros" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines?rev=8b94a80a2d8f12a2916fe28e3218162aa71e8539#8b94a80a2d8f12a2916fe28e3218162aa71e8539" +source = "git+https://github.com/Brendonovich/prisma-engines?rev=5d34c9a567aaec4065a48d8cf6c2ee885e6ca281#5d34c9a567aaec4065a48d8cf6c2ee885e6ca281" dependencies = [ "proc-macro2", "quote", @@ -4767,7 +4844,7 @@ dependencies = [ [[package]] name = "user-facing-errors" version = "0.1.0" -source = "git+https://github.com/Brendonovich/prisma-engines?rev=8b94a80a2d8f12a2916fe28e3218162aa71e8539#8b94a80a2d8f12a2916fe28e3218162aa71e8539" +source = "git+https://github.com/Brendonovich/prisma-engines?rev=5d34c9a567aaec4065a48d8cf6c2ee885e6ca281#5d34c9a567aaec4065a48d8cf6c2ee885e6ca281" dependencies = [ "backtrace", "indoc", @@ -4806,6 +4883,12 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "void" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" + [[package]] name = "walkdir" version = "2.3.2" diff --git a/packages/core/package.json b/packages/core/package.json index 5fa4d1108..6842d5bda 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -14,7 +14,7 @@ "build:move-rocket": "trash ../../target/release/Rocket.toml && cp ./server/Rocket.toml ../../target/release/Rocket.toml", "build:docker": "docker build -t stump .", "server:start": "cd server && ROCKET_PROFILE=debug cargo run", - "server:dev": "cd server && ROCKET_PROFILE=debug cargo watch -x run", + "server:dev": "cd server && cargo watch -x run", "server:build": "cd server && ROCKET_PROFILE=release cargo build --release", "server:check": "cargo check", "server:fmt": "cargo fmt --all --manifest-path=server/Cargo.toml", diff --git a/packages/core/server/Cargo.toml b/packages/core/server/Cargo.toml index 2c4eb3c04..5d4e4fa00 100644 --- a/packages/core/server/Cargo.toml +++ b/packages/core/server/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" default-run = "stump" [dependencies] -prisma-client-rust = { git = "https://github.com/Brendonovich/prisma-client-rust", tag = "0.4.1" } +prisma-client-rust = { git = "https://github.com/Brendonovich/prisma-client-rust", tag = "0.5.0" } serde = { version = "1.0", features = ["derive"] } dotenv = "0.15.0" # env_logger = "0.9.0" diff --git a/packages/core/server/prisma-cli/Cargo.toml b/packages/core/server/prisma-cli/Cargo.toml index 039dd2de1..9ed9a2062 100644 --- a/packages/core/server/prisma-cli/Cargo.toml +++ b/packages/core/server/prisma-cli/Cargo.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2021" [dependencies] -prisma-client-rust-cli = { git = "https://github.com/Brendonovich/prisma-client-rust", tag = "0.4.1" } \ No newline at end of file +prisma-client-rust-cli = { git = "https://github.com/Brendonovich/prisma-client-rust", tag = "0.5.0" } \ No newline at end of file diff --git a/packages/core/server/prisma/migrations/20220525133313_initial_migration/migration.sql b/packages/core/server/prisma/migrations/20220526164945_/migration.sql similarity index 76% rename from packages/core/server/prisma/migrations/20220525133313_initial_migration/migration.sql rename to packages/core/server/prisma/migrations/20220526164945_/migration.sql index 99c0128df..fa1b1fde7 100644 --- a/packages/core/server/prisma/migrations/20220525133313_initial_migration/migration.sql +++ b/packages/core/server/prisma/migrations/20220526164945_/migration.sql @@ -114,11 +114,27 @@ CREATE TABLE "server_preferences" ( ); -- CreateTable -CREATE TABLE "_MediaToMediaTag" ( +CREATE TABLE "_LibraryToTag" ( "A" TEXT NOT NULL, "B" TEXT NOT NULL, - FOREIGN KEY ("A") REFERENCES "media" ("id") ON DELETE CASCADE ON UPDATE CASCADE, - FOREIGN KEY ("B") REFERENCES "tags" ("id") ON DELETE CASCADE ON UPDATE CASCADE + CONSTRAINT "_LibraryToTag_A_fkey" FOREIGN KEY ("A") REFERENCES "libraries" ("id") ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT "_LibraryToTag_B_fkey" FOREIGN KEY ("B") REFERENCES "tags" ("id") ON DELETE CASCADE ON UPDATE CASCADE +); + +-- CreateTable +CREATE TABLE "_SeriesToTag" ( + "A" TEXT NOT NULL, + "B" TEXT NOT NULL, + CONSTRAINT "_SeriesToTag_A_fkey" FOREIGN KEY ("A") REFERENCES "series" ("id") ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT "_SeriesToTag_B_fkey" FOREIGN KEY ("B") REFERENCES "tags" ("id") ON DELETE CASCADE ON UPDATE CASCADE +); + +-- CreateTable +CREATE TABLE "_MediaToTag" ( + "A" TEXT NOT NULL, + "B" TEXT NOT NULL, + CONSTRAINT "_MediaToTag_A_fkey" FOREIGN KEY ("A") REFERENCES "media" ("id") ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT "_MediaToTag_B_fkey" FOREIGN KEY ("B") REFERENCES "tags" ("id") ON DELETE CASCADE ON UPDATE CASCADE ); -- CreateIndex @@ -149,7 +165,19 @@ CREATE UNIQUE INDEX "reading_list_access_userId_readingListId_key" ON "reading_l CREATE UNIQUE INDEX "read_progresses_userId_mediaId_key" ON "read_progresses"("userId", "mediaId"); -- CreateIndex -CREATE UNIQUE INDEX "_MediaToMediaTag_AB_unique" ON "_MediaToMediaTag"("A", "B"); +CREATE UNIQUE INDEX "_LibraryToTag_AB_unique" ON "_LibraryToTag"("A", "B"); + +-- CreateIndex +CREATE INDEX "_LibraryToTag_B_index" ON "_LibraryToTag"("B"); + +-- CreateIndex +CREATE UNIQUE INDEX "_SeriesToTag_AB_unique" ON "_SeriesToTag"("A", "B"); + +-- CreateIndex +CREATE INDEX "_SeriesToTag_B_index" ON "_SeriesToTag"("B"); + +-- CreateIndex +CREATE UNIQUE INDEX "_MediaToTag_AB_unique" ON "_MediaToTag"("A", "B"); -- CreateIndex -CREATE INDEX "_MediaToMediaTag_B_index" ON "_MediaToMediaTag"("B"); +CREATE INDEX "_MediaToTag_B_index" ON "_MediaToTag"("B"); diff --git a/packages/core/server/src/db/migration.rs b/packages/core/server/src/db/migration.rs index 45495f8c6..2e1ae2717 100644 --- a/packages/core/server/src/db/migration.rs +++ b/packages/core/server/src/db/migration.rs @@ -1,4 +1,6 @@ use anyhow::Result; +use prisma_client_rust::raw; +use serde::Deserialize; use std::io::BufReader; use include_dir::{include_dir, Dir}; @@ -12,16 +14,42 @@ static MIGRATIONS_DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR/prisma/migrations const CREATE_MIGRATIONS_TABLE: &str = include_str!("../../prisma/migrations/migrations.sql"); -// https://github.com/Brendonovich/prisma-client-rust/discussions/57 -// Cannot complete this until above is resolved :( +#[derive(Deserialize, Debug)] +struct CountQueryReturn { + count: u32, +} + +fn get_sql_stmts(sql_str: &str) -> Vec<&str> { + sql_str + .split(";") + .filter(|s| !s.trim().is_empty()) + .collect() +} + pub async fn run_migrations(db: &prisma::PrismaClient) -> Result<()> { - // // Check if the migration table exists - // let count = ... "SELECT count(*) FROM sqlite_master WHERE type='table' AND name='migrations'; + log::info!("Checking for `migrations` table"); + + let res: Vec = db + ._query_raw(raw!( + "SELECT count(*) as count FROM sqlite_master WHERE type='table' AND name='migrations';" + )) + .await?; // If the table doesn't exist, create it - // if count == 0 { - // log::info!("Creating migrations table"); - // } + if res.get(0).unwrap().count == 0 { + log::info!("`migrations` table not found, creating it"); + + let stmts = get_sql_stmts(CREATE_MIGRATIONS_TABLE); + + for stmt in stmts { + log::debug!("{}", stmt); + db._execute_raw(raw!(stmt)).await?; + } + + log::info!("`migrations` table created"); + } else { + log::info!("`migrations` table already exists"); + } // migration structure: directory with name like [timstamp: i64]_[name], with a file named migration.sql let mut migration_dirs = MIGRATIONS_DIR.dirs().collect::>(); @@ -40,16 +68,16 @@ pub async fn run_migrations(db: &prisma::PrismaClient) -> Result<()> { a_timestamp.cmp(&b_timestamp) }); + log::info!("Migrations sorted by timestamp"); + for dir in migration_dirs { let name = dir.path().file_name().unwrap().to_str().unwrap(); - let sql_file = dir.get_file("migration.sql").unwrap(); + let sql_file = dir.get_file(dir.path().join("migration.sql")).unwrap(); let sql_str = sql_file.contents_utf8().unwrap(); let checksum = digest_from_reader(BufReader::new(sql_file.contents()))?; - log::info!("{:?}", &checksum); - let existing_migration = db .migration() .find_unique(migration::checksum::equals(checksum.clone())) @@ -57,19 +85,47 @@ pub async fn run_migrations(db: &prisma::PrismaClient) -> Result<()> { .await?; // Only run migrations that have not been run yet + // TODO: check success? if existing_migration.is_some() { + log::info!( + "Migration {} already applied (checksum: {})", + name, + checksum + ); continue; } log::info!("Running migration {}", name); - // TODO: run the migration - // db._query_raw(sql_str).await?; + let stmts = get_sql_stmts(sql_str); // TODO: do I bother letting this process continue with failed migrations? // I don't see why I should, if the previous migration fails I feel like // the next one shouldn't get run. Which makes the success field on migrations // pointless. TBD. + for stmt in stmts { + log::debug!("{}", stmt); + + match db._execute_raw(raw!(stmt)).await { + Ok(_) => continue, + Err(e) => { + log::error!("Migration {} failed: {}", name, e); + + db.migration() + .create( + migration::name::set(name.to_string()), + migration::checksum::set(checksum.clone()), + vec![migration::success::set(false)], + ) + .exec() + .await?; + + return Err(anyhow::anyhow!(e)); + }, + }; + } + + log::info!("Migration {} applied", name); db.migration() .create( diff --git a/packages/core/server/src/main.rs b/packages/core/server/src/main.rs index ef1aeda42..68b10dc39 100644 --- a/packages/core/server/src/main.rs +++ b/packages/core/server/src/main.rs @@ -66,14 +66,14 @@ async fn rocket() -> _ { // Context clone that will be managed by Rocket let route_ctx = core_ctx.get_ctx(); - // match run_migrations(route_ctx.get_db()).await { - // Ok(_) => { - // log::info!("Migrations ran successfully"); - // }, - // Err(e) => { - // panic!("Failed to run migrations: {:?}", e); - // }, - // }; + match run_migrations(route_ctx.get_db()).await { + Ok(_) => { + log::info!("Migrations ran successfully"); + }, + Err(e) => { + panic!("Failed to run migrations: {:?}", e); + }, + }; tokio::spawn(async move { EventManager::new(core_ctx) diff --git a/packages/core/server/src/routes/api/media.rs b/packages/core/server/src/routes/api/media.rs index 5dd595762..2b3c80e0f 100644 --- a/packages/core/server/src/routes/api/media.rs +++ b/packages/core/server/src/routes/api/media.rs @@ -1,5 +1,5 @@ use prisma_client_rust::Direction; -use rocket::{fs::NamedFile, serde::json::Json, http::ContentType}; +use rocket::{fs::NamedFile, serde::json::Json}; use crate::{ fs, @@ -9,7 +9,7 @@ use crate::{ alias::{ApiResult, Context}, errors::ApiError, http::ImageResponse, - }, utils, + }, }; // TODO: paginate some of these? @@ -194,17 +194,19 @@ pub async fn update_media_progress( // update the progress, otherwise create it Ok(Json( db.read_progress() - .upsert(read_progress::UniqueWhereParam::UserIdMediaIdEquals( - auth.0.id.clone(), - id.clone(), - )) - .create( - read_progress::page::set(page), - read_progress::media::link(media::id::equals(id.clone())), - read_progress::user::link(user::id::equals(auth.0.id.clone())), - vec![], + .upsert( + read_progress::UniqueWhereParam::UserIdMediaIdEquals( + auth.0.id.clone(), + id.clone(), + ), + ( + read_progress::page::set(page), + read_progress::media::link(media::id::equals(id.clone())), + read_progress::user::link(user::id::equals(auth.0.id.clone())), + vec![], + ), + (vec![read_progress::page::set(page)]), ) - .update(vec![read_progress::page::set(page)]) .exec() .await?, )) diff --git a/packages/core/server/src/routes/mod.rs b/packages/core/server/src/routes/mod.rs index d7e944a5f..b9f6e9290 100644 --- a/packages/core/server/src/routes/mod.rs +++ b/packages/core/server/src/routes/mod.rs @@ -1,3 +1,2 @@ pub mod api; pub mod opds; -// pub mod openapi; diff --git a/packages/core/server/src/routes/openapi.rs b/packages/core/server/src/routes/openapi.rs index 0d785e62a..4e57a6b1f 100644 --- a/packages/core/server/src/routes/openapi.rs +++ b/packages/core/server/src/routes/openapi.rs @@ -14,7 +14,7 @@ pub fn openapi() -> Vec { routes.append(&mut api::api()); // Add the routes from `opds` crate. - routes.append(&mut opds::opds()); + // routes.append(&mut opds::opds()); routes } diff --git a/packages/core/server/src/types/errors.rs b/packages/core/server/src/types/errors.rs index 4bf6ca047..752ff059f 100644 --- a/packages/core/server/src/types/errors.rs +++ b/packages/core/server/src/types/errors.rs @@ -96,8 +96,8 @@ impl From for ScanError { } } -impl From for ScanError { - fn from(e: prisma_client_rust::query::Error) -> Self { +impl From for ScanError { + fn from(e: prisma_client_rust::Error) -> Self { ScanError::QueryError(e.to_string()) } } @@ -120,8 +120,8 @@ impl From for Status { } } -impl From for ApiError { - fn from(error: prisma_client_rust::query::Error) -> ApiError { +impl From for ApiError { + fn from(error: prisma_client_rust::Error) -> ApiError { ApiError::InternalServerError(error.to_string()) } } @@ -170,6 +170,12 @@ impl From for ApiError { } } +impl From<&str> for ApiError { + fn from(msg: &str) -> ApiError { + ApiError::InternalServerError(msg.to_string()) + } +} + impl From for ApiError { fn from(error: std::num::TryFromIntError) -> ApiError { ApiError::InternalServerError(error.to_string()) diff --git a/packages/website/src/components/Footer.tsx b/packages/website/src/components/Footer.tsx index 58736a1da..09a5bb6e0 100644 --- a/packages/website/src/components/Footer.tsx +++ b/packages/website/src/components/Footer.tsx @@ -61,7 +61,7 @@ interface LinkSectionProps { const LinkSection = ({ title, links }: LinkSectionProps) => { return ( -
+

{title}

diff --git a/packages/website/src/components/Layout.tsx b/packages/website/src/components/Layout.tsx index 5f2c62286..823c43499 100644 --- a/packages/website/src/components/Layout.tsx +++ b/packages/website/src/components/Layout.tsx @@ -25,13 +25,12 @@ export default function Layout({ children, toc }: Props) { return ( <> - {/* FIXME: determine why I need to do overflow-x-hidden on mobile, I am probably doing something wrong somewhere */}
{isDocs ? : null}
{children} diff --git a/packages/website/src/pages/index.tsx b/packages/website/src/pages/index.tsx index 157e76b89..77f66e054 100644 --- a/packages/website/src/pages/index.tsx +++ b/packages/website/src/pages/index.tsx @@ -9,7 +9,7 @@ export default function Landing() { Stump -
+