@fidelios/db 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/dist/backup.js +1 -1
  2. package/dist/backup.js.map +1 -1
  3. package/dist/migration-runtime.js +8 -8
  4. package/dist/migration-runtime.js.map +1 -1
  5. package/dist/restore.js +3 -3
  6. package/dist/restore.js.map +1 -1
  7. package/dist/test-embedded-postgres.js +6 -6
  8. package/dist/test-embedded-postgres.js.map +1 -1
  9. package/package.json +1 -1
  10. package/dist/migrations/migrations/0000_mature_masked_marvel.sql +0 -208
  11. package/dist/migrations/migrations/0001_fast_northstar.sql +0 -87
  12. package/dist/migrations/migrations/0002_big_zaladane.sql +0 -1
  13. package/dist/migrations/migrations/0003_shallow_quentin_quire.sql +0 -5
  14. package/dist/migrations/migrations/0004_issue_identifiers.sql +0 -28
  15. package/dist/migrations/migrations/0005_chief_luke_cage.sql +0 -19
  16. package/dist/migrations/migrations/0006_overjoyed_mister_sinister.sql +0 -36
  17. package/dist/migrations/migrations/0007_new_quentin_quire.sql +0 -20
  18. package/dist/migrations/migrations/0008_amused_zzzax.sql +0 -1
  19. package/dist/migrations/migrations/0009_fast_jackal.sql +0 -36
  20. package/dist/migrations/migrations/0010_stale_justin_hammer.sql +0 -37
  21. package/dist/migrations/migrations/0011_windy_corsair.sql +0 -18
  22. package/dist/migrations/migrations/0012_perpetual_ser_duncan.sql +0 -2
  23. package/dist/migrations/migrations/0013_dashing_wasp.sql +0 -4
  24. package/dist/migrations/migrations/0014_many_mikhail_rasputin.sql +0 -135
  25. package/dist/migrations/migrations/0015_project_color_archived.sql +0 -2
  26. package/dist/migrations/migrations/0016_agent_icon.sql +0 -1
  27. package/dist/migrations/migrations/0017_tiresome_gabe_jones.sql +0 -51
  28. package/dist/migrations/migrations/0018_flat_sleepwalker.sql +0 -26
  29. package/dist/migrations/migrations/0019_public_victor_mancha.sql +0 -18
  30. package/dist/migrations/migrations/0020_white_anita_blake.sql +0 -1
  31. package/dist/migrations/migrations/0021_chief_vindicator.sql +0 -1
  32. package/dist/migrations/migrations/0022_company_brand_color.sql +0 -1
  33. package/dist/migrations/migrations/0023_fair_lethal_legion.sql +0 -3
  34. package/dist/migrations/migrations/0024_far_beast.sql +0 -2
  35. package/dist/migrations/migrations/0025_nasty_salo.sql +0 -15
  36. package/dist/migrations/migrations/0026_lying_pete_wisdom.sql +0 -39
  37. package/dist/migrations/migrations/0027_tranquil_tenebrous.sql +0 -2
  38. package/dist/migrations/migrations/0028_harsh_goliath.sql +0 -54
  39. package/dist/migrations/migrations/0029_plugin_tables.sql +0 -177
  40. package/dist/migrations/migrations/0030_rich_magneto.sql +0 -12
  41. package/dist/migrations/migrations/0031_zippy_magma.sql +0 -51
  42. package/dist/migrations/migrations/0032_pretty_doctor_octopus.sql +0 -102
  43. package/dist/migrations/migrations/0033_shiny_black_tarantula.sql +0 -2
  44. package/dist/migrations/migrations/0034_fat_dormammu.sql +0 -2
  45. package/dist/migrations/migrations/0035_marvelous_satana.sql +0 -91
  46. package/dist/migrations/migrations/0036_cheerful_nitro.sql +0 -9
  47. package/dist/migrations/migrations/0037_friendly_eddie_brock.sql +0 -29
  48. package/dist/migrations/migrations/0038_careless_iron_monger.sql +0 -5
  49. package/dist/migrations/migrations/0039_fat_magneto.sql +0 -161
  50. package/dist/migrations/migrations/0040_eager_shotgun.sql +0 -5
  51. package/dist/migrations/migrations/0041_curly_maria_hill.sql +0 -1
  52. package/dist/migrations/migrations/0042_spotty_the_renegades.sql +0 -26
  53. package/dist/migrations/migrations/0043_reflective_captain_universe.sql +0 -6
  54. package/dist/migrations/migrations/0044_illegal_toad.sql +0 -56
  55. package/dist/migrations/migrations/0045_workable_shockwave.sql +0 -17
  56. package/dist/migrations/migrations/meta/0000_snapshot.json +0 -1743
  57. package/dist/migrations/migrations/meta/0001_snapshot.json +0 -2441
  58. package/dist/migrations/migrations/meta/0002_snapshot.json +0 -2454
  59. package/dist/migrations/migrations/meta/0003_snapshot.json +0 -2502
  60. package/dist/migrations/migrations/meta/0005_snapshot.json +0 -2719
  61. package/dist/migrations/migrations/meta/0006_snapshot.json +0 -3048
  62. package/dist/migrations/migrations/meta/0007_snapshot.json +0 -3258
  63. package/dist/migrations/migrations/meta/0008_snapshot.json +0 -3264
  64. package/dist/migrations/migrations/meta/0009_snapshot.json +0 -3587
  65. package/dist/migrations/migrations/meta/0010_snapshot.json +0 -3929
  66. package/dist/migrations/migrations/meta/0011_snapshot.json +0 -4068
  67. package/dist/migrations/migrations/meta/0012_snapshot.json +0 -4087
  68. package/dist/migrations/migrations/meta/0013_snapshot.json +0 -4118
  69. package/dist/migrations/migrations/meta/0014_snapshot.json +0 -5187
  70. package/dist/migrations/migrations/meta/0017_snapshot.json +0 -5215
  71. package/dist/migrations/migrations/meta/0018_snapshot.json +0 -5450
  72. package/dist/migrations/migrations/meta/0019_snapshot.json +0 -5603
  73. package/dist/migrations/migrations/meta/0020_snapshot.json +0 -5603
  74. package/dist/migrations/migrations/meta/0021_snapshot.json +0 -5609
  75. package/dist/migrations/migrations/meta/0023_snapshot.json +0 -5633
  76. package/dist/migrations/migrations/meta/0024_snapshot.json +0 -5693
  77. package/dist/migrations/migrations/meta/0025_snapshot.json +0 -5849
  78. package/dist/migrations/migrations/meta/0027_snapshot.json +0 -6205
  79. package/dist/migrations/migrations/meta/0028_snapshot.json +0 -6710
  80. package/dist/migrations/migrations/meta/0029_snapshot.json +0 -7899
  81. package/dist/migrations/migrations/meta/0030_snapshot.json +0 -8003
  82. package/dist/migrations/migrations/meta/0031_snapshot.json +0 -7242
  83. package/dist/migrations/migrations/meta/0032_snapshot.json +0 -7733
  84. package/dist/migrations/migrations/meta/0033_snapshot.json +0 -9038
  85. package/dist/migrations/migrations/meta/0034_snapshot.json +0 -9039
  86. package/dist/migrations/migrations/meta/0035_snapshot.json +0 -9959
  87. package/dist/migrations/migrations/meta/0036_snapshot.json +0 -10023
  88. package/dist/migrations/migrations/meta/0037_snapshot.json +0 -10263
  89. package/dist/migrations/migrations/meta/0038_snapshot.json +0 -11350
  90. package/dist/migrations/migrations/meta/0039_snapshot.json +0 -10308
  91. package/dist/migrations/migrations/meta/0040_snapshot.json +0 -10481
  92. package/dist/migrations/migrations/meta/0041_snapshot.json +0 -11393
  93. package/dist/migrations/migrations/meta/0044_snapshot.json +0 -11701
  94. package/dist/migrations/migrations/meta/0045_snapshot.json +0 -11857
  95. package/dist/migrations/migrations/meta/_journal.json +0 -328
@@ -1,36 +0,0 @@
1
- CREATE TABLE "agent_config_revisions" (
2
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
3
- "company_id" uuid NOT NULL,
4
- "agent_id" uuid NOT NULL,
5
- "created_by_agent_id" uuid,
6
- "created_by_user_id" text,
7
- "source" text DEFAULT 'patch' NOT NULL,
8
- "rolled_back_from_revision_id" uuid,
9
- "changed_keys" jsonb DEFAULT '[]'::jsonb NOT NULL,
10
- "before_config" jsonb NOT NULL,
11
- "after_config" jsonb NOT NULL,
12
- "created_at" timestamp with time zone DEFAULT now() NOT NULL
13
- );
14
- --> statement-breakpoint
15
- CREATE TABLE "issue_approvals" (
16
- "company_id" uuid NOT NULL,
17
- "issue_id" uuid NOT NULL,
18
- "approval_id" uuid NOT NULL,
19
- "linked_by_agent_id" uuid,
20
- "linked_by_user_id" text,
21
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
22
- CONSTRAINT "issue_approvals_pk" PRIMARY KEY("issue_id","approval_id")
23
- );
24
- --> statement-breakpoint
25
- ALTER TABLE "agent_config_revisions" ADD CONSTRAINT "agent_config_revisions_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
26
- ALTER TABLE "agent_config_revisions" ADD CONSTRAINT "agent_config_revisions_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
27
- ALTER TABLE "agent_config_revisions" ADD CONSTRAINT "agent_config_revisions_created_by_agent_id_agents_id_fk" FOREIGN KEY ("created_by_agent_id") REFERENCES "public"."agents"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
28
- ALTER TABLE "issue_approvals" ADD CONSTRAINT "issue_approvals_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
29
- ALTER TABLE "issue_approvals" ADD CONSTRAINT "issue_approvals_issue_id_issues_id_fk" FOREIGN KEY ("issue_id") REFERENCES "public"."issues"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
30
- ALTER TABLE "issue_approvals" ADD CONSTRAINT "issue_approvals_approval_id_approvals_id_fk" FOREIGN KEY ("approval_id") REFERENCES "public"."approvals"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
31
- ALTER TABLE "issue_approvals" ADD CONSTRAINT "issue_approvals_linked_by_agent_id_agents_id_fk" FOREIGN KEY ("linked_by_agent_id") REFERENCES "public"."agents"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
32
- CREATE INDEX "agent_config_revisions_company_agent_created_idx" ON "agent_config_revisions" USING btree ("company_id","agent_id","created_at");--> statement-breakpoint
33
- CREATE INDEX "agent_config_revisions_agent_created_idx" ON "agent_config_revisions" USING btree ("agent_id","created_at");--> statement-breakpoint
34
- CREATE INDEX "issue_approvals_issue_idx" ON "issue_approvals" USING btree ("issue_id");--> statement-breakpoint
35
- CREATE INDEX "issue_approvals_approval_idx" ON "issue_approvals" USING btree ("approval_id");--> statement-breakpoint
36
- CREATE INDEX "issue_approvals_company_idx" ON "issue_approvals" USING btree ("company_id");
@@ -1,20 +0,0 @@
1
- CREATE TABLE "agent_task_sessions" (
2
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
3
- "company_id" uuid NOT NULL,
4
- "agent_id" uuid NOT NULL,
5
- "adapter_type" text NOT NULL,
6
- "task_key" text NOT NULL,
7
- "session_params_json" jsonb,
8
- "session_display_id" text,
9
- "last_run_id" uuid,
10
- "last_error" text,
11
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
12
- "updated_at" timestamp with time zone DEFAULT now() NOT NULL
13
- );
14
- --> statement-breakpoint
15
- ALTER TABLE "agent_task_sessions" ADD CONSTRAINT "agent_task_sessions_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
16
- ALTER TABLE "agent_task_sessions" ADD CONSTRAINT "agent_task_sessions_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
17
- ALTER TABLE "agent_task_sessions" ADD CONSTRAINT "agent_task_sessions_last_run_id_heartbeat_runs_id_fk" FOREIGN KEY ("last_run_id") REFERENCES "public"."heartbeat_runs"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
18
- CREATE UNIQUE INDEX "agent_task_sessions_company_agent_adapter_task_uniq" ON "agent_task_sessions" USING btree ("company_id","agent_id","adapter_type","task_key");--> statement-breakpoint
19
- CREATE INDEX "agent_task_sessions_company_agent_updated_idx" ON "agent_task_sessions" USING btree ("company_id","agent_id","updated_at");--> statement-breakpoint
20
- CREATE INDEX "agent_task_sessions_company_task_updated_idx" ON "agent_task_sessions" USING btree ("company_id","task_key","updated_at");
@@ -1 +0,0 @@
1
- ALTER TABLE "issues" ADD COLUMN "hidden_at" timestamp with time zone;
@@ -1,36 +0,0 @@
1
- CREATE TABLE "company_secret_versions" (
2
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
3
- "secret_id" uuid NOT NULL,
4
- "version" integer NOT NULL,
5
- "material" jsonb NOT NULL,
6
- "value_sha256" text NOT NULL,
7
- "created_by_agent_id" uuid,
8
- "created_by_user_id" text,
9
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
10
- "revoked_at" timestamp with time zone
11
- );
12
- --> statement-breakpoint
13
- CREATE TABLE "company_secrets" (
14
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
15
- "company_id" uuid NOT NULL,
16
- "name" text NOT NULL,
17
- "provider" text DEFAULT 'local_encrypted' NOT NULL,
18
- "external_ref" text,
19
- "latest_version" integer DEFAULT 1 NOT NULL,
20
- "description" text,
21
- "created_by_agent_id" uuid,
22
- "created_by_user_id" text,
23
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
24
- "updated_at" timestamp with time zone DEFAULT now() NOT NULL
25
- );
26
- --> statement-breakpoint
27
- ALTER TABLE "company_secret_versions" ADD CONSTRAINT "company_secret_versions_secret_id_company_secrets_id_fk" FOREIGN KEY ("secret_id") REFERENCES "public"."company_secrets"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
28
- ALTER TABLE "company_secret_versions" ADD CONSTRAINT "company_secret_versions_created_by_agent_id_agents_id_fk" FOREIGN KEY ("created_by_agent_id") REFERENCES "public"."agents"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
29
- ALTER TABLE "company_secrets" ADD CONSTRAINT "company_secrets_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
30
- ALTER TABLE "company_secrets" ADD CONSTRAINT "company_secrets_created_by_agent_id_agents_id_fk" FOREIGN KEY ("created_by_agent_id") REFERENCES "public"."agents"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
31
- CREATE INDEX "company_secret_versions_secret_idx" ON "company_secret_versions" USING btree ("secret_id","created_at");--> statement-breakpoint
32
- CREATE INDEX "company_secret_versions_value_sha256_idx" ON "company_secret_versions" USING btree ("value_sha256");--> statement-breakpoint
33
- CREATE UNIQUE INDEX "company_secret_versions_secret_version_uq" ON "company_secret_versions" USING btree ("secret_id","version");--> statement-breakpoint
34
- CREATE INDEX "company_secrets_company_idx" ON "company_secrets" USING btree ("company_id");--> statement-breakpoint
35
- CREATE INDEX "company_secrets_company_provider_idx" ON "company_secrets" USING btree ("company_id","provider");--> statement-breakpoint
36
- CREATE UNIQUE INDEX "company_secrets_company_name_uq" ON "company_secrets" USING btree ("company_id","name");
@@ -1,37 +0,0 @@
1
- CREATE TABLE "assets" (
2
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
3
- "company_id" uuid NOT NULL,
4
- "provider" text NOT NULL,
5
- "object_key" text NOT NULL,
6
- "content_type" text NOT NULL,
7
- "byte_size" integer NOT NULL,
8
- "sha256" text NOT NULL,
9
- "original_filename" text,
10
- "created_by_agent_id" uuid,
11
- "created_by_user_id" text,
12
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
13
- "updated_at" timestamp with time zone DEFAULT now() NOT NULL
14
- );
15
- --> statement-breakpoint
16
- CREATE TABLE "issue_attachments" (
17
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
18
- "company_id" uuid NOT NULL,
19
- "issue_id" uuid NOT NULL,
20
- "asset_id" uuid NOT NULL,
21
- "issue_comment_id" uuid,
22
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
23
- "updated_at" timestamp with time zone DEFAULT now() NOT NULL
24
- );
25
- --> statement-breakpoint
26
- ALTER TABLE "assets" ADD CONSTRAINT "assets_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
27
- ALTER TABLE "assets" ADD CONSTRAINT "assets_created_by_agent_id_agents_id_fk" FOREIGN KEY ("created_by_agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
28
- ALTER TABLE "issue_attachments" ADD CONSTRAINT "issue_attachments_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
29
- ALTER TABLE "issue_attachments" ADD CONSTRAINT "issue_attachments_issue_id_issues_id_fk" FOREIGN KEY ("issue_id") REFERENCES "public"."issues"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
30
- ALTER TABLE "issue_attachments" ADD CONSTRAINT "issue_attachments_asset_id_assets_id_fk" FOREIGN KEY ("asset_id") REFERENCES "public"."assets"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
31
- ALTER TABLE "issue_attachments" ADD CONSTRAINT "issue_attachments_issue_comment_id_issue_comments_id_fk" FOREIGN KEY ("issue_comment_id") REFERENCES "public"."issue_comments"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
32
- CREATE INDEX "assets_company_created_idx" ON "assets" USING btree ("company_id","created_at");--> statement-breakpoint
33
- CREATE INDEX "assets_company_provider_idx" ON "assets" USING btree ("company_id","provider");--> statement-breakpoint
34
- CREATE UNIQUE INDEX "assets_company_object_key_uq" ON "assets" USING btree ("company_id","object_key");--> statement-breakpoint
35
- CREATE INDEX "issue_attachments_company_issue_idx" ON "issue_attachments" USING btree ("company_id","issue_id");--> statement-breakpoint
36
- CREATE INDEX "issue_attachments_issue_comment_idx" ON "issue_attachments" USING btree ("issue_comment_id");--> statement-breakpoint
37
- CREATE UNIQUE INDEX "issue_attachments_asset_uq" ON "issue_attachments" USING btree ("asset_id");
@@ -1,18 +0,0 @@
1
- CREATE TABLE "project_goals" (
2
- "project_id" uuid NOT NULL,
3
- "goal_id" uuid NOT NULL,
4
- "company_id" uuid NOT NULL,
5
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
6
- "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
7
- CONSTRAINT "project_goals_project_id_goal_id_pk" PRIMARY KEY("project_id","goal_id")
8
- );
9
- --> statement-breakpoint
10
- ALTER TABLE "project_goals" ADD CONSTRAINT "project_goals_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
11
- ALTER TABLE "project_goals" ADD CONSTRAINT "project_goals_goal_id_goals_id_fk" FOREIGN KEY ("goal_id") REFERENCES "public"."goals"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
12
- ALTER TABLE "project_goals" ADD CONSTRAINT "project_goals_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
13
- CREATE INDEX "project_goals_project_idx" ON "project_goals" USING btree ("project_id");--> statement-breakpoint
14
- CREATE INDEX "project_goals_goal_idx" ON "project_goals" USING btree ("goal_id");--> statement-breakpoint
15
- CREATE INDEX "project_goals_company_idx" ON "project_goals" USING btree ("company_id");--> statement-breakpoint
16
- INSERT INTO "project_goals" ("project_id", "goal_id", "company_id")
17
- SELECT "id", "goal_id", "company_id" FROM "projects" WHERE "goal_id" IS NOT NULL
18
- ON CONFLICT DO NOTHING;
@@ -1,2 +0,0 @@
1
- ALTER TABLE "issues" ADD COLUMN "checkout_run_id" uuid;--> statement-breakpoint
2
- ALTER TABLE "issues" ADD CONSTRAINT "issues_checkout_run_id_heartbeat_runs_id_fk" FOREIGN KEY ("checkout_run_id") REFERENCES "public"."heartbeat_runs"("id") ON DELETE set null ON UPDATE no action;
@@ -1,4 +0,0 @@
1
- ALTER TABLE "issues" ADD COLUMN "execution_run_id" uuid;--> statement-breakpoint
2
- ALTER TABLE "issues" ADD COLUMN "execution_agent_name_key" text;--> statement-breakpoint
3
- ALTER TABLE "issues" ADD COLUMN "execution_locked_at" timestamp with time zone;--> statement-breakpoint
4
- ALTER TABLE "issues" ADD CONSTRAINT "issues_execution_run_id_heartbeat_runs_id_fk" FOREIGN KEY ("execution_run_id") REFERENCES "public"."heartbeat_runs"("id") ON DELETE set null ON UPDATE no action;
@@ -1,135 +0,0 @@
1
- CREATE TABLE "account" (
2
- "id" text PRIMARY KEY NOT NULL,
3
- "account_id" text NOT NULL,
4
- "provider_id" text NOT NULL,
5
- "user_id" text NOT NULL,
6
- "access_token" text,
7
- "refresh_token" text,
8
- "id_token" text,
9
- "access_token_expires_at" timestamp with time zone,
10
- "refresh_token_expires_at" timestamp with time zone,
11
- "scope" text,
12
- "password" text,
13
- "created_at" timestamp with time zone NOT NULL,
14
- "updated_at" timestamp with time zone NOT NULL
15
- );
16
- --> statement-breakpoint
17
- CREATE TABLE "session" (
18
- "id" text PRIMARY KEY NOT NULL,
19
- "expires_at" timestamp with time zone NOT NULL,
20
- "token" text NOT NULL,
21
- "created_at" timestamp with time zone NOT NULL,
22
- "updated_at" timestamp with time zone NOT NULL,
23
- "ip_address" text,
24
- "user_agent" text,
25
- "user_id" text NOT NULL
26
- );
27
- --> statement-breakpoint
28
- CREATE TABLE "user" (
29
- "id" text PRIMARY KEY NOT NULL,
30
- "name" text NOT NULL,
31
- "email" text NOT NULL,
32
- "email_verified" boolean DEFAULT false NOT NULL,
33
- "image" text,
34
- "created_at" timestamp with time zone NOT NULL,
35
- "updated_at" timestamp with time zone NOT NULL
36
- );
37
- --> statement-breakpoint
38
- CREATE TABLE "verification" (
39
- "id" text PRIMARY KEY NOT NULL,
40
- "identifier" text NOT NULL,
41
- "value" text NOT NULL,
42
- "expires_at" timestamp with time zone NOT NULL,
43
- "created_at" timestamp with time zone,
44
- "updated_at" timestamp with time zone
45
- );
46
- --> statement-breakpoint
47
- CREATE TABLE "company_memberships" (
48
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
49
- "company_id" uuid NOT NULL,
50
- "principal_type" text NOT NULL,
51
- "principal_id" text NOT NULL,
52
- "status" text DEFAULT 'active' NOT NULL,
53
- "membership_role" text,
54
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
55
- "updated_at" timestamp with time zone DEFAULT now() NOT NULL
56
- );
57
- --> statement-breakpoint
58
- CREATE TABLE "instance_user_roles" (
59
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
60
- "user_id" text NOT NULL,
61
- "role" text DEFAULT 'instance_admin' NOT NULL,
62
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
63
- "updated_at" timestamp with time zone DEFAULT now() NOT NULL
64
- );
65
- --> statement-breakpoint
66
- CREATE TABLE "invites" (
67
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
68
- "company_id" uuid,
69
- "invite_type" text DEFAULT 'company_join' NOT NULL,
70
- "token_hash" text NOT NULL,
71
- "allowed_join_types" text DEFAULT 'both' NOT NULL,
72
- "defaults_payload" jsonb,
73
- "expires_at" timestamp with time zone NOT NULL,
74
- "invited_by_user_id" text,
75
- "revoked_at" timestamp with time zone,
76
- "accepted_at" timestamp with time zone,
77
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
78
- "updated_at" timestamp with time zone DEFAULT now() NOT NULL
79
- );
80
- --> statement-breakpoint
81
- CREATE TABLE "join_requests" (
82
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
83
- "invite_id" uuid NOT NULL,
84
- "company_id" uuid NOT NULL,
85
- "request_type" text NOT NULL,
86
- "status" text DEFAULT 'pending_approval' NOT NULL,
87
- "request_ip" text NOT NULL,
88
- "requesting_user_id" text,
89
- "request_email_snapshot" text,
90
- "agent_name" text,
91
- "adapter_type" text,
92
- "capabilities" text,
93
- "agent_defaults_payload" jsonb,
94
- "created_agent_id" uuid,
95
- "approved_by_user_id" text,
96
- "approved_at" timestamp with time zone,
97
- "rejected_by_user_id" text,
98
- "rejected_at" timestamp with time zone,
99
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
100
- "updated_at" timestamp with time zone DEFAULT now() NOT NULL
101
- );
102
- --> statement-breakpoint
103
- CREATE TABLE "principal_permission_grants" (
104
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
105
- "company_id" uuid NOT NULL,
106
- "principal_type" text NOT NULL,
107
- "principal_id" text NOT NULL,
108
- "permission_key" text NOT NULL,
109
- "scope" jsonb,
110
- "granted_by_user_id" text,
111
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
112
- "updated_at" timestamp with time zone DEFAULT now() NOT NULL
113
- );
114
- --> statement-breakpoint
115
- ALTER TABLE "issues" ADD COLUMN "assignee_user_id" text;--> statement-breakpoint
116
- ALTER TABLE "account" ADD CONSTRAINT "account_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
117
- ALTER TABLE "session" ADD CONSTRAINT "session_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
118
- ALTER TABLE "company_memberships" ADD CONSTRAINT "company_memberships_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
119
- ALTER TABLE "invites" ADD CONSTRAINT "invites_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
120
- ALTER TABLE "join_requests" ADD CONSTRAINT "join_requests_invite_id_invites_id_fk" FOREIGN KEY ("invite_id") REFERENCES "public"."invites"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
121
- ALTER TABLE "join_requests" ADD CONSTRAINT "join_requests_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
122
- ALTER TABLE "join_requests" ADD CONSTRAINT "join_requests_created_agent_id_agents_id_fk" FOREIGN KEY ("created_agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
123
- ALTER TABLE "principal_permission_grants" ADD CONSTRAINT "principal_permission_grants_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
124
- CREATE UNIQUE INDEX "company_memberships_company_principal_unique_idx" ON "company_memberships" USING btree ("company_id","principal_type","principal_id");--> statement-breakpoint
125
- CREATE INDEX "company_memberships_principal_status_idx" ON "company_memberships" USING btree ("principal_type","principal_id","status");--> statement-breakpoint
126
- CREATE INDEX "company_memberships_company_status_idx" ON "company_memberships" USING btree ("company_id","status");--> statement-breakpoint
127
- CREATE UNIQUE INDEX "instance_user_roles_user_role_unique_idx" ON "instance_user_roles" USING btree ("user_id","role");--> statement-breakpoint
128
- CREATE INDEX "instance_user_roles_role_idx" ON "instance_user_roles" USING btree ("role");--> statement-breakpoint
129
- CREATE UNIQUE INDEX "invites_token_hash_unique_idx" ON "invites" USING btree ("token_hash");--> statement-breakpoint
130
- CREATE INDEX "invites_company_invite_state_idx" ON "invites" USING btree ("company_id","invite_type","revoked_at","expires_at");--> statement-breakpoint
131
- CREATE UNIQUE INDEX "join_requests_invite_unique_idx" ON "join_requests" USING btree ("invite_id");--> statement-breakpoint
132
- CREATE INDEX "join_requests_company_status_type_created_idx" ON "join_requests" USING btree ("company_id","status","request_type","created_at");--> statement-breakpoint
133
- CREATE UNIQUE INDEX "principal_permission_grants_unique_idx" ON "principal_permission_grants" USING btree ("company_id","principal_type","principal_id","permission_key");--> statement-breakpoint
134
- CREATE INDEX "principal_permission_grants_company_permission_idx" ON "principal_permission_grants" USING btree ("company_id","permission_key");--> statement-breakpoint
135
- CREATE INDEX "issues_company_assignee_user_status_idx" ON "issues" USING btree ("company_id","assignee_user_id","status");
@@ -1,2 +0,0 @@
1
- ALTER TABLE "projects" ADD COLUMN "color" text;
2
- ALTER TABLE "projects" ADD COLUMN "archived_at" timestamp with time zone;
@@ -1 +0,0 @@
1
- ALTER TABLE "agents" ADD COLUMN "icon" text;
@@ -1,51 +0,0 @@
1
- DROP INDEX "issues_company_identifier_idx";--> statement-breakpoint
2
-
3
- -- Rebuild issue prefixes to be company-specific and globally unique.
4
- -- Base prefix is first 3 letters of company name (A-Z only), fallback "CMP".
5
- -- Duplicate bases receive deterministic letter suffixes: PAP, PAPA, PAPAA, ...
6
- WITH ranked_companies AS (
7
- SELECT
8
- c.id,
9
- COALESCE(NULLIF(SUBSTRING(REGEXP_REPLACE(UPPER(c.name), '[^A-Z]', '', 'g') FROM 1 FOR 3), ''), 'CMP') AS base_prefix,
10
- ROW_NUMBER() OVER (
11
- PARTITION BY COALESCE(NULLIF(SUBSTRING(REGEXP_REPLACE(UPPER(c.name), '[^A-Z]', '', 'g') FROM 1 FOR 3), ''), 'CMP')
12
- ORDER BY c.created_at, c.id
13
- ) AS prefix_rank
14
- FROM companies c
15
- )
16
- UPDATE companies c
17
- SET issue_prefix = CASE
18
- WHEN ranked_companies.prefix_rank = 1 THEN ranked_companies.base_prefix
19
- ELSE ranked_companies.base_prefix || REPEAT('A', (ranked_companies.prefix_rank - 1)::integer)
20
- END
21
- FROM ranked_companies
22
- WHERE c.id = ranked_companies.id;--> statement-breakpoint
23
-
24
- -- Reassign issue numbers sequentially per company to guarantee uniqueness.
25
- WITH numbered_issues AS (
26
- SELECT
27
- i.id,
28
- ROW_NUMBER() OVER (PARTITION BY i.company_id ORDER BY i.created_at, i.id) AS issue_number
29
- FROM issues i
30
- )
31
- UPDATE issues i
32
- SET issue_number = numbered_issues.issue_number
33
- FROM numbered_issues
34
- WHERE i.id = numbered_issues.id;--> statement-breakpoint
35
-
36
- -- Rebuild identifiers from normalized prefix + issue number.
37
- UPDATE issues i
38
- SET identifier = c.issue_prefix || '-' || i.issue_number
39
- FROM companies c
40
- WHERE c.id = i.company_id;--> statement-breakpoint
41
-
42
- -- Sync counters to the largest issue number currently assigned per company.
43
- UPDATE companies c
44
- SET issue_counter = COALESCE((
45
- SELECT MAX(i.issue_number)
46
- FROM issues i
47
- WHERE i.company_id = c.id
48
- ), 0);--> statement-breakpoint
49
-
50
- CREATE UNIQUE INDEX "companies_issue_prefix_idx" ON "companies" USING btree ("issue_prefix");--> statement-breakpoint
51
- CREATE UNIQUE INDEX "issues_identifier_idx" ON "issues" USING btree ("identifier");
@@ -1,26 +0,0 @@
1
- CREATE TABLE "issue_labels" (
2
- "issue_id" uuid NOT NULL,
3
- "label_id" uuid NOT NULL,
4
- "company_id" uuid NOT NULL,
5
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
6
- CONSTRAINT "issue_labels_pk" PRIMARY KEY("issue_id","label_id")
7
- );
8
- --> statement-breakpoint
9
- CREATE TABLE "labels" (
10
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
11
- "company_id" uuid NOT NULL,
12
- "name" text NOT NULL,
13
- "color" text NOT NULL,
14
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
15
- "updated_at" timestamp with time zone DEFAULT now() NOT NULL
16
- );
17
- --> statement-breakpoint
18
- 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
19
- 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
20
- ALTER TABLE "issue_labels" ADD CONSTRAINT "issue_labels_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
21
- ALTER TABLE "labels" ADD CONSTRAINT "labels_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
22
- CREATE INDEX "issue_labels_issue_idx" ON "issue_labels" USING btree ("issue_id");--> statement-breakpoint
23
- CREATE INDEX "issue_labels_label_idx" ON "issue_labels" USING btree ("label_id");--> statement-breakpoint
24
- CREATE INDEX "issue_labels_company_idx" ON "issue_labels" USING btree ("company_id");--> statement-breakpoint
25
- CREATE INDEX "labels_company_idx" ON "labels" USING btree ("company_id");--> statement-breakpoint
26
- CREATE UNIQUE INDEX "labels_company_name_idx" ON "labels" USING btree ("company_id","name");
@@ -1,18 +0,0 @@
1
- CREATE TABLE "project_workspaces" (
2
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
3
- "company_id" uuid NOT NULL,
4
- "project_id" uuid NOT NULL,
5
- "name" text NOT NULL,
6
- "cwd" text NOT NULL,
7
- "repo_url" text,
8
- "repo_ref" text,
9
- "metadata" jsonb,
10
- "is_primary" boolean DEFAULT false NOT NULL,
11
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
12
- "updated_at" timestamp with time zone DEFAULT now() NOT NULL
13
- );
14
- --> statement-breakpoint
15
- ALTER TABLE "project_workspaces" ADD CONSTRAINT "project_workspaces_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
16
- ALTER TABLE "project_workspaces" ADD CONSTRAINT "project_workspaces_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
17
- CREATE INDEX "project_workspaces_company_project_idx" ON "project_workspaces" USING btree ("company_id","project_id");--> statement-breakpoint
18
- CREATE INDEX "project_workspaces_project_primary_idx" ON "project_workspaces" USING btree ("project_id","is_primary");
@@ -1 +0,0 @@
1
- ALTER TABLE "project_workspaces" ALTER COLUMN "cwd" DROP NOT NULL;
@@ -1 +0,0 @@
1
- ALTER TABLE "issues" ADD COLUMN "assignee_adapter_overrides" jsonb;
@@ -1 +0,0 @@
1
- ALTER TABLE "companies" ADD COLUMN "brand_color" text;
@@ -1,3 +0,0 @@
1
- ALTER TABLE "join_requests" ADD COLUMN "claim_secret_hash" text;--> statement-breakpoint
2
- ALTER TABLE "join_requests" ADD COLUMN "claim_secret_expires_at" timestamp with time zone;--> statement-breakpoint
3
- ALTER TABLE "join_requests" ADD COLUMN "claim_secret_consumed_at" timestamp with time zone;
@@ -1,2 +0,0 @@
1
- CREATE INDEX "issue_comments_company_issue_created_at_idx" ON "issue_comments" USING btree ("company_id","issue_id","created_at");--> statement-breakpoint
2
- CREATE INDEX "issue_comments_company_author_issue_created_at_idx" ON "issue_comments" USING btree ("company_id","author_user_id","issue_id","created_at");
@@ -1,15 +0,0 @@
1
- CREATE TABLE "issue_read_states" (
2
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
3
- "company_id" uuid NOT NULL,
4
- "issue_id" uuid NOT NULL,
5
- "user_id" text NOT NULL,
6
- "last_read_at" timestamp with time zone DEFAULT now() NOT NULL,
7
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
8
- "updated_at" timestamp with time zone DEFAULT now() NOT NULL
9
- );
10
- --> statement-breakpoint
11
- ALTER TABLE "issue_read_states" ADD CONSTRAINT "issue_read_states_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
12
- ALTER TABLE "issue_read_states" ADD CONSTRAINT "issue_read_states_issue_id_issues_id_fk" FOREIGN KEY ("issue_id") REFERENCES "public"."issues"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
13
- CREATE INDEX "issue_read_states_company_issue_idx" ON "issue_read_states" USING btree ("company_id","issue_id");--> statement-breakpoint
14
- CREATE INDEX "issue_read_states_company_user_idx" ON "issue_read_states" USING btree ("company_id","user_id");--> statement-breakpoint
15
- CREATE UNIQUE INDEX "issue_read_states_company_issue_user_idx" ON "issue_read_states" USING btree ("company_id","issue_id","user_id");
@@ -1,39 +0,0 @@
1
- CREATE TABLE "workspace_runtime_services" (
2
- "id" uuid PRIMARY KEY NOT NULL,
3
- "company_id" uuid NOT NULL,
4
- "project_id" uuid,
5
- "project_workspace_id" uuid,
6
- "issue_id" uuid,
7
- "scope_type" text NOT NULL,
8
- "scope_id" text,
9
- "service_name" text NOT NULL,
10
- "status" text NOT NULL,
11
- "lifecycle" text NOT NULL,
12
- "reuse_key" text,
13
- "command" text,
14
- "cwd" text,
15
- "port" integer,
16
- "url" text,
17
- "provider" text NOT NULL,
18
- "provider_ref" text,
19
- "owner_agent_id" uuid,
20
- "started_by_run_id" uuid,
21
- "last_used_at" timestamp with time zone DEFAULT now() NOT NULL,
22
- "started_at" timestamp with time zone DEFAULT now() NOT NULL,
23
- "stopped_at" timestamp with time zone,
24
- "stop_policy" jsonb,
25
- "health_status" text DEFAULT 'unknown' NOT NULL,
26
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
27
- "updated_at" timestamp with time zone DEFAULT now() NOT NULL
28
- );
29
- --> statement-breakpoint
30
- ALTER TABLE "workspace_runtime_services" ADD CONSTRAINT "workspace_runtime_services_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
31
- ALTER TABLE "workspace_runtime_services" ADD CONSTRAINT "workspace_runtime_services_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
32
- ALTER TABLE "workspace_runtime_services" ADD CONSTRAINT "workspace_runtime_services_project_workspace_id_project_workspaces_id_fk" FOREIGN KEY ("project_workspace_id") REFERENCES "public"."project_workspaces"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
33
- ALTER TABLE "workspace_runtime_services" ADD CONSTRAINT "workspace_runtime_services_issue_id_issues_id_fk" FOREIGN KEY ("issue_id") REFERENCES "public"."issues"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
34
- ALTER TABLE "workspace_runtime_services" ADD CONSTRAINT "workspace_runtime_services_owner_agent_id_agents_id_fk" FOREIGN KEY ("owner_agent_id") REFERENCES "public"."agents"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
35
- ALTER TABLE "workspace_runtime_services" ADD CONSTRAINT "workspace_runtime_services_started_by_run_id_heartbeat_runs_id_fk" FOREIGN KEY ("started_by_run_id") REFERENCES "public"."heartbeat_runs"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
36
- CREATE INDEX "workspace_runtime_services_company_workspace_status_idx" ON "workspace_runtime_services" USING btree ("company_id","project_workspace_id","status");--> statement-breakpoint
37
- CREATE INDEX "workspace_runtime_services_company_project_status_idx" ON "workspace_runtime_services" USING btree ("company_id","project_id","status");--> statement-breakpoint
38
- CREATE INDEX "workspace_runtime_services_run_idx" ON "workspace_runtime_services" USING btree ("started_by_run_id");--> statement-breakpoint
39
- CREATE INDEX "workspace_runtime_services_company_updated_idx" ON "workspace_runtime_services" USING btree ("company_id","updated_at");
@@ -1,2 +0,0 @@
1
- ALTER TABLE "issues" ADD COLUMN "execution_workspace_settings" jsonb;--> statement-breakpoint
2
- ALTER TABLE "projects" ADD COLUMN "execution_workspace_policy" jsonb;
@@ -1,54 +0,0 @@
1
- CREATE TABLE "document_revisions" (
2
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
3
- "company_id" uuid NOT NULL,
4
- "document_id" uuid NOT NULL,
5
- "revision_number" integer NOT NULL,
6
- "body" text NOT NULL,
7
- "change_summary" text,
8
- "created_by_agent_id" uuid,
9
- "created_by_user_id" text,
10
- "created_at" timestamp with time zone DEFAULT now() NOT NULL
11
- );
12
- --> statement-breakpoint
13
- CREATE TABLE "documents" (
14
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
15
- "company_id" uuid NOT NULL,
16
- "title" text,
17
- "format" text DEFAULT 'markdown' NOT NULL,
18
- "latest_body" text NOT NULL,
19
- "latest_revision_id" uuid,
20
- "latest_revision_number" integer DEFAULT 1 NOT NULL,
21
- "created_by_agent_id" uuid,
22
- "created_by_user_id" text,
23
- "updated_by_agent_id" uuid,
24
- "updated_by_user_id" text,
25
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
26
- "updated_at" timestamp with time zone DEFAULT now() NOT NULL
27
- );
28
- --> statement-breakpoint
29
- CREATE TABLE "issue_documents" (
30
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
31
- "company_id" uuid NOT NULL,
32
- "issue_id" uuid NOT NULL,
33
- "document_id" uuid NOT NULL,
34
- "key" text NOT NULL,
35
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
36
- "updated_at" timestamp with time zone DEFAULT now() NOT NULL
37
- );
38
- --> statement-breakpoint
39
- ALTER TABLE "document_revisions" ADD CONSTRAINT "document_revisions_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
40
- ALTER TABLE "document_revisions" ADD CONSTRAINT "document_revisions_document_id_documents_id_fk" FOREIGN KEY ("document_id") REFERENCES "public"."documents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
41
- ALTER TABLE "document_revisions" ADD CONSTRAINT "document_revisions_created_by_agent_id_agents_id_fk" FOREIGN KEY ("created_by_agent_id") REFERENCES "public"."agents"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
42
- ALTER TABLE "documents" ADD CONSTRAINT "documents_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
43
- ALTER TABLE "documents" ADD CONSTRAINT "documents_created_by_agent_id_agents_id_fk" FOREIGN KEY ("created_by_agent_id") REFERENCES "public"."agents"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
44
- ALTER TABLE "documents" ADD CONSTRAINT "documents_updated_by_agent_id_agents_id_fk" FOREIGN KEY ("updated_by_agent_id") REFERENCES "public"."agents"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
45
- ALTER TABLE "issue_documents" ADD CONSTRAINT "issue_documents_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
46
- ALTER TABLE "issue_documents" ADD CONSTRAINT "issue_documents_issue_id_issues_id_fk" FOREIGN KEY ("issue_id") REFERENCES "public"."issues"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
47
- ALTER TABLE "issue_documents" ADD CONSTRAINT "issue_documents_document_id_documents_id_fk" FOREIGN KEY ("document_id") REFERENCES "public"."documents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
48
- CREATE UNIQUE INDEX "document_revisions_document_revision_uq" ON "document_revisions" USING btree ("document_id","revision_number");--> statement-breakpoint
49
- CREATE INDEX "document_revisions_company_document_created_idx" ON "document_revisions" USING btree ("company_id","document_id","created_at");--> statement-breakpoint
50
- CREATE INDEX "documents_company_updated_idx" ON "documents" USING btree ("company_id","updated_at");--> statement-breakpoint
51
- CREATE INDEX "documents_company_created_idx" ON "documents" USING btree ("company_id","created_at");--> statement-breakpoint
52
- CREATE UNIQUE INDEX "issue_documents_company_issue_key_uq" ON "issue_documents" USING btree ("company_id","issue_id","key");--> statement-breakpoint
53
- CREATE UNIQUE INDEX "issue_documents_document_uq" ON "issue_documents" USING btree ("document_id");--> statement-breakpoint
54
- CREATE INDEX "issue_documents_company_issue_updated_idx" ON "issue_documents" USING btree ("company_id","issue_id","updated_at");