diff --git a/.vscode/launch.json b/.vscode/launch.json index fa627bc..d1475d8 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -3,8 +3,8 @@ "compounds": [ { "name": "Development Server", - "configurations": ["Prisma: Development server", "GQL: Development server", "Astro: Development server"], - "stopAll": false + "configurations": [/*"Prisma: Development server",*/ "GQL: Development server", "Astro: Development server"], + "stopAll": true } ], "configurations": [ diff --git a/auth.config.ts b/auth.config.ts index 323a64e..be9d5ed 100644 --- a/auth.config.ts +++ b/auth.config.ts @@ -1,40 +1,31 @@ import { CredentialsSignin } from '@auth/core/errors' import { defineConfig } from 'auth-astro' -import Credentials from "@auth/core/providers/credentials" +import Credentials from '@auth/core/providers/credentials' import bcrypt from 'bcrypt' - -import User from 'sequelize/models/user' - -declare module "@auth/core" { - interface Session { - id: string - username: string - } -} +import prismaClient from 'prisma/client' class InvalidLoginError extends CredentialsSignin { - code = "Invalid username/email or password" + code = 'Invalid username/email or password' } export default defineConfig({ providers: [ Credentials({ credentials: { - username: { label: "Username" }, - password: { label: "Password", type: "password" }, + username: { label: 'Username', required: true }, + password: { label: 'Password', type: 'password', required: true } }, async authorize(credentials) { if (!credentials?.username || !credentials.password) throw new InvalidLoginError() - const user = await User.findByPk(credentials.username) + const user = await prismaClient.users.findUnique({ where: { username: credentials.username } }) if (!user) throw new InvalidLoginError() - // @ts-ignore const valid = await bcrypt.compare(credentials.password, user.password) if (!valid) throw new InvalidLoginError() - return { id: user.username, username: user.username } - }, - }), - ], -}) \ No newline at end of file + return { id: user.username } + } + }) + ] +}) diff --git a/codegen.ts b/codegen.ts index f5e4c54..bba5044 100644 --- a/codegen.ts +++ b/codegen.ts @@ -14,7 +14,7 @@ const config: CodegenConfig = { './src/graphql/__generated__/': defineConfig({ resolverGeneration: 'disabled', typesPluginsConfig: { - contextType: '../client.mts#ResolverContext', + contextType: '../client.ts#ResolverContext', maybeValue: 'T' }, add: { diff --git a/prisma/migrations/0_init/migration.sql b/prisma/migrations/0_init/migration.sql new file mode 100644 index 0000000..64db63c --- /dev/null +++ b/prisma/migrations/0_init/migration.sql @@ -0,0 +1,658 @@ +-- CreateTable +CREATE TABLE `Album_Animation` ( + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + `albumId` INTEGER NOT NULL, + `animationId` INTEGER NOT NULL, + + INDEX `animationId`(`animationId`), + PRIMARY KEY (`albumId`, `animationId`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `Album_Artist` ( + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + `albumId` INTEGER NOT NULL, + `artistSlug` VARCHAR(255) NOT NULL, + + INDEX `artistSlug`(`artistSlug`), + PRIMARY KEY (`albumId`, `artistSlug`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `Album_Category` ( + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + `categoryName` VARCHAR(255) NOT NULL, + `albumId` INTEGER NOT NULL, + + INDEX `ostId`(`albumId`), + PRIMARY KEY (`categoryName`, `albumId`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `Album_Classification` ( + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + `albumId` INTEGER NOT NULL, + `classificationName` VARCHAR(255) NOT NULL, + + INDEX `categoryName`(`classificationName`), + PRIMARY KEY (`albumId`, `classificationName`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `Album_Game` ( + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + `gameSlug` VARCHAR(255) NOT NULL, + `albumId` INTEGER NOT NULL, + + INDEX `ostId`(`albumId`), + PRIMARY KEY (`gameSlug`, `albumId`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `Album_Platform` ( + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + `albumId` INTEGER NOT NULL, + `platformId` INTEGER NOT NULL, + + INDEX `platformId`(`platformId`), + PRIMARY KEY (`albumId`, `platformId`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `Album_Type` ( + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + `albumId` INTEGER NOT NULL, + `typeId` INTEGER NOT NULL, + + INDEX `typeId`(`typeId`), + PRIMARY KEY (`albumId`, `typeId`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `Game_Platform` ( + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + `gameSlug` VARCHAR(255) NOT NULL, + `platformId` INTEGER NOT NULL, + + INDEX `platformId`(`platformId`), + PRIMARY KEY (`gameSlug`, `platformId`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `Publisher_Game` ( + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + `gameSlug` VARCHAR(255) NOT NULL, + `publisherId` INTEGER NOT NULL, + + INDEX `publisherId`(`publisherId`), + PRIMARY KEY (`gameSlug`, `publisherId`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `SequelizeMeta` ( + `name` VARCHAR(255) NOT NULL, + + UNIQUE INDEX `name`(`name`), + PRIMARY KEY (`name`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `Series_Game` ( + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + `gameSlug` VARCHAR(255) NOT NULL, + `seriesSlug` VARCHAR(255) NOT NULL, + + INDEX `seriesSlug`(`seriesSlug`), + PRIMARY KEY (`gameSlug`, `seriesSlug`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `Studio_Animation` ( + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + `animationId` INTEGER NOT NULL, + `studioSlug` VARCHAR(255) NOT NULL, + + INDEX `studioSlug`(`studioSlug`), + PRIMARY KEY (`animationId`, `studioSlug`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `User_Role` ( + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + `userUsername` VARCHAR(255) NOT NULL, + `roleName` VARCHAR(255) NOT NULL, + + INDEX `roleName`(`roleName`), + PRIMARY KEY (`userUsername`, `roleName`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `albumHistories` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `updatedData` JSON NULL, + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + `username` VARCHAR(255) NULL, + `albumId` INTEGER NULL, + + INDEX `ostId`(`albumId`), + INDEX `username`(`username`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `albums` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `title` VARCHAR(255) NULL, + `subTitle` TEXT NULL, + `releaseDate` DATE NULL, + `label` VARCHAR(255) NULL, + `vgmdb` VARCHAR(255) NULL, + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + `description` VARCHAR(255) NULL, + `createdBy` VARCHAR(255) NULL, + `status` VARCHAR(255) NULL, + `placeholder` TEXT NULL, + `headerColor` VARCHAR(255) NULL DEFAULT '#ffffff', + + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `animation` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `title` VARCHAR(255) NULL, + `releaseDate` DATE NULL, + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + `studioSlug` VARCHAR(255) NULL, + `subTitle` VARCHAR(255) NULL, + `placeholder` TEXT NULL, + `headerColor` VARCHAR(255) NULL DEFAULT '#ffffff', + + UNIQUE INDEX `title`(`title`), + UNIQUE INDEX `subTitle`(`subTitle`), + INDEX `studioSlug`(`studioSlug`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `artist` ( + `slug` VARCHAR(255) NOT NULL, + `name` VARCHAR(255) NULL, + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + + PRIMARY KEY (`slug`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `availables` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `url` VARCHAR(255) NULL, + `provider` VARCHAR(255) NULL, + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + `albumId` INTEGER NULL, + + INDEX `ostId`(`albumId`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `category` ( + `name` VARCHAR(255) NOT NULL, + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + + PRIMARY KEY (`name`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `classification` ( + `name` VARCHAR(255) NOT NULL, + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + + PRIMARY KEY (`name`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `comments` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `text` VARCHAR(300) NULL, + `anon` BOOLEAN NULL, + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + `albumId` INTEGER NULL, + `username` VARCHAR(255) NULL, + + INDEX `ostId`(`albumId`), + INDEX `username`(`username`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `config` ( + `name` VARCHAR(255) NOT NULL, + `value` VARCHAR(255) NULL DEFAULT '', + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + + PRIMARY KEY (`name`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `discs` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `number` INTEGER NULL, + `body` TEXT NULL, + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + `albumId` INTEGER NULL, + + INDEX `ostId`(`albumId`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `downloads` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `title` VARCHAR(255) NULL, + `small` BOOLEAN NULL, + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + `albumId` INTEGER NULL, + + INDEX `ostId`(`albumId`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `favorites` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + `albumId` INTEGER NULL, + `username` VARCHAR(255) NULL, + + INDEX `ostId`(`albumId`), + INDEX `username`(`username`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `forgors` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `expires` DATETIME(0) NULL, + `key` VARCHAR(255) NULL, + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + `username` VARCHAR(255) NULL, + + INDEX `username`(`username`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `game` ( + `slug` VARCHAR(255) NOT NULL, + `name` VARCHAR(255) NULL, + `releaseDate` DATE NULL, + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + `placeholder` TEXT NULL, + `headerColor` VARCHAR(255) NULL DEFAULT '#ffffff', + + PRIMARY KEY (`slug`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `linkCategories` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `title` VARCHAR(255) NULL, + `small` BOOLEAN NULL, + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + `albumId` INTEGER NULL, + + INDEX `ostId`(`albumId`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `links` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `url` VARCHAR(255) NULL, + `directUrl` VARCHAR(255) NULL, + `provider` VARCHAR(255) NULL, + `custom` VARCHAR(255) NULL, + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + `downloadId` INTEGER NULL, + `url2` VARCHAR(255) NULL, + + INDEX `downloadId`(`downloadId`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `logs` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `action` VARCHAR(255) NULL, + `data` TEXT NULL, + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + `username` VARCHAR(255) NULL, + + INDEX `username`(`username`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `pendings` ( + `id` INTEGER NOT NULL, + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `platform` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `name` VARCHAR(255) NULL, + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + `type` VARCHAR(255) NULL DEFAULT 'Game', + + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `publisher` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `name` VARCHAR(255) NULL, + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `ratings` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `score` INTEGER NULL, + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + `albumId` INTEGER NULL, + `username` VARCHAR(255) NULL, + + INDEX `ostId`(`albumId`), + INDEX `username`(`username`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `related_album` ( + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + `albumId` INTEGER NOT NULL, + `relatedId` INTEGER NOT NULL, + + INDEX `relatedId`(`relatedId`), + PRIMARY KEY (`albumId`, `relatedId`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `requests` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `title` VARCHAR(255) NULL, + `link` VARCHAR(255) NULL, + `user` VARCHAR(255) NULL, + `userID` VARCHAR(255) NULL, + `state` VARCHAR(255) NOT NULL, + `donator` BOOLEAN NOT NULL, + `reason` VARCHAR(255) NULL, + `comments` VARCHAR(255) NULL, + `message` VARCHAR(255) NULL, + `createdAt` DATETIME(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0), + `updatedAt` DATETIME(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0), + + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `roles` ( + `name` VARCHAR(255) NOT NULL, + `permissions` JSON NULL, + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + + PRIMARY KEY (`name`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `series` ( + `slug` VARCHAR(255) NOT NULL, + `name` VARCHAR(255) NULL, + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + `placeholder` TEXT NULL, + `headerColor` VARCHAR(255) NULL DEFAULT '#ffffff', + + PRIMARY KEY (`slug`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `stores` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `url` VARCHAR(255) NULL, + `provider` VARCHAR(255) NULL, + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + `albumId` INTEGER NULL, + + INDEX `ostId`(`albumId`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `studio` ( + `slug` VARCHAR(255) NOT NULL, + `name` VARCHAR(255) NULL, + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + + PRIMARY KEY (`slug`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `submissions` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `state` VARCHAR(255) NULL DEFAULT 'pending', + `title` VARCHAR(255) NULL, + `vgmdb` VARCHAR(255) NULL, + `links` TEXT NULL, + `score` INTEGER NULL DEFAULT 0, + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + `userUsername` VARCHAR(255) NULL, + `requestId` INTEGER NULL, + + INDEX `requestId`(`requestId`), + INDEX `userUsername`(`userUsername`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `type` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `name` VARCHAR(255) NULL, + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- CreateTable +CREATE TABLE `users` ( + `username` VARCHAR(255) NOT NULL, + `email` VARCHAR(255) NULL, + `password` VARCHAR(255) NULL, + `createdAt` DATETIME(0) NOT NULL, + `updatedAt` DATETIME(0) NOT NULL, + `placeholder` TEXT NULL, + `imgId` VARCHAR(255) NULL, + + PRIMARY KEY (`username`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- AddForeignKey +ALTER TABLE `Album_Animation` ADD CONSTRAINT `Album_Animation_ibfk_1` FOREIGN KEY (`albumId`) REFERENCES `albums`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Album_Animation` ADD CONSTRAINT `Album_Animation_ibfk_2` FOREIGN KEY (`animationId`) REFERENCES `animation`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Album_Artist` ADD CONSTRAINT `Album_Artist_ibfk_1` FOREIGN KEY (`albumId`) REFERENCES `albums`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Album_Artist` ADD CONSTRAINT `Album_Artist_ibfk_2` FOREIGN KEY (`artistSlug`) REFERENCES `artist`(`slug`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Album_Category` ADD CONSTRAINT `Album_Category_ibfk_1` FOREIGN KEY (`categoryName`) REFERENCES `category`(`name`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Album_Category` ADD CONSTRAINT `Album_Category_ibfk_2` FOREIGN KEY (`albumId`) REFERENCES `albums`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Album_Classification` ADD CONSTRAINT `Album_Classification_ibfk_1` FOREIGN KEY (`albumId`) REFERENCES `albums`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Album_Classification` ADD CONSTRAINT `Album_Classification_ibfk_2` FOREIGN KEY (`classificationName`) REFERENCES `classification`(`name`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Album_Game` ADD CONSTRAINT `Album_Game_ibfk_1` FOREIGN KEY (`gameSlug`) REFERENCES `game`(`slug`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Album_Game` ADD CONSTRAINT `Album_Game_ibfk_2` FOREIGN KEY (`albumId`) REFERENCES `albums`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Album_Platform` ADD CONSTRAINT `Album_Platform_ibfk_1` FOREIGN KEY (`albumId`) REFERENCES `albums`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Album_Platform` ADD CONSTRAINT `Album_Platform_ibfk_2` FOREIGN KEY (`platformId`) REFERENCES `platform`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Album_Type` ADD CONSTRAINT `Album_Type_ibfk_1` FOREIGN KEY (`albumId`) REFERENCES `albums`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Album_Type` ADD CONSTRAINT `Album_Type_ibfk_2` FOREIGN KEY (`typeId`) REFERENCES `type`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Game_Platform` ADD CONSTRAINT `Game_Platform_ibfk_1` FOREIGN KEY (`gameSlug`) REFERENCES `game`(`slug`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Game_Platform` ADD CONSTRAINT `Game_Platform_ibfk_2` FOREIGN KEY (`platformId`) REFERENCES `platform`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Publisher_Game` ADD CONSTRAINT `Publisher_Game_ibfk_1` FOREIGN KEY (`gameSlug`) REFERENCES `game`(`slug`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Publisher_Game` ADD CONSTRAINT `Publisher_Game_ibfk_2` FOREIGN KEY (`publisherId`) REFERENCES `publisher`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Series_Game` ADD CONSTRAINT `Series_Game_ibfk_1` FOREIGN KEY (`gameSlug`) REFERENCES `game`(`slug`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Series_Game` ADD CONSTRAINT `Series_Game_ibfk_2` FOREIGN KEY (`seriesSlug`) REFERENCES `series`(`slug`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Studio_Animation` ADD CONSTRAINT `Studio_Animation_ibfk_1` FOREIGN KEY (`animationId`) REFERENCES `animation`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `Studio_Animation` ADD CONSTRAINT `Studio_Animation_ibfk_2` FOREIGN KEY (`studioSlug`) REFERENCES `studio`(`slug`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `User_Role` ADD CONSTRAINT `User_Role_ibfk_1` FOREIGN KEY (`userUsername`) REFERENCES `users`(`username`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `User_Role` ADD CONSTRAINT `User_Role_ibfk_2` FOREIGN KEY (`roleName`) REFERENCES `roles`(`name`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `albumHistories` ADD CONSTRAINT `albumHistories_ibfk_1` FOREIGN KEY (`username`) REFERENCES `users`(`username`) ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `albumHistories` ADD CONSTRAINT `albumHistories_ibfk_2` FOREIGN KEY (`albumId`) REFERENCES `albums`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `animation` ADD CONSTRAINT `animation_ibfk_1` FOREIGN KEY (`studioSlug`) REFERENCES `studio`(`slug`) ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `availables` ADD CONSTRAINT `availables_ibfk_1` FOREIGN KEY (`albumId`) REFERENCES `albums`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `comments` ADD CONSTRAINT `comments_ibfk_1` FOREIGN KEY (`albumId`) REFERENCES `albums`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `comments` ADD CONSTRAINT `comments_ibfk_2` FOREIGN KEY (`username`) REFERENCES `users`(`username`) ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `discs` ADD CONSTRAINT `discs_ibfk_1` FOREIGN KEY (`albumId`) REFERENCES `albums`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `downloads` ADD CONSTRAINT `downloads_ibfk_1` FOREIGN KEY (`albumId`) REFERENCES `albums`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `favorites` ADD CONSTRAINT `favorites_ibfk_1` FOREIGN KEY (`albumId`) REFERENCES `albums`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `favorites` ADD CONSTRAINT `favorites_ibfk_2` FOREIGN KEY (`username`) REFERENCES `users`(`username`) ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `forgors` ADD CONSTRAINT `forgors_ibfk_1` FOREIGN KEY (`username`) REFERENCES `users`(`username`) ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `linkCategories` ADD CONSTRAINT `linkCategories_ibfk_1` FOREIGN KEY (`albumId`) REFERENCES `albums`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `links` ADD CONSTRAINT `links_ibfk_1` FOREIGN KEY (`downloadId`) REFERENCES `downloads`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `logs` ADD CONSTRAINT `logs_ibfk_1` FOREIGN KEY (`username`) REFERENCES `users`(`username`) ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `ratings` ADD CONSTRAINT `ratings_ibfk_1` FOREIGN KEY (`albumId`) REFERENCES `albums`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `ratings` ADD CONSTRAINT `ratings_ibfk_2` FOREIGN KEY (`username`) REFERENCES `users`(`username`) ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `related_album` ADD CONSTRAINT `related_album_ibfk_1` FOREIGN KEY (`albumId`) REFERENCES `albums`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `related_album` ADD CONSTRAINT `related_album_ibfk_2` FOREIGN KEY (`relatedId`) REFERENCES `albums`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `stores` ADD CONSTRAINT `stores_ibfk_1` FOREIGN KEY (`albumId`) REFERENCES `albums`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `submissions` ADD CONSTRAINT `submissions_ibfk_1` FOREIGN KEY (`userUsername`) REFERENCES `users`(`username`) ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `submissions` ADD CONSTRAINT `submissions_ibfk_2` FOREIGN KEY (`requestId`) REFERENCES `requests`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; + diff --git a/prisma/schema.prisma b/prisma/schema.prisma new file mode 100644 index 0000000..f2eca75 --- /dev/null +++ b/prisma/schema.prisma @@ -0,0 +1,530 @@ +generator client { + provider = "prisma-client-js" + previewFeatures = ["fullTextSearch"] +} + +datasource db { + provider = "mysql" + url = env("DATABASE_URL") +} + +model Album_Animation { + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + albumId Int + animationId Int + albums albums @relation(fields: [albumId], references: [id], onDelete: Cascade, map: "Album_Animation_ibfk_1") + animation animation @relation(fields: [animationId], references: [id], onDelete: Cascade, map: "Album_Animation_ibfk_2") + + @@id([albumId, animationId]) + @@index([animationId], map: "animationId") +} + +model Album_Artist { + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + albumId Int + artistSlug String @db.VarChar(255) + albums albums @relation(fields: [albumId], references: [id], onDelete: Cascade, map: "Album_Artist_ibfk_1") + artist artist @relation(fields: [artistSlug], references: [slug], onDelete: Cascade, map: "Album_Artist_ibfk_2") + + @@id([albumId, artistSlug]) + @@index([artistSlug], map: "artistSlug") +} + +model Album_Category { + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + categoryName String @db.VarChar(255) + albumId Int + category category @relation(fields: [categoryName], references: [name], onDelete: Cascade, map: "Album_Category_ibfk_1") + albums albums @relation(fields: [albumId], references: [id], onDelete: Cascade, map: "Album_Category_ibfk_2") + + @@id([categoryName, albumId]) + @@index([albumId], map: "ostId") +} + +model Album_Classification { + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + albumId Int + classificationName String @db.VarChar(255) + albums albums @relation(fields: [albumId], references: [id], onDelete: Cascade, map: "Album_Classification_ibfk_1") + classification classification @relation(fields: [classificationName], references: [name], onDelete: Cascade, map: "Album_Classification_ibfk_2") + + @@id([albumId, classificationName]) + @@index([classificationName], map: "categoryName") +} + +model Album_Game { + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + gameSlug String @db.VarChar(255) + albumId Int + game game @relation(fields: [gameSlug], references: [slug], onDelete: Cascade, map: "Album_Game_ibfk_1") + albums albums @relation(fields: [albumId], references: [id], onDelete: Cascade, map: "Album_Game_ibfk_2") + + @@id([gameSlug, albumId]) + @@index([albumId], map: "ostId") +} + +model Album_Platform { + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + albumId Int + platformId Int + albums albums @relation(fields: [albumId], references: [id], onDelete: Cascade, map: "Album_Platform_ibfk_1") + platform platform @relation(fields: [platformId], references: [id], onDelete: Cascade, map: "Album_Platform_ibfk_2") + + @@id([albumId, platformId]) + @@index([platformId], map: "platformId") +} + +model Album_Type { + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + albumId Int + typeId Int + albums albums @relation(fields: [albumId], references: [id], onDelete: Cascade, map: "Album_Type_ibfk_1") + type type @relation(fields: [typeId], references: [id], onDelete: Cascade, map: "Album_Type_ibfk_2") + + @@id([albumId, typeId]) + @@index([typeId], map: "typeId") +} + +model Game_Platform { + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + gameSlug String @db.VarChar(255) + platformId Int + game game @relation(fields: [gameSlug], references: [slug], onDelete: Cascade, map: "Game_Platform_ibfk_1") + platform platform @relation(fields: [platformId], references: [id], onDelete: Cascade, map: "Game_Platform_ibfk_2") + + @@id([gameSlug, platformId]) + @@index([platformId], map: "platformId") +} + +model Publisher_Game { + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + gameSlug String @db.VarChar(255) + publisherId Int + game game @relation(fields: [gameSlug], references: [slug], onDelete: Cascade, map: "Publisher_Game_ibfk_1") + publisher publisher @relation(fields: [publisherId], references: [id], onDelete: Cascade, map: "Publisher_Game_ibfk_2") + + @@id([gameSlug, publisherId]) + @@index([publisherId], map: "publisherId") +} + +model SequelizeMeta { + name String @id @unique(map: "name") @db.VarChar(255) +} + +model Series_Game { + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + gameSlug String @db.VarChar(255) + seriesSlug String @db.VarChar(255) + game game @relation(fields: [gameSlug], references: [slug], onDelete: Cascade, map: "Series_Game_ibfk_1") + series series @relation(fields: [seriesSlug], references: [slug], onDelete: Cascade, map: "Series_Game_ibfk_2") + + @@id([gameSlug, seriesSlug]) + @@index([seriesSlug], map: "seriesSlug") +} + +model Studio_Animation { + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + animationId Int + studioSlug String @db.VarChar(255) + animation animation @relation(fields: [animationId], references: [id], onDelete: Cascade, map: "Studio_Animation_ibfk_1") + studio studio @relation(fields: [studioSlug], references: [slug], onDelete: Cascade, map: "Studio_Animation_ibfk_2") + + @@id([animationId, studioSlug]) + @@index([studioSlug], map: "studioSlug") +} + +model User_Role { + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + userUsername String @db.VarChar(255) + roleName String @db.VarChar(255) + users users @relation(fields: [userUsername], references: [username], onDelete: Cascade, map: "User_Role_ibfk_1") + roles roles @relation(fields: [roleName], references: [name], onDelete: Cascade, map: "User_Role_ibfk_2") + + @@id([userUsername, roleName]) + @@index([roleName], map: "roleName") +} + +model albumHistories { + id Int @id @default(autoincrement()) + updatedData Json? + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + username String? @db.VarChar(255) + albumId Int? + users users? @relation(fields: [username], references: [username], map: "albumHistories_ibfk_1") + albums albums? @relation(fields: [albumId], references: [id], map: "albumHistories_ibfk_2") + + @@index([albumId], map: "ostId") + @@index([username], map: "username") +} + +model albums { + id Int @id @default(autoincrement()) + title String? @db.VarChar(255) + subTitle String? @db.Text + releaseDate DateTime? @db.Date + label String? @db.VarChar(255) + vgmdb String? @db.VarChar(255) + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + description String? @db.VarChar(255) + createdBy String? @db.VarChar(255) + status String? @db.VarChar(255) + placeholder String? @db.Text + headerColor String? @default("#ffffff") @db.VarChar(255) + Album_Animation Album_Animation[] + Album_Artist Album_Artist[] + Album_Category Album_Category[] + Album_Classification Album_Classification[] + Album_Game Album_Game[] + Album_Platform Album_Platform[] + Album_Type Album_Type[] + albumHistories albumHistories[] + availables availables[] + comments comments[] + discs discs[] + downloads downloads[] + favorites favorites[] + linkCategories linkCategories[] + ratings ratings[] + related_album_related_album_albumIdToalbums related_album[] @relation("related_album_albumIdToalbums") + related_album_related_album_relatedIdToalbums related_album[] @relation("related_album_relatedIdToalbums") + stores stores[] +} + +model animation { + id Int @id @default(autoincrement()) + title String? @unique(map: "title") @db.VarChar(255) + releaseDate DateTime? @db.Date + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + studioSlug String? @db.VarChar(255) + subTitle String? @unique(map: "subTitle") @db.VarChar(255) + placeholder String? @db.Text + headerColor String? @default("#ffffff") @db.VarChar(255) + Album_Animation Album_Animation[] + Studio_Animation Studio_Animation[] + studio studio? @relation(fields: [studioSlug], references: [slug], map: "animation_ibfk_1") + + @@index([studioSlug], map: "studioSlug") +} + +model artist { + slug String @id @db.VarChar(255) + name String? @db.VarChar(255) + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + Album_Artist Album_Artist[] +} + +model availables { + id Int @id @default(autoincrement()) + url String? @db.VarChar(255) + provider String? @db.VarChar(255) + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + albumId Int? + albums albums? @relation(fields: [albumId], references: [id], map: "availables_ibfk_1") + + @@index([albumId], map: "ostId") +} + +model category { + name String @id @db.VarChar(255) + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + Album_Category Album_Category[] +} + +model classification { + name String @id @db.VarChar(255) + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + Album_Classification Album_Classification[] +} + +model comments { + id Int @id @default(autoincrement()) + text String? @db.VarChar(300) + anon Boolean? + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + albumId Int? + username String? @db.VarChar(255) + albums albums? @relation(fields: [albumId], references: [id], map: "comments_ibfk_1") + users users? @relation(fields: [username], references: [username], map: "comments_ibfk_2") + + @@index([albumId], map: "ostId") + @@index([username], map: "username") +} + +model config { + name String @id @db.VarChar(255) + value String? @default("") @db.VarChar(255) + createdAt DateTime @default(now()) @db.DateTime(0) + updatedAt DateTime @default(now()) @db.DateTime(0) +} + +model discs { + id Int @id @default(autoincrement()) + number Int? + body String? @db.Text + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + albumId Int? + albums albums? @relation(fields: [albumId], references: [id], map: "discs_ibfk_1") + + @@index([albumId], map: "ostId") +} + +model downloads { + id Int @id @default(autoincrement()) + title String? @db.VarChar(255) + small Boolean? + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + albumId Int? + albums albums? @relation(fields: [albumId], references: [id], onDelete: Cascade, map: "downloads_ibfk_1") + links links[] + + @@index([albumId], map: "ostId") +} + +model favorites { + id Int @id @default(autoincrement()) + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + albumId Int? + username String? @db.VarChar(255) + albums albums? @relation(fields: [albumId], references: [id], map: "favorites_ibfk_1") + users users? @relation(fields: [username], references: [username], map: "favorites_ibfk_2") + + @@index([albumId], map: "ostId") + @@index([username], map: "username") +} + +model forgors { + id Int @id @default(autoincrement()) + expires DateTime? @db.DateTime(0) + key String? @db.VarChar(255) + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + username String? @db.VarChar(255) + users users? @relation(fields: [username], references: [username], map: "forgors_ibfk_1") + + @@index([username], map: "username") +} + +model game { + slug String @id @db.VarChar(255) + name String? @db.VarChar(255) + releaseDate DateTime? @db.Date + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + placeholder String? @db.Text + headerColor String? @default("#ffffff") @db.VarChar(255) + Album_Game Album_Game[] + Game_Platform Game_Platform[] + Publisher_Game Publisher_Game[] + Series_Game Series_Game[] +} + +model linkCategories { + id Int @id @default(autoincrement()) + title String? @db.VarChar(255) + small Boolean? + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + albumId Int? + albums albums? @relation(fields: [albumId], references: [id], map: "linkCategories_ibfk_1") + + @@index([albumId], map: "ostId") +} + +model links { + id Int @id @default(autoincrement()) + url String? @db.VarChar(255) + directUrl String? @db.VarChar(255) + provider String? @db.VarChar(255) + custom String? @db.VarChar(255) + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + downloadId Int? + url2 String? @db.VarChar(255) + downloads downloads? @relation(fields: [downloadId], references: [id], map: "links_ibfk_1") + + @@index([downloadId], map: "downloadId") +} + +model logs { + id Int @id @default(autoincrement()) + action String? @db.VarChar(255) + data String? @db.Text + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + username String? @db.VarChar(255) + users users? @relation(fields: [username], references: [username], map: "logs_ibfk_1") + + @@index([username], map: "username") +} + +model pendings { + id Int @id + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) +} + +model platform { + id Int @id @default(autoincrement()) + name String? @db.VarChar(255) + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + type String? @default("Game") @db.VarChar(255) + Album_Platform Album_Platform[] + Game_Platform Game_Platform[] +} + +model publisher { + id Int @id @default(autoincrement()) + name String? @db.VarChar(255) + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + Publisher_Game Publisher_Game[] +} + +model ratings { + id Int @id @default(autoincrement()) + score Int? + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + albumId Int? + username String? @db.VarChar(255) + albums albums? @relation(fields: [albumId], references: [id], map: "ratings_ibfk_1") + users users? @relation(fields: [username], references: [username], map: "ratings_ibfk_2") + + @@index([albumId], map: "ostId") + @@index([username], map: "username") +} + +model related_album { + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + albumId Int + relatedId Int + albums_related_album_albumIdToalbums albums @relation("related_album_albumIdToalbums", fields: [albumId], references: [id], onDelete: Cascade, map: "related_album_ibfk_1") + albums_related_album_relatedIdToalbums albums @relation("related_album_relatedIdToalbums", fields: [relatedId], references: [id], onDelete: Cascade, map: "related_album_ibfk_2") + + @@id([albumId, relatedId]) + @@index([relatedId], map: "relatedId") +} + +model requests { + id Int @id @default(autoincrement()) + title String? @db.VarChar(255) + link String? @db.VarChar(255) + user String? @db.VarChar(255) + userID String? @db.VarChar(255) + state String @db.VarChar(255) + donator Boolean + reason String? @db.VarChar(255) + comments String? @db.VarChar(255) + message String? @db.VarChar(255) + createdAt DateTime @default(now()) @db.DateTime(0) + updatedAt DateTime @default(now()) @db.DateTime(0) + submissions submissions[] +} + +model roles { + name String @id @db.VarChar(255) + permissions Json? + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + User_Role User_Role[] +} + +model series { + slug String @id @db.VarChar(255) + name String? @db.VarChar(255) + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + placeholder String? @db.Text + headerColor String? @default("#ffffff") @db.VarChar(255) + Series_Game Series_Game[] +} + +model stores { + id Int @id @default(autoincrement()) + url String? @db.VarChar(255) + provider String? @db.VarChar(255) + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + albumId Int? + albums albums? @relation(fields: [albumId], references: [id], onDelete: Cascade, map: "stores_ibfk_1") + + @@index([albumId], map: "ostId") +} + +model studio { + slug String @id @db.VarChar(255) + name String? @db.VarChar(255) + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + Studio_Animation Studio_Animation[] + animation animation[] +} + +model submissions { + id Int @id @default(autoincrement()) + state String? @default("pending") @db.VarChar(255) + title String? @db.VarChar(255) + vgmdb String? @db.VarChar(255) + links String? @db.Text + score Int? @default(0) + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + userUsername String? @db.VarChar(255) + requestId Int? + users users? @relation(fields: [userUsername], references: [username], map: "submissions_ibfk_1") + requests requests? @relation(fields: [requestId], references: [id], map: "submissions_ibfk_2") + + @@index([requestId], map: "requestId") + @@index([userUsername], map: "userUsername") +} + +model type { + id Int @id @default(autoincrement()) + name String? @db.VarChar(255) + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + Album_Type Album_Type[] +} + +model users { + username String @id @db.VarChar(255) + email String? @db.VarChar(255) + password String? @db.VarChar(255) + createdAt DateTime @db.DateTime(0) + updatedAt DateTime @db.DateTime(0) + placeholder String? @db.Text + imgId String? @db.VarChar(255) + User_Role User_Role[] + albumHistories albumHistories[] + comments comments[] + favorites favorites[] + forgors forgors[] + logs logs[] + ratings ratings[] + submissions submissions[] +} diff --git a/src/components/Header.astro b/src/components/Header.astro index 18aca23..ca738b0 100644 --- a/src/components/Header.astro +++ b/src/components/Header.astro @@ -1,6 +1,6 @@ --- import { gql } from '@/graphql/__generated__/client/index.js' -import { getApolloClient } from '@/graphql/apolloClient.mjs' +import { getApolloClient } from '@/graphql/apolloClient.js' import { Image, Picture } from 'astro:assets' import { getSession } from 'auth-astro/server' import * as m from '../paraglide/messages.js' @@ -45,13 +45,7 @@ const session = await getSession(Astro.request)
- logo + logo
diff --git a/src/graphql/apolloClient.mts b/src/graphql/apolloClient.mts deleted file mode 100644 index 213054a..0000000 --- a/src/graphql/apolloClient.mts +++ /dev/null @@ -1,24 +0,0 @@ -import ApolloPackage from '@apollo/client' -const { ApolloClient, InMemoryCache } = ApolloPackage; -import { SchemaLink } from "@apollo/client/link/schema" -import { makeExecutableSchema } from "@graphql-tools/schema"; -import { getSession } from 'auth-astro/server'; -import type { Session } from '@auth/core/types'; - -import { typeDefs } from "./__generated__/typeDefs.generated"; -import resolvers from '@/graphql/resolvers' - -import db from 'sequelize'; - -const schema = makeExecutableSchema({ typeDefs, resolvers }) -export type ResolverContext = { request?: Request, session?: Session } - -export async function getApolloClient(request?: Request) { - const session = request ? await getSession(request) : null - - return new ApolloClient({ - ssrMode: true, - link: new SchemaLink({ schema, context: { request, session, db } }), - cache: new InMemoryCache() - }) -} \ No newline at end of file diff --git a/src/graphql/apolloClient.ts b/src/graphql/apolloClient.ts new file mode 100644 index 0000000..ba8e02f --- /dev/null +++ b/src/graphql/apolloClient.ts @@ -0,0 +1,23 @@ +import { ApolloClient, InMemoryCache } from '@apollo/client/core' +import { SchemaLink } from '@apollo/client/link/schema' +import { makeExecutableSchema } from '@graphql-tools/schema' +import { getSession } from 'auth-astro/server' +import type { Session } from '@auth/core/types' +import prismaClient, { type users } from 'prisma/client' + +import { typeDefs } from './__generated__/typeDefs.generated' +import resolvers from '@/graphql/resolvers' + +const schema = makeExecutableSchema({ typeDefs, resolvers }) +export type ResolverContext = { request?: Request; session?: Session; user?: users } + +export async function getApolloClient(request?: Request) { + const session = async () => (request ? getSession(request) : null) + const user = async () => (session ? prismaClient.users.findUnique({ where: { username: session.id } }) : null) + + return new ApolloClient({ + ssrMode: true, + link: new SchemaLink({ schema, context: { request, session, user } }), + cache: new InMemoryCache() + }) +} diff --git a/src/graphql/resolvers/queries/search.ts b/src/graphql/resolvers/queries/search.ts index 38e5def..8ae1b99 100644 --- a/src/graphql/resolvers/queries/search.ts +++ b/src/graphql/resolvers/queries/search.ts @@ -1,35 +1,41 @@ -import { Op, literal } from '@sequelize/core' +import prismaClient from 'prisma/client' + import type { Resolvers } from '@/graphql/__generated__/types.generated' -import Category from 'sequelize/models/category' -import Album from 'sequelize/models/album' - -const fuzzySearch = (words: string[]) => `^${words.map(w => `(?=.*\b${w}\b)`)}.+/i` - const resolvers: Resolvers = { Query: { - // @ts-ignore - searchAlbum: async (_, args, { db }) => { - const { title, categories, limit = 10, offset = 0, order = ['createdAt'], mode = 'DESC', status = ['show'] } = args - const fuzzyCondition = title ? { - [Op.or]: [ - { title: { [Op.regexp]: fuzzySearch(title.split(' ')) } }, - { subTitle: { [Op.regexp]: fuzzySearch(title.split(' ')) } } - ] - } : {} + searchAlbum: async (_, args, context, info) => { + const { + title, + categories, + limit = 10, + offset = 0, + order = ['createdAt'], + mode = 'DESC', + status = ['show'] + } = args + const fuzzyCondition = title + ? { + OR: [ + { title: { search: title.toLowerCase().split(' ').join(' & ') } }, + { subTitle: { search: title.toLowerCase().split(' ').join(' & ') } } + ] + } + : {} - const include = [] - if (categories) include.push({ model: Category, where: { name: { [Op.in]: categories } } }) - - const result = await Album.findAndCountAll({ - limit, offset, + const result = prismaClient.albums.findMany({ + take: limit, + skip: offset, where: { - ...fuzzyCondition, - status: { [Op.in]: status } + AND: { + ...fuzzyCondition, + // category condition + status: { in: status } + } }, - include, - // @ts-ignore - order: [literal('`album`.`status` = \'coming\' DESC'), ...order.map(o => [o, mode])] + include: { Album_Category: !!categories }, + orderBy: [...order.map((o) => ({ [o]: mode.toLowerCase() }))] + // order: [literal("`album`.`status` = 'coming' DESC")] }) return result diff --git a/src/graphql/resolvers/queries/site.ts b/src/graphql/resolvers/queries/site.ts index a739de5..093f7a3 100644 --- a/src/graphql/resolvers/queries/site.ts +++ b/src/graphql/resolvers/queries/site.ts @@ -1,22 +1,21 @@ // import fg from 'fast-glob' -import type { Resolvers } from '@/graphql/__generated__/types.generated' import { composeResolvers } from '@graphql-tools/resolvers-composition' -import Config from 'sequelize/models/config' - -// import { hasRole } from 'server/utils/resolvers' +import type { Resolvers } from '@/graphql/__generated__/types.generated' +import prismaClient from 'prisma/client' const resolversComposition = { /* 'Query.banners': hasRole('UPDATE') */ } + const resolvers: Resolvers = { Query: { - config: async (_, args) => { - const { name } = args - const [result] = await Config.findOrCreate({ where: { name } }) - - return result - }, + config: async (_, { name }) => + prismaClient.config.upsert({ + where: { name }, + create: { name }, + update: {} + }) /* highlight: async (parent, args, { db }) => { const { value } = await db.models.config.findByPk('highlight') diff --git a/src/graphql/resolvers/types/album.ts b/src/graphql/resolvers/types/album.ts index 969a135..4e6dd04 100644 --- a/src/graphql/resolvers/types/album.ts +++ b/src/graphql/resolvers/types/album.ts @@ -1,12 +1,12 @@ // import { GraphQLUpload } from 'graphql-upload-minimal' -import type { Resolvers } from "@/graphql/__generated__/types.generated" -import type Album from "sequelize/models/album" +import prismaClient from 'prisma/client' + +import type { Resolvers } from '@/graphql/__generated__/types.generated' const resolvers: Resolvers = { // Upload: GraphQLUpload, Album: { - // @ts-ignore - artists: (parent, args, context, info) => parent.getArtists(), + artists: (album) => prismaClient.artist.findMany({ where: { Album_Artist: { some: { albumId: album.id } } } }) /* categories: (parent, args, context, info) => parent.getCategories(), classifications: (parent, args, context, info) => parent.getClassifications(), @@ -46,7 +46,7 @@ const resolvers: Resolvers = { placeholder: (album, _, { db }) => checkPlaceholder(album, 'album'), headerColor: (album, _, { db }) => checkHeaderColor(album, 'album'), avgRating: async (album, _, { db }) => solveRating(album) */ - }, + } /* Comment: { username: (parent) => (parent.anon ? null : parent.username), diff --git a/src/graphql/typeDefs/album.graphql b/src/graphql/typeDefs/album.graphql index f915428..257ef2c 100644 --- a/src/graphql/typeDefs/album.graphql +++ b/src/graphql/typeDefs/album.graphql @@ -150,7 +150,7 @@ type Query { order: [String] mode: String status: [String!] - ): SearchAlbumResult + ): [Album]! searchAlbumByArtist( name: String! categories: [String] @@ -160,34 +160,10 @@ type Query { mode: String status: [String!] ): SearchAlbumResult - searchAnimation( - title: String - limit: Int - page: Int - order: String - mode: String - ): SearchAnimResult - searchStudio( - name: String - limit: Int - page: Int - order: String - mode: String - ): SearchStudioResult - searchGame( - name: String - limit: Int - page: Int - order: String - mode: String - ): SearchGameResult - searchSeries( - name: String - limit: Int - page: Int - order: String - mode: String - ): SearchSeriesResult + searchAnimation(title: String, limit: Int, page: Int, order: String, mode: String): SearchAnimResult + searchStudio(name: String, limit: Int, page: Int, order: String, mode: String): SearchStudioResult + searchGame(name: String, limit: Int, page: Int, order: String, mode: String): SearchGameResult + searchSeries(name: String, limit: Int, page: Int, order: String, mode: String): SearchSeriesResult searchSeriesByName(name: String): [Series] recentSeries(limit: Int!): [Series] @@ -237,13 +213,7 @@ type Mutation { updateStudio(slug: String, name: String): Studio! deleteStudio(slug: String!): Int - createAnimation( - title: String - subTitle: String - releaseDate: String - studios: [String] - cover: Upload - ): Animation + createAnimation(title: String, subTitle: String, releaseDate: String, studios: [String], cover: Upload): Animation updateAnimation( id: ID! title: String diff --git a/src/graphql/typeDefs/searchResults.graphql b/src/graphql/typeDefs/searchResults.graphql index 42d3c2d..8d36cbb 100644 --- a/src/graphql/typeDefs/searchResults.graphql +++ b/src/graphql/typeDefs/searchResults.graphql @@ -21,4 +21,4 @@ type SearchGameResult { type SearchSeriesResult { rows: [Series] count: Int -} \ No newline at end of file +} diff --git a/src/pages/rss.xml.ts b/src/pages/rss.xml.ts index e485a04..6023b50 100644 --- a/src/pages/rss.xml.ts +++ b/src/pages/rss.xml.ts @@ -1,13 +1,12 @@ -import rss, { type RSSFeedItem } from '@astrojs/rss'; -import type { APIContext } from 'astro'; +import rss, { type RSSFeedItem } from '@astrojs/rss' +import type { APIContext } from 'astro' -import { getApolloClient } from '@/graphql/apolloClient.mjs'; -import { gql } from '@/graphql/__generated__/client'; +import { getApolloClient } from '@/graphql/apolloClient.js' +import { gql } from '@/graphql/__generated__/client' const addedQuery = gql(` query LastAdded ($limit: Int) { added: searchAlbum(limit: $limit, status: ["show"]) { - rows { id createdAt title @@ -15,7 +14,6 @@ const addedQuery = gql(` artists { name } - } } } `) @@ -23,15 +21,13 @@ const addedQuery = gql(` export async function GET(context: APIContext) { const client = await getApolloClient() const { data } = await client.query({ query: addedQuery, variables: { limit: 15 } }) + const { added } = data - if (!data.added?.rows) throw new Error() - const { rows } = data.added - - const items: RSSFeedItem[] = rows.map((album) => ({ + const items: RSSFeedItem[] = added.map((album) => ({ guid: `album/${album?.id}`, title: album?.title, pubDate: new Date(album?.createdAt || ''), - description: album?.subTitle || album?.artists.map(a => a?.name).join(' - '), + description: album?.subTitle || album?.artists.map((a) => a?.name).join(' - '), link: `https://www.sittingonclouds.net/album/${album?.id}`, customData: ` - `, + ` })) return rss({ xmlns: { - media: "http://search.yahoo.com/mrss/", + media: 'http://search.yahoo.com/mrss/' }, stylesheet: '/rss/pretty-feed-v3.xsl', title: 'Sitting on Clouds', description: 'High Quality soundtrack library', site: context.site as unknown as string, trailingSlash: false, - items, - }); -} \ No newline at end of file + items + }) +} diff --git a/src/prisma/client.ts b/src/prisma/client.ts new file mode 100644 index 0000000..6f337ee --- /dev/null +++ b/src/prisma/client.ts @@ -0,0 +1,5 @@ +import { PrismaClient } from '@prisma/client' + +const prismaClient = new PrismaClient() + +export default prismaClient \ No newline at end of file