CREATE TABLE "email_verification_tokens" ( "id" text PRIMARY KEY NOT NULL, "user_id" text NOT NULL, "token" text NOT NULL, "expires_at" timestamp NOT NULL, "created_at" timestamp DEFAULT now() NOT NULL, CONSTRAINT "email_verification_tokens_token_unique" UNIQUE("token") ); --> statement-breakpoint CREATE TABLE "gpg_keys" ( "id" text PRIMARY KEY NOT NULL, "user_id" text NOT NULL, "name" text NOT NULL, "key_id" text NOT NULL, "public_key" text NOT NULL, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "oauth_accounts" ( "id" text PRIMARY KEY NOT NULL, "user_id" text NOT NULL, "provider" text NOT NULL, "provider_account_id" text NOT NULL, "access_token" text, "refresh_token" text, "expires_at" timestamp, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "password_reset_tokens" ( "id" text PRIMARY KEY NOT NULL, "user_id" text NOT NULL, "token" text NOT NULL, "expires_at" timestamp NOT NULL, "created_at" timestamp DEFAULT now() NOT NULL, CONSTRAINT "password_reset_tokens_token_unique" UNIQUE("token") ); --> statement-breakpoint CREATE TABLE "personal_access_tokens" ( "id" text PRIMARY KEY NOT NULL, "user_id" text NOT NULL, "name" text NOT NULL, "token" text NOT NULL, "expires_at" timestamp, "last_used_at" timestamp, "created_at" timestamp DEFAULT now() NOT NULL, CONSTRAINT "personal_access_tokens_token_unique" UNIQUE("token") ); --> statement-breakpoint CREATE TABLE "sessions" ( "id" text PRIMARY KEY NOT NULL, "user_id" text NOT NULL, "token" text NOT NULL, "user_agent" text, "ip_address" text, "expires_at" timestamp NOT NULL, "created_at" timestamp DEFAULT now() NOT NULL, CONSTRAINT "sessions_token_unique" UNIQUE("token") ); --> statement-breakpoint CREATE TABLE "ssh_keys" ( "id" text PRIMARY KEY NOT NULL, "user_id" text NOT NULL, "title" text NOT NULL, "fingerprint" text NOT NULL, "public_key" text NOT NULL, "key_type" text NOT NULL, "last_used_at" timestamp, "created_at" timestamp DEFAULT now() NOT NULL, CONSTRAINT "ssh_keys_fingerprint_unique" UNIQUE("fingerprint") ); --> statement-breakpoint CREATE TABLE "user_followers" ( "follower_id" text NOT NULL, "followee_id" text NOT NULL, "created_at" timestamp DEFAULT now() NOT NULL, CONSTRAINT "user_followers_follower_id_followee_id_pk" PRIMARY KEY("follower_id","followee_id") ); --> statement-breakpoint CREATE TABLE "users" ( "id" text PRIMARY KEY NOT NULL, "username" text NOT NULL, "email" text NOT NULL, "password_hash" text, "display_name" text, "bio" text, "avatar_url" text, "location" text, "website" text, "company" text, "is_admin" boolean DEFAULT false, "is_active" boolean DEFAULT true, "email_verified" boolean DEFAULT false, "two_factor_enabled" boolean DEFAULT false, "two_factor_secret" text, "last_login_at" timestamp, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL, "ai_config" text, CONSTRAINT "users_username_unique" UNIQUE("username"), CONSTRAINT "users_email_unique" UNIQUE("email") ); --> statement-breakpoint CREATE TABLE "deploy_keys" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "title" text NOT NULL, "key" text NOT NULL, "fingerprint" text NOT NULL, "read_only" boolean DEFAULT true NOT NULL, "created_at" timestamp DEFAULT now() NOT NULL, "last_used_at" timestamp ); --> statement-breakpoint CREATE TABLE "branches" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "name" text NOT NULL, "commit_sha" text NOT NULL, "is_protected" boolean DEFAULT false, "is_default" boolean DEFAULT false, "protection_rules" text, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "commits" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "sha" text NOT NULL, "message" text NOT NULL, "author_name" text NOT NULL, "author_email" text NOT NULL, "author_date" timestamp NOT NULL, "committer_name" text NOT NULL, "committer_email" text NOT NULL, "committer_date" timestamp NOT NULL, "parent_shas" text, "tree_sha" text, "user_id" text, "stats" text, "signature" text, "is_verified" boolean DEFAULT false, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "releases" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "tag_id" text, "name" text NOT NULL, "body" text, "is_draft" boolean DEFAULT false, "is_prerelease" boolean DEFAULT false, "author_id" text, "assets" text, "download_count" integer DEFAULT 0, "published_at" timestamp, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "repositories" ( "id" text PRIMARY KEY NOT NULL, "name" text NOT NULL, "slug" text NOT NULL, "description" text, "owner_id" text NOT NULL, "owner_type" text DEFAULT 'user' NOT NULL, "visibility" text DEFAULT 'public' NOT NULL, "default_branch" text DEFAULT 'main' NOT NULL, "disk_path" text NOT NULL, "ssh_clone_url" text, "http_clone_url" text, "website" text, "star_count" integer DEFAULT 0 NOT NULL, "fork_count" integer DEFAULT 0 NOT NULL, "watch_count" integer DEFAULT 0 NOT NULL, "open_issue_count" integer DEFAULT 0 NOT NULL, "open_pr_count" integer DEFAULT 0 NOT NULL, "size" integer DEFAULT 0 NOT NULL, "is_fork" boolean DEFAULT false, "forked_from_id" text, "is_archived" boolean DEFAULT false, "is_template" boolean DEFAULT false, "is_mirror" boolean DEFAULT false, "mirror_url" text, "last_mirror_sync_at" timestamp, "mirror_sync_status" text, "has_issues" boolean DEFAULT true, "has_wiki" boolean DEFAULT true, "has_actions" boolean DEFAULT true, "allow_forking" boolean DEFAULT true, "license_type" text, "topics" text, "language" text, "languages" text, "last_activity_at" timestamp, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "repository_collaborators" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "user_id" text NOT NULL, "role" text DEFAULT 'developer' NOT NULL, "added_by_id" text, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "repository_stars" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "user_id" text NOT NULL, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "repository_watchers" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "user_id" text NOT NULL, "watch_level" text DEFAULT 'watching' NOT NULL, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "tags" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "name" text NOT NULL, "commit_sha" text NOT NULL, "message" text, "tagger_name" text, "tagger_email" text, "tagged_at" timestamp, "is_release" boolean DEFAULT false, "release_id" text, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "issue_assignees" ( "id" text PRIMARY KEY NOT NULL, "issue_id" text NOT NULL, "user_id" text NOT NULL, "assigned_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "issue_comments" ( "id" text PRIMARY KEY NOT NULL, "issue_id" text NOT NULL, "author_id" text NOT NULL, "body" text NOT NULL, "reactions" text, "is_edited" boolean DEFAULT false, "edited_at" timestamp, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "issue_labels" ( "id" text PRIMARY KEY NOT NULL, "issue_id" text NOT NULL, "label_id" text NOT NULL ); --> statement-breakpoint CREATE TABLE "issue_subscribers" ( "id" text PRIMARY KEY NOT NULL, "issue_id" text NOT NULL, "user_id" text NOT NULL, "subscribed_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "issues" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "number" integer NOT NULL, "title" text NOT NULL, "body" text, "state" text DEFAULT 'open' NOT NULL, "status_id" text, "type" text DEFAULT 'issue' NOT NULL, "parent_id" text, "author_id" text NOT NULL, "assignee_id" text, "milestone_id" text, "is_pinned" boolean DEFAULT false, "is_locked" boolean DEFAULT false, "lock_reason" text, "comment_count" integer DEFAULT 0, "reactions" text, "closed_at" timestamp, "closed_by_id" text, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "labels" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "name" text NOT NULL, "color" text DEFAULT '#6b7280' NOT NULL, "description" text, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "milestones" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "title" text NOT NULL, "description" text, "state" text DEFAULT 'open' NOT NULL, "due_date" timestamp, "open_issue_count" integer DEFAULT 0, "closed_issue_count" integer DEFAULT 0, "closed_at" timestamp, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "pull_request_assignees" ( "id" text PRIMARY KEY NOT NULL, "pull_request_id" text NOT NULL, "user_id" text NOT NULL, "assigned_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "pull_request_checks" ( "id" text PRIMARY KEY NOT NULL, "pull_request_id" text NOT NULL, "name" text NOT NULL, "status" text NOT NULL, "conclusion" text, "head_sha" text NOT NULL, "external_id" text, "details_url" text, "output" text, "started_at" timestamp, "completed_at" timestamp, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "pull_request_comments" ( "id" text PRIMARY KEY NOT NULL, "pull_request_id" text NOT NULL, "review_id" text, "author_id" text NOT NULL, "body" text NOT NULL, "path" text, "line" integer, "side" text, "start_line" integer, "start_side" text, "commit_sha" text, "original_commit_sha" text, "original_line" integer, "in_reply_to_id" text, "reactions" text, "is_resolved" boolean DEFAULT false, "resolved_by_id" text, "resolved_at" timestamp, "is_edited" boolean DEFAULT false, "edited_at" timestamp, "suggestion_content" text, "suggestion_applied" boolean DEFAULT false, "suggestion_applied_by_id" text, "suggestion_applied_at" timestamp, "suggestion_commit_sha" text, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "pull_request_labels" ( "id" text PRIMARY KEY NOT NULL, "pull_request_id" text NOT NULL, "label_id" text NOT NULL ); --> statement-breakpoint CREATE TABLE "pull_request_reviewers" ( "id" text PRIMARY KEY NOT NULL, "pull_request_id" text NOT NULL, "user_id" text NOT NULL, "is_required" boolean DEFAULT false, "requested_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "pull_request_reviews" ( "id" text PRIMARY KEY NOT NULL, "pull_request_id" text NOT NULL, "reviewer_id" text NOT NULL, "state" text NOT NULL, "body" text, "commit_sha" text, "submitted_at" timestamp, "dismissed_at" timestamp, "dismissed_by_id" text, "dismissal_reason" text, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "pull_requests" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "number" integer NOT NULL, "title" text NOT NULL, "body" text, "state" text DEFAULT 'open' NOT NULL, "author_id" text NOT NULL, "assignee_id" text, "milestone_id" text, "head_branch" text NOT NULL, "head_sha" text NOT NULL, "head_repository_id" text, "base_branch" text NOT NULL, "base_sha" text NOT NULL, "is_draft" boolean DEFAULT false, "is_merged" boolean DEFAULT false, "merged_at" timestamp, "merged_by_id" text, "merge_commit_sha" text, "merge_sha" text, "merge_method" text, "additions" integer DEFAULT 0, "deletions" integer DEFAULT 0, "changed_files" integer DEFAULT 0, "comment_count" integer DEFAULT 0, "review_count" integer DEFAULT 0, "mergeable" boolean, "mergeable_state" text, "rebaseable" boolean, "maintainer_can_modify" boolean DEFAULT true, "allow_auto_merge" boolean DEFAULT false, "auto_merge_method" text, "auto_merge_enabled_by_id" text, "auto_merge_enabled_at" timestamp, "state_id" text, "custom_state_changed_at" timestamp, "closed_at" timestamp, "closed_by_id" text, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "project_cards" ( "id" text PRIMARY KEY NOT NULL, "column_id" text NOT NULL, "content_id" text, "content_type" text, "note" text, "order" integer NOT NULL, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL, "creator_id" text NOT NULL ); --> statement-breakpoint CREATE TABLE "project_columns" ( "id" text PRIMARY KEY NOT NULL, "project_id" text NOT NULL, "name" text NOT NULL, "order" integer NOT NULL, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "projects" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "name" text NOT NULL, "description" text, "number" integer NOT NULL, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL, "creator_id" text NOT NULL ); --> statement-breakpoint 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 CREATE TABLE "wiki_pages" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "slug" text NOT NULL, "title" text NOT NULL, "content" text NOT NULL, "format" text DEFAULT 'markdown' NOT NULL, "parent_id" text, "order" integer DEFAULT 0, "last_editor_id" text, "view_count" integer DEFAULT 0, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "wiki_revisions" ( "id" text PRIMARY KEY NOT NULL, "page_id" text NOT NULL, "content" text NOT NULL, "message" text, "author_id" text NOT NULL, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "organization_members" ( "organization_id" text NOT NULL, "user_id" text NOT NULL, "role" text DEFAULT 'member' NOT NULL, "custom_role_id" text, "created_at" timestamp DEFAULT now() NOT NULL, CONSTRAINT "organization_members_organization_id_user_id_pk" PRIMARY KEY("organization_id","user_id") ); --> statement-breakpoint CREATE TABLE "organizations" ( "id" text PRIMARY KEY NOT NULL, "name" text NOT NULL, "display_name" text, "description" text, "email" text, "location" text, "website" text, "avatar_url" text, "is_verified" boolean DEFAULT false, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL, CONSTRAINT "organizations_name_unique" UNIQUE("name") ); --> statement-breakpoint CREATE TABLE "custom_roles" ( "id" text PRIMARY KEY NOT NULL, "organization_id" text NOT NULL, "name" text NOT NULL, "description" text, "permissions" jsonb DEFAULT '[]'::jsonb NOT NULL, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "team_members" ( "team_id" text NOT NULL, "user_id" text NOT NULL, "role" text DEFAULT 'member' NOT NULL, "created_at" timestamp DEFAULT now() NOT NULL, CONSTRAINT "team_members_team_id_user_id_pk" PRIMARY KEY("team_id","user_id") ); --> statement-breakpoint CREATE TABLE "team_repositories" ( "team_id" text NOT NULL, "repository_id" text NOT NULL, "permission" text DEFAULT 'read' NOT NULL, "created_at" timestamp DEFAULT now() NOT NULL, CONSTRAINT "team_repositories_team_id_repository_id_pk" PRIMARY KEY("team_id","repository_id") ); --> statement-breakpoint CREATE TABLE "teams" ( "id" text PRIMARY KEY NOT NULL, "organization_id" text NOT NULL, "name" text NOT NULL, "slug" text NOT NULL, "description" text, "privacy" text DEFAULT 'visible', "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "activities" ( "id" text PRIMARY KEY NOT NULL, "user_id" text NOT NULL, "repository_id" text, "type" text NOT NULL, "action" text NOT NULL, "ref_type" text, "ref_name" text, "target_type" text, "target_id" text, "payload" text, "is_public" boolean DEFAULT true, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "audit_logs" ( "id" text PRIMARY KEY NOT NULL, "user_id" text, "repository_id" text, "organization_id" text, "action" text NOT NULL, "actor_type" text DEFAULT 'user' NOT NULL, "actor_id" text, "actor_ip" text, "actor_user_agent" text, "target_type" text, "target_id" text, "target_name" text, "data" text, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "notifications" ( "id" text PRIMARY KEY NOT NULL, "user_id" text NOT NULL, "repository_id" text, "type" text NOT NULL, "title" text NOT NULL, "body" text, "url" text, "actor_id" text, "subject_type" text, "subject_id" text, "reason" text NOT NULL, "is_read" boolean DEFAULT false, "read_at" timestamp, "is_archived" boolean DEFAULT false, "archived_at" timestamp, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "security_scans" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "status" text DEFAULT 'queued' NOT NULL, "started_at" timestamp, "completed_at" timestamp, "critical_count" integer DEFAULT 0, "high_count" integer DEFAULT 0, "medium_count" integer DEFAULT 0, "low_count" integer DEFAULT 0, "unknown_count" integer DEFAULT 0, "logs" text ); --> statement-breakpoint CREATE TABLE "security_vulnerabilities" ( "id" text PRIMARY KEY NOT NULL, "scan_id" text NOT NULL, "vulnerability_id" text NOT NULL, "pkg_name" text NOT NULL, "installed_version" text, "fixed_version" text, "severity" text NOT NULL, "title" text, "description" text, "target" text, "class" text ); --> statement-breakpoint CREATE TABLE "security_policies" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "enforcement_mode" text DEFAULT 'warn' NOT NULL, "secret_blocked_types" text DEFAULT '[]' NOT NULL, "secret_min_severity" text DEFAULT 'HIGH' NOT NULL, "license_allowed_types" text DEFAULT '["permissive"]' NOT NULL, "license_blocked_licenses" text DEFAULT '[]' NOT NULL, "is_enabled" boolean DEFAULT true NOT NULL, "updated_by_id" text, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "pipeline_runners" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text, "token" text NOT NULL, "name" text NOT NULL, "os" text, "arch" text, "version" text, "status" text DEFAULT 'offline' NOT NULL, "last_seen_at" timestamp, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "pr_stack_entries" ( "id" text PRIMARY KEY NOT NULL, "stack_id" text NOT NULL, "pull_request_id" text NOT NULL, "stack_order" integer NOT NULL, "parent_pr_id" text, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "pr_stacks" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "name" text, "base_branch" text NOT NULL, "status" text DEFAULT 'active' NOT NULL, "created_by_id" text NOT NULL, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "merge_queue" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "pull_request_id" text NOT NULL, "stack_id" text, "status" text DEFAULT 'pending' NOT NULL, "priority" integer DEFAULT 0, "position" integer DEFAULT 0, "ci_status" text DEFAULT 'pending', "merge_method" text DEFAULT 'merge', "delete_on_merge" boolean DEFAULT true, "execution_branch" text, "attempt_count" integer DEFAULT 0, "last_attempt_at" timestamp, "added_by_id" text, "added_at" timestamp DEFAULT now() NOT NULL, "queued_at" timestamp DEFAULT now() NOT NULL, "started_at" timestamp, "completed_at" timestamp, "failure_reason" text ); --> statement-breakpoint CREATE TABLE "merge_queue_speculative_runs" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "pull_request_ids" text NOT NULL, "branch_name" text NOT NULL, "base_branch" text NOT NULL, "status" text DEFAULT 'pending' NOT NULL, "ci_url" text, "created_at" timestamp DEFAULT now() NOT NULL, "started_at" timestamp, "completed_at" timestamp, "failure_reason" text, "commit_sha" text ); --> statement-breakpoint CREATE TABLE "ai_review_suggestions" ( "id" text PRIMARY KEY NOT NULL, "ai_review_id" text NOT NULL, "path" text NOT NULL, "line" integer, "end_line" integer, "severity" text NOT NULL, "type" text NOT NULL, "category" text, "title" text NOT NULL, "message" text NOT NULL, "suggested_fix" text, "explanation" text, "is_applied" boolean DEFAULT false, "is_dismissed" boolean DEFAULT false, "applied_at" timestamp, "applied_by_id" text, "dismissed_at" timestamp, "dismissed_by_id" text, "dismiss_reason" text, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "ai_reviews" ( "id" text PRIMARY KEY NOT NULL, "pull_request_id" text NOT NULL, "status" text DEFAULT 'pending' NOT NULL, "model" text NOT NULL, "provider" text NOT NULL, "stack_context" text, "includes_stack_context" boolean DEFAULT false, "summary" text, "overall_severity" text, "suggestions_count" integer DEFAULT 0, "tokens_used" integer, "prompt_tokens" integer, "completion_tokens" integer, "cost_cents" integer, "raw_response" text, "triggered_by_id" text, "created_at" timestamp DEFAULT now() NOT NULL, "started_at" timestamp, "completed_at" timestamp, "error_message" text ); --> statement-breakpoint CREATE TABLE "pr_metrics" ( "id" text PRIMARY KEY NOT NULL, "pull_request_id" text NOT NULL, "repository_id" text NOT NULL, "author_id" text NOT NULL, "time_to_first_review" integer, "time_to_approval" integer, "time_to_merge" integer, "total_cycle_time" integer, "review_rounds" integer DEFAULT 1, "reviewers_count" integer DEFAULT 0, "comments_count" integer DEFAULT 0, "changes_requested_count" integer DEFAULT 0, "lines_added" integer DEFAULT 0, "lines_removed" integer DEFAULT 0, "files_changed" integer DEFAULT 0, "commits" integer DEFAULT 1, "is_stacked" boolean DEFAULT false, "stack_position" integer, "pr_created_at" timestamp, "first_review_at" timestamp, "approved_at" timestamp, "merged_at" timestamp, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "repo_metrics" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "week_of" text NOT NULL, "prs_opened" integer DEFAULT 0, "prs_merged" integer DEFAULT 0, "prs_closed" integer DEFAULT 0, "avg_time_to_first_review" integer, "avg_time_to_merge" integer, "avg_review_rounds" integer, "avg_lines_changed" integer, "avg_files_changed" integer, "stacked_prs" integer DEFAULT 0, "stacked_prs_percentage" integer DEFAULT 0, "active_authors" integer DEFAULT 0, "active_reviewers" integer DEFAULT 0, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "review_metrics" ( "id" text PRIMARY KEY NOT NULL, "user_id" text NOT NULL, "repository_id" text, "week_of" text NOT NULL, "prs_authored" integer DEFAULT 0, "prs_authored_merged" integer DEFAULT 0, "avg_time_to_merge_authored" integer, "lines_authored_added" integer DEFAULT 0, "lines_authored_removed" integer DEFAULT 0, "prs_reviewed" integer DEFAULT 0, "avg_time_to_review" integer, "comments_given" integer DEFAULT 0, "approvals_given" integer DEFAULT 0, "changes_requested_given" integer DEFAULT 0, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "slack_channel_mappings" ( "id" text PRIMARY KEY NOT NULL, "workspace_id" text NOT NULL, "repository_id" text NOT NULL, "channel_id" text NOT NULL, "channel_name" text, "notify_on" text DEFAULT '["pr_created","pr_merged","review_requested","ci_failed"]', "notify_branches" text, "notify_authors" text, "is_active" boolean DEFAULT true, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "slack_user_mappings" ( "id" text PRIMARY KEY NOT NULL, "user_id" text NOT NULL, "workspace_id" text NOT NULL, "slack_user_id" text NOT NULL, "slack_username" text, "dm_preferences" text DEFAULT '{"review_requested":true,"pr_approved":true,"ci_failed":true}', "dnd_enabled" boolean DEFAULT false, "dnd_start" text, "dnd_end" text, "dnd_timezone" text, "is_active" boolean DEFAULT true, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "slack_workspaces" ( "id" text PRIMARY KEY NOT NULL, "team_id" text NOT NULL, "team_name" text, "team_domain" text, "access_token" text NOT NULL, "bot_user_id" text, "bot_access_token" text, "scopes" text, "installed_by_id" text NOT NULL, "installed_at" timestamp DEFAULT now() NOT NULL, "is_active" boolean DEFAULT true, "last_used_at" timestamp ); --> statement-breakpoint CREATE TABLE "webhook_deliveries" ( "id" text PRIMARY KEY NOT NULL, "webhook_id" text NOT NULL, "event" text NOT NULL, "payload" text NOT NULL, "status" text NOT NULL, "response_code" integer, "response_body" text, "duration_ms" integer, "error" text, "request_headers" text, "response_headers" text, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "webhooks" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "provider" text DEFAULT 'generic', "name" text, "url" text NOT NULL, "secret" text, "events" text NOT NULL, "active" boolean DEFAULT true NOT NULL, "enabled" boolean DEFAULT true NOT NULL, "content_type" text DEFAULT 'json' NOT NULL, "delivery_count" integer DEFAULT 0, "last_delivery_status" text, "last_delivery_at" timestamp, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL, "created_by_id" text ); --> statement-breakpoint CREATE TABLE "branch_protection" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "pattern" text NOT NULL, "active" boolean DEFAULT true, "requires_pr" boolean DEFAULT false, "required_approvals" integer DEFAULT 1, "dismiss_stale_reviews" boolean DEFAULT false, "require_code_owner_reviews" boolean DEFAULT false, "allow_force_pushes" boolean DEFAULT false, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL, "created_by_id" text ); --> statement-breakpoint CREATE TABLE "system_config" ( "key" text PRIMARY KEY NOT NULL, "value" text NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL, "updated_by_id" text ); --> statement-breakpoint CREATE TABLE "inbox_sections" ( "id" text PRIMARY KEY NOT NULL, "user_id" text NOT NULL, "name" text NOT NULL, "icon" text, "color" text, "filters" text, "position" integer DEFAULT 0 NOT NULL, "is_default" boolean DEFAULT false, "is_collapsed" boolean DEFAULT false, "show_count" boolean DEFAULT true, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "shared_inbox_sections" ( "id" text PRIMARY KEY NOT NULL, "section_id" text NOT NULL, "shared_with_user_id" text, "shared_with_team_id" text, "permission" text DEFAULT 'view' NOT NULL, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "automation_executions" ( "id" text PRIMARY KEY NOT NULL, "rule_id" text NOT NULL, "triggered_by_id" text, "triggered_by_type" text, "trigger_event" text NOT NULL, "conditions_matched" boolean, "actions_executed" text, "status" text DEFAULT 'pending' NOT NULL, "error_message" text, "duration_ms" integer, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "automation_rules" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text, "organization_id" text, "created_by_id" text NOT NULL, "name" text NOT NULL, "description" text, "trigger" text NOT NULL, "conditions" text, "actions" text NOT NULL, "is_enabled" boolean DEFAULT true, "priority" integer DEFAULT 0, "run_count" integer DEFAULT 0, "last_run_at" timestamp, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "ai_codebase_context" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "context_type" text NOT NULL, "name" text NOT NULL, "description" text, "examples" text, "anti_patterns" text, "is_auto_detected" boolean DEFAULT false, "confidence" integer, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "ai_review_rule_templates" ( "id" text PRIMARY KEY NOT NULL, "name" text NOT NULL, "description" text, "rule_type" text NOT NULL, "ai_prompt" text, "regex_pattern" text, "severity" text NOT NULL, "category" text, "file_globs" text, "languages" text, "is_built_in" boolean DEFAULT false, "usage_count" integer DEFAULT 0, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "ai_review_rules" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text, "organization_id" text, "created_by_id" text NOT NULL, "name" text NOT NULL, "description" text, "rule_type" text DEFAULT 'ai_prompt' NOT NULL, "ai_prompt" text, "regex_pattern" text, "severity" text DEFAULT 'info' NOT NULL, "category" text, "file_globs" text, "exclude_globs" text, "languages" text, "is_enabled" boolean DEFAULT true, "is_auto_fix" boolean DEFAULT false, "priority" integer DEFAULT 0, "match_count" integer DEFAULT 0, "last_match_at" timestamp, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "email_digest_settings" ( "id" text PRIMARY KEY NOT NULL, "user_id" text NOT NULL, "digest_type" text DEFAULT 'none' NOT NULL, "digest_time" text DEFAULT '09:00', "digest_day" integer DEFAULT 1, "timezone" text DEFAULT 'UTC' NOT NULL, "last_sent_at" timestamp, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "notification_preferences" ( "id" text PRIMARY KEY NOT NULL, "user_id" text NOT NULL, "event_type" text NOT NULL, "email_enabled" boolean DEFAULT true, "slack_enabled" boolean DEFAULT false, "in_app_enabled" boolean DEFAULT true, "browser_push_enabled" boolean DEFAULT false, "repository_id" text, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "notification_quiet_hours" ( "id" text PRIMARY KEY NOT NULL, "user_id" text NOT NULL, "is_enabled" boolean DEFAULT false, "start_time" text DEFAULT '22:00' NOT NULL, "end_time" text DEFAULT '08:00' NOT NULL, "timezone" text DEFAULT 'UTC' NOT NULL, "days_of_week" text DEFAULT '0,1,2,3,4,5,6', "allow_urgent" boolean DEFAULT true, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "push_subscriptions" ( "id" text PRIMARY KEY NOT NULL, "user_id" text NOT NULL, "endpoint" text NOT NULL, "p256dh_key" text NOT NULL, "auth_key" text NOT NULL, "user_agent" text, "is_active" boolean DEFAULT true, "last_used_at" timestamp, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "sso_configs" ( "id" text PRIMARY KEY NOT NULL, "name" text NOT NULL, "type" text DEFAULT 'oidc' NOT NULL, "issuer" text NOT NULL, "client_id" text NOT NULL, "client_secret" text NOT NULL, "scopes" text DEFAULT 'openid,profile,email', "authorization_url" text, "token_url" text, "userinfo_url" text, "jwks_uri" text, "enabled" boolean DEFAULT false, "auto_create_users" boolean DEFAULT true, "allowed_domains" text, "default_role" text DEFAULT 'member', "organization_id" text, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL, "created_by_id" text ); --> statement-breakpoint CREATE TABLE "repository_path_permissions" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "path_pattern" text NOT NULL, "user_id" text, "team_id" text, "permission" text DEFAULT 'write' NOT NULL, "require_approval" text DEFAULT 'false', "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "pr_state_definitions" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "name" text NOT NULL, "display_name" text NOT NULL, "description" text, "color" text DEFAULT '#6B7280' NOT NULL, "icon" text, "order" integer DEFAULT 0 NOT NULL, "is_default" boolean DEFAULT false, "is_final" boolean DEFAULT false, "allow_merge" boolean DEFAULT false, "require_code_owner" boolean DEFAULT false, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "pr_state_reviewers" ( "id" text PRIMARY KEY NOT NULL, "state_definition_id" text NOT NULL, "user_id" text, "team_id" text, "required_count" integer DEFAULT 1, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "pr_state_transitions" ( "id" text PRIMARY KEY NOT NULL, "pull_request_id" text NOT NULL, "from_state" text, "to_state" text NOT NULL, "changed_by_id" text NOT NULL, "reason" text, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "issue_statuses" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "name" text NOT NULL, "color" text DEFAULT '#808080' NOT NULL, "order" integer DEFAULT 0 NOT NULL, "type" text DEFAULT 'open' NOT NULL, "is_default" integer DEFAULT 0, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "custom_field_definitions" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "name" text NOT NULL, "description" text, "type" text NOT NULL, "options" json, "required" boolean DEFAULT false, "order" integer DEFAULT 0, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "issue_custom_field_values" ( "id" text PRIMARY KEY NOT NULL, "issue_id" text NOT NULL, "field_id" text NOT NULL, "value" text, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "auto_merge_rules" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "name" text NOT NULL, "description" text, "match_labels" text, "required_labels" text, "required_checks" text, "min_approvals" integer DEFAULT 0, "require_code_owner" boolean DEFAULT false, "allow_draft" boolean DEFAULT false, "min_time_in_queue_minutes" integer DEFAULT 0, "merge_method" text, "is_enabled" boolean DEFAULT true, "match_count" integer DEFAULT 0, "last_matched_at" timestamp, "last_mismatch_reason" text, "created_by_id" text, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "external_ci_integrations" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "token_hash" text NOT NULL, "name" text, "created_by_id" text, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL, "last_used_at" timestamp ); --> statement-breakpoint CREATE TABLE "review_requirements" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "min_approvals" integer DEFAULT 1, "require_code_owner" boolean DEFAULT false, "require_team_lead" boolean DEFAULT false, "dismiss_stale_reviews" boolean DEFAULT false, "require_rereview_on_push" boolean DEFAULT false, "created_by_id" text, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "reviewer_rules" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "name" text NOT NULL, "rule_type" text NOT NULL, "target_id" text, "count" integer, "path_pattern" text, "is_required" boolean DEFAULT true, "is_enabled" boolean DEFAULT true, "created_by_id" text, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "api_change_detections" ( "id" text PRIMARY KEY NOT NULL, "pull_request_id" text NOT NULL, "change_type" text NOT NULL, "path" text NOT NULL, "method" text, "breaking" boolean DEFAULT false, "details" text NOT NULL, "affected_files" jsonb, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "breaking_changes" ( "id" text PRIMARY KEY NOT NULL, "pull_request_id" text NOT NULL, "change_type" text NOT NULL, "severity" text NOT NULL, "description" text NOT NULL, "affected_files" jsonb, "suggested_action" text, "acknowledged" boolean DEFAULT false, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "change_set_items" ( "id" text PRIMARY KEY NOT NULL, "change_set_id" text NOT NULL, "pull_request_id" text, "repository_id" text NOT NULL, "order" integer DEFAULT 0, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "change_sets" ( "id" text PRIMARY KEY NOT NULL, "name" text NOT NULL, "description" text, "created_by_id" text NOT NULL, "status" text DEFAULT 'draft' NOT NULL, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "chat_integrations" ( "id" text PRIMARY KEY NOT NULL, "organization_id" text, "repository_id" text, "provider" text NOT NULL, "name" text NOT NULL, "webhook_url" text, "api_token" text, "channel_id" text, "is_enabled" boolean DEFAULT true, "events" jsonb DEFAULT '[]'::jsonb, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "cloud_configs" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text, "organization_id" text, "provider" text NOT NULL, "name" text NOT NULL, "region" text, "credentials" jsonb, "settings" jsonb, "is_enabled" boolean DEFAULT true, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "code_quality_configs" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "provider" text NOT NULL, "project_key" text, "api_token" text, "server_url" text, "webhook_secret" text, "is_enabled" boolean DEFAULT true, "report_on_pr" boolean DEFAULT true, "block_on_fail" boolean DEFAULT false, "min_coverage" real, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "code_quality_issues" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "pull_request_id" text, "commit_sha" text NOT NULL, "provider" text NOT NULL, "issue_type" text NOT NULL, "severity" text NOT NULL, "message" text NOT NULL, "file" text, "line" integer, "rule" text, "effort" text, "status" text DEFAULT 'open', "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "coverage_reports" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "pull_request_id" text, "commit_sha" text NOT NULL, "provider" text NOT NULL, "coverage" real NOT NULL, "lines_covered" integer, "lines_total" integer, "branch_coverage" real, "delta" real, "status" text NOT NULL, "report_url" text, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "cross_repo_issue_links" ( "id" text PRIMARY KEY NOT NULL, "source_issue_id" text NOT NULL, "target_issue_id" text NOT NULL, "link_type" text NOT NULL, "created_by_id" text NOT NULL, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "custom_dashboards" ( "id" text PRIMARY KEY NOT NULL, "user_id" text NOT NULL, "name" text NOT NULL, "description" text, "is_public" boolean DEFAULT false, "layout" jsonb, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "dashboard_widgets" ( "id" text PRIMARY KEY NOT NULL, "dashboard_id" text NOT NULL, "widget_type" text NOT NULL, "title" text NOT NULL, "config" jsonb, "position" jsonb, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "cloud_deployments" ( "id" text PRIMARY KEY NOT NULL, "config_id" text NOT NULL, "pull_request_id" text, "commit_sha" text NOT NULL, "environment" text NOT NULL, "status" text NOT NULL, "url" text, "logs" text, "started_at" timestamp, "completed_at" timestamp, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "email_settings" ( "id" text PRIMARY KEY NOT NULL, "organization_id" text, "smtp_host" text, "smtp_port" text, "smtp_user" text, "smtp_pass" text, "from_address" text, "from_name" text, "is_enabled" boolean DEFAULT true, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "external_builds" ( "id" text PRIMARY KEY NOT NULL, "config_id" text NOT NULL, "pull_request_id" text, "external_build_id" text NOT NULL, "build_number" text, "status" text NOT NULL, "url" text, "started_at" timestamp, "completed_at" timestamp, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "external_ci_configs" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "provider" text NOT NULL, "name" text NOT NULL, "base_url" text NOT NULL, "api_token" text, "project_id" text, "webhook_secret" text, "is_enabled" boolean DEFAULT true, "sync_status" boolean DEFAULT true, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "file_approvals" ( "id" text PRIMARY KEY NOT NULL, "pull_request_id" text NOT NULL, "path" text NOT NULL, "approved_by_id" text NOT NULL, "approved_at" timestamp DEFAULT now() NOT NULL, "commit_sha" text NOT NULL, "comment" text, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "file_hotspots" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "file_path" text NOT NULL, "change_count" integer DEFAULT 0, "bug_count" integer DEFAULT 0, "review_count" integer DEFAULT 0, "complexity_score" real, "last_modified" timestamp, "calculated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "ip_allow_lists" ( "id" text PRIMARY KEY NOT NULL, "organization_id" text NOT NULL, "name" text NOT NULL, "cidr_block" text NOT NULL, "description" text, "is_enabled" boolean DEFAULT true, "created_at" timestamp DEFAULT now() NOT NULL, "created_by_id" text NOT NULL ); --> statement-breakpoint CREATE TABLE "issue_tracker_configs" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "provider" text NOT NULL, "name" text NOT NULL, "api_url" text, "api_token" text, "project_key" text, "webhook_secret" text, "is_enabled" boolean DEFAULT true, "sync_to_external" boolean DEFAULT true, "sync_from_external" boolean DEFAULT true, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "issue_tracker_links" ( "id" text PRIMARY KEY NOT NULL, "config_id" text NOT NULL, "local_issue_id" text, "external_id" text NOT NULL, "external_key" text, "external_url" text, "last_sync_at" timestamp, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "license_scans" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "commit_sha" text NOT NULL, "package_name" text NOT NULL, "package_version" text, "license" text NOT NULL, "license_type" text NOT NULL, "is_compliant" boolean NOT NULL, "policy_violation" text, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "merge_gates" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "name" text NOT NULL, "description" text, "gate_type" text NOT NULL, "config" text, "condition_script" text, "is_enabled" boolean DEFAULT true, "order" integer DEFAULT 0, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "metric_snapshots" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text, "organization_id" text, "metric_type" text NOT NULL, "value" real NOT NULL, "dimensions" jsonb, "timestamp" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "migration_detections" ( "id" text PRIMARY KEY NOT NULL, "pull_request_id" text NOT NULL, "migration_type" text NOT NULL, "tool" text, "files" jsonb, "is_reversible" boolean, "requires_downtime" boolean, "notes" text, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "pr_issue_links" ( "id" text PRIMARY KEY NOT NULL, "pull_request_id" text NOT NULL, "issue_id" text NOT NULL, "link_type" text NOT NULL, "created_by_id" text NOT NULL, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "rate_limit_logs" ( "id" text PRIMARY KEY NOT NULL, "rule_id" text NOT NULL, "key" text NOT NULL, "request_count" integer NOT NULL, "window_start" timestamp NOT NULL, "blocked" boolean DEFAULT false ); --> statement-breakpoint CREATE TABLE "rate_limit_rules" ( "id" text PRIMARY KEY NOT NULL, "name" text NOT NULL, "path" text NOT NULL, "method" text, "window_ms" integer NOT NULL, "max_requests" integer NOT NULL, "key_type" text DEFAULT 'ip', "is_enabled" boolean DEFAULT true, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "repository_workflows" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "name" text NOT NULL, "path" text NOT NULL, "content" text NOT NULL, "template_id" text, "is_enabled" boolean DEFAULT true, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "required_status_checks" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "branch" text NOT NULL, "check_name" text NOT NULL, "is_required" boolean DEFAULT true, "strict_mode" boolean DEFAULT true, "path_filter" text, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "review_templates" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "organization_id" text, "name" text NOT NULL, "description" text, "category" text, "content" text NOT NULL, "is_default" boolean DEFAULT false NOT NULL, "created_by_id" text NOT NULL, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "saml_configs" ( "id" text PRIMARY KEY NOT NULL, "organization_id" text NOT NULL, "entity_id" text NOT NULL, "sso_url" text NOT NULL, "certificate" text NOT NULL, "signature_algorithm" text DEFAULT 'RSA-SHA256', "digest_algorithm" text DEFAULT 'SHA256', "is_enabled" boolean DEFAULT true, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "secret_scan_results" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "commit_sha" text NOT NULL, "secret_type" text NOT NULL, "file" text NOT NULL, "line" integer, "snippet" text, "severity" text NOT NULL, "status" text DEFAULT 'open', "resolved_at" timestamp, "resolved_by_id" text, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "workflow_states" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "name" text NOT NULL, "category" text NOT NULL, "color" text DEFAULT '#6b7280', "icon" text, "display_order" integer DEFAULT 0, "is_default" boolean DEFAULT false, "is_closed_state" boolean DEFAULT false, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "workflow_templates" ( "id" text PRIMARY KEY NOT NULL, "name" text NOT NULL, "description" text, "category" text NOT NULL, "language" text, "content" text NOT NULL, "is_official" boolean DEFAULT false, "is_public" boolean DEFAULT true, "created_by_id" text, "downloads" text DEFAULT '0', "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "workflow_transitions" ( "id" text PRIMARY KEY NOT NULL, "repository_id" text NOT NULL, "from_state_id" text, "to_state_id" text NOT NULL, "requires_comment" boolean DEFAULT false, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "package_versions" ( "id" text PRIMARY KEY NOT NULL, "package_id" text NOT NULL, "version" text NOT NULL, "digest" text, "size_bytes" integer, "storage_path" text NOT NULL, "metadata" jsonb, "tags" jsonb DEFAULT '[]'::jsonb, "git_ref" text, "published_by_id" text, "download_count" integer DEFAULT 0 NOT NULL, "yanked" boolean DEFAULT false, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "packages" ( "id" text PRIMARY KEY NOT NULL, "organization_id" text, "repository_id" text, "type" text NOT NULL, "name" text NOT NULL, "description" text, "visibility" text DEFAULT 'private' NOT NULL, "download_count" integer DEFAULT 0 NOT NULL, "created_by_id" text, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "ai_inline_comments" ( "id" text PRIMARY KEY NOT NULL, "analysis_id" text NOT NULL, "pull_request_id" text NOT NULL, "file_path" text NOT NULL, "line" integer NOT NULL, "end_line" integer, "side" text DEFAULT 'right', "severity" text NOT NULL, "type" text NOT NULL, "category" text, "title" text NOT NULL, "message" text NOT NULL, "suggested_fix" text, "explanation" text, "confidence" integer, "is_resolved" integer DEFAULT 0, "is_applied" integer DEFAULT 0, "applied_at" timestamp, "dismissed_at" timestamp, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "ai_review_threads" ( "id" text PRIMARY KEY NOT NULL, "analysis_id" text NOT NULL, "pull_request_id" text NOT NULL, "file_path" text, "line" integer, "messages" jsonb NOT NULL, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "file_summaries" ( "id" text PRIMARY KEY NOT NULL, "analysis_id" text NOT NULL, "file_path" text NOT NULL, "language" text, "summary" text, "risk_level" text, "additions" integer, "deletions" integer, "complexity_score" integer, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "pr_review_analyses" ( "id" text PRIMARY KEY NOT NULL, "pull_request_id" text NOT NULL, "repository_id" text NOT NULL, "status" text DEFAULT 'pending' NOT NULL, "complexity_data" jsonb, "dependency_graph" jsonb, "architecture_impact" jsonb, "change_groups" jsonb, "blast_radius" jsonb, "health_score" integer, "health_grade" text, "summaries" jsonb, "base_sha" text, "head_sha" text, "files_analyzed" integer, "chunks_processed" integer, "total_additions" integer, "total_deletions" integer, "model" text, "provider" text, "tokens_used" integer, "cost_cents" integer, "raw_ai_response" jsonb, "triggered_by_id" text, "created_at" timestamp DEFAULT now() NOT NULL, "started_at" timestamp, "completed_at" timestamp, "error_message" text ); --> statement-breakpoint ALTER TABLE "email_verification_tokens" ADD CONSTRAINT "email_verification_tokens_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "gpg_keys" ADD CONSTRAINT "gpg_keys_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "oauth_accounts" ADD CONSTRAINT "oauth_accounts_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "password_reset_tokens" ADD CONSTRAINT "password_reset_tokens_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "personal_access_tokens" ADD CONSTRAINT "personal_access_tokens_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "sessions" ADD CONSTRAINT "sessions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "ssh_keys" ADD CONSTRAINT "ssh_keys_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "user_followers" ADD CONSTRAINT "user_followers_follower_id_users_id_fk" FOREIGN KEY ("follower_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "user_followers" ADD CONSTRAINT "user_followers_followee_id_users_id_fk" FOREIGN KEY ("followee_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "deploy_keys" ADD CONSTRAINT "deploy_keys_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "branches" ADD CONSTRAINT "branches_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "commits" ADD CONSTRAINT "commits_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "commits" ADD CONSTRAINT "commits_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "releases" ADD CONSTRAINT "releases_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "releases" ADD CONSTRAINT "releases_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 "releases" ADD CONSTRAINT "releases_author_id_users_id_fk" FOREIGN KEY ("author_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "repositories" ADD CONSTRAINT "repositories_owner_id_users_id_fk" FOREIGN KEY ("owner_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "repositories" ADD CONSTRAINT "repositories_forked_from_id_repositories_id_fk" FOREIGN KEY ("forked_from_id") REFERENCES "public"."repositories"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "repository_collaborators" ADD CONSTRAINT "repository_collaborators_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "repository_collaborators" ADD CONSTRAINT "repository_collaborators_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "repository_collaborators" ADD CONSTRAINT "repository_collaborators_added_by_id_users_id_fk" FOREIGN KEY ("added_by_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "repository_stars" ADD CONSTRAINT "repository_stars_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "repository_stars" ADD CONSTRAINT "repository_stars_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "repository_watchers" ADD CONSTRAINT "repository_watchers_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "repository_watchers" ADD CONSTRAINT "repository_watchers_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "tags" ADD CONSTRAINT "tags_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "issue_assignees" ADD CONSTRAINT "issue_assignees_issue_id_issues_id_fk" FOREIGN KEY ("issue_id") REFERENCES "public"."issues"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "issue_assignees" ADD CONSTRAINT "issue_assignees_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "issue_comments" ADD CONSTRAINT "issue_comments_issue_id_issues_id_fk" FOREIGN KEY ("issue_id") REFERENCES "public"."issues"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "issue_comments" ADD CONSTRAINT "issue_comments_author_id_users_id_fk" FOREIGN KEY ("author_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "issue_labels" ADD CONSTRAINT "issue_labels_issue_id_issues_id_fk" FOREIGN KEY ("issue_id") REFERENCES "public"."issues"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "issue_labels" ADD CONSTRAINT "issue_labels_label_id_labels_id_fk" FOREIGN KEY ("label_id") REFERENCES "public"."labels"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "issue_subscribers" ADD CONSTRAINT "issue_subscribers_issue_id_issues_id_fk" FOREIGN KEY ("issue_id") REFERENCES "public"."issues"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "issue_subscribers" ADD CONSTRAINT "issue_subscribers_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "issues" ADD CONSTRAINT "issues_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "issues" ADD CONSTRAINT "issues_status_id_issue_statuses_id_fk" FOREIGN KEY ("status_id") REFERENCES "public"."issue_statuses"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "issues" ADD CONSTRAINT "issues_author_id_users_id_fk" FOREIGN KEY ("author_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "issues" ADD CONSTRAINT "issues_assignee_id_users_id_fk" FOREIGN KEY ("assignee_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "issues" ADD CONSTRAINT "issues_closed_by_id_users_id_fk" FOREIGN KEY ("closed_by_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "labels" ADD CONSTRAINT "labels_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "milestones" ADD CONSTRAINT "milestones_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pull_request_assignees" ADD CONSTRAINT "pull_request_assignees_pull_request_id_pull_requests_id_fk" FOREIGN KEY ("pull_request_id") REFERENCES "public"."pull_requests"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pull_request_assignees" ADD CONSTRAINT "pull_request_assignees_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pull_request_checks" ADD CONSTRAINT "pull_request_checks_pull_request_id_pull_requests_id_fk" FOREIGN KEY ("pull_request_id") REFERENCES "public"."pull_requests"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pull_request_comments" ADD CONSTRAINT "pull_request_comments_pull_request_id_pull_requests_id_fk" FOREIGN KEY ("pull_request_id") REFERENCES "public"."pull_requests"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pull_request_comments" ADD CONSTRAINT "pull_request_comments_review_id_pull_request_reviews_id_fk" FOREIGN KEY ("review_id") REFERENCES "public"."pull_request_reviews"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pull_request_comments" ADD CONSTRAINT "pull_request_comments_author_id_users_id_fk" FOREIGN KEY ("author_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pull_request_comments" ADD CONSTRAINT "pull_request_comments_in_reply_to_id_pull_request_comments_id_fk" FOREIGN KEY ("in_reply_to_id") REFERENCES "public"."pull_request_comments"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pull_request_comments" ADD CONSTRAINT "pull_request_comments_resolved_by_id_users_id_fk" FOREIGN KEY ("resolved_by_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pull_request_comments" ADD CONSTRAINT "pull_request_comments_suggestion_applied_by_id_users_id_fk" FOREIGN KEY ("suggestion_applied_by_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pull_request_labels" ADD CONSTRAINT "pull_request_labels_pull_request_id_pull_requests_id_fk" FOREIGN KEY ("pull_request_id") REFERENCES "public"."pull_requests"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pull_request_labels" ADD CONSTRAINT "pull_request_labels_label_id_labels_id_fk" FOREIGN KEY ("label_id") REFERENCES "public"."labels"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pull_request_reviewers" ADD CONSTRAINT "pull_request_reviewers_pull_request_id_pull_requests_id_fk" FOREIGN KEY ("pull_request_id") REFERENCES "public"."pull_requests"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pull_request_reviewers" ADD CONSTRAINT "pull_request_reviewers_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pull_request_reviews" ADD CONSTRAINT "pull_request_reviews_pull_request_id_pull_requests_id_fk" FOREIGN KEY ("pull_request_id") REFERENCES "public"."pull_requests"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pull_request_reviews" ADD CONSTRAINT "pull_request_reviews_reviewer_id_users_id_fk" FOREIGN KEY ("reviewer_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pull_request_reviews" ADD CONSTRAINT "pull_request_reviews_dismissed_by_id_users_id_fk" FOREIGN KEY ("dismissed_by_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pull_requests" ADD CONSTRAINT "pull_requests_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pull_requests" ADD CONSTRAINT "pull_requests_author_id_users_id_fk" FOREIGN KEY ("author_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pull_requests" ADD CONSTRAINT "pull_requests_assignee_id_users_id_fk" FOREIGN KEY ("assignee_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pull_requests" ADD CONSTRAINT "pull_requests_head_repository_id_repositories_id_fk" FOREIGN KEY ("head_repository_id") REFERENCES "public"."repositories"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pull_requests" ADD CONSTRAINT "pull_requests_merged_by_id_users_id_fk" FOREIGN KEY ("merged_by_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pull_requests" ADD CONSTRAINT "pull_requests_auto_merge_enabled_by_id_users_id_fk" FOREIGN KEY ("auto_merge_enabled_by_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pull_requests" ADD CONSTRAINT "pull_requests_state_id_pr_state_definitions_id_fk" FOREIGN KEY ("state_id") REFERENCES "public"."pr_state_definitions"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pull_requests" ADD CONSTRAINT "pull_requests_closed_by_id_users_id_fk" FOREIGN KEY ("closed_by_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "project_cards" ADD CONSTRAINT "project_cards_column_id_project_columns_id_fk" FOREIGN KEY ("column_id") REFERENCES "public"."project_columns"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "project_cards" ADD CONSTRAINT "project_cards_creator_id_users_id_fk" FOREIGN KEY ("creator_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "project_columns" ADD CONSTRAINT "project_columns_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "projects" ADD CONSTRAINT "projects_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "projects" ADD CONSTRAINT "projects_creator_id_users_id_fk" FOREIGN KEY ("creator_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> 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;--> statement-breakpoint ALTER TABLE "wiki_pages" ADD CONSTRAINT "wiki_pages_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "wiki_pages" ADD CONSTRAINT "wiki_pages_parent_id_wiki_pages_id_fk" FOREIGN KEY ("parent_id") REFERENCES "public"."wiki_pages"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "wiki_pages" ADD CONSTRAINT "wiki_pages_last_editor_id_users_id_fk" FOREIGN KEY ("last_editor_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "wiki_revisions" ADD CONSTRAINT "wiki_revisions_page_id_wiki_pages_id_fk" FOREIGN KEY ("page_id") REFERENCES "public"."wiki_pages"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "wiki_revisions" ADD CONSTRAINT "wiki_revisions_author_id_users_id_fk" FOREIGN KEY ("author_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "organization_members" ADD CONSTRAINT "organization_members_organization_id_organizations_id_fk" FOREIGN KEY ("organization_id") REFERENCES "public"."organizations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "organization_members" ADD CONSTRAINT "organization_members_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "custom_roles" ADD CONSTRAINT "custom_roles_organization_id_organizations_id_fk" FOREIGN KEY ("organization_id") REFERENCES "public"."organizations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "team_members" ADD CONSTRAINT "team_members_team_id_teams_id_fk" FOREIGN KEY ("team_id") REFERENCES "public"."teams"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "team_members" ADD CONSTRAINT "team_members_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "team_repositories" ADD CONSTRAINT "team_repositories_team_id_teams_id_fk" FOREIGN KEY ("team_id") REFERENCES "public"."teams"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "team_repositories" ADD CONSTRAINT "team_repositories_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "teams" ADD CONSTRAINT "teams_organization_id_organizations_id_fk" FOREIGN KEY ("organization_id") REFERENCES "public"."organizations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "activities" ADD CONSTRAINT "activities_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "activities" ADD CONSTRAINT "activities_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "audit_logs" ADD CONSTRAINT "audit_logs_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "audit_logs" ADD CONSTRAINT "audit_logs_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "notifications" ADD CONSTRAINT "notifications_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "notifications" ADD CONSTRAINT "notifications_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "notifications" ADD CONSTRAINT "notifications_actor_id_users_id_fk" FOREIGN KEY ("actor_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "security_scans" ADD CONSTRAINT "security_scans_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "security_vulnerabilities" ADD CONSTRAINT "security_vulnerabilities_scan_id_security_scans_id_fk" FOREIGN KEY ("scan_id") REFERENCES "public"."security_scans"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "security_policies" ADD CONSTRAINT "security_policies_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "security_policies" ADD CONSTRAINT "security_policies_updated_by_id_users_id_fk" FOREIGN KEY ("updated_by_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pipeline_runners" ADD CONSTRAINT "pipeline_runners_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pr_stack_entries" ADD CONSTRAINT "pr_stack_entries_stack_id_pr_stacks_id_fk" FOREIGN KEY ("stack_id") REFERENCES "public"."pr_stacks"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pr_stack_entries" ADD CONSTRAINT "pr_stack_entries_pull_request_id_pull_requests_id_fk" FOREIGN KEY ("pull_request_id") REFERENCES "public"."pull_requests"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pr_stack_entries" ADD CONSTRAINT "pr_stack_entries_parent_pr_id_pull_requests_id_fk" FOREIGN KEY ("parent_pr_id") REFERENCES "public"."pull_requests"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pr_stacks" ADD CONSTRAINT "pr_stacks_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pr_stacks" ADD CONSTRAINT "pr_stacks_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 "merge_queue" ADD CONSTRAINT "merge_queue_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "merge_queue" ADD CONSTRAINT "merge_queue_pull_request_id_pull_requests_id_fk" FOREIGN KEY ("pull_request_id") REFERENCES "public"."pull_requests"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "merge_queue" ADD CONSTRAINT "merge_queue_added_by_id_users_id_fk" FOREIGN KEY ("added_by_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "merge_queue_speculative_runs" ADD CONSTRAINT "merge_queue_speculative_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 "ai_review_suggestions" ADD CONSTRAINT "ai_review_suggestions_ai_review_id_ai_reviews_id_fk" FOREIGN KEY ("ai_review_id") REFERENCES "public"."ai_reviews"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "ai_review_suggestions" ADD CONSTRAINT "ai_review_suggestions_applied_by_id_users_id_fk" FOREIGN KEY ("applied_by_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "ai_review_suggestions" ADD CONSTRAINT "ai_review_suggestions_dismissed_by_id_users_id_fk" FOREIGN KEY ("dismissed_by_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "ai_reviews" ADD CONSTRAINT "ai_reviews_pull_request_id_pull_requests_id_fk" FOREIGN KEY ("pull_request_id") REFERENCES "public"."pull_requests"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "ai_reviews" ADD CONSTRAINT "ai_reviews_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 "pr_metrics" ADD CONSTRAINT "pr_metrics_pull_request_id_pull_requests_id_fk" FOREIGN KEY ("pull_request_id") REFERENCES "public"."pull_requests"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pr_metrics" ADD CONSTRAINT "pr_metrics_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pr_metrics" ADD CONSTRAINT "pr_metrics_author_id_users_id_fk" FOREIGN KEY ("author_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "repo_metrics" ADD CONSTRAINT "repo_metrics_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "review_metrics" ADD CONSTRAINT "review_metrics_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "review_metrics" ADD CONSTRAINT "review_metrics_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "slack_channel_mappings" ADD CONSTRAINT "slack_channel_mappings_workspace_id_slack_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."slack_workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "slack_channel_mappings" ADD CONSTRAINT "slack_channel_mappings_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "slack_user_mappings" ADD CONSTRAINT "slack_user_mappings_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "slack_user_mappings" ADD CONSTRAINT "slack_user_mappings_workspace_id_slack_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."slack_workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "slack_workspaces" ADD CONSTRAINT "slack_workspaces_installed_by_id_users_id_fk" FOREIGN KEY ("installed_by_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "webhook_deliveries" ADD CONSTRAINT "webhook_deliveries_webhook_id_webhooks_id_fk" FOREIGN KEY ("webhook_id") REFERENCES "public"."webhooks"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "webhooks" ADD CONSTRAINT "webhooks_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "webhooks" ADD CONSTRAINT "webhooks_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 "branch_protection" ADD CONSTRAINT "branch_protection_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "branch_protection" ADD CONSTRAINT "branch_protection_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 "system_config" ADD CONSTRAINT "system_config_updated_by_id_users_id_fk" FOREIGN KEY ("updated_by_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "inbox_sections" ADD CONSTRAINT "inbox_sections_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "shared_inbox_sections" ADD CONSTRAINT "shared_inbox_sections_section_id_inbox_sections_id_fk" FOREIGN KEY ("section_id") REFERENCES "public"."inbox_sections"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "shared_inbox_sections" ADD CONSTRAINT "shared_inbox_sections_shared_with_user_id_users_id_fk" FOREIGN KEY ("shared_with_user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "automation_executions" ADD CONSTRAINT "automation_executions_rule_id_automation_rules_id_fk" FOREIGN KEY ("rule_id") REFERENCES "public"."automation_rules"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "automation_rules" ADD CONSTRAINT "automation_rules_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "automation_rules" ADD CONSTRAINT "automation_rules_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 "ai_codebase_context" ADD CONSTRAINT "ai_codebase_context_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "ai_review_rules" ADD CONSTRAINT "ai_review_rules_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "ai_review_rules" ADD CONSTRAINT "ai_review_rules_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 "email_digest_settings" ADD CONSTRAINT "email_digest_settings_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "notification_preferences" ADD CONSTRAINT "notification_preferences_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "notification_preferences" ADD CONSTRAINT "notification_preferences_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "notification_quiet_hours" ADD CONSTRAINT "notification_quiet_hours_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "push_subscriptions" ADD CONSTRAINT "push_subscriptions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "sso_configs" ADD CONSTRAINT "sso_configs_organization_id_organizations_id_fk" FOREIGN KEY ("organization_id") REFERENCES "public"."organizations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "repository_path_permissions" ADD CONSTRAINT "repository_path_permissions_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "repository_path_permissions" ADD CONSTRAINT "repository_path_permissions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "repository_path_permissions" ADD CONSTRAINT "repository_path_permissions_team_id_teams_id_fk" FOREIGN KEY ("team_id") REFERENCES "public"."teams"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pr_state_definitions" ADD CONSTRAINT "pr_state_definitions_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pr_state_reviewers" ADD CONSTRAINT "pr_state_reviewers_state_definition_id_pr_state_definitions_id_fk" FOREIGN KEY ("state_definition_id") REFERENCES "public"."pr_state_definitions"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pr_state_reviewers" ADD CONSTRAINT "pr_state_reviewers_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pr_state_reviewers" ADD CONSTRAINT "pr_state_reviewers_team_id_teams_id_fk" FOREIGN KEY ("team_id") REFERENCES "public"."teams"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pr_state_transitions" ADD CONSTRAINT "pr_state_transitions_changed_by_id_users_id_fk" FOREIGN KEY ("changed_by_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "issue_statuses" ADD CONSTRAINT "issue_statuses_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "custom_field_definitions" ADD CONSTRAINT "custom_field_definitions_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "issue_custom_field_values" ADD CONSTRAINT "issue_custom_field_values_issue_id_issues_id_fk" FOREIGN KEY ("issue_id") REFERENCES "public"."issues"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "issue_custom_field_values" ADD CONSTRAINT "issue_custom_field_values_field_id_custom_field_definitions_id_fk" FOREIGN KEY ("field_id") REFERENCES "public"."custom_field_definitions"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "auto_merge_rules" ADD CONSTRAINT "auto_merge_rules_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "auto_merge_rules" ADD CONSTRAINT "auto_merge_rules_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 "external_ci_integrations" ADD CONSTRAINT "external_ci_integrations_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "external_ci_integrations" ADD CONSTRAINT "external_ci_integrations_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 "review_requirements" ADD CONSTRAINT "review_requirements_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "review_requirements" ADD CONSTRAINT "review_requirements_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 "reviewer_rules" ADD CONSTRAINT "reviewer_rules_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "reviewer_rules" ADD CONSTRAINT "reviewer_rules_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 "api_change_detections" ADD CONSTRAINT "api_change_detections_pull_request_id_pull_requests_id_fk" FOREIGN KEY ("pull_request_id") REFERENCES "public"."pull_requests"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "breaking_changes" ADD CONSTRAINT "breaking_changes_pull_request_id_pull_requests_id_fk" FOREIGN KEY ("pull_request_id") REFERENCES "public"."pull_requests"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "change_set_items" ADD CONSTRAINT "change_set_items_change_set_id_change_sets_id_fk" FOREIGN KEY ("change_set_id") REFERENCES "public"."change_sets"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "change_set_items" ADD CONSTRAINT "change_set_items_pull_request_id_pull_requests_id_fk" FOREIGN KEY ("pull_request_id") REFERENCES "public"."pull_requests"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint ALTER TABLE "change_set_items" ADD CONSTRAINT "change_set_items_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "change_sets" ADD CONSTRAINT "change_sets_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 "cloud_configs" ADD CONSTRAINT "cloud_configs_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "code_quality_configs" ADD CONSTRAINT "code_quality_configs_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "code_quality_issues" ADD CONSTRAINT "code_quality_issues_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "coverage_reports" ADD CONSTRAINT "coverage_reports_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "cross_repo_issue_links" ADD CONSTRAINT "cross_repo_issue_links_source_issue_id_issues_id_fk" FOREIGN KEY ("source_issue_id") REFERENCES "public"."issues"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "cross_repo_issue_links" ADD CONSTRAINT "cross_repo_issue_links_target_issue_id_issues_id_fk" FOREIGN KEY ("target_issue_id") REFERENCES "public"."issues"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "custom_dashboards" ADD CONSTRAINT "custom_dashboards_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "dashboard_widgets" ADD CONSTRAINT "dashboard_widgets_dashboard_id_custom_dashboards_id_fk" FOREIGN KEY ("dashboard_id") REFERENCES "public"."custom_dashboards"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "cloud_deployments" ADD CONSTRAINT "cloud_deployments_config_id_cloud_configs_id_fk" FOREIGN KEY ("config_id") REFERENCES "public"."cloud_configs"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "external_builds" ADD CONSTRAINT "external_builds_config_id_external_ci_configs_id_fk" FOREIGN KEY ("config_id") REFERENCES "public"."external_ci_configs"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "external_ci_configs" ADD CONSTRAINT "external_ci_configs_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "file_approvals" ADD CONSTRAINT "file_approvals_pull_request_id_pull_requests_id_fk" FOREIGN KEY ("pull_request_id") REFERENCES "public"."pull_requests"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "file_approvals" ADD CONSTRAINT "file_approvals_approved_by_id_users_id_fk" FOREIGN KEY ("approved_by_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "file_hotspots" ADD CONSTRAINT "file_hotspots_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "issue_tracker_configs" ADD CONSTRAINT "issue_tracker_configs_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "issue_tracker_links" ADD CONSTRAINT "issue_tracker_links_config_id_issue_tracker_configs_id_fk" FOREIGN KEY ("config_id") REFERENCES "public"."issue_tracker_configs"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "issue_tracker_links" ADD CONSTRAINT "issue_tracker_links_local_issue_id_issues_id_fk" FOREIGN KEY ("local_issue_id") REFERENCES "public"."issues"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "license_scans" ADD CONSTRAINT "license_scans_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "merge_gates" ADD CONSTRAINT "merge_gates_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "metric_snapshots" ADD CONSTRAINT "metric_snapshots_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "migration_detections" ADD CONSTRAINT "migration_detections_pull_request_id_pull_requests_id_fk" FOREIGN KEY ("pull_request_id") REFERENCES "public"."pull_requests"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pr_issue_links" ADD CONSTRAINT "pr_issue_links_pull_request_id_pull_requests_id_fk" FOREIGN KEY ("pull_request_id") REFERENCES "public"."pull_requests"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pr_issue_links" ADD CONSTRAINT "pr_issue_links_issue_id_issues_id_fk" FOREIGN KEY ("issue_id") REFERENCES "public"."issues"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "rate_limit_logs" ADD CONSTRAINT "rate_limit_logs_rule_id_rate_limit_rules_id_fk" FOREIGN KEY ("rule_id") REFERENCES "public"."rate_limit_rules"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "repository_workflows" ADD CONSTRAINT "repository_workflows_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "repository_workflows" ADD CONSTRAINT "repository_workflows_template_id_workflow_templates_id_fk" FOREIGN KEY ("template_id") REFERENCES "public"."workflow_templates"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "required_status_checks" ADD CONSTRAINT "required_status_checks_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "review_templates" ADD CONSTRAINT "review_templates_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "secret_scan_results" ADD CONSTRAINT "secret_scan_results_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_states" ADD CONSTRAINT "workflow_states_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_transitions" ADD CONSTRAINT "workflow_transitions_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_transitions" ADD CONSTRAINT "workflow_transitions_from_state_id_workflow_states_id_fk" FOREIGN KEY ("from_state_id") REFERENCES "public"."workflow_states"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "workflow_transitions" ADD CONSTRAINT "workflow_transitions_to_state_id_workflow_states_id_fk" FOREIGN KEY ("to_state_id") REFERENCES "public"."workflow_states"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "package_versions" ADD CONSTRAINT "package_versions_package_id_packages_id_fk" FOREIGN KEY ("package_id") REFERENCES "public"."packages"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "package_versions" ADD CONSTRAINT "package_versions_published_by_id_users_id_fk" FOREIGN KEY ("published_by_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "packages" ADD CONSTRAINT "packages_organization_id_organizations_id_fk" FOREIGN KEY ("organization_id") REFERENCES "public"."organizations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "packages" ADD CONSTRAINT "packages_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint ALTER TABLE "packages" ADD CONSTRAINT "packages_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 "ai_inline_comments" ADD CONSTRAINT "ai_inline_comments_analysis_id_pr_review_analyses_id_fk" FOREIGN KEY ("analysis_id") REFERENCES "public"."pr_review_analyses"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "ai_inline_comments" ADD CONSTRAINT "ai_inline_comments_pull_request_id_pull_requests_id_fk" FOREIGN KEY ("pull_request_id") REFERENCES "public"."pull_requests"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "ai_review_threads" ADD CONSTRAINT "ai_review_threads_analysis_id_pr_review_analyses_id_fk" FOREIGN KEY ("analysis_id") REFERENCES "public"."pr_review_analyses"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "ai_review_threads" ADD CONSTRAINT "ai_review_threads_pull_request_id_pull_requests_id_fk" FOREIGN KEY ("pull_request_id") REFERENCES "public"."pull_requests"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "file_summaries" ADD CONSTRAINT "file_summaries_analysis_id_pr_review_analyses_id_fk" FOREIGN KEY ("analysis_id") REFERENCES "public"."pr_review_analyses"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pr_review_analyses" ADD CONSTRAINT "pr_review_analyses_pull_request_id_pull_requests_id_fk" FOREIGN KEY ("pull_request_id") REFERENCES "public"."pull_requests"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pr_review_analyses" ADD CONSTRAINT "pr_review_analyses_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "pr_review_analyses" ADD CONSTRAINT "pr_review_analyses_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 CREATE INDEX "sessions_user_idx" ON "sessions" USING btree ("user_id");--> statement-breakpoint CREATE INDEX "sessions_expires_idx" ON "sessions" USING btree ("expires_at");--> statement-breakpoint CREATE INDEX "ssh_keys_user_idx" ON "ssh_keys" USING btree ("user_id");--> statement-breakpoint CREATE UNIQUE INDEX "branches_repo_name_idx" ON "branches" USING btree ("repository_id","name");--> statement-breakpoint CREATE UNIQUE INDEX "commits_repo_sha_idx" ON "commits" USING btree ("repository_id","sha");--> statement-breakpoint CREATE INDEX "commits_repo_idx" ON "commits" USING btree ("repository_id");--> statement-breakpoint CREATE UNIQUE INDEX "repositories_owner_name_idx" ON "repositories" USING btree ("owner_id","name");--> statement-breakpoint CREATE UNIQUE INDEX "repositories_owner_slug_idx" ON "repositories" USING btree ("owner_id","slug");--> statement-breakpoint CREATE INDEX "repositories_owner_idx" ON "repositories" USING btree ("owner_id");--> statement-breakpoint CREATE UNIQUE INDEX "collaborators_repo_user_idx" ON "repository_collaborators" USING btree ("repository_id","user_id");--> statement-breakpoint CREATE UNIQUE INDEX "stars_repo_user_idx" ON "repository_stars" USING btree ("repository_id","user_id");--> statement-breakpoint CREATE UNIQUE INDEX "watchers_repo_user_idx" ON "repository_watchers" USING btree ("repository_id","user_id");--> statement-breakpoint CREATE UNIQUE INDEX "tags_repo_name_idx" ON "tags" USING btree ("repository_id","name");--> statement-breakpoint CREATE INDEX "issue_comments_issue_idx" ON "issue_comments" USING btree ("issue_id");--> statement-breakpoint CREATE UNIQUE INDEX "issues_repo_number_idx" ON "issues" USING btree ("repository_id","number");--> statement-breakpoint CREATE INDEX "issues_repo_state_idx" ON "issues" USING btree ("repository_id","state");--> statement-breakpoint CREATE INDEX "issues_author_idx" ON "issues" USING btree ("author_id");--> statement-breakpoint CREATE INDEX "issues_assignee_idx" ON "issues" USING btree ("assignee_id");--> statement-breakpoint CREATE UNIQUE INDEX "labels_repo_name_idx" ON "labels" USING btree ("repository_id","name");--> statement-breakpoint CREATE INDEX "pr_checks_pr_idx" ON "pull_request_checks" USING btree ("pull_request_id");--> statement-breakpoint CREATE INDEX "pr_checks_head_sha_idx" ON "pull_request_checks" USING btree ("head_sha");--> statement-breakpoint CREATE INDEX "pr_comments_pr_idx" ON "pull_request_comments" USING btree ("pull_request_id");--> statement-breakpoint CREATE INDEX "pr_reviews_pr_idx" ON "pull_request_reviews" USING btree ("pull_request_id");--> statement-breakpoint CREATE UNIQUE INDEX "prs_repo_number_idx" ON "pull_requests" USING btree ("repository_id","number");--> statement-breakpoint CREATE INDEX "prs_repo_state_idx" ON "pull_requests" USING btree ("repository_id","state");--> statement-breakpoint CREATE INDEX "prs_author_idx" ON "pull_requests" USING btree ("author_id");--> statement-breakpoint CREATE INDEX "workflow_jobs_run_idx" ON "workflow_jobs" USING btree ("run_id");--> statement-breakpoint CREATE INDEX "workflow_runs_workflow_idx" ON "workflow_runs" USING btree ("workflow_id");--> statement-breakpoint CREATE INDEX "workflow_runs_repo_idx" ON "workflow_runs" USING btree ("repository_id");--> statement-breakpoint CREATE INDEX "workflow_runs_status_idx" ON "workflow_runs" USING btree ("status");--> statement-breakpoint CREATE INDEX "workflows_repo_idx" ON "workflows" USING btree ("repository_id");--> statement-breakpoint CREATE INDEX "activities_user_idx" ON "activities" USING btree ("user_id");--> statement-breakpoint CREATE INDEX "activities_repo_idx" ON "activities" USING btree ("repository_id");--> statement-breakpoint CREATE INDEX "activities_created_idx" ON "activities" USING btree ("created_at");--> statement-breakpoint CREATE INDEX "audit_logs_action_idx" ON "audit_logs" USING btree ("action");--> statement-breakpoint CREATE INDEX "audit_logs_actor_idx" ON "audit_logs" USING btree ("actor_id");--> statement-breakpoint CREATE INDEX "audit_logs_created_idx" ON "audit_logs" USING btree ("created_at");--> statement-breakpoint CREATE INDEX "audit_logs_target_idx" ON "audit_logs" USING btree ("target_type","target_id");--> statement-breakpoint CREATE INDEX "notifications_user_read_idx" ON "notifications" USING btree ("user_id","is_read");--> statement-breakpoint CREATE INDEX "notifications_user_idx" ON "notifications" USING btree ("user_id");--> statement-breakpoint CREATE INDEX "webhook_deliveries_webhook_idx" ON "webhook_deliveries" USING btree ("webhook_id");--> statement-breakpoint CREATE INDEX "webhook_deliveries_created_idx" ON "webhook_deliveries" USING btree ("created_at");--> statement-breakpoint CREATE INDEX "webhooks_repo_idx" ON "webhooks" USING btree ("repository_id");--> statement-breakpoint CREATE UNIQUE INDEX "pkg_version_idx" ON "package_versions" USING btree ("package_id","version");--> statement-breakpoint CREATE INDEX "pkg_digest_idx" ON "package_versions" USING btree ("digest");--> statement-breakpoint CREATE UNIQUE INDEX "pkg_org_type_name_idx" ON "packages" USING btree ("organization_id","type","name");--> statement-breakpoint CREATE INDEX "pkg_type_idx" ON "packages" USING btree ("type");--> statement-breakpoint CREATE INDEX "ai_inline_comments_analysis_idx" ON "ai_inline_comments" USING btree ("analysis_id");--> statement-breakpoint CREATE INDEX "ai_inline_comments_pr_idx" ON "ai_inline_comments" USING btree ("pull_request_id");--> statement-breakpoint CREATE INDEX "ai_inline_comments_path_idx" ON "ai_inline_comments" USING btree ("file_path");--> statement-breakpoint CREATE INDEX "ai_inline_comments_severity_idx" ON "ai_inline_comments" USING btree ("severity");--> statement-breakpoint CREATE INDEX "ai_thread_analysis_idx" ON "ai_review_threads" USING btree ("analysis_id");--> statement-breakpoint CREATE INDEX "ai_thread_pr_idx" ON "ai_review_threads" USING btree ("pull_request_id");--> statement-breakpoint CREATE INDEX "file_summaries_analysis_idx" ON "file_summaries" USING btree ("analysis_id");--> statement-breakpoint CREATE INDEX "file_summaries_path_idx" ON "file_summaries" USING btree ("file_path");--> statement-breakpoint CREATE INDEX "pr_analysis_pr_idx" ON "pr_review_analyses" USING btree ("pull_request_id");--> statement-breakpoint CREATE INDEX "pr_analysis_repo_idx" ON "pr_review_analyses" USING btree ("repository_id");--> statement-breakpoint CREATE INDEX "pr_analysis_status_idx" ON "pr_review_analyses" USING btree ("status");--> statement-breakpoint CREATE INDEX "pr_analysis_created_idx" ON "pr_review_analyses" USING btree ("created_at");