@devitek/mailsink-cli 0.0.0-stage → 0.3.0
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.
- package/LICENSE +21 -0
- package/README.md +53 -2
- package/dist/bin.mjs +2924 -0
- package/dist/mcp-CN6V5uOE.mjs +98 -0
- package/dist/migrate-yxDoMMKo.mjs +570 -0
- package/dist/migrations/0000_init.sql +330 -0
- package/dist/migrations/0001_fk_indexes_and_simulation_defaults.sql +8 -0
- package/dist/migrations/0002_jobs_failed_at_and_message_indexes.sql +7 -0
- package/dist/migrations/0003_api_log_response_headers.sql +1 -0
- package/dist/migrations/0004_invalid_status_and_url_credentials.sql +47 -0
- package/dist/migrations/meta/0000_snapshot.json +2431 -0
- package/dist/migrations/meta/0001_snapshot.json +2493 -0
- package/dist/migrations/meta/0002_snapshot.json +2520 -0
- package/dist/migrations/meta/0003_snapshot.json +2526 -0
- package/dist/migrations/meta/0004_snapshot.json +2529 -0
- package/dist/migrations/meta/_journal.json +41 -0
- package/package.json +68 -3
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
CREATE TYPE "public"."api_dialect" AS ENUM('native', 'resend', 'brevo', 'admin', 'capture', 'mcp');--> statement-breakpoint
|
|
2
|
+
CREATE TYPE "public"."api_key_scope" AS ENUM('workspace', 'connection');--> statement-breakpoint
|
|
3
|
+
CREATE TYPE "public"."brevo_auth_type" AS ENUM('none', 'bearer', 'basic');--> statement-breakpoint
|
|
4
|
+
CREATE TYPE "public"."connection_kind" AS ENUM('resend', 'brevo', 'smtp');--> statement-breakpoint
|
|
5
|
+
CREATE TYPE "public"."delivery_status" AS ENUM('queued', 'sent', 'delivered', 'deferred', 'soft_bounce', 'hard_bounce', 'complained', 'failed', 'suppressed');--> statement-breakpoint
|
|
6
|
+
CREATE TYPE "public"."event_origin" AS ENUM('simulation', 'api', 'ui', 'mcp');--> statement-breakpoint
|
|
7
|
+
CREATE TYPE "public"."event_type" AS ENUM('accepted', 'sent', 'delivered', 'deferred', 'soft_bounce', 'hard_bounce', 'complained', 'failed', 'suppressed', 'opened', 'clicked');--> statement-breakpoint
|
|
8
|
+
CREATE TYPE "public"."message_source" AS ENUM('native', 'resend', 'brevo', 'smtp');--> statement-breakpoint
|
|
9
|
+
CREATE TYPE "public"."payload_format" AS ENUM('unified', 'resend', 'brevo');--> statement-breakpoint
|
|
10
|
+
CREATE TYPE "public"."recipient_kind" AS ENUM('to', 'cc', 'bcc');--> statement-breakpoint
|
|
11
|
+
CREATE TYPE "public"."replay_mode" AS ENUM('exact', 'resign');--> statement-breakpoint
|
|
12
|
+
CREATE TYPE "public"."smtp_outcome" AS ENUM('accepted', 'rejected', 'auth_failed', 'error');--> statement-breakpoint
|
|
13
|
+
CREATE TYPE "public"."suppression_reason" AS ENUM('hard_bounce', 'complained', 'manual');--> statement-breakpoint
|
|
14
|
+
CREATE TYPE "public"."webhook_delivery_status" AS ENUM('pending', 'retrying', 'succeeded', 'failed');--> statement-breakpoint
|
|
15
|
+
CREATE TYPE "public"."webhook_event" AS ENUM('email.sent', 'email.delivered', 'email.deferred', 'email.soft_bounced', 'email.hard_bounced', 'email.complained', 'email.opened', 'email.clicked', 'email.suppressed', 'email.failed');--> statement-breakpoint
|
|
16
|
+
CREATE TABLE "attachments" (
|
|
17
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
18
|
+
"message_id" text NOT NULL,
|
|
19
|
+
"filename" text,
|
|
20
|
+
"content_type" text NOT NULL,
|
|
21
|
+
"content_id" text,
|
|
22
|
+
"disposition" text NOT NULL,
|
|
23
|
+
"size_bytes" integer NOT NULL,
|
|
24
|
+
"blob_id" text NOT NULL
|
|
25
|
+
);
|
|
26
|
+
--> statement-breakpoint
|
|
27
|
+
CREATE TABLE "blobs" (
|
|
28
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
29
|
+
"workspace_id" text NOT NULL,
|
|
30
|
+
"sha256" text NOT NULL,
|
|
31
|
+
"size_bytes" integer NOT NULL,
|
|
32
|
+
"data" "bytea" NOT NULL,
|
|
33
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
34
|
+
);
|
|
35
|
+
--> statement-breakpoint
|
|
36
|
+
CREATE TABLE "connections" (
|
|
37
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
38
|
+
"workspace_id" text NOT NULL,
|
|
39
|
+
"name" text NOT NULL,
|
|
40
|
+
"kind" "connection_kind" NOT NULL,
|
|
41
|
+
"smtp_username" text,
|
|
42
|
+
"smtp_password_hash" text,
|
|
43
|
+
"retention_seconds" integer,
|
|
44
|
+
"rate_limit" jsonb,
|
|
45
|
+
"simulation" jsonb,
|
|
46
|
+
"disabled_at" timestamp with time zone,
|
|
47
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
48
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
49
|
+
CONSTRAINT "connections_smtp_username_unique" UNIQUE("smtp_username"),
|
|
50
|
+
CONSTRAINT "connections_smtp_creds" CHECK (("connections"."kind" = 'smtp') = ("connections"."smtp_username" is not null))
|
|
51
|
+
);
|
|
52
|
+
--> statement-breakpoint
|
|
53
|
+
CREATE TABLE "message_events" (
|
|
54
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
55
|
+
"workspace_id" text NOT NULL,
|
|
56
|
+
"message_id" text NOT NULL,
|
|
57
|
+
"recipient_email" text,
|
|
58
|
+
"type" "event_type" NOT NULL,
|
|
59
|
+
"origin" "event_origin" NOT NULL,
|
|
60
|
+
"data" jsonb,
|
|
61
|
+
"occurred_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
62
|
+
);
|
|
63
|
+
--> statement-breakpoint
|
|
64
|
+
CREATE TABLE "idempotency_keys" (
|
|
65
|
+
"workspace_id" text NOT NULL,
|
|
66
|
+
"key" text NOT NULL,
|
|
67
|
+
"request_hash" text NOT NULL,
|
|
68
|
+
"response_status" integer NOT NULL,
|
|
69
|
+
"response_body" jsonb NOT NULL,
|
|
70
|
+
"expires_at" timestamp with time zone NOT NULL,
|
|
71
|
+
CONSTRAINT "idempotency_keys_workspace_id_key_pk" PRIMARY KEY("workspace_id","key")
|
|
72
|
+
);
|
|
73
|
+
--> statement-breakpoint
|
|
74
|
+
CREATE TABLE "jobs" (
|
|
75
|
+
"id" bigserial PRIMARY KEY NOT NULL,
|
|
76
|
+
"kind" text NOT NULL,
|
|
77
|
+
"workspace_id" text NOT NULL,
|
|
78
|
+
"payload" jsonb NOT NULL,
|
|
79
|
+
"run_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
80
|
+
"attempts" integer DEFAULT 0 NOT NULL,
|
|
81
|
+
"locked_until" timestamp with time zone,
|
|
82
|
+
"last_error" text
|
|
83
|
+
);
|
|
84
|
+
--> statement-breakpoint
|
|
85
|
+
CREATE TABLE "api_keys" (
|
|
86
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
87
|
+
"workspace_id" text NOT NULL,
|
|
88
|
+
"connection_id" text,
|
|
89
|
+
"scope" "api_key_scope" NOT NULL,
|
|
90
|
+
"name" text,
|
|
91
|
+
"display_prefix" text NOT NULL,
|
|
92
|
+
"hash" text NOT NULL,
|
|
93
|
+
"last_used_at" timestamp with time zone,
|
|
94
|
+
"revoked_at" timestamp with time zone,
|
|
95
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
96
|
+
CONSTRAINT "api_keys_hash_unique" UNIQUE("hash"),
|
|
97
|
+
CONSTRAINT "api_keys_scope" CHECK (("api_keys"."scope" = 'connection') = ("api_keys"."connection_id" is not null))
|
|
98
|
+
);
|
|
99
|
+
--> statement-breakpoint
|
|
100
|
+
CREATE TABLE "api_logs" (
|
|
101
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
102
|
+
"workspace_id" text,
|
|
103
|
+
"connection_id" text,
|
|
104
|
+
"dialect" "api_dialect" NOT NULL,
|
|
105
|
+
"method" text NOT NULL,
|
|
106
|
+
"path" text NOT NULL,
|
|
107
|
+
"status_code" integer NOT NULL,
|
|
108
|
+
"duration_ms" integer NOT NULL,
|
|
109
|
+
"request_headers" jsonb,
|
|
110
|
+
"request_body" jsonb,
|
|
111
|
+
"response_body" jsonb,
|
|
112
|
+
"message_ids" text[],
|
|
113
|
+
"error_code" text,
|
|
114
|
+
"ip" text,
|
|
115
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
116
|
+
);
|
|
117
|
+
--> statement-breakpoint
|
|
118
|
+
CREATE TABLE "smtp_sessions" (
|
|
119
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
120
|
+
"workspace_id" text,
|
|
121
|
+
"connection_id" text,
|
|
122
|
+
"remote_address" text NOT NULL,
|
|
123
|
+
"client_hostname" text,
|
|
124
|
+
"auth_user" text,
|
|
125
|
+
"secure" boolean DEFAULT false NOT NULL,
|
|
126
|
+
"transcript" jsonb NOT NULL,
|
|
127
|
+
"message_ids" text[],
|
|
128
|
+
"outcome" "smtp_outcome" NOT NULL,
|
|
129
|
+
"error" text,
|
|
130
|
+
"started_at" timestamp with time zone NOT NULL,
|
|
131
|
+
"ended_at" timestamp with time zone
|
|
132
|
+
);
|
|
133
|
+
--> statement-breakpoint
|
|
134
|
+
CREATE TABLE "message_recipients" (
|
|
135
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
136
|
+
"message_id" text NOT NULL,
|
|
137
|
+
"workspace_id" text NOT NULL,
|
|
138
|
+
"kind" "recipient_kind" NOT NULL,
|
|
139
|
+
"email" text NOT NULL,
|
|
140
|
+
"name" text,
|
|
141
|
+
"status" "delivery_status" DEFAULT 'queued' NOT NULL,
|
|
142
|
+
"status_reason" text,
|
|
143
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
144
|
+
);
|
|
145
|
+
--> statement-breakpoint
|
|
146
|
+
CREATE TABLE "messages" (
|
|
147
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
148
|
+
"workspace_id" text NOT NULL,
|
|
149
|
+
"connection_id" text,
|
|
150
|
+
"source" "message_source" NOT NULL,
|
|
151
|
+
"provider_message_id" text NOT NULL,
|
|
152
|
+
"from" jsonb NOT NULL,
|
|
153
|
+
"reply_to" jsonb,
|
|
154
|
+
"subject" text DEFAULT '' NOT NULL,
|
|
155
|
+
"html" text,
|
|
156
|
+
"text" text,
|
|
157
|
+
"headers" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
|
158
|
+
"tags" jsonb DEFAULT '[]'::jsonb NOT NULL,
|
|
159
|
+
"metadata" jsonb,
|
|
160
|
+
"template_ref" jsonb,
|
|
161
|
+
"links" jsonb DEFAULT '[]'::jsonb NOT NULL,
|
|
162
|
+
"raw_blob_id" text,
|
|
163
|
+
"size_bytes" integer NOT NULL,
|
|
164
|
+
"status" "delivery_status" DEFAULT 'queued' NOT NULL,
|
|
165
|
+
"simulation" jsonb,
|
|
166
|
+
"idempotency_key" text,
|
|
167
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
168
|
+
"status_updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
169
|
+
);
|
|
170
|
+
--> statement-breakpoint
|
|
171
|
+
CREATE TABLE "overrides" (
|
|
172
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
173
|
+
"workspace_id" text NOT NULL,
|
|
174
|
+
"connection_id" text,
|
|
175
|
+
"config" jsonb NOT NULL,
|
|
176
|
+
"activated_via" "event_origin" NOT NULL,
|
|
177
|
+
"expires_at" timestamp with time zone,
|
|
178
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
179
|
+
"reset_at" timestamp with time zone
|
|
180
|
+
);
|
|
181
|
+
--> statement-breakpoint
|
|
182
|
+
CREATE TABLE "suppressions" (
|
|
183
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
184
|
+
"workspace_id" text NOT NULL,
|
|
185
|
+
"email" text NOT NULL,
|
|
186
|
+
"reason" "suppression_reason" NOT NULL,
|
|
187
|
+
"message_id" text,
|
|
188
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
189
|
+
);
|
|
190
|
+
--> statement-breakpoint
|
|
191
|
+
CREATE TABLE "templates" (
|
|
192
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
193
|
+
"workspace_id" text NOT NULL,
|
|
194
|
+
"external_id" integer NOT NULL,
|
|
195
|
+
"name" text NOT NULL,
|
|
196
|
+
"subject" text NOT NULL,
|
|
197
|
+
"html" text,
|
|
198
|
+
"text" text,
|
|
199
|
+
"sender" jsonb,
|
|
200
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
201
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
202
|
+
);
|
|
203
|
+
--> statement-breakpoint
|
|
204
|
+
CREATE TABLE "webhook_attempts" (
|
|
205
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
206
|
+
"delivery_id" text NOT NULL,
|
|
207
|
+
"attempt_no" integer NOT NULL,
|
|
208
|
+
"request_headers" jsonb NOT NULL,
|
|
209
|
+
"signed_at" integer,
|
|
210
|
+
"response_status" integer,
|
|
211
|
+
"response_body" text,
|
|
212
|
+
"duration_ms" integer NOT NULL,
|
|
213
|
+
"error" text,
|
|
214
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
215
|
+
);
|
|
216
|
+
--> statement-breakpoint
|
|
217
|
+
CREATE TABLE "webhook_deliveries" (
|
|
218
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
219
|
+
"workspace_id" text NOT NULL,
|
|
220
|
+
"endpoint_id" text NOT NULL,
|
|
221
|
+
"event_id" text,
|
|
222
|
+
"message_id" text,
|
|
223
|
+
"payload_format" "payload_format" NOT NULL,
|
|
224
|
+
"canonical_event" "webhook_event" NOT NULL,
|
|
225
|
+
"dialect_event" text NOT NULL,
|
|
226
|
+
"recipient" text,
|
|
227
|
+
"body" text NOT NULL,
|
|
228
|
+
"content_type" text DEFAULT 'application/json' NOT NULL,
|
|
229
|
+
"status" "webhook_delivery_status" DEFAULT 'pending' NOT NULL,
|
|
230
|
+
"attempt_count" integer DEFAULT 0 NOT NULL,
|
|
231
|
+
"next_attempt_at" timestamp with time zone,
|
|
232
|
+
"last_status_code" integer,
|
|
233
|
+
"replay_of" text,
|
|
234
|
+
"replay_mode" "replay_mode",
|
|
235
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
236
|
+
);
|
|
237
|
+
--> statement-breakpoint
|
|
238
|
+
CREATE TABLE "webhook_endpoints" (
|
|
239
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
240
|
+
"numeric_id" integer GENERATED ALWAYS AS IDENTITY (sequence name "webhook_endpoints_numeric_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
|
|
241
|
+
"workspace_id" text NOT NULL,
|
|
242
|
+
"connection_id" text,
|
|
243
|
+
"url" text NOT NULL,
|
|
244
|
+
"payload_format" "payload_format" NOT NULL,
|
|
245
|
+
"events" "webhook_event"[] NOT NULL,
|
|
246
|
+
"secret" text,
|
|
247
|
+
"brevo_auth" "brevo_auth_type" DEFAULT 'none' NOT NULL,
|
|
248
|
+
"custom_headers" jsonb DEFAULT '[]'::jsonb NOT NULL,
|
|
249
|
+
"description" text,
|
|
250
|
+
"enabled" boolean DEFAULT true NOT NULL,
|
|
251
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
252
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
253
|
+
CONSTRAINT "webhook_endpoints_numeric_id_unique" UNIQUE("numeric_id"),
|
|
254
|
+
CONSTRAINT "webhook_secret_required" CHECK ("webhook_endpoints"."payload_format" = 'brevo' or "webhook_endpoints"."secret" is not null)
|
|
255
|
+
);
|
|
256
|
+
--> statement-breakpoint
|
|
257
|
+
CREATE TABLE "workspaces" (
|
|
258
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
259
|
+
"slug" text NOT NULL,
|
|
260
|
+
"name" text NOT NULL,
|
|
261
|
+
"description" text,
|
|
262
|
+
"ephemeral" boolean DEFAULT false NOT NULL,
|
|
263
|
+
"idle_ttl_seconds" integer,
|
|
264
|
+
"last_activity_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
265
|
+
"expires_at" timestamp with time zone,
|
|
266
|
+
"retention_seconds" integer DEFAULT 604800 NOT NULL,
|
|
267
|
+
"max_messages" integer,
|
|
268
|
+
"rate_limit" jsonb,
|
|
269
|
+
"simulation" jsonb DEFAULT '{"rates":{"delivered":100}}'::jsonb NOT NULL,
|
|
270
|
+
"metadata" jsonb,
|
|
271
|
+
"timezone" text DEFAULT 'UTC' NOT NULL,
|
|
272
|
+
"created_via" text NOT NULL,
|
|
273
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
274
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
275
|
+
CONSTRAINT "workspaces_slug_unique" UNIQUE("slug")
|
|
276
|
+
);
|
|
277
|
+
--> statement-breakpoint
|
|
278
|
+
ALTER TABLE "attachments" ADD CONSTRAINT "attachments_message_id_messages_id_fk" FOREIGN KEY ("message_id") REFERENCES "public"."messages"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
279
|
+
ALTER TABLE "attachments" ADD CONSTRAINT "attachments_blob_id_blobs_id_fk" FOREIGN KEY ("blob_id") REFERENCES "public"."blobs"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
280
|
+
ALTER TABLE "blobs" ADD CONSTRAINT "blobs_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
281
|
+
ALTER TABLE "connections" ADD CONSTRAINT "connections_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
282
|
+
ALTER TABLE "message_events" ADD CONSTRAINT "message_events_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
283
|
+
ALTER TABLE "message_events" ADD CONSTRAINT "message_events_message_id_messages_id_fk" FOREIGN KEY ("message_id") REFERENCES "public"."messages"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
284
|
+
ALTER TABLE "idempotency_keys" ADD CONSTRAINT "idempotency_keys_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
285
|
+
ALTER TABLE "jobs" ADD CONSTRAINT "jobs_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
286
|
+
ALTER TABLE "api_keys" ADD CONSTRAINT "api_keys_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
287
|
+
ALTER TABLE "api_keys" ADD CONSTRAINT "api_keys_connection_id_connections_id_fk" FOREIGN KEY ("connection_id") REFERENCES "public"."connections"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
288
|
+
ALTER TABLE "api_logs" ADD CONSTRAINT "api_logs_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
289
|
+
ALTER TABLE "api_logs" ADD CONSTRAINT "api_logs_connection_id_connections_id_fk" FOREIGN KEY ("connection_id") REFERENCES "public"."connections"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
290
|
+
ALTER TABLE "smtp_sessions" ADD CONSTRAINT "smtp_sessions_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
291
|
+
ALTER TABLE "smtp_sessions" ADD CONSTRAINT "smtp_sessions_connection_id_connections_id_fk" FOREIGN KEY ("connection_id") REFERENCES "public"."connections"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
292
|
+
ALTER TABLE "message_recipients" ADD CONSTRAINT "message_recipients_message_id_messages_id_fk" FOREIGN KEY ("message_id") REFERENCES "public"."messages"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
293
|
+
ALTER TABLE "messages" ADD CONSTRAINT "messages_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
294
|
+
ALTER TABLE "messages" ADD CONSTRAINT "messages_connection_id_connections_id_fk" FOREIGN KEY ("connection_id") REFERENCES "public"."connections"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
295
|
+
ALTER TABLE "messages" ADD CONSTRAINT "messages_raw_blob_id_blobs_id_fk" FOREIGN KEY ("raw_blob_id") REFERENCES "public"."blobs"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
296
|
+
ALTER TABLE "overrides" ADD CONSTRAINT "overrides_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
297
|
+
ALTER TABLE "overrides" ADD CONSTRAINT "overrides_connection_id_connections_id_fk" FOREIGN KEY ("connection_id") REFERENCES "public"."connections"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
298
|
+
ALTER TABLE "suppressions" ADD CONSTRAINT "suppressions_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
299
|
+
ALTER TABLE "suppressions" ADD CONSTRAINT "suppressions_message_id_messages_id_fk" FOREIGN KEY ("message_id") REFERENCES "public"."messages"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
300
|
+
ALTER TABLE "templates" ADD CONSTRAINT "templates_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
301
|
+
ALTER TABLE "webhook_attempts" ADD CONSTRAINT "webhook_attempts_delivery_id_webhook_deliveries_id_fk" FOREIGN KEY ("delivery_id") REFERENCES "public"."webhook_deliveries"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
302
|
+
ALTER TABLE "webhook_deliveries" ADD CONSTRAINT "webhook_deliveries_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
303
|
+
ALTER TABLE "webhook_deliveries" ADD CONSTRAINT "webhook_deliveries_endpoint_id_webhook_endpoints_id_fk" FOREIGN KEY ("endpoint_id") REFERENCES "public"."webhook_endpoints"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
304
|
+
ALTER TABLE "webhook_deliveries" ADD CONSTRAINT "webhook_deliveries_event_id_message_events_id_fk" FOREIGN KEY ("event_id") REFERENCES "public"."message_events"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
305
|
+
ALTER TABLE "webhook_deliveries" ADD CONSTRAINT "webhook_deliveries_message_id_messages_id_fk" FOREIGN KEY ("message_id") REFERENCES "public"."messages"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
306
|
+
ALTER TABLE "webhook_endpoints" ADD CONSTRAINT "webhook_endpoints_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
307
|
+
ALTER TABLE "webhook_endpoints" ADD CONSTRAINT "webhook_endpoints_connection_id_connections_id_fk" FOREIGN KEY ("connection_id") REFERENCES "public"."connections"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
308
|
+
CREATE UNIQUE INDEX "blobs_dedup_uq" ON "blobs" USING btree ("workspace_id","sha256");--> statement-breakpoint
|
|
309
|
+
CREATE INDEX "connections_workspace_idx" ON "connections" USING btree ("workspace_id");--> statement-breakpoint
|
|
310
|
+
CREATE INDEX "events_message_idx" ON "message_events" USING btree ("message_id","occurred_at");--> statement-breakpoint
|
|
311
|
+
CREATE INDEX "events_ws_time_idx" ON "message_events" USING btree ("workspace_id","occurred_at");--> statement-breakpoint
|
|
312
|
+
CREATE INDEX "jobs_due_idx" ON "jobs" USING btree ("run_at");--> statement-breakpoint
|
|
313
|
+
CREATE INDEX "api_logs_ws_time_idx" ON "api_logs" USING btree ("workspace_id","created_at" DESC NULLS LAST);--> statement-breakpoint
|
|
314
|
+
CREATE INDEX "smtp_sessions_ws_time_idx" ON "smtp_sessions" USING btree ("workspace_id","started_at" DESC NULLS LAST);--> statement-breakpoint
|
|
315
|
+
CREATE INDEX "recipients_ws_email_idx" ON "message_recipients" USING btree ("workspace_id","email");--> statement-breakpoint
|
|
316
|
+
CREATE INDEX "recipients_message_idx" ON "message_recipients" USING btree ("message_id");--> statement-breakpoint
|
|
317
|
+
CREATE INDEX "messages_ws_created_idx" ON "messages" USING btree ("workspace_id","created_at" DESC NULLS LAST);--> statement-breakpoint
|
|
318
|
+
CREATE INDEX "messages_ws_status_idx" ON "messages" USING btree ("workspace_id","status");--> statement-breakpoint
|
|
319
|
+
CREATE INDEX "messages_ws_connection_idx" ON "messages" USING btree ("workspace_id","connection_id","created_at" DESC NULLS LAST);--> statement-breakpoint
|
|
320
|
+
CREATE INDEX "messages_tags_gin" ON "messages" USING gin ("tags");--> statement-breakpoint
|
|
321
|
+
CREATE UNIQUE INDEX "messages_provider_id_uq" ON "messages" USING btree ("workspace_id","provider_message_id");--> statement-breakpoint
|
|
322
|
+
CREATE UNIQUE INDEX "overrides_active_scope_uq" ON "overrides" USING btree ("workspace_id",coalesce("connection_id", '')) WHERE "overrides"."reset_at" is null;--> statement-breakpoint
|
|
323
|
+
CREATE UNIQUE INDEX "suppressions_ws_email_uq" ON "suppressions" USING btree ("workspace_id","email");--> statement-breakpoint
|
|
324
|
+
CREATE UNIQUE INDEX "templates_external_uq" ON "templates" USING btree ("workspace_id","external_id");--> statement-breakpoint
|
|
325
|
+
CREATE INDEX "deliveries_ws_time_idx" ON "webhook_deliveries" USING btree ("workspace_id","created_at" DESC NULLS LAST);--> statement-breakpoint
|
|
326
|
+
CREATE INDEX "deliveries_message_idx" ON "webhook_deliveries" USING btree ("message_id");--> statement-breakpoint
|
|
327
|
+
CREATE INDEX "deliveries_ws_format_idx" ON "webhook_deliveries" USING btree ("workspace_id","payload_format");--> statement-breakpoint
|
|
328
|
+
CREATE INDEX "webhook_endpoints_scope_idx" ON "webhook_endpoints" USING btree ("workspace_id","connection_id");--> statement-breakpoint
|
|
329
|
+
CREATE INDEX "workspaces_expiry_idx" ON "workspaces" USING btree ("expires_at") WHERE "workspaces"."ephemeral";--> statement-breakpoint
|
|
330
|
+
CREATE INDEX "workspaces_picker_idx" ON "workspaces" USING btree ("ephemeral","name");
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
ALTER TABLE "workspaces" ALTER COLUMN "simulation" SET DEFAULT '{"rates":{"delivered":100},"rules":[],"latency":{"minMs":0,"maxMs":0},"openRate":0,"clickRate":0}'::jsonb;--> statement-breakpoint
|
|
2
|
+
CREATE INDEX "attachments_message_idx" ON "attachments" USING btree ("message_id");--> statement-breakpoint
|
|
3
|
+
CREATE INDEX "attachments_blob_idx" ON "attachments" USING btree ("blob_id");--> statement-breakpoint
|
|
4
|
+
CREATE INDEX "messages_raw_blob_idx" ON "messages" USING btree ("raw_blob_id");--> statement-breakpoint
|
|
5
|
+
CREATE INDEX "attempts_delivery_idx" ON "webhook_attempts" USING btree ("delivery_id");--> statement-breakpoint
|
|
6
|
+
-- Hand-written backfill: 0000 stored `rates` only; complete rows with the contract defaults,
|
|
7
|
+
-- keys already stored win (shallow merge, so a stored `rates` replaces the default one).
|
|
8
|
+
UPDATE "workspaces" SET "simulation" = '{"rates":{"delivered":100},"rules":[],"latency":{"minMs":0,"maxMs":0},"openRate":0,"clickRate":0}'::jsonb || "simulation";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
DROP INDEX "messages_ws_created_idx";--> statement-breakpoint
|
|
2
|
+
ALTER TABLE "jobs" ADD COLUMN "failed_at" timestamp with time zone;--> statement-breakpoint
|
|
3
|
+
CREATE INDEX "messages_search_gin" ON "messages" USING gin (to_tsvector('simple', left("subject" || ' ' || coalesce("text", '') || ' ' ||
|
|
4
|
+
coalesce("html", ''), 100000)));--> statement-breakpoint
|
|
5
|
+
CREATE INDEX "messages_ws_created_idx" ON "messages" USING btree ("workspace_id","created_at","id");--> statement-breakpoint
|
|
6
|
+
-- Hand-written backfill: jobs given up on before this migration start their grace period now.
|
|
7
|
+
UPDATE "jobs" SET "failed_at" = now() WHERE "run_at" = '9999-12-31T00:00:00Z' AND "failed_at" IS NULL;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ALTER TABLE "api_logs" ADD COLUMN "response_headers" jsonb;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
ALTER TYPE "public"."delivery_status" ADD VALUE 'invalid' BEFORE 'suppressed';--> statement-breakpoint
|
|
2
|
+
ALTER TYPE "public"."event_type" ADD VALUE 'invalid' BEFORE 'suppressed';--> statement-breakpoint
|
|
3
|
+
-- Hand-written (#153): webhook_event is recreated instead of `ADD VALUE`, because a value
|
|
4
|
+
-- added to an existing enum cannot be used in the migration transaction, and the backfill
|
|
5
|
+
-- below writes 'email.invalid'.
|
|
6
|
+
ALTER TYPE "public"."webhook_event" RENAME TO "webhook_event_0003";--> statement-breakpoint
|
|
7
|
+
CREATE TYPE "public"."webhook_event" AS ENUM('email.sent', 'email.delivered', 'email.deferred', 'email.soft_bounced', 'email.hard_bounced', 'email.complained', 'email.opened', 'email.clicked', 'email.suppressed', 'email.failed', 'email.invalid');--> statement-breakpoint
|
|
8
|
+
ALTER TABLE "webhook_endpoints" ALTER COLUMN "events" SET DATA TYPE "public"."webhook_event"[] USING "events"::text[]::"public"."webhook_event"[];--> statement-breakpoint
|
|
9
|
+
ALTER TABLE "webhook_deliveries" ALTER COLUMN "canonical_event" SET DATA TYPE "public"."webhook_event" USING "canonical_event"::text::"public"."webhook_event";--> statement-breakpoint
|
|
10
|
+
DROP TYPE "public"."webhook_event_0003";--> statement-breakpoint
|
|
11
|
+
-- Resend emits email.invalid as `email.failed` (D280): a Resend endpoint subscribed to it keeps
|
|
12
|
+
-- receiving every event of that name.
|
|
13
|
+
UPDATE "webhook_endpoints" SET "events" = array_append("events", 'email.invalid')
|
|
14
|
+
WHERE "payload_format" = 'resend' AND 'email.failed' = ANY("events")
|
|
15
|
+
AND NOT 'email.invalid' = ANY("events");--> statement-breakpoint
|
|
16
|
+
-- Credentials written in a brevo endpoint URL before D278 move to brevo_auth basic,
|
|
17
|
+
-- percent-decoded like decodeURIComponent (a part that does not decode is kept as written),
|
|
18
|
+
-- as create and PATCH do now (D281). Other rows keep the send-time fallback.
|
|
19
|
+
CREATE FUNCTION pg_temp.mailsink_percent_decode(value text) RETURNS text LANGUAGE plpgsql AS $$
|
|
20
|
+
BEGIN
|
|
21
|
+
IF value = '' THEN
|
|
22
|
+
RETURN '';
|
|
23
|
+
END IF;
|
|
24
|
+
RETURN (
|
|
25
|
+
SELECT convert_from(string_agg(
|
|
26
|
+
CASE WHEN t.m[1] IS NOT NULL THEN decode(substr(t.m[1], 2), 'hex')
|
|
27
|
+
ELSE convert_to(t.m[2], 'UTF8') END, ''::bytea ORDER BY t.n), 'UTF8')
|
|
28
|
+
FROM regexp_matches(value, '(%[0-9A-Fa-f]{2})|([^%]+|%)', 'g') WITH ORDINALITY AS t(m, n)
|
|
29
|
+
);
|
|
30
|
+
EXCEPTION WHEN OTHERS THEN
|
|
31
|
+
RETURN value;
|
|
32
|
+
END
|
|
33
|
+
$$;--> statement-breakpoint
|
|
34
|
+
WITH "split" AS (
|
|
35
|
+
SELECT "id", regexp_match("url", '^([A-Za-z][A-Za-z0-9+.-]*://)([^/?#]*)@(.*)$') AS "m"
|
|
36
|
+
FROM "webhook_endpoints"
|
|
37
|
+
WHERE "payload_format" = 'brevo' AND "brevo_auth" = 'none'
|
|
38
|
+
AND "url" ~ '^[A-Za-z][A-Za-z0-9+.-]*://[^/?#]*@'
|
|
39
|
+
)
|
|
40
|
+
UPDATE "webhook_endpoints" AS "e" SET
|
|
41
|
+
"url" = "s"."m"[1] || "s"."m"[3],
|
|
42
|
+
"brevo_auth" = 'basic',
|
|
43
|
+
"secret" = pg_temp.mailsink_percent_decode(split_part("s"."m"[2], ':', 1)) || ':' ||
|
|
44
|
+
pg_temp.mailsink_percent_decode(CASE WHEN position(':' in "s"."m"[2]) > 0
|
|
45
|
+
THEN substr("s"."m"[2], position(':' in "s"."m"[2]) + 1) ELSE '' END)
|
|
46
|
+
FROM "split" AS "s" WHERE "e"."id" = "s"."id";--> statement-breakpoint
|
|
47
|
+
DROP FUNCTION pg_temp.mailsink_percent_decode(text);
|