1+ CREATE TABLE `address_integration_subscriptions ` (
2+ ` id` text PRIMARY KEY NOT NULL ,
3+ ` organization_id` text NOT NULL ,
4+ ` address_id` text NOT NULL ,
5+ ` integration_id` text NOT NULL ,
6+ ` event_type` text NOT NULL ,
7+ ` enabled` integer DEFAULT true NOT NULL ,
8+ ` created_at` integer DEFAULT (cast(unixepoch(' subsecond' ) * 1000 as integer )) NOT NULL ,
9+ ` updated_at` integer DEFAULT (cast(unixepoch(' subsecond' ) * 1000 as integer )) NOT NULL ,
10+ FOREIGN KEY (` organization_id` ) REFERENCES ` organizations` (` id` ) ON UPDATE no action ON DELETE cascade ,
11+ FOREIGN KEY (` address_id` ) REFERENCES ` email_addresses` (` id` ) ON UPDATE no action ON DELETE cascade ,
12+ FOREIGN KEY (` integration_id` ) REFERENCES ` organization_integrations` (` id` ) ON UPDATE no action ON DELETE cascade
13+ );
14+ -- > statement-breakpoint
15+ CREATE UNIQUE INDEX `address_integration_subscriptions_address_event_uidx ` ON ` address_integration_subscriptions` (` address_id` ,` integration_id` ,` event_type` );-- > statement-breakpoint
16+ CREATE INDEX `address_integration_subscriptions_org_address_event_idx ` ON ` address_integration_subscriptions` (` organization_id` ,` address_id` ,` event_type` );-- > statement-breakpoint
17+ CREATE INDEX `address_integration_subscriptions_integration_event_idx ` ON ` address_integration_subscriptions` (` integration_id` ,` event_type` );-- > statement-breakpoint
18+ CREATE TABLE `integration_delivery_attempts ` (
19+ ` id` text PRIMARY KEY NOT NULL ,
20+ ` dispatch_id` text NOT NULL ,
21+ ` organization_id` text NOT NULL ,
22+ ` integration_id` text NOT NULL ,
23+ ` attempt_number` integer NOT NULL ,
24+ ` outcome` text NOT NULL ,
25+ ` error` text ,
26+ ` error_code` text ,
27+ ` error_status` integer ,
28+ ` error_retry_after_seconds` integer ,
29+ ` started_at` integer DEFAULT (cast(unixepoch(' subsecond' ) * 1000 as integer )) NOT NULL ,
30+ ` completed_at` integer ,
31+ FOREIGN KEY (` dispatch_id` ) REFERENCES ` integration_dispatches` (` id` ) ON UPDATE no action ON DELETE cascade ,
32+ FOREIGN KEY (` organization_id` ) REFERENCES ` organizations` (` id` ) ON UPDATE no action ON DELETE cascade ,
33+ FOREIGN KEY (` integration_id` ) REFERENCES ` organization_integrations` (` id` ) ON UPDATE no action ON DELETE cascade
34+ );
35+ -- > statement-breakpoint
36+ CREATE UNIQUE INDEX `integration_delivery_attempts_dispatch_attempt_uidx ` ON ` integration_delivery_attempts` (` dispatch_id` ,` attempt_number` );-- > statement-breakpoint
37+ CREATE INDEX `integration_delivery_attempts_integration_started_idx ` ON ` integration_delivery_attempts` (` integration_id` ,` started_at` );-- > statement-breakpoint
38+ CREATE TABLE `integration_dispatches ` (
39+ ` id` text PRIMARY KEY NOT NULL ,
40+ ` organization_id` text NOT NULL ,
41+ ` integration_id` text NOT NULL ,
42+ ` subscription_id` text NOT NULL ,
43+ ` provider` text NOT NULL ,
44+ ` event_type` text NOT NULL ,
45+ ` source_email_id` text NOT NULL ,
46+ ` payload_json` text NOT NULL ,
47+ ` idempotency_key` text NOT NULL ,
48+ ` status` text NOT NULL ,
49+ ` attempt_count` integer DEFAULT 0 NOT NULL ,
50+ ` max_attempt_window_ms` integer NOT NULL ,
51+ ` next_attempt_at` integer ,
52+ ` processing_started_at` integer ,
53+ ` delivered_at` integer ,
54+ ` last_error` text ,
55+ ` last_error_code` text ,
56+ ` last_error_status` integer ,
57+ ` last_error_retry_after_seconds` integer ,
58+ ` queue_message_id` text ,
59+ ` created_at` integer DEFAULT (cast(unixepoch(' subsecond' ) * 1000 as integer )) NOT NULL ,
60+ ` updated_at` integer DEFAULT (cast(unixepoch(' subsecond' ) * 1000 as integer )) NOT NULL ,
61+ FOREIGN KEY (` organization_id` ) REFERENCES ` organizations` (` id` ) ON UPDATE no action ON DELETE cascade ,
62+ FOREIGN KEY (` integration_id` ) REFERENCES ` organization_integrations` (` id` ) ON UPDATE no action ON DELETE cascade ,
63+ FOREIGN KEY (` subscription_id` ) REFERENCES ` address_integration_subscriptions` (` id` ) ON UPDATE no action ON DELETE cascade ,
64+ FOREIGN KEY (` source_email_id` ) REFERENCES ` emails` (` id` ) ON UPDATE no action ON DELETE cascade
65+ );
66+ -- > statement-breakpoint
67+ CREATE UNIQUE INDEX `integration_dispatches_idempotency_key_uidx ` ON ` integration_dispatches` (` idempotency_key` );-- > statement-breakpoint
68+ CREATE INDEX `integration_dispatches_integration_status_created_idx ` ON ` integration_dispatches` (` integration_id` ,` status` ,` created_at` );-- > statement-breakpoint
69+ CREATE INDEX `integration_dispatches_org_status_created_idx ` ON ` integration_dispatches` (` organization_id` ,` status` ,` created_at` );-- > statement-breakpoint
70+ CREATE INDEX `integration_dispatches_source_email_idx ` ON ` integration_dispatches` (` source_email_id` );-- > statement-breakpoint
71+ CREATE TABLE `organization_integration_secrets ` (
72+ ` integration_id` text NOT NULL ,
73+ ` version` integer NOT NULL ,
74+ ` encrypted_config_json` text NOT NULL ,
75+ ` created_at` integer DEFAULT (cast(unixepoch(' subsecond' ) * 1000 as integer )) NOT NULL ,
76+ FOREIGN KEY (` integration_id` ) REFERENCES ` organization_integrations` (` id` ) ON UPDATE no action ON DELETE cascade
77+ );
78+ -- > statement-breakpoint
79+ CREATE UNIQUE INDEX `organization_integration_secrets_pk ` ON ` organization_integration_secrets` (` integration_id` ,` version` );-- > statement-breakpoint
80+ CREATE TABLE `organization_integrations ` (
81+ ` id` text PRIMARY KEY NOT NULL ,
82+ ` organization_id` text NOT NULL ,
83+ ` provider` text NOT NULL ,
84+ ` name` text NOT NULL ,
85+ ` status` text NOT NULL ,
86+ ` created_by_user_id` text NOT NULL ,
87+ ` public_config_json` text NOT NULL ,
88+ ` active_secret_version` integer NOT NULL ,
89+ ` last_validated_at` integer ,
90+ ` created_at` integer DEFAULT (cast(unixepoch(' subsecond' ) * 1000 as integer )) NOT NULL ,
91+ ` updated_at` integer DEFAULT (cast(unixepoch(' subsecond' ) * 1000 as integer )) NOT NULL ,
92+ FOREIGN KEY (` organization_id` ) REFERENCES ` organizations` (` id` ) ON UPDATE no action ON DELETE cascade ,
93+ FOREIGN KEY (` created_by_user_id` ) REFERENCES ` users` (` id` ) ON UPDATE no action ON DELETE cascade
94+ );
95+ -- > statement-breakpoint
96+ CREATE INDEX `organization_integrations_org_provider_status_idx ` ON ` organization_integrations` (` organization_id` ,` provider` ,` status` );-- > statement-breakpoint
97+ CREATE UNIQUE INDEX `organization_integrations_org_provider_name_uidx ` ON ` organization_integrations` (` organization_id` ,` provider` ,` name` );-- > statement-breakpoint
98+ CREATE UNIQUE INDEX `organization_integrations_org_provider_config_uidx ` ON ` organization_integrations` (` organization_id` ,` provider` ,` public_config_json` );
0 commit comments