-- Current sql file was generated after introspecting the database
-- If you want to run this migration please uncomment this code before executing migrations
/*
CREATE TABLE "configs" (
	"id" text PRIMARY KEY NOT NULL,
	"created_at" timestamp with time zone DEFAULT now() NOT NULL,
	"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
	"name" text NOT NULL,
	"type" text NOT NULL,
	"config" jsonb NOT NULL
);
--> statement-breakpoint
CREATE TABLE "default_providers" (
	"id" text PRIMARY KEY NOT NULL,
	"label" text NOT NULL,
	"group" text NOT NULL,
	"config" jsonb NOT NULL
);
--> statement-breakpoint
CREATE TABLE "applications" (
	"id" text PRIMARY KEY NOT NULL,
	"created_at" timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
	"updated_at" timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
	"name" text,
	"description" text,
	"status" integer,
	"security_config" jsonb,
	"use_case" text,
	"provider_config" jsonb NOT NULL,
	"project_id" text,
	"test_runs" integer
);
--> statement-breakpoint
CREATE TABLE "datasets" (
	"id" text PRIMARY KEY NOT NULL,
	"tests" jsonb,
	"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "evals" (
	"id" text PRIMARY KEY NOT NULL,
	"created_at" timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
	"author" text,
	"description" text,
	"results" jsonb NOT NULL,
	"config" jsonb NOT NULL,
	"prompts" jsonb,
	"project_id" text,
	"vars" jsonb,
	"application_id" text
);
--> statement-breakpoint
CREATE TABLE "assertions" (
	"id" text PRIMARY KEY NOT NULL,
	"created_at" timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
	"updated_at" timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
	"name" text NOT NULL,
	"description" text,
	"group" text,
	"value_type" text,
	"mandatory" integer DEFAULT 0,
	"additional_fields" jsonb,
	"label" text,
	"options" jsonb,
	"help_text" text,
	"placeholder" text
);
--> statement-breakpoint
CREATE TABLE "plugins_presets" (
	"id" text PRIMARY KEY NOT NULL,
	"name" text NOT NULL,
	"description" text,
	"plugins" jsonb
);
--> statement-breakpoint
CREATE TABLE "prompts" (
	"id" text PRIMARY KEY NOT NULL,
	"created_at" timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
	"prompt" text NOT NULL,
	"project_id" text NOT NULL,
	"tests" jsonb,
	"dataset" jsonb,
	"type" text,
	"user_intentions" jsonb,
	"user_profiles" jsonb,
	"opening_message" text,
	"minimum_turns" integer,
	"maximum_turns" integer,
	"chat_stop_criteria" text
);
--> statement-breakpoint
CREATE TABLE "prompts_library" (
	"id" text PRIMARY KEY NOT NULL,
	"created_at" timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
	"updated_at" timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
	"name" text,
	"status" integer,
	"global_metrics" jsonb[],
	"project_id" text NOT NULL
);
--> statement-breakpoint
CREATE TABLE "provider_supported_languages" (
	"id" text PRIMARY KEY NOT NULL,
	"name" text NOT NULL,
	"code" text NOT NULL,
	"SpeechSynthesisLanguage" text NOT NULL,
	"SpeechSynthesisVoiceName" text NOT NULL
);
--> statement-breakpoint
CREATE TABLE "security_config" (
	"id" text PRIMARY KEY NOT NULL,
	"name" text NOT NULL,
	"status" integer NOT NULL,
	"config" jsonb NOT NULL,
	"project_id" text,
	"created_at" timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
	"updated_at" timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
);
--> statement-breakpoint
CREATE TABLE "strategy_presets" (
	"id" text PRIMARY KEY NOT NULL,
	"name" text NOT NULL,
	"description" text,
	"strategies" jsonb,
	"options" jsonb
);
--> statement-breakpoint
CREATE TABLE "eval_results" (
	"id" text PRIMARY KEY NOT NULL,
	"created_at" timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
	"updated_at" timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
	"eval_id" text NOT NULL,
	"prompt_idx" integer NOT NULL,
	"test_idx" integer NOT NULL,
	"test_case" jsonb NOT NULL,
	"prompt" jsonb NOT NULL,
	"prompt_id" text,
	"application_id" text,
	"provider" jsonb NOT NULL,
	"latency_ms" integer,
	"cost" real,
	"response" jsonb,
	"error" text,
	"failure_reason" integer DEFAULT 0 NOT NULL,
	"success" integer NOT NULL,
	"score" real NOT NULL,
	"grading_result" jsonb,
	"named_scores" jsonb,
	"metadata" jsonb,
	"is_redteam" integer DEFAULT 0,
	"trace_id" text,
	"project_id" text
);
--> statement-breakpoint
CREATE TABLE "trusys_datasets" (
	"id" text PRIMARY KEY NOT NULL,
	"name" text NOT NULL,
	"type" text,
	"project_id" text NOT NULL,
	"data" jsonb,
	"count" integer DEFAULT 0,
	"fields" jsonb,
	"config" jsonb,
	"status" integer DEFAULT 0 NOT NULL,
	"created_at" timestamp DEFAULT now() NOT NULL,
	"updated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "tags" (
	"id" text PRIMARY KEY NOT NULL,
	"name" text NOT NULL,
	"value" text NOT NULL
);
--> statement-breakpoint
CREATE TABLE "prompts_library_prompts" (
	"library_id" text NOT NULL,
	"prompt_id" text NOT NULL
);
--> statement-breakpoint
CREATE TABLE "monitoring_alerts" (
	"id" text PRIMARY KEY NOT NULL,
	"application_id" text NOT NULL,
	"alerts" jsonb NOT NULL,
	"emails" text NOT NULL,
	"webhook" text NOT NULL,
	"created_at" timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
	"updated_at" timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
);
--> statement-breakpoint
CREATE TABLE "test_runs" (
	"id" text PRIMARY KEY NOT NULL,
	"type" text DEFAULT 'eval',
	"created_at" timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
	"updated_at" timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
	"status" text DEFAULT 'pending' NOT NULL,
	"project_id" text,
	"application_ids" jsonb NOT NULL,
	"library_id" text,
	"total_test_case" integer
);
--> statement-breakpoint
CREATE TABLE "monitoring" (
	"id" text PRIMARY KEY NOT NULL,
	"created_at" timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
	"updated_at" timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
	"application_id" text NOT NULL,
	"log_location" text NOT NULL,
	"service_provider" text NOT NULL,
	"location_url" text NOT NULL,
	"sampling_frequency" text NOT NULL,
	"sampling_percentage" integer NOT NULL,
	"sampling_count" integer NOT NULL,
	"evaluation_window" integer NOT NULL,
	"metrics" jsonb NOT NULL,
	"secret_name" text NOT NULL,
	"pluginsByCategory" jsonb
);
--> statement-breakpoint
CREATE TABLE "evals_to_datasets" (
	"eval_id" text NOT NULL,
	"dataset_id" text NOT NULL,
	CONSTRAINT "evals_to_datasets_eval_id_dataset_id_pk" PRIMARY KEY("eval_id","dataset_id")
);
--> statement-breakpoint
CREATE TABLE "evals_to_prompts" (
	"eval_id" text NOT NULL,
	"prompt_id" text NOT NULL,
	CONSTRAINT "evals_to_prompts_eval_id_prompt_id_pk" PRIMARY KEY("eval_id","prompt_id")
);
--> statement-breakpoint
CREATE TABLE "evals_to_tags" (
	"eval_id" text NOT NULL,
	"tag_id" text NOT NULL,
	CONSTRAINT "evals_to_tags_eval_id_tag_id_pk" PRIMARY KEY("eval_id","tag_id")
);
--> statement-breakpoint
CREATE TABLE "test_runs_to_datasets" (
	"test_run_id" text NOT NULL,
	"dataset_id" text NOT NULL,
	CONSTRAINT "test_runs_to_datasets_test_run_id_dataset_id_pk" PRIMARY KEY("test_run_id","dataset_id")
);
--> statement-breakpoint
CREATE TABLE "test_runs_to_security_configs" (
	"test_run_id" text NOT NULL,
	"security_config_id" text NOT NULL,
	CONSTRAINT "test_runs_to_security_configs_test_run_id_security_config_id_pk" PRIMARY KEY("test_run_id","security_config_id")
);
--> statement-breakpoint
CREATE TABLE "test_runs_to_evals" (
	"test_run_id" text NOT NULL,
	"eval_id" text NOT NULL,
	CONSTRAINT "test_runs_to_evals_test_run_id_eval_id_pk" PRIMARY KEY("test_run_id","eval_id")
);
--> statement-breakpoint
CREATE TABLE "evals_to_traces" (
	"eval_id" text NOT NULL,
	"trace_id" text NOT NULL,
	"project_id" text NOT NULL,
	"created_at" timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
	CONSTRAINT "evals_to_traces_eval_id_trace_id_pk" PRIMARY KEY("eval_id","trace_id")
);
--> statement-breakpoint
ALTER TABLE "evals" ADD CONSTRAINT "evals_application_id_applications_id_fk" FOREIGN KEY ("application_id") REFERENCES "public"."applications"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "eval_results" ADD CONSTRAINT "eval_results_eval_id_evals_id_fk" FOREIGN KEY ("eval_id") REFERENCES "public"."evals"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "eval_results" ADD CONSTRAINT "eval_results_prompt_id_prompts_id_fk" FOREIGN KEY ("prompt_id") REFERENCES "public"."prompts"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "eval_results" ADD CONSTRAINT "eval_results_application_id_applications_id_fk" FOREIGN KEY ("application_id") REFERENCES "public"."applications"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "prompts_library_prompts" ADD CONSTRAINT "prompts_library_prompts_library_id_prompts_library_id_fk" FOREIGN KEY ("library_id") REFERENCES "public"."prompts_library"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "prompts_library_prompts" ADD CONSTRAINT "prompts_library_prompts_prompt_id_prompts_id_fk" FOREIGN KEY ("prompt_id") REFERENCES "public"."prompts"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "monitoring_alerts" ADD CONSTRAINT "monitoring_alerts_application_id_applications_id_fk" FOREIGN KEY ("application_id") REFERENCES "public"."applications"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "test_runs" ADD CONSTRAINT "test_runs_library_id_prompts_library_id_fk" FOREIGN KEY ("library_id") REFERENCES "public"."prompts_library"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "monitoring" ADD CONSTRAINT "monitoring_application_id_applications_id_fk" FOREIGN KEY ("application_id") REFERENCES "public"."applications"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "evals_to_datasets" ADD CONSTRAINT "evals_to_datasets_eval_id_evals_id_fk" FOREIGN KEY ("eval_id") REFERENCES "public"."evals"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "evals_to_datasets" ADD CONSTRAINT "evals_to_datasets_dataset_id_datasets_id_fk" FOREIGN KEY ("dataset_id") REFERENCES "public"."datasets"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "evals_to_prompts" ADD CONSTRAINT "evals_to_prompts_eval_id_evals_id_fk" FOREIGN KEY ("eval_id") REFERENCES "public"."evals"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "evals_to_prompts" ADD CONSTRAINT "evals_to_prompts_prompt_id_prompts_id_fk" FOREIGN KEY ("prompt_id") REFERENCES "public"."prompts"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "evals_to_tags" ADD CONSTRAINT "evals_to_tags_eval_id_evals_id_fk" FOREIGN KEY ("eval_id") REFERENCES "public"."evals"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "evals_to_tags" ADD CONSTRAINT "evals_to_tags_tag_id_tags_id_fk" FOREIGN KEY ("tag_id") REFERENCES "public"."tags"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "test_runs_to_datasets" ADD CONSTRAINT "test_runs_to_datasets_test_run_id_test_runs_id_fk" FOREIGN KEY ("test_run_id") REFERENCES "public"."test_runs"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "test_runs_to_datasets" ADD CONSTRAINT "test_runs_to_datasets_dataset_id_trusys_datasets_id_fk" FOREIGN KEY ("dataset_id") REFERENCES "public"."trusys_datasets"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "test_runs_to_security_configs" ADD CONSTRAINT "test_runs_to_security_configs_test_run_id_test_runs_id_fk" FOREIGN KEY ("test_run_id") REFERENCES "public"."test_runs"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "test_runs_to_security_configs" ADD CONSTRAINT "test_runs_to_security_configs_security_config_id_security_confi" FOREIGN KEY ("security_config_id") REFERENCES "public"."security_config"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "test_runs_to_evals" ADD CONSTRAINT "test_runs_to_evals_test_run_id_test_runs_id_fk" FOREIGN KEY ("test_run_id") REFERENCES "public"."test_runs"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "test_runs_to_evals" ADD CONSTRAINT "test_runs_to_evals_eval_id_evals_id_fk" FOREIGN KEY ("eval_id") REFERENCES "public"."evals"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "evals_to_traces" ADD CONSTRAINT "evals_to_traces_eval_id_evals_id_fk" FOREIGN KEY ("eval_id") REFERENCES "public"."evals"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "configs_created_at_idx" ON "configs" USING btree ("created_at" timestamptz_ops);--> statement-breakpoint
CREATE INDEX "configs_type_idx" ON "configs" USING btree ("type" text_ops);--> statement-breakpoint
CREATE INDEX "default_providers_group_idx" ON "default_providers" USING btree ("group" text_ops);--> statement-breakpoint
CREATE INDEX "default_providers_label_idx" ON "default_providers" USING btree ("label" text_ops);--> statement-breakpoint
CREATE INDEX "applications_created_at_idx" ON "applications" USING btree ("created_at" timestamptz_ops);--> statement-breakpoint
CREATE INDEX "evals_author_idx" ON "evals" USING btree ("author" text_ops);--> statement-breakpoint
CREATE INDEX "evals_created_at_idx" ON "evals" USING btree ("created_at" timestamptz_ops);--> statement-breakpoint
CREATE INDEX "assertions_created_at_idx" ON "assertions" USING btree ("created_at" timestamptz_ops);--> statement-breakpoint
CREATE INDEX "assertions_group_idx" ON "assertions" USING btree ("group" text_ops);--> statement-breakpoint
CREATE INDEX "assertions_name_idx" ON "assertions" USING btree ("name" text_ops);--> statement-breakpoint
CREATE INDEX "plugins_presets_name_idx" ON "plugins_presets" USING btree ("name" text_ops);--> statement-breakpoint
CREATE INDEX "prompts_created_at_idx" ON "prompts" USING btree ("created_at" timestamptz_ops);--> statement-breakpoint
CREATE INDEX "prompts_library_created_at_idx" ON "prompts_library" USING btree ("created_at" timestamptz_ops);--> statement-breakpoint
CREATE INDEX "provider_supported_languages_code_idx" ON "provider_supported_languages" USING btree ("code" text_ops);--> statement-breakpoint
CREATE INDEX "provider_supported_languages_name_idx" ON "provider_supported_languages" USING btree ("name" text_ops);--> statement-breakpoint
CREATE INDEX "security_config_name_idx" ON "security_config" USING btree ("name" text_ops);--> statement-breakpoint
CREATE INDEX "security_config_project_id_idx" ON "security_config" USING btree ("project_id" text_ops);--> statement-breakpoint
CREATE INDEX "security_config_status_idx" ON "security_config" USING btree ("status" int4_ops);--> statement-breakpoint
CREATE INDEX "strategy_presets_name_idx" ON "strategy_presets" USING btree ("name" text_ops);--> statement-breakpoint
CREATE INDEX "eval_result_eval_id_idx" ON "eval_results" USING btree ("eval_id" text_ops);--> statement-breakpoint
CREATE INDEX "eval_result_test_idx" ON "eval_results" USING btree ("test_idx" int4_ops);--> statement-breakpoint
CREATE INDEX "trusys_datasets_created_at_idx" ON "trusys_datasets" USING btree ("created_at" timestamp_ops);--> statement-breakpoint
CREATE INDEX "trusys_datasets_project_id_idx" ON "trusys_datasets" USING btree ("project_id" text_ops);--> statement-breakpoint
CREATE INDEX "tags_name_idx" ON "tags" USING btree ("name" text_ops);--> statement-breakpoint
CREATE UNIQUE INDEX "tags_name_value_unique" ON "tags" USING btree ("name" text_ops,"value" text_ops);--> statement-breakpoint
CREATE INDEX "monitoring_alerts_application_id_idx" ON "monitoring_alerts" USING btree ("application_id" text_ops);--> statement-breakpoint
CREATE INDEX "test_runs_created_at_idx" ON "test_runs" USING btree ("created_at" timestamptz_ops);--> statement-breakpoint
CREATE INDEX "test_runs_status_idx" ON "test_runs" USING btree ("status" text_ops);--> statement-breakpoint
CREATE INDEX "monitoring_application_id_idx" ON "monitoring" USING btree ("application_id" text_ops);--> statement-breakpoint
CREATE INDEX "evals_to_datasets_dataset_id_idx" ON "evals_to_datasets" USING btree ("dataset_id" text_ops);--> statement-breakpoint
CREATE INDEX "evals_to_datasets_eval_id_idx" ON "evals_to_datasets" USING btree ("eval_id" text_ops);--> statement-breakpoint
CREATE INDEX "evals_to_prompts_eval_id_idx" ON "evals_to_prompts" USING btree ("eval_id" text_ops);--> statement-breakpoint
CREATE INDEX "evals_to_prompts_prompt_id_idx" ON "evals_to_prompts" USING btree ("prompt_id" text_ops);--> statement-breakpoint
CREATE INDEX "evals_to_tags_eval_id_idx" ON "evals_to_tags" USING btree ("eval_id" text_ops);--> statement-breakpoint
CREATE INDEX "evals_to_tags_tag_id_idx" ON "evals_to_tags" USING btree ("tag_id" text_ops);--> statement-breakpoint
CREATE INDEX "test_runs_to_datasets_dataset_id_idx" ON "test_runs_to_datasets" USING btree ("dataset_id" text_ops);--> statement-breakpoint
CREATE INDEX "test_runs_to_datasets_test_run_id_idx" ON "test_runs_to_datasets" USING btree ("test_run_id" text_ops);--> statement-breakpoint
CREATE INDEX "test_runs_to_security_configs_security_config_id_idx" ON "test_runs_to_security_configs" USING btree ("security_config_id" text_ops);--> statement-breakpoint
CREATE INDEX "test_runs_to_security_configs_test_run_id_idx" ON "test_runs_to_security_configs" USING btree ("test_run_id" text_ops);--> statement-breakpoint
CREATE INDEX "test_runs_to_evals_eval_id_idx" ON "test_runs_to_evals" USING btree ("eval_id" text_ops);--> statement-breakpoint
CREATE INDEX "test_runs_to_evals_test_run_id_idx" ON "test_runs_to_evals" USING btree ("test_run_id" text_ops);--> statement-breakpoint
CREATE INDEX "evals_to_traces_eval_id_idx" ON "evals_to_traces" USING btree ("eval_id" text_ops);--> statement-breakpoint
CREATE INDEX "evals_to_traces_project_id_idx" ON "evals_to_traces" USING btree ("project_id" text_ops);--> statement-breakpoint
CREATE INDEX "evals_to_traces_trace_id_idx" ON "evals_to_traces" USING btree ("trace_id" text_ops);
*/