Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove typeorm stuff #3

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,538 changes: 616 additions & 922 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "@convictionsai/api",
"version": "0.0.1",
"private": true,
"prisma": {
"seed": "ts-node prisma/seed.ts"
},
"scripts": {
"build": "tsc",
"start:local": "concurrently --handle-input \"wait-on dist/main.js && ENVIRONMENT=local nodemon dist/main.js\" \"tsc -w -p tsconfig.json\" ",
Expand All @@ -17,10 +20,10 @@
"@nestjs/core": "^9.0.9",
"@nestjs/platform-express": "^9.3.12",
"@nestjs/swagger": "^6.0.5",
"@nestjs/typeorm": "^9.0.1",
"@prisma/client": "^4.12.0",
"amqplib": "^0.10.2",
"aws-sdk": "^2.1214.0",
"bcrypt": "^5.1.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.13.2",
"compression": "^1.7.4",
Expand All @@ -31,8 +34,7 @@
"mysql": "^2.18.1",
"openai": "^3.2.1",
"rxjs": "^7.5.6",
"swagger-ui-express": "^4.5.0",
"typeorm": "^0.3.7"
"swagger-ui-express": "^4.5.0"
},
"devDependencies": {
"@nestjs/testing": "^9.0.9",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- AlterTable
ALTER TABLE `Verse` MODIFY `content` TEXT NOT NULL;

-- CreateTable
CREATE TABLE `QAResult` (
`id` VARCHAR(191) NOT NULL,
`hash` VARCHAR(191) NOT NULL,
`prompt` TEXT NOT NULL,
`answer` TEXT NOT NULL,
`tokens` INTEGER NOT NULL,
`time` INTEGER NOT NULL,
`qaResultStatus` ENUM('ACTIVE', 'EXPIRED', 'BLOCKED', 'FAILED') NOT NULL,
`hit` ENUM('CACHE', 'LIVE') NOT NULL,
`bookId` VARCHAR(191) NOT NULL,

PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- AddForeignKey
ALTER TABLE `QAResult` ADD CONSTRAINT `QAResult_bookId_fkey` FOREIGN KEY (`bookId`) REFERENCES `Book`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
Warnings:

- You are about to drop the column `qaResultStatus` on the `QAResult` table. All the data in the column will be lost.
- Added the required column `status` to the `QAResult` table without a default value. This is not possible if the table is not empty.

*/
-- AlterTable
ALTER TABLE `QAResult` DROP COLUMN `qaResultStatus`,
ADD COLUMN `status` ENUM('ACTIVE', 'EXPIRED', 'BLOCKED', 'FAILED') NOT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Warnings:

- You are about to drop the column `bookId` on the `QAResult` table. All the data in the column will be lost.

*/
-- DropForeignKey
ALTER TABLE `QAResult` DROP FOREIGN KEY `QAResult_bookId_fkey`;

-- AlterTable
ALTER TABLE `QAResult` DROP COLUMN `bookId`;

-- CreateTable
CREATE TABLE `QAResultToBook` (
`id` VARCHAR(191) NOT NULL,
`qAResultId` VARCHAR(191) NOT NULL,
`bookId` VARCHAR(191) NOT NULL,

PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- AddForeignKey
ALTER TABLE `QAResultToBook` ADD CONSTRAINT `QAResultToBook_qAResultId_fkey` FOREIGN KEY (`qAResultId`) REFERENCES `QAResult`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `QAResultToBook` ADD CONSTRAINT `QAResultToBook_bookId_fkey` FOREIGN KEY (`bookId`) REFERENCES `Book`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:

- A unique constraint covering the columns `[name,language]` on the table `Bible` will be added. If there are existing duplicate values, this will fail.

*/
-- CreateIndex
CREATE UNIQUE INDEX `Bible_name_language_key` ON `Bible`(`name`, `language`);
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
-- DropForeignKey
ALTER TABLE `Book` DROP FOREIGN KEY `Book_bibleId_fkey`;

-- DropForeignKey
ALTER TABLE `Chapter` DROP FOREIGN KEY `Chapter_bibleId_fkey`;

-- DropForeignKey
ALTER TABLE `Chapter` DROP FOREIGN KEY `Chapter_bookId_fkey`;

-- DropForeignKey
ALTER TABLE `QAResultToBook` DROP FOREIGN KEY `QAResultToBook_bookId_fkey`;

-- DropForeignKey
ALTER TABLE `QAResultToBook` DROP FOREIGN KEY `QAResultToBook_qAResultId_fkey`;

-- DropForeignKey
ALTER TABLE `Verse` DROP FOREIGN KEY `Verse_bibleId_fkey`;

-- DropForeignKey
ALTER TABLE `Verse` DROP FOREIGN KEY `Verse_bookId_fkey`;

-- AddForeignKey
ALTER TABLE `Book` ADD CONSTRAINT `Book_bibleId_fkey` FOREIGN KEY (`bibleId`) REFERENCES `Bible`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Chapter` ADD CONSTRAINT `Chapter_bibleId_fkey` FOREIGN KEY (`bibleId`) REFERENCES `Bible`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Chapter` ADD CONSTRAINT `Chapter_bookId_fkey` FOREIGN KEY (`bookId`) REFERENCES `Book`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Verse` ADD CONSTRAINT `Verse_bibleId_fkey` FOREIGN KEY (`bibleId`) REFERENCES `Bible`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Verse` ADD CONSTRAINT `Verse_bookId_fkey` FOREIGN KEY (`bookId`) REFERENCES `Book`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `QAResultToBook` ADD CONSTRAINT `QAResultToBook_qAResultId_fkey` FOREIGN KEY (`qAResultId`) REFERENCES `QAResult`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `QAResultToBook` ADD CONSTRAINT `QAResultToBook_bookId_fkey` FOREIGN KEY (`bookId`) REFERENCES `Book`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
59 changes: 47 additions & 12 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ enum Language {
EN
}

enum QAResultStatus {
ACTIVE
EXPIRED
BLOCKED
FAILED
}

enum QAHitType {
CACHE
LIVE
}

model Bible {
id String @id @default(uuid())
name String
Expand All @@ -23,23 +35,26 @@ model Bible {
Book Book[]
Chapter Chapter[]
Verse Verse[]

@@unique([name, language])
}

model Book {
id String @id @default(uuid())
bible Bible @relation(fields: [bibleId], references: [id])
bibleId String
name String
description String
Chapter Chapter[]
Verse Verse[]
id String @id @default(uuid())
bible Bible @relation(fields: [bibleId], references: [id], onDelete: Cascade, onUpdate: Cascade)
bibleId String
name String
description String
Chapter Chapter[]
Verse Verse[]
QAResultToBook QAResultToBook[]
}

model Chapter {
id String @id @default(uuid())
bible Bible @relation(fields: [bibleId], references: [id])
bible Bible @relation(fields: [bibleId], references: [id], onDelete: Cascade, onUpdate: Cascade)
bibleId String
book Book @relation(fields: [bookId], references: [id])
book Book @relation(fields: [bookId], references: [id], onDelete: Cascade, onUpdate: Cascade)
bookId String
number Int
name String?
Expand All @@ -48,12 +63,32 @@ model Chapter {

model Verse {
id String @id @default(uuid())
bible Bible @relation(fields: [bibleId], references: [id])
bible Bible @relation(fields: [bibleId], references: [id], onDelete: Cascade, onUpdate: Cascade)
bibleId String
book Book @relation(fields: [bookId], references: [id])
book Book @relation(fields: [bookId], references: [id], onDelete: Cascade, onUpdate: Cascade)
bookId String
number Int
name String?
description String?
content String
content String @db.Text
}

model QAResult {
id String @id @default(uuid())
hash String
prompt String @db.Text
answer String @db.Text
tokens Int
time Int
status QAResultStatus
hit QAHitType
QAResultToBook QAResultToBook[]
}

model QAResultToBook {
id String @id @default(uuid())
qAResultId String
QAResult QAResult @relation(fields: [qAResultId], references: [id], onDelete: Cascade, onUpdate: Cascade)
bookId String
Book Book @relation(fields: [bookId], references: [id], onDelete: Cascade, onUpdate: Cascade)
}
27 changes: 27 additions & 0 deletions prisma/seed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { PrismaClient, Language } from '@prisma/client'
import { Bible } from './seeds/bible'

const prisma = new PrismaClient()

async function main() {
const kjv = await prisma.bible.upsert({
where: {
name_language: {
name: 'KJV',
language: Language.EN
}
},
update: {},
create: Bible
})
console.log({ kjv })
}
main()
.then(async () => {
await prisma.$disconnect()
})
.catch(async (e) => {
console.error(e)
await prisma.$disconnect()
process.exit(1)
})
11 changes: 11 additions & 0 deletions prisma/seeds/bible.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Books } from './books'
import { Language } from '@prisma/client'

export const Bible = {
name: 'KJV',
language: Language.EN,
description: 'King James Version (KJV)',
Book: {
create: Books
}
}
Loading