From 4833a29859737dc68844d942605014d4d4c5e902 Mon Sep 17 00:00:00 2001 From: Corban-Lee Date: Wed, 28 May 2025 23:49:31 +0100 Subject: [PATCH] working on data model rewrite --- .../20250505155254_init/migration.sql | 87 ------------------- .../20250505155447_unique_names/migration.sql | 19 ---- .../migration.sql | 2 - .../migration.sql | 12 --- prisma/migrations/migration_lock.toml | 3 - prisma/schema.prisma | 79 +++++++++++++---- 6 files changed, 64 insertions(+), 138 deletions(-) delete mode 100644 prisma/migrations/20250505155254_init/migration.sql delete mode 100644 prisma/migrations/20250505155447_unique_names/migration.sql delete mode 100644 prisma/migrations/20250505215144_style_colour_size/migration.sql delete mode 100644 prisma/migrations/20250506174806_add_publish_threshold_to_feed/migration.sql delete mode 100644 prisma/migrations/migration_lock.toml diff --git a/prisma/migrations/20250505155254_init/migration.sql b/prisma/migrations/20250505155254_init/migration.sql deleted file mode 100644 index bc624f3..0000000 --- a/prisma/migrations/20250505155254_init/migration.sql +++ /dev/null @@ -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; diff --git a/prisma/migrations/20250505155447_unique_names/migration.sql b/prisma/migrations/20250505155447_unique_names/migration.sql deleted file mode 100644 index 717f610..0000000 --- a/prisma/migrations/20250505155447_unique_names/migration.sql +++ /dev/null @@ -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"); diff --git a/prisma/migrations/20250505215144_style_colour_size/migration.sql b/prisma/migrations/20250505215144_style_colour_size/migration.sql deleted file mode 100644 index ff299ac..0000000 --- a/prisma/migrations/20250505215144_style_colour_size/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterTable -ALTER TABLE "MessageStyle" ALTER COLUMN "colour" SET DATA TYPE VARCHAR(7); diff --git a/prisma/migrations/20250506174806_add_publish_threshold_to_feed/migration.sql b/prisma/migrations/20250506174806_add_publish_threshold_to_feed/migration.sql deleted file mode 100644 index 88d77ac..0000000 --- a/prisma/migrations/20250506174806_add_publish_threshold_to_feed/migration.sql +++ /dev/null @@ -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; diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml deleted file mode 100644 index 044d57c..0000000 --- a/prisma/migrations/migration_lock.toml +++ /dev/null @@ -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" diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 602b3d7..04a1769 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -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