From 6a943b8b10f11ff9f5057ed393faab66aa70bea9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Berg=C3=A9?= Date: Sun, 5 Jan 2025 14:04:50 +0100 Subject: [PATCH] chore: remove crawls and captures table They are not used. --- .../20250105130307_remove-crawls-captures.js | 11 ++ apps/backend/db/structure.sql | 183 +----------------- apps/backend/src/database/models/Capture.ts | 65 ------- apps/backend/src/database/models/Crawl.ts | 41 ---- apps/backend/src/database/models/index.ts | 2 - apps/backend/src/graphql/services/project.ts | 10 - 6 files changed, 13 insertions(+), 299 deletions(-) create mode 100644 apps/backend/db/migrations/20250105130307_remove-crawls-captures.js delete mode 100644 apps/backend/src/database/models/Capture.ts delete mode 100644 apps/backend/src/database/models/Crawl.ts diff --git a/apps/backend/db/migrations/20250105130307_remove-crawls-captures.js b/apps/backend/db/migrations/20250105130307_remove-crawls-captures.js new file mode 100644 index 000000000..91229c976 --- /dev/null +++ b/apps/backend/db/migrations/20250105130307_remove-crawls-captures.js @@ -0,0 +1,11 @@ +/** + * @param {import('knex').Knex} knex + */ +export const up = async (knex) => { + await knex.schema.dropTable("captures"); + await knex.schema.dropTable("crawls"); +}; + +export const down = async () => { + throw new Error("There is no way to go back from hell 😈"); +}; diff --git a/apps/backend/db/structure.sql b/apps/backend/db/structure.sql index 43015b4ad..02fc61e47 100644 --- a/apps/backend/db/structure.sql +++ b/apps/backend/db/structure.sql @@ -296,82 +296,6 @@ ALTER TABLE public.builds_id_seq OWNER TO postgres; ALTER SEQUENCE public.builds_id_seq OWNED BY public.builds.id; --- --- Name: captures; Type: TABLE; Schema: public; Owner: postgres --- - -CREATE TABLE public.captures ( - id bigint NOT NULL, - "createdAt" timestamp with time zone NOT NULL, - "updatedAt" timestamp with time zone NOT NULL, - "jobStatus" public.job_status NOT NULL, - "crawlId" bigint NOT NULL, - "screenshotId" bigint, - "fileId" bigint, - url character varying(255) NOT NULL -); - - -ALTER TABLE public.captures OWNER TO postgres; - --- --- Name: captures_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres --- - -CREATE SEQUENCE public.captures_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE public.captures_id_seq OWNER TO postgres; - --- --- Name: captures_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres --- - -ALTER SEQUENCE public.captures_id_seq OWNED BY public.captures.id; - - --- --- Name: crawls; Type: TABLE; Schema: public; Owner: postgres --- - -CREATE TABLE public.crawls ( - id bigint NOT NULL, - "createdAt" timestamp with time zone NOT NULL, - "updatedAt" timestamp with time zone NOT NULL, - "jobStatus" public.job_status NOT NULL, - "buildId" bigint NOT NULL, - "baseUrl" character varying(255) NOT NULL -); - - -ALTER TABLE public.crawls OWNER TO postgres; - --- --- Name: crawls_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres --- - -CREATE SEQUENCE public.crawls_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE public.crawls_id_seq OWNER TO postgres; - --- --- Name: crawls_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres --- - -ALTER SEQUENCE public.crawls_id_seq OWNED BY public.crawls.id; - - -- -- Name: files; Type: TABLE; Schema: public; Owner: postgres -- @@ -1436,20 +1360,6 @@ ALTER TABLE ONLY public.build_shards ALTER COLUMN id SET DEFAULT nextval('public ALTER TABLE ONLY public.builds ALTER COLUMN id SET DEFAULT nextval('public.builds_id_seq'::regclass); --- --- Name: captures id; Type: DEFAULT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY public.captures ALTER COLUMN id SET DEFAULT nextval('public.captures_id_seq'::regclass); - - --- --- Name: crawls id; Type: DEFAULT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY public.crawls ALTER COLUMN id SET DEFAULT nextval('public.crawls_id_seq'::regclass); - - -- -- Name: files id; Type: DEFAULT; Schema: public; Owner: postgres -- @@ -1689,22 +1599,6 @@ ALTER TABLE ONLY public.builds ADD CONSTRAINT builds_pkey PRIMARY KEY (id); --- --- Name: captures captures_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY public.captures - ADD CONSTRAINT captures_pkey PRIMARY KEY (id); - - --- --- Name: crawls crawls_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY public.crawls - ADD CONSTRAINT crawls_pkey PRIMARY KEY (id); - - -- -- Name: files files_key_unique; Type: CONSTRAINT; Schema: public; Owner: postgres -- @@ -2113,48 +2007,6 @@ CREATE INDEX builds_projectid_index ON public.builds USING btree ("projectId"); CREATE INDEX builds_runid_index ON public.builds USING btree ("runId"); --- --- Name: captures_crawlid_index; Type: INDEX; Schema: public; Owner: postgres --- - -CREATE INDEX captures_crawlid_index ON public.captures USING btree ("crawlId"); - - --- --- Name: captures_fileid_index; Type: INDEX; Schema: public; Owner: postgres --- - -CREATE INDEX captures_fileid_index ON public.captures USING btree ("fileId"); - - --- --- Name: captures_jobstatus_index; Type: INDEX; Schema: public; Owner: postgres --- - -CREATE INDEX captures_jobstatus_index ON public.captures USING btree ("jobStatus"); - - --- --- Name: captures_screenshotid_index; Type: INDEX; Schema: public; Owner: postgres --- - -CREATE INDEX captures_screenshotid_index ON public.captures USING btree ("screenshotId"); - - --- --- Name: crawls_buildid_index; Type: INDEX; Schema: public; Owner: postgres --- - -CREATE INDEX crawls_buildid_index ON public.crawls USING btree ("buildId"); - - --- --- Name: crawls_jobstatus_index; Type: INDEX; Schema: public; Owner: postgres --- - -CREATE INDEX crawls_jobstatus_index ON public.crawls USING btree ("jobStatus"); - - -- -- Name: github_account_members_githubaccountid_index; Type: INDEX; Schema: public; Owner: postgres -- @@ -2575,38 +2427,6 @@ ALTER TABLE ONLY public.builds ADD CONSTRAINT builds_projectid_foreign FOREIGN KEY ("projectId") REFERENCES public.projects(id); --- --- Name: captures captures_crawlid_foreign; Type: FK CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY public.captures - ADD CONSTRAINT captures_crawlid_foreign FOREIGN KEY ("crawlId") REFERENCES public.crawls(id); - - --- --- Name: captures captures_fileid_foreign; Type: FK CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY public.captures - ADD CONSTRAINT captures_fileid_foreign FOREIGN KEY ("fileId") REFERENCES public.files(id); - - --- --- Name: captures captures_screenshotid_foreign; Type: FK CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY public.captures - ADD CONSTRAINT captures_screenshotid_foreign FOREIGN KEY ("screenshotId") REFERENCES public.screenshots(id); - - --- --- Name: crawls crawls_buildid_foreign; Type: FK CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY public.crawls - ADD CONSTRAINT crawls_buildid_foreign FOREIGN KEY ("buildId") REFERENCES public.builds(id); - - -- -- Name: github_account_members github_account_members_githubaccountid_foreign; Type: FK CONSTRAINT; Schema: public; Owner: postgres -- @@ -3010,4 +2830,5 @@ INSERT INTO public.knex_migrations(name, batch, migration_time) VALUES ('2024121 INSERT INTO public.knex_migrations(name, batch, migration_time) VALUES ('20241231154644_build-status.js', 1, NOW()); INSERT INTO public.knex_migrations(name, batch, migration_time) VALUES ('20250102150800_build-review.js', 1, NOW()); INSERT INTO public.knex_migrations(name, batch, migration_time) VALUES ('20250103090503_remove-validation-status-column.js', 1, NOW()); -INSERT INTO public.knex_migrations(name, batch, migration_time) VALUES ('20250103131406_plan-interval.js', 1, NOW()); \ No newline at end of file +INSERT INTO public.knex_migrations(name, batch, migration_time) VALUES ('20250103131406_plan-interval.js', 1, NOW()); +INSERT INTO public.knex_migrations(name, batch, migration_time) VALUES ('20250105130307_remove-crawls-captures.js', 1, NOW()); \ No newline at end of file diff --git a/apps/backend/src/database/models/Capture.ts b/apps/backend/src/database/models/Capture.ts deleted file mode 100644 index cc3c22e0a..000000000 --- a/apps/backend/src/database/models/Capture.ts +++ /dev/null @@ -1,65 +0,0 @@ -import type { RelationMappings } from "objection"; - -import { Model } from "../util/model.js"; -import { - jobModelSchema, - JobStatus, - mergeSchemas, - timestampsSchema, -} from "../util/schemas.js"; -import { Crawl } from "./Crawl.js"; -import { File } from "./File.js"; -import { Screenshot } from "./Screenshot.js"; - -export class Capture extends Model { - static override tableName = "captures"; - - static override jsonSchema = mergeSchemas(timestampsSchema, jobModelSchema, { - required: ["crawlId", "url"], - properties: { - crawlId: { type: "string" }, - url: { type: "string" }, - screenshotId: { type: ["string", "null"] }, - fileId: { type: ["string", "null"] }, - }, - }); - - jobStatus!: JobStatus; - crawlId!: string; - url!: string; - screenshotId!: string | null; - fileId!: string | null; - - static override get relationMappings(): RelationMappings { - return { - crawl: { - relation: Model.BelongsToOneRelation, - modelClass: Crawl, - join: { - from: "captures.crawlId", - to: "crawls.id", - }, - }, - screenshot: { - relation: Model.HasOneRelation, - modelClass: Screenshot, - join: { - from: "captures.screenshotId", - to: "screenshots.id", - }, - }, - file: { - relation: Model.HasOneRelation, - modelClass: File, - join: { - from: "captures.fileId", - to: "files.id", - }, - }, - }; - } - - crawl?: Crawl; - screenshot?: Screenshot | null; - file?: File | null; -} diff --git a/apps/backend/src/database/models/Crawl.ts b/apps/backend/src/database/models/Crawl.ts deleted file mode 100644 index af87fe74b..000000000 --- a/apps/backend/src/database/models/Crawl.ts +++ /dev/null @@ -1,41 +0,0 @@ -import type { RelationMappings } from "objection"; - -import { Model } from "../util/model.js"; -import { - jobModelSchema, - JobStatus, - mergeSchemas, - timestampsSchema, -} from "../util/schemas.js"; -import { Build } from "./Build.js"; - -export class Crawl extends Model { - static override tableName = "crawls"; - - static override jsonSchema = mergeSchemas(timestampsSchema, jobModelSchema, { - required: ["buildId", "baseUrl"], - properties: { - buildId: { type: "string" }, - baseUrl: { type: "string" }, - }, - }); - - jobStatus!: JobStatus; - buildId!: string; - baseUrl!: string; - - static override get relationMappings(): RelationMappings { - return { - build: { - relation: Model.BelongsToOneRelation, - modelClass: Build, - join: { - from: "crawls.buildId", - to: "builds.id", - }, - }, - }; - } - - build?: Build; -} diff --git a/apps/backend/src/database/models/index.ts b/apps/backend/src/database/models/index.ts index d4a92a4cd..91ec06c79 100644 --- a/apps/backend/src/database/models/index.ts +++ b/apps/backend/src/database/models/index.ts @@ -3,8 +3,6 @@ export * from "./Build.js"; export * from "./BuildShard.js"; export * from "./BuildNotification.js"; export * from "./BuildReview.js"; -export * from "./Capture.js"; -export * from "./Crawl.js"; export * from "./File.js"; export * from "./GithubAccount.js"; export * from "./GithubAccountMember.js"; diff --git a/apps/backend/src/graphql/services/project.ts b/apps/backend/src/graphql/services/project.ts index 6321122f5..418062fe7 100644 --- a/apps/backend/src/graphql/services/project.ts +++ b/apps/backend/src/graphql/services/project.ts @@ -5,8 +5,6 @@ import { Build, BuildNotification, BuildReview, - Capture, - Crawl, Project, Screenshot, ScreenshotBucket, @@ -57,14 +55,6 @@ export async function unsafe_deleteProject(args: { trx?: TransactionOrKnex; }) { await transaction(args.trx, async (trx) => { - await Capture.query(trx) - .joinRelated("crawl.build") - .where("crawl:build.projectId", args.projectId) - .delete(); - await Crawl.query(trx) - .joinRelated("build") - .where("build.projectId", args.projectId) - .delete(); await ScreenshotDiff.query(trx) .joinRelated("build") .where("build.projectId", args.projectId)