working on data model rewrite

This commit is contained in:
Corban-Lee Jones 2025-05-28 23:49:31 +01:00
parent 51808c326f
commit 4833a29859
6 changed files with 64 additions and 138 deletions

View File

@ -1,87 +0,0 @@
-- CreateEnum
CREATE TYPE "MatchingAlgorithms" AS ENUM ('ANY', 'ALL', 'EXACT', 'REGEX', 'FUZZY');
-- CreateEnum
CREATE TYPE "TextMutator" AS ENUM ('UWUIFY', 'UWUIFY_SFW', 'GOTHIC_SCRIPT', 'EMOJI_SUBSTITUTE', 'ZALGO', 'MORSE_CODE', 'BINARY', 'HEXADECIMAL', 'REMOVE_VOWELS', 'DOUBLE_CHARACTERS', 'SMALL_CASE', 'LEET_SPEAK', 'PIG_LATIN', 'UPSIDE_DOWN', 'ALL_REVERSED', 'REVERSED_WORDS', 'SHUFFLE_WORDS', 'RANDOM_CASE', 'GIBBERISH', 'SHAKESPEAREAN');
-- CreateTable
CREATE TABLE "Feed" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"url" TEXT NOT NULL,
"guild_id" TEXT NOT NULL,
"active" BOOLEAN NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Feed_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Channel" (
"id" SERIAL NOT NULL,
"channel_id" TEXT NOT NULL,
"feedId" INTEGER NOT NULL,
CONSTRAINT "Channel_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Filter" (
"id" SERIAL NOT NULL,
"guild_id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"value" TEXT NOT NULL,
"matching_algorithm" "MatchingAlgorithms" NOT NULL,
"is_insensitive" BOOLEAN NOT NULL,
"is_whitelist" BOOLEAN NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "Filter_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "MessageStyle" (
"id" SERIAL NOT NULL,
"guild_id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"show_author" BOOLEAN NOT NULL,
"show_image" BOOLEAN NOT NULL,
"show_thumbnail" BOOLEAN NOT NULL,
"show_footer" BOOLEAN NOT NULL,
"show_timestamp" BOOLEAN NOT NULL,
"colour" VARCHAR(6) NOT NULL,
"title_mutator" "TextMutator",
"description_mutator" "TextMutator",
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "MessageStyle_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "_FeedToFilter" (
"A" INTEGER NOT NULL,
"B" INTEGER NOT NULL,
CONSTRAINT "_FeedToFilter_AB_pkey" PRIMARY KEY ("A","B")
);
-- CreateIndex
CREATE INDEX "Feed_guild_id_created_at_idx" ON "Feed"("guild_id", "created_at" DESC);
-- CreateIndex
CREATE INDEX "Filter_guild_id_created_at_idx" ON "Filter"("guild_id", "created_at" DESC);
-- CreateIndex
CREATE INDEX "_FeedToFilter_B_index" ON "_FeedToFilter"("B");
-- AddForeignKey
ALTER TABLE "Channel" ADD CONSTRAINT "Channel_feedId_fkey" FOREIGN KEY ("feedId") REFERENCES "Feed"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "_FeedToFilter" ADD CONSTRAINT "_FeedToFilter_A_fkey" FOREIGN KEY ("A") REFERENCES "Feed"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "_FeedToFilter" ADD CONSTRAINT "_FeedToFilter_B_fkey" FOREIGN KEY ("B") REFERENCES "Filter"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -1,19 +0,0 @@
/*
Warnings:
- A unique constraint covering the columns `[guild_id,name]` on the table `Feed` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[guild_id,name]` on the table `Filter` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[guild_id,name]` on the table `MessageStyle` will be added. If there are existing duplicate values, this will fail.
*/
-- CreateIndex
CREATE UNIQUE INDEX "Feed_guild_id_name_key" ON "Feed"("guild_id", "name");
-- CreateIndex
CREATE UNIQUE INDEX "Filter_guild_id_name_key" ON "Filter"("guild_id", "name");
-- CreateIndex
CREATE INDEX "MessageStyle_guild_id_created_at_idx" ON "MessageStyle"("guild_id", "created_at" DESC);
-- CreateIndex
CREATE UNIQUE INDEX "MessageStyle_guild_id_name_key" ON "MessageStyle"("guild_id", "name");

View File

@ -1,2 +0,0 @@
-- AlterTable
ALTER TABLE "MessageStyle" ALTER COLUMN "colour" SET DATA TYPE VARCHAR(7);

View File

@ -1,12 +0,0 @@
/*
Warnings:
- Added the required column `published_threshold` to the `Feed` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "Feed" ADD COLUMN "message_style_id" INTEGER,
ADD COLUMN "published_threshold" TIMESTAMP(3) NOT NULL;
-- AddForeignKey
ALTER TABLE "Feed" ADD CONSTRAINT "Feed_message_style_id_fkey" FOREIGN KEY ("message_style_id") REFERENCES "MessageStyle"("id") ON DELETE SET NULL ON UPDATE CASCADE;

View File

@ -1,3 +0,0 @@
# Please do not edit this file manually
# It should be added in your version-control system (e.g., Git)
provider = "postgresql"

View File

@ -11,21 +11,69 @@ datasource db {
url = env("DATABASE_URL")
}
model Feed {
id Int @id @default(autoincrement())
name String
url String
guild_id String
active Boolean
created_at DateTime @default(now())
updated_at DateTime @updatedAt
channels Channel[]
filters Filter[]
message_style MessageStyle? @relation(fields: [message_style_id], references: [id], onDelete: SetNull)
message_style_id Int?
published_threshold DateTime
enum FeedSourceType {
RSS
JSON
}
enum FeedSourceHTTPMethod {
GET
POST
}
model FeedSourceHTTPHeader {
id Int @id @default(autoincrement())
name String
value String
feed_source FeedSource @relation(fields: feed_source_id, references: [id], onDelete: Cascade)
feed_source_id Int
}
model FeedSourceCookies {
id Int @id @default(autoincrement())
name String
value String
feed_source FeedSource @relation(fields: feed_source_id, references: [id], onDelete: Cascade)
feed_source_id Int
}
// start new
// todo: user modal to input url, then auto fetch details needed for this model
// user can then submit or not.
model FeedSource {
id Int @id @default(autoincrement())
url String
http_username String?
http_password String? // todo: encrypt this
http_headers FeedSourceHTTPHeader[]
http_method FeedSourceHTTPMethod @default(GET)
http_post_payload String?
redirect_limit Int @default(0)
timeout_seconds Int?
cookies FeedSourceCookies[]
feed Feed?
}
model Feed {
id Int @id @default(autoincrement())
source FeedSource @relation(fields: [source_id], references: [id], onDelete: Cascade)
source_id Int @unique
guild_id Int
name String
description String
website_url String?
active Boolean
channels Channel[]
filters Filter[]
message_style MessageStyle? @relation(fields:message_style_id, references: [id], onDelete: SetNull)
message_style_id Int?
created_at DateTime @default(now())
updated_at DateTime @updatedAt @default(now())
@@unique([guild_id, name])
@@index([guild_id, created_at(sort: Desc)])
}
@ -44,6 +92,7 @@ model Filter {
matching_algorithm MatchingAlgorithms
is_insensitive Boolean
is_whitelist Boolean
published_threshold DateTime?
created_at DateTime @default(now())
updated_at DateTime @updatedAt
feeds Feed[]
@ -64,7 +113,7 @@ model MessageStyle {
id Int @id @default(autoincrement())
guild_id String
name String
colour String @db.VarChar(7) // hex colour: #5865F2
colour String @db.VarChar(7) // hex colour including hashtag, example: #5865F2
show_author Boolean
show_image Boolean
show_thumbnail Boolean