SPB Git forge

spb/fetcha

Public
11commits 1branches 0releases
1.5 MBsize
maindefault branch
16 days agolast push
TypeScript 97.5% SQL 1.4% Python 0.8%
3.9 KB · 77 lines sql
Raw Blame History
1CREATE TABLE "crawl_jobs" (2	"id" text PRIMARY KEY NOT NULL,3	"organization_id" text NOT NULL,4	"project_id" text NOT NULL,5	"api_key_id" text,6	"source" text DEFAULT 'api' NOT NULL,7	"label" text,8	"seed_url" text NOT NULL,9	"domain" text NOT NULL,10	"options" jsonb NOT NULL,11	"status" text DEFAULT 'queued' NOT NULL,12	"worker_id" text,13	"pages_discovered" integer DEFAULT 0 NOT NULL,14	"pages_fetched" integer DEFAULT 0 NOT NULL,15	"pages_ok" integer DEFAULT 0 NOT NULL,16	"pages_blocked" integer DEFAULT 0 NOT NULL,17	"pages_failed" integer DEFAULT 0 NOT NULL,18	"bytes" bigint DEFAULT 0 NOT NULL,19	"cost_usd" double precision DEFAULT 0 NOT NULL,20	"error_code" text,21	"error_message" text,22	"webhook_status" text,23	"created_at" timestamp with time zone DEFAULT now() NOT NULL,24	"started_at" timestamp with time zone,25	"heartbeat_at" timestamp with time zone,26	"completed_at" timestamp with time zone27);28--> statement-breakpoint29CREATE TABLE "crawl_pages" (30	"id" text PRIMARY KEY NOT NULL,31	"job_id" text NOT NULL,32	"url" text NOT NULL,33	"final_url" text,34	"depth" integer DEFAULT 0 NOT NULL,35	"parent_url" text,36	"status" text DEFAULT 'pending' NOT NULL,37	"http_status" integer,38	"error_code" text,39	"request_id" text,40	"title" text,41	"description" text,42	"content_type" text,43	"content" text,44	"links_count" integer DEFAULT 0 NOT NULL,45	"bytes" bigint DEFAULT 0 NOT NULL,46	"duration_ms" integer,47	"mode" text,48	"created_at" timestamp with time zone DEFAULT now() NOT NULL,49	"fetched_at" timestamp with time zone50);51--> statement-breakpoint52CREATE TABLE "signup_allowlist" (53	"email" text PRIMARY KEY NOT NULL,54	"note" text,55	"invited_by_user_id" text,56	"invited_at" timestamp with time zone,57	"used_at" timestamp with time zone,58	"user_id" text,59	"created_at" timestamp with time zone DEFAULT now() NOT NULL60);61--> statement-breakpoint62ALTER TABLE "organizations" ALTER COLUMN "plan" SET DEFAULT 'unlimited';--> statement-breakpoint63ALTER TABLE "fetch_requests" ADD COLUMN "mode" text;--> statement-breakpoint64ALTER TABLE "request_attempts" ADD COLUMN "mode" text DEFAULT 'http' NOT NULL;--> statement-breakpoint65ALTER TABLE "crawl_jobs" ADD CONSTRAINT "crawl_jobs_organization_id_organizations_id_fk" FOREIGN KEY ("organization_id") REFERENCES "public"."organizations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint66ALTER TABLE "crawl_jobs" ADD CONSTRAINT "crawl_jobs_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint67ALTER TABLE "crawl_jobs" ADD CONSTRAINT "crawl_jobs_api_key_id_api_keys_id_fk" FOREIGN KEY ("api_key_id") REFERENCES "public"."api_keys"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint68ALTER TABLE "crawl_pages" ADD CONSTRAINT "crawl_pages_job_id_crawl_jobs_id_fk" FOREIGN KEY ("job_id") REFERENCES "public"."crawl_jobs"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint69ALTER TABLE "signup_allowlist" ADD CONSTRAINT "signup_allowlist_invited_by_user_id_users_id_fk" FOREIGN KEY ("invited_by_user_id") REFERENCES "public"."users"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint70ALTER TABLE "signup_allowlist" ADD CONSTRAINT "signup_allowlist_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint71CREATE INDEX "crawl_jobs_project_created_idx" ON "crawl_jobs" USING btree ("project_id","created_at");--> statement-breakpoint72CREATE INDEX "crawl_jobs_status_idx" ON "crawl_jobs" USING btree ("status");--> statement-breakpoint73CREATE INDEX "crawl_pages_job_idx" ON "crawl_pages" USING btree ("job_id","created_at");--> statement-breakpoint74CREATE UNIQUE INDEX "crawl_pages_job_url_uq" ON "crawl_pages" USING btree ("job_id","url");--> statement-breakpoint75CREATE INDEX "signup_allowlist_user_idx" ON "signup_allowlist" USING btree ("user_id");--> statement-breakpoint76UPDATE "organizations" SET "plan" = 'unlimited' WHERE "plan" <> 'unlimited';77