combination WIP, add client

This commit is contained in:
Nathan Rashleigh committed 2024-05-04 17:20:35 +10:00
1 parent 3c5e7d9aee
commit 4097b05cf9
44 files changed
+22234 -5001

No files matched your search

@@ -0,0 +1,38 @@
-- CreateTable
CREATE TABLE "attachments" (
"id" BIGINT NOT NULL,
"msgId" BIGINT NOT NULL,
"channelId" BIGINT NOT NULL,
"memeId" UUID NOT NULL,
"url" TEXT NOT NULL,
"contentType" TEXT NOT NULL,
"message" JSONB NOT NULL,
"guild" JSONB NOT NULL,
"channel" JSONB NOT NULL,
"vision" JSONB NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "attachments_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "memes" (
"id" UUID NOT NULL DEFAULT gen_random_uuid(),
"url" TEXT NOT NULL,
"text" TEXT NOT NULL,
"tags" JSONB NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "memes_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "attachments_memeId_key" ON "attachments"("memeId");
-- CreateIndex
CREATE INDEX "attachments_channelId_idx" ON "attachments"("channelId");
-- AddForeignKey
ALTER TABLE "attachments" ADD CONSTRAINT "attachments_memeId_fkey" FOREIGN KEY ("memeId") REFERENCES "memes"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
@@ -0,0 +1,11 @@
/*
Warnings:
- A unique constraint covering the columns `[attachmentId]` on the table `memes` will be added. If there are existing duplicate values, this will fail.
*/
-- AlterTable
ALTER TABLE "memes" ADD COLUMN "attachmentId" BIGINT;
-- CreateIndex
CREATE UNIQUE INDEX "memes_attachmentId_key" ON "memes"("attachmentId");
@@ -0,0 +1,9 @@
-- CreateTable
CREATE TABLE "channelhistory" (
"id" BIGINT NOT NULL,
"earliestMessageId" BIGINT NOT NULL,
"latestMessageId" BIGINT NOT NULL,
"backfillComplete" BOOLEAN NOT NULL DEFAULT false,
CONSTRAINT "channelhistory_pkey" PRIMARY KEY ("id")
);
@@ -0,0 +1,8 @@
/*
Warnings:
- You are about to drop the column `backfillComplete` on the `channelhistory` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "channelhistory" DROP COLUMN "backfillComplete";
@@ -0,0 +1,25 @@
/*
Warnings:
- Added the required column `postedAt` to the `attachments` table without a default value. This is not possible if the table is not empty.
- Added the required column `timestamp` to the `memes` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "attachments"
ADD COLUMN "postedAt"
TIMESTAMP(3);
UPDATE "attachments"
set "postedAt" = TIMESTAMP 'epoch' + ((id >> 22) + 1420070400000) * INTERVAL '1 millisecond';
-- AlterTable
ALTER TABLE "memes"
ADD COLUMN "postedAt"
TIMESTAMP(3);
UPDATE "memes"
set "postedAt" = TIMESTAMP 'epoch' + (("attachmentId" >> 22) + 1420070400000) * INTERVAL '1 millisecond';
ALTER TABLE "attachments" ALTER COLUMN "postedAt" SET NOT NULL;
ALTER TABLE "memes" ALTER COLUMN "postedAt" SET NOT NULL;
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "postgresql"
+66
View File
@@ -0,0 +1,66 @@
generator client {
provider = "prisma-client-js"
// include for node docker image
binaryTargets = ["native", "debian-openssl-1.1.x", "debian-openssl-3.0.x"]
}
datasource db {
provider = "postgresql"
url = env("POSTGRES_URL")
}
model Attachment {
id BigInt @id
msgId BigInt
channelId BigInt
memeId String @unique @db.Uuid
meme Meme @relation(fields: [memeId], references: [id], onDelete: Restrict)
url String
contentType String
message Json
guild Json
channel Json
vision Json
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
postedAt DateTime
@@index([channelId])
@@map("attachments")
}
model Meme {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
url String
text String
tags Json
// need an timestamp for giving to meili to sort by
// i think a usize would actually work but can't
// convince the meili-js lib to serialize it properly to json
// this one actually has to be .valueOf()'d before we send it
// cause js numbers are bigger than postgres int4
postedAt DateTime
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
// required to prevent the same attachment being uploaded multiple times
// nullable because maybe will have memes that don't come from a discord attachment
attachmentId BigInt? @unique
attachment Attachment?
@@map("memes")
}
model ChannelHistory {
id BigInt @id
earliestMessageId BigInt
latestMessageId BigInt
// we do this because you have to always wrap table names in "" if they have capitals
@@map("channelhistory")
}