-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSCHEMA.sql
More file actions
2569 lines (1742 loc) · 77 KB
/
Copy pathSCHEMA.sql
File metadata and controls
2569 lines (1742 loc) · 77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--
-- PostgreSQL database dump
--
\restrict Wa9cVbD20aiSD1mg8hdX4ucJSCAI1Zo8GH1ywdS2KyvkPycAg0afifQTGjdzEay
-- Dumped from database version 16.13 (Debian 16.13-1.pgdg12+1)
-- Dumped by pg_dump version 16.14 (Ubuntu 16.14-0ubuntu0.24.04.1)
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
--
-- Name: public; Type: SCHEMA; Schema: -; Owner: -
--
CREATE SCHEMA public;
--
-- Name: SCHEMA public; Type: COMMENT; Schema: -; Owner: -
--
COMMENT ON SCHEMA public IS 'standard public schema';
SET default_tablespace = '';
SET default_table_access_method = heap;
--
-- Name: api_keys; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.api_keys (
id uuid DEFAULT gen_random_uuid() NOT NULL,
org_id uuid NOT NULL,
identity_id uuid NOT NULL,
name text NOT NULL,
key_hash text NOT NULL,
key_prefix text NOT NULL,
scopes text[] DEFAULT '{}'::text[] NOT NULL,
expires_at timestamp with time zone,
last_used_at timestamp with time zone,
revoked_at timestamp with time zone,
created_at timestamp with time zone DEFAULT now() NOT NULL,
revoked_reason text
);
--
-- Name: approvals; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.approvals (
id uuid DEFAULT gen_random_uuid() NOT NULL,
org_id uuid NOT NULL,
identity_id uuid NOT NULL,
action_summary text NOT NULL,
action_detail jsonb,
permission_keys text[] DEFAULT '{}'::text[] NOT NULL,
status text DEFAULT 'pending'::text NOT NULL,
resolved_at timestamp with time zone,
resolved_by text,
remember boolean DEFAULT false NOT NULL,
token text NOT NULL,
expires_at timestamp with time zone NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
current_resolver_identity_id uuid NOT NULL,
resolver_assigned_at timestamp with time zone DEFAULT now() NOT NULL,
disclosed_fields jsonb,
replay_payload jsonb,
CONSTRAINT approvals_status_check CHECK ((status = ANY (ARRAY['pending'::text, 'allowed'::text, 'denied'::text, 'expired'::text])))
);
--
-- Name: audit_log; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.audit_log (
id uuid DEFAULT gen_random_uuid() NOT NULL,
org_id uuid NOT NULL,
identity_id uuid,
action text NOT NULL,
resource_type text,
resource_id uuid,
detail jsonb DEFAULT '{}'::jsonb NOT NULL,
ip_address text,
created_at timestamp with time zone DEFAULT now() NOT NULL,
description text,
impersonated_by_identity_id uuid
);
--
-- Name: billing_email_log; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.billing_email_log (
id uuid DEFAULT gen_random_uuid() NOT NULL,
stripe_event_id text NOT NULL,
kind text NOT NULL,
user_id uuid NOT NULL,
attempted_at timestamp with time zone DEFAULT now() NOT NULL,
sent_at timestamp with time zone,
CONSTRAINT billing_email_log_kind_check CHECK ((kind = ANY (ARRAY['invoice_paid'::text, 'invoice_payment_failed'::text, 'subscription_canceled'::text])))
);
--
-- Name: byoc_credentials; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.byoc_credentials (
id uuid DEFAULT gen_random_uuid() NOT NULL,
org_id uuid NOT NULL,
identity_id uuid NOT NULL,
provider_key text NOT NULL,
encrypted_client_id bytea NOT NULL,
encrypted_client_secret bytea NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL
);
--
-- Name: connections; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.connections (
id uuid DEFAULT gen_random_uuid() NOT NULL,
org_id uuid NOT NULL,
identity_id uuid NOT NULL,
provider_key text NOT NULL,
encrypted_access_token bytea NOT NULL,
encrypted_refresh_token bytea,
token_expires_at timestamp with time zone,
scopes text[],
account_email text,
byoc_credential_id uuid,
is_default boolean DEFAULT true NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
integration_managed boolean DEFAULT false NOT NULL
);
--
-- Name: email_unsubscribe_tokens; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.email_unsubscribe_tokens (
token uuid DEFAULT gen_random_uuid() NOT NULL,
user_id uuid NOT NULL,
org_id uuid NOT NULL,
purpose text DEFAULT 'welcome'::text NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
redeemed_at timestamp with time zone,
CONSTRAINT email_unsubscribe_tokens_purpose_check CHECK ((purpose = ANY (ARRAY['welcome'::text, 'webhook_digest'::text])))
);
--
-- Name: enabled_global_templates; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.enabled_global_templates (
org_id uuid NOT NULL,
template_key text NOT NULL,
enabled_by uuid,
created_at timestamp with time zone DEFAULT now() NOT NULL
);
--
-- Name: executions; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.executions (
id uuid DEFAULT gen_random_uuid() NOT NULL,
approval_id uuid NOT NULL,
org_id uuid NOT NULL,
status text NOT NULL,
remember boolean DEFAULT false NOT NULL,
remember_keys text[],
remember_rule_ttl timestamp with time zone,
result jsonb,
error text,
triggered_by text,
started_at timestamp with time zone,
completed_at timestamp with time zone,
expires_at timestamp with time zone NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
result_viewed_at timestamp with time zone,
CONSTRAINT executions_status_check CHECK ((status = ANY (ARRAY['pending'::text, 'executing'::text, 'executed'::text, 'failed'::text, 'cancelled'::text, 'expired'::text])))
);
--
-- Name: group_grants; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.group_grants (
id uuid DEFAULT gen_random_uuid() NOT NULL,
group_id uuid NOT NULL,
service_instance_id uuid NOT NULL,
access_level text NOT NULL,
auto_approve_reads boolean DEFAULT false NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT group_grants_access_level_check CHECK ((access_level = ANY (ARRAY['read'::text, 'write'::text, 'admin'::text])))
);
--
-- Name: groups; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.groups (
id uuid DEFAULT gen_random_uuid() NOT NULL,
org_id uuid NOT NULL,
name text NOT NULL,
description text DEFAULT ''::text NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
is_system boolean DEFAULT false NOT NULL,
system_kind text,
owner_identity_id uuid,
CONSTRAINT groups_owner_only_for_self CHECK (((system_kind = 'self'::text) = (owner_identity_id IS NOT NULL))),
CONSTRAINT groups_system_kind_check CHECK ((system_kind = ANY (ARRAY['everyone'::text, 'admins'::text, 'self'::text])))
);
--
-- Name: identities; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.identities (
id uuid DEFAULT gen_random_uuid() NOT NULL,
org_id uuid NOT NULL,
name text NOT NULL,
kind text NOT NULL,
external_id text,
metadata jsonb DEFAULT '{}'::jsonb NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
email text,
parent_id uuid,
depth integer DEFAULT 0 NOT NULL,
owner_id uuid,
inherit_permissions boolean DEFAULT false NOT NULL,
last_active_at timestamp with time zone DEFAULT now() NOT NULL,
archived_at timestamp with time zone,
archived_reason text,
preferences jsonb DEFAULT '{}'::jsonb NOT NULL,
is_org_admin boolean DEFAULT false NOT NULL,
user_id uuid,
auto_call_on_approve boolean DEFAULT true NOT NULL,
CONSTRAINT identities_is_org_admin_only_user CHECK (((kind = 'user'::text) OR (is_org_admin = false))),
CONSTRAINT identities_kind_check CHECK ((kind = ANY (ARRAY['user'::text, 'agent'::text, 'sub_agent'::text])))
);
--
-- Name: identity_groups; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.identity_groups (
identity_id uuid NOT NULL,
group_id uuid NOT NULL,
assigned_at timestamp with time zone DEFAULT now() NOT NULL
);
--
-- Name: mcp_client_agent_bindings; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.mcp_client_agent_bindings (
id uuid DEFAULT gen_random_uuid() NOT NULL,
org_id uuid NOT NULL,
user_identity_id uuid NOT NULL,
client_id text NOT NULL,
agent_identity_id uuid NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
elicitation_enabled boolean DEFAULT false NOT NULL,
self_approve_enabled boolean DEFAULT false NOT NULL
);
--
-- Name: mcp_refresh_tokens; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.mcp_refresh_tokens (
id uuid DEFAULT gen_random_uuid() NOT NULL,
client_id text NOT NULL,
identity_id uuid NOT NULL,
org_id uuid NOT NULL,
hash bytea NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
expires_at timestamp with time zone NOT NULL,
revoked_at timestamp with time zone,
replaced_by_id uuid
);
--
-- Name: mcp_upstream_connections; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.mcp_upstream_connections (
id uuid DEFAULT gen_random_uuid() NOT NULL,
identity_id uuid NOT NULL,
org_id uuid NOT NULL,
upstream_resource text NOT NULL,
upstream_client_id text NOT NULL,
status text DEFAULT 'pending_auth'::text NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
last_refreshed_at timestamp with time zone,
CONSTRAINT mcp_upstream_connections_status_check CHECK ((status = ANY (ARRAY['pending_auth'::text, 'ready'::text, 'revoked'::text, 'error'::text])))
);
--
-- Name: mcp_upstream_flows; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.mcp_upstream_flows (
id text NOT NULL,
identity_id uuid NOT NULL,
org_id uuid NOT NULL,
upstream_resource text NOT NULL,
upstream_client_id text NOT NULL,
upstream_as_issuer text NOT NULL,
upstream_token_endpoint text NOT NULL,
upstream_authorize_url text NOT NULL,
pkce_code_verifier text NOT NULL,
expires_at timestamp with time zone NOT NULL,
consumed_at timestamp with time zone,
created_at timestamp with time zone DEFAULT now() NOT NULL,
created_ip text,
created_user_agent text
);
--
-- Name: mcp_upstream_tokens; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.mcp_upstream_tokens (
id uuid DEFAULT gen_random_uuid() NOT NULL,
connection_id uuid NOT NULL,
access_token_ciphertext bytea NOT NULL,
refresh_token_ciphertext bytea,
access_token_expires_at timestamp with time zone,
scope text,
created_at timestamp with time zone DEFAULT now() NOT NULL,
superseded_at timestamp with time zone
);
--
-- Name: oauth_connection_flows; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.oauth_connection_flows (
id text NOT NULL,
org_id uuid NOT NULL,
identity_id uuid NOT NULL,
actor_identity_id uuid NOT NULL,
provider_key text NOT NULL,
byoc_credential_id uuid,
scopes text[] DEFAULT '{}'::text[] NOT NULL,
pkce_code_verifier text,
upstream_authorize_url text NOT NULL,
expires_at timestamp with time zone NOT NULL,
consumed_at timestamp with time zone,
created_at timestamp with time zone DEFAULT now() NOT NULL,
created_ip text,
created_user_agent text,
return_url text,
upgrade_connection_id uuid,
service_instance_id uuid
);
--
-- Name: oauth_handoff_codes; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.oauth_handoff_codes (
code text NOT NULL,
jwt text NOT NULL,
origin text NOT NULL,
next_path text,
created_at timestamp with time zone DEFAULT now() NOT NULL,
expires_at timestamp with time zone NOT NULL,
consumed_at timestamp with time zone
);
--
-- Name: oauth_mcp_clients; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.oauth_mcp_clients (
id uuid DEFAULT gen_random_uuid() NOT NULL,
client_id text NOT NULL,
client_name text,
redirect_uris text[] NOT NULL,
software_id text,
software_version text,
created_at timestamp with time zone DEFAULT now() NOT NULL,
last_seen_at timestamp with time zone,
created_ip text,
created_user_agent text,
is_revoked boolean DEFAULT false NOT NULL,
capabilities jsonb,
client_info jsonb,
protocol_version text,
last_session_id uuid
);
--
-- Name: oauth_preview_origins; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.oauth_preview_origins (
preview_id uuid NOT NULL,
origin text NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
expires_at timestamp with time zone NOT NULL,
nonce text DEFAULT ''::text NOT NULL,
pkce_verifier text,
org_slug text,
next_path text
);
--
-- Name: oauth_providers; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.oauth_providers (
key text NOT NULL,
display_name text NOT NULL,
authorization_endpoint text NOT NULL,
token_endpoint text NOT NULL,
revocation_endpoint text,
userinfo_endpoint text,
client_id_pattern text,
supports_pkce boolean DEFAULT false NOT NULL,
supports_refresh boolean DEFAULT true NOT NULL,
extra_auth_params jsonb DEFAULT '{}'::jsonb NOT NULL,
is_builtin boolean DEFAULT true NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
token_auth_method text DEFAULT 'client_secret_post'::text NOT NULL,
issuer_url text,
jwks_uri text,
default_identity_scopes text[] DEFAULT '{}'::text[] NOT NULL
);
--
-- Name: org_idp_configs; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.org_idp_configs (
id uuid DEFAULT gen_random_uuid() NOT NULL,
org_id uuid NOT NULL,
provider_key text NOT NULL,
encrypted_client_id bytea,
encrypted_client_secret bytea,
enabled boolean DEFAULT true NOT NULL,
allowed_email_domains text[] DEFAULT '{}'::text[] NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
is_default boolean DEFAULT false NOT NULL,
CONSTRAINT org_idp_configs_creds_both_or_neither CHECK ((((encrypted_client_id IS NULL) AND (encrypted_client_secret IS NULL)) OR ((encrypted_client_id IS NOT NULL) AND (encrypted_client_secret IS NOT NULL))))
);
--
-- Name: org_invites; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.org_invites (
id uuid DEFAULT gen_random_uuid() NOT NULL,
org_id uuid NOT NULL,
email text NOT NULL,
role text NOT NULL,
invited_by uuid,
created_at timestamp with time zone DEFAULT now() NOT NULL,
accepted_at timestamp with time zone,
accepted_by_user_id uuid,
CONSTRAINT org_invites_email_lower CHECK ((email = lower(email))),
CONSTRAINT org_invites_role_check CHECK ((role = ANY (ARRAY['admin'::text, 'member'::text])))
);
--
-- Name: org_subscriptions; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.org_subscriptions (
org_id uuid NOT NULL,
stripe_subscription_id text NOT NULL,
stripe_customer_id text NOT NULL,
plan text DEFAULT 'team'::text NOT NULL,
seats integer DEFAULT 2 NOT NULL,
status text NOT NULL,
currency text NOT NULL,
current_period_start timestamp with time zone,
current_period_end timestamp with time zone,
cancel_at_period_end boolean DEFAULT false NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL
);
--
-- Name: orgs; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.orgs (
id uuid DEFAULT gen_random_uuid() NOT NULL,
name text NOT NULL,
slug text NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
subagent_idle_timeout_secs integer DEFAULT 14400 NOT NULL,
subagent_archive_retention_days integer DEFAULT 30 NOT NULL,
approval_auto_bubble_secs integer DEFAULT 300 NOT NULL,
allow_user_templates boolean DEFAULT false NOT NULL,
global_templates_enabled boolean DEFAULT true NOT NULL,
allow_unsigned_secret_provide boolean DEFAULT true NOT NULL,
is_personal boolean DEFAULT false NOT NULL,
plan text DEFAULT 'standard'::text NOT NULL,
default_deferred_execution boolean DEFAULT false NOT NULL,
allow_overslash_managed_signin boolean DEFAULT false NOT NULL,
creator_user_id uuid,
audit_response_body_mode text DEFAULT 'off'::text NOT NULL,
CONSTRAINT orgs_approval_auto_bubble_secs_check CHECK ((approval_auto_bubble_secs >= 0)),
CONSTRAINT orgs_audit_response_body_mode_check CHECK ((audit_response_body_mode = ANY (ARRAY['off'::text, 'errors_only'::text, 'all'::text]))),
CONSTRAINT orgs_plan_check CHECK ((plan = ANY (ARRAY['standard'::text, 'free_unlimited'::text])))
);
--
-- Name: pending_checkouts; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.pending_checkouts (
id text NOT NULL,
user_id uuid NOT NULL,
org_name text NOT NULL,
org_slug text NOT NULL,
seats integer NOT NULL,
currency text NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
expires_at timestamp with time zone DEFAULT (now() + '02:00:00'::interval) NOT NULL,
fulfilled_org_id uuid
);
--
-- Name: pending_mcp_elicitations; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.pending_mcp_elicitations (
elicit_id text NOT NULL,
session_id uuid NOT NULL,
agent_identity_id uuid NOT NULL,
approval_id uuid NOT NULL,
status text DEFAULT 'pending'::text NOT NULL,
final_response jsonb,
created_at timestamp with time zone DEFAULT now() NOT NULL,
completed_at timestamp with time zone
);
--
-- Name: permission_rules; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.permission_rules (
id uuid DEFAULT gen_random_uuid() NOT NULL,
org_id uuid NOT NULL,
identity_id uuid NOT NULL,
action_pattern text NOT NULL,
effect text DEFAULT 'allow'::text NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
expires_at timestamp with time zone,
CONSTRAINT permission_rules_effect_check CHECK ((effect = ANY (ARRAY['allow'::text, 'deny'::text])))
);
--
-- Name: rate_limits; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.rate_limits (
id uuid DEFAULT gen_random_uuid() NOT NULL,
org_id uuid NOT NULL,
identity_id uuid,
group_id uuid,
scope text NOT NULL,
max_requests integer DEFAULT 1000 NOT NULL,
window_seconds integer DEFAULT 60 NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT rate_limits_scope_check CHECK ((scope = ANY (ARRAY['org'::text, 'group'::text, 'user'::text, 'identity_cap'::text])))
);
--
-- Name: secret_requests; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.secret_requests (
id text NOT NULL,
org_id uuid NOT NULL,
identity_id uuid NOT NULL,
secret_name text NOT NULL,
requested_by uuid NOT NULL,
reason text,
token_hash bytea NOT NULL,
expires_at timestamp with time zone NOT NULL,
fulfilled_at timestamp with time zone,
created_at timestamp with time zone DEFAULT now() NOT NULL,
require_user_session boolean DEFAULT false NOT NULL
);
--
-- Name: secret_versions; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.secret_versions (
id uuid DEFAULT gen_random_uuid() NOT NULL,
secret_id uuid NOT NULL,
version integer NOT NULL,
encrypted_value bytea NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
created_by uuid,
provisioned_by_user_id uuid
);
--
-- Name: secrets; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.secrets (
id uuid DEFAULT gen_random_uuid() NOT NULL,
org_id uuid NOT NULL,
name text NOT NULL,
current_version integer DEFAULT 1 NOT NULL,
deleted_at timestamp with time zone,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
owner_identity_id uuid
);
--
-- Name: service_action_embeddings; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.service_action_embeddings (
id uuid DEFAULT gen_random_uuid() NOT NULL,
tier text NOT NULL,
org_id uuid,
owner_identity_id uuid,
template_key text NOT NULL,
action_key text NOT NULL,
source_text text NOT NULL,
embedding public.vector(384) NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT service_action_embeddings_tier_check CHECK ((tier = ANY (ARRAY['global'::text, 'org'::text, 'user'::text])))
);
--
-- Name: service_instances; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.service_instances (
id uuid DEFAULT gen_random_uuid() NOT NULL,
org_id uuid NOT NULL,
owner_identity_id uuid,
name text NOT NULL,
template_source text NOT NULL,
template_key text NOT NULL,
template_id uuid,
connection_id uuid,
secret_name text,
status text DEFAULT 'active'::text NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
is_system boolean DEFAULT false NOT NULL,
url text,
CONSTRAINT service_instances_status_check CHECK ((status = ANY (ARRAY['draft'::text, 'active'::text, 'archived'::text]))),
CONSTRAINT service_instances_template_source_check CHECK ((template_source = ANY (ARRAY['global'::text, 'org'::text, 'user'::text])))
);
--
-- Name: service_templates; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.service_templates (
id uuid DEFAULT gen_random_uuid() NOT NULL,
org_id uuid NOT NULL,
owner_identity_id uuid,
key text NOT NULL,
display_name text NOT NULL,
description text DEFAULT ''::text NOT NULL,
category text DEFAULT ''::text NOT NULL,
hosts text[] DEFAULT '{}'::text[] NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
openapi jsonb NOT NULL,
status text DEFAULT 'active'::text NOT NULL,
CONSTRAINT service_templates_status_check CHECK ((status = ANY (ARRAY['draft'::text, 'active'::text])))
);
--
-- Name: user_org_memberships; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.user_org_memberships (
user_id uuid NOT NULL,
org_id uuid NOT NULL,
role text NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT user_org_memberships_role_check CHECK ((role = ANY (ARRAY['admin'::text, 'member'::text])))
);
--
-- Name: users; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.users (
id uuid DEFAULT gen_random_uuid() NOT NULL,
email text,
display_name text,
overslash_idp_provider text,
overslash_idp_subject text,
personal_org_id uuid,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
stripe_customer_id text,
is_instance_admin boolean DEFAULT false NOT NULL,
welcome_email_sent_at timestamp with time zone,
welcome_emails_unsubscribed_at timestamp with time zone,
webhook_digest_unsubscribed_at timestamp with time zone,
CONSTRAINT users_instance_admin_requires_overslash_idp CHECK (((NOT is_instance_admin) OR (overslash_idp_provider IS NOT NULL)))
);
--
-- Name: webhook_deliveries; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.webhook_deliveries (
id uuid DEFAULT gen_random_uuid() NOT NULL,
subscription_id uuid NOT NULL,
event text NOT NULL,
payload jsonb NOT NULL,
status_code integer,
response_body text,
attempts integer DEFAULT 0 NOT NULL,
next_retry_at timestamp with time zone,
delivered_at timestamp with time zone,
created_at timestamp with time zone DEFAULT now() NOT NULL
);
--
-- Name: webhook_digest_runs; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.webhook_digest_runs (
org_id uuid NOT NULL,
run_date date NOT NULL,
sent_at timestamp with time zone DEFAULT now() NOT NULL
);
--
-- Name: webhook_subscriptions; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.webhook_subscriptions (
id uuid DEFAULT gen_random_uuid() NOT NULL,
org_id uuid NOT NULL,
url text NOT NULL,
events text[] NOT NULL,
secret text NOT NULL,
active boolean DEFAULT true NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL
);
--
-- Name: api_keys api_keys_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.api_keys
ADD CONSTRAINT api_keys_pkey PRIMARY KEY (id);
--
-- Name: approvals approvals_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.approvals
ADD CONSTRAINT approvals_pkey PRIMARY KEY (id);
--
-- Name: approvals approvals_token_key; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.approvals
ADD CONSTRAINT approvals_token_key UNIQUE (token);
--
-- Name: audit_log audit_log_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.audit_log
ADD CONSTRAINT audit_log_pkey PRIMARY KEY (id);
--
-- Name: billing_email_log billing_email_log_event_kind_unique; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.billing_email_log
ADD CONSTRAINT billing_email_log_event_kind_unique UNIQUE (stripe_event_id, kind);
--
-- Name: billing_email_log billing_email_log_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.billing_email_log
ADD CONSTRAINT billing_email_log_pkey PRIMARY KEY (id);
--
-- Name: byoc_credentials byoc_credentials_org_id_identity_id_provider_key_key; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.byoc_credentials
ADD CONSTRAINT byoc_credentials_org_id_identity_id_provider_key_key UNIQUE (org_id, identity_id, provider_key);
--
-- Name: byoc_credentials byoc_credentials_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.byoc_credentials
ADD CONSTRAINT byoc_credentials_pkey PRIMARY KEY (id);
--
-- Name: connections connections_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.connections
ADD CONSTRAINT connections_pkey PRIMARY KEY (id);
--
-- Name: email_unsubscribe_tokens email_unsubscribe_tokens_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.email_unsubscribe_tokens
ADD CONSTRAINT email_unsubscribe_tokens_pkey PRIMARY KEY (token);
--
-- Name: enabled_global_templates enabled_global_templates_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.enabled_global_templates
ADD CONSTRAINT enabled_global_templates_pkey PRIMARY KEY (org_id, template_key);
--
-- Name: executions executions_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.executions
ADD CONSTRAINT executions_pkey PRIMARY KEY (id);
--
-- Name: group_grants group_grants_group_id_service_instance_id_key; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.group_grants
ADD CONSTRAINT group_grants_group_id_service_instance_id_key UNIQUE (group_id, service_instance_id);
--
-- Name: group_grants group_grants_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.group_grants
ADD CONSTRAINT group_grants_pkey PRIMARY KEY (id);
--
-- Name: groups groups_org_id_name_key; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.groups
ADD CONSTRAINT groups_org_id_name_key UNIQUE (org_id, name);
--
-- Name: groups groups_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.groups
ADD CONSTRAINT groups_pkey PRIMARY KEY (id);
--
-- Name: identities identities_org_id_external_id_key; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.identities
ADD CONSTRAINT identities_org_id_external_id_key UNIQUE (org_id, external_id);
--
-- Name: identities identities_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.identities
ADD CONSTRAINT identities_pkey PRIMARY KEY (id);
--
-- Name: identity_groups identity_groups_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.identity_groups
ADD CONSTRAINT identity_groups_pkey PRIMARY KEY (identity_id, group_id);
--
-- Name: mcp_client_agent_bindings mcp_client_agent_bindings_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.mcp_client_agent_bindings
ADD CONSTRAINT mcp_client_agent_bindings_pkey PRIMARY KEY (id);
--
-- Name: mcp_client_agent_bindings mcp_client_agent_bindings_user_identity_id_client_id_key; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.mcp_client_agent_bindings
ADD CONSTRAINT mcp_client_agent_bindings_user_identity_id_client_id_key UNIQUE (user_identity_id, client_id);
--
-- Name: mcp_refresh_tokens mcp_refresh_tokens_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.mcp_refresh_tokens
ADD CONSTRAINT mcp_refresh_tokens_pkey PRIMARY KEY (id);
--
-- Name: mcp_upstream_connections mcp_upstream_connections_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.mcp_upstream_connections
ADD CONSTRAINT mcp_upstream_connections_pkey PRIMARY KEY (id);