CREATE TABLE "scheduled_workflows" ( "id" text PRIMARY KEY NOT NULL, "workflow_id" text NOT NULL, "cron_expression" text NOT NULL, "timezone" text DEFAULT 'UTC', "is_enabled" boolean DEFAULT true, "last_run_at" timestamp, "next_run_at" timestamp, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "workflow_artifacts" ( "id" text PRIMARY KEY NOT NULL, "run_id" text NOT NULL, "job_id" text, "name" text NOT NULL, "size_bytes" integer NOT NULL, "storage_path" text NOT NULL, "mime_type" text, "download_count" integer DEFAULT 0, "expires_at" timestamp, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "workflow_jobs" ( "id" text PRIMARY KEY NOT NULL, "run_id" text NOT NULL, "name" text NOT NULL, "status" text DEFAULT 'queued' NOT NULL, "conclusion" text, "runner_id" text, "runner_name" text, "runner_group_id" text, "runner_group_name" text, "container_id" text, "container_image" text, "needs" text, "environment" text, "environment_url" text, "matrix" text, "started_at" timestamp, "completed_at" timestamp, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "workflow_logs" ( "id" text PRIMARY KEY NOT NULL, "job_id" text NOT NULL, "step_id" text, "log_level" text DEFAULT 'info' NOT NULL, "message" text NOT NULL, "timestamp" text NOT NULL, "line_number" integer, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "workflow_runs" ( "id" text PRIMARY KEY NOT NULL, "workflow_id" text NOT NULL, "repository_id" text NOT NULL, "run_number" integer NOT NULL, "run_attempt" integer DEFAULT 1 NOT NULL, "name" text NOT NULL, "display_title" text, "status" text DEFAULT 'queued' NOT NULL, "conclusion" text, "event" text NOT NULL, "head_branch" text, "head_sha" text NOT NULL, "base_branch" text, "base_sha" text, "pull_request_id" text, "triggered_by_id" text, "started_at" timestamp, "completed_at" timestamp, "workflow_config" text, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "workflow_secrets" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "name" text NOT NULL, "encrypted_value" text NOT NULL, "environment" text, "created_by_id" text, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "workflow_steps" ( "id" text PRIMARY KEY NOT NULL, "job_id" text NOT NULL, "number" integer NOT NULL, "name" text NOT NULL, "status" text DEFAULT 'queued' NOT NULL, "conclusion" text, "uses" text, "run" text, "shell" text, "working_directory" text, "env" text, "with" text, "if" text, "continue_on_error" boolean DEFAULT false, "timeout_minutes" integer, "started_at" timestamp, "completed_at" timestamp, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "workflow_variables" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "name" text NOT NULL, "value" text NOT NULL, "environment" text, "created_by_id" text, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "workflows" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "name" text NOT NULL, "path" text NOT NULL, "state" text DEFAULT 'active' NOT NULL, "badge_url" text, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint ALTER TABLE "issues" ADD COLUMN "type" text DEFAULT 'issue' NOT NULL;--> statement-breakpoint ALTER TABLE "issues" ADD COLUMN "parent_id" text;--> statement-breakpoint ALTER TABLE "scheduled_workflows" ADD CONSTRAINT "scheduled_workflows_workflow_id_workflows_id_fk" FOREIGN KEY ("workflow_id") REFERENCES "public"."workflows"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "workflow_artifacts" ADD CONSTRAINT "workflow_artifacts_run_id_workflow_runs_id_fk" FOREIGN KEY ("run_id") REFERENCES "public"."workflow_runs"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "workflow_artifacts" ADD CONSTRAINT "workflow_artifacts_job_id_workflow_jobs_id_fk" FOREIGN KEY ("job_id") REFERENCES "public"."workflow_jobs"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "workflow_jobs" ADD CONSTRAINT "workflow_jobs_run_id_workflow_runs_id_fk" FOREIGN KEY ("run_id") REFERENCES "public"."workflow_runs"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "workflow_logs" ADD CONSTRAINT "workflow_logs_job_id_workflow_jobs_id_fk" FOREIGN KEY ("job_id") REFERENCES "public"."workflow_jobs"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "workflow_logs" ADD CONSTRAINT "workflow_logs_step_id_workflow_steps_id_fk" FOREIGN KEY ("step_id") REFERENCES "public"."workflow_steps"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "workflow_runs" ADD CONSTRAINT "workflow_runs_workflow_id_workflows_id_fk" FOREIGN KEY ("workflow_id") REFERENCES "public"."workflows"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "workflow_runs" ADD CONSTRAINT "workflow_runs_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "workflow_runs" ADD CONSTRAINT "workflow_runs_pull_request_id_pull_requests_id_fk" FOREIGN KEY ("pull_request_id") REFERENCES "public"."pull_requests"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "workflow_runs" ADD CONSTRAINT "workflow_runs_triggered_by_id_users_id_fk" FOREIGN KEY ("triggered_by_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "workflow_secrets" ADD CONSTRAINT "workflow_secrets_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "workflow_secrets" ADD CONSTRAINT "workflow_secrets_created_by_id_users_id_fk" FOREIGN KEY ("created_by_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "workflow_steps" ADD CONSTRAINT "workflow_steps_job_id_workflow_jobs_id_fk" FOREIGN KEY ("job_id") REFERENCES "public"."workflow_jobs"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "workflow_variables" ADD CONSTRAINT "workflow_variables_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "workflow_variables" ADD CONSTRAINT "workflow_variables_created_by_id_users_id_fk" FOREIGN KEY ("created_by_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "workflows" ADD CONSTRAINT "workflows_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;