notifkit 0.1.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.
@@ -0,0 +1,189 @@
1
+ CREATE TYPE "public"."api_key_role" AS ENUM('admin', 'read_only');--> statement-breakpoint
2
+ CREATE TYPE "public"."channel" AS ENUM('email', 'sms', 'push', 'webhook', 'in-app');--> statement-breakpoint
3
+ CREATE TYPE "public"."workflow_status" AS ENUM('pending', 'running', 'completed', 'failed');--> statement-breakpoint
4
+ CREATE TABLE "contact_topic_preferences" (
5
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
6
+ "contact_id" uuid NOT NULL,
7
+ "topic" varchar NOT NULL,
8
+ "enabled" boolean NOT NULL,
9
+ CONSTRAINT "contact_topic_preferences_contact_id_topic_unique" UNIQUE("contact_id","topic")
10
+ );
11
+ --> statement-breakpoint
12
+ CREATE TABLE "delivery_outbox" (
13
+ "task_id" varchar NOT NULL,
14
+ "channel" "channel" NOT NULL,
15
+ "destination" text NOT NULL,
16
+ "provider_message_id" varchar,
17
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
18
+ CONSTRAINT "delivery_outbox_task_id_channel_destination_pk" PRIMARY KEY("task_id","channel","destination")
19
+ );
20
+ --> statement-breakpoint
21
+ CREATE TABLE "message_logs" (
22
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
23
+ "project_id" uuid NOT NULL,
24
+ "task_id" varchar NOT NULL,
25
+ "provider_message_id" varchar,
26
+ "template_id" varchar,
27
+ "workflow_instance_id" uuid,
28
+ "channel" "channel" NOT NULL,
29
+ "attempt" integer DEFAULT 1 NOT NULL,
30
+ "kind" varchar DEFAULT 'attempt' NOT NULL,
31
+ "status" varchar NOT NULL,
32
+ "timestamp" timestamp with time zone DEFAULT now() NOT NULL,
33
+ CONSTRAINT "task_channel_attempt_uidx" UNIQUE("task_id","channel","attempt","kind")
34
+ );
35
+ --> statement-breakpoint
36
+ CREATE TABLE "project_api_keys" (
37
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
38
+ "project_id" uuid NOT NULL,
39
+ "key_hash" varchar NOT NULL,
40
+ "role" "api_key_role" DEFAULT 'admin' NOT NULL,
41
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
42
+ CONSTRAINT "project_api_keys_key_hash_unique" UNIQUE("key_hash")
43
+ );
44
+ --> statement-breakpoint
45
+ CREATE TABLE "projects" (
46
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
47
+ "name" varchar NOT NULL,
48
+ "rate_limit_rpm" integer,
49
+ "throttle_limit" integer,
50
+ "throttle_window_hours" integer,
51
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL
52
+ );
53
+ --> statement-breakpoint
54
+ CREATE TABLE "quiet_hours" (
55
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
56
+ "user_id" uuid,
57
+ "contact_id" uuid,
58
+ "start_time" time NOT NULL,
59
+ "end_time" time NOT NULL,
60
+ CONSTRAINT "check_owner" CHECK (num_nonnulls(user_id, contact_id) = 1)
61
+ );
62
+ --> statement-breakpoint
63
+ CREATE TABLE "scheduled_payloads" (
64
+ "task_id" varchar PRIMARY KEY NOT NULL,
65
+ "payload" jsonb NOT NULL,
66
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL
67
+ );
68
+ --> statement-breakpoint
69
+ CREATE TABLE "templates" (
70
+ "project_id" uuid NOT NULL,
71
+ "id" varchar NOT NULL,
72
+ "channel" "channel" NOT NULL,
73
+ "topics" text[] NOT NULL,
74
+ "content" jsonb NOT NULL,
75
+ "ai_prompts" jsonb,
76
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
77
+ CONSTRAINT "templates_project_id_id_pk" PRIMARY KEY("project_id","id")
78
+ );
79
+ --> statement-breakpoint
80
+ CREATE TABLE "user_channel_preferences" (
81
+ "user_id" uuid NOT NULL,
82
+ "channel" "channel" NOT NULL,
83
+ "enabled" boolean NOT NULL,
84
+ CONSTRAINT "user_channel_preferences_user_id_channel_pk" PRIMARY KEY("user_id","channel")
85
+ );
86
+ --> statement-breakpoint
87
+ CREATE TABLE "user_contacts" (
88
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
89
+ "user_id" uuid NOT NULL,
90
+ "channel" "channel" NOT NULL,
91
+ "target" text NOT NULL,
92
+ "label" text,
93
+ "is_primary" boolean DEFAULT false NOT NULL,
94
+ "enabled" boolean DEFAULT true NOT NULL,
95
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
96
+ CONSTRAINT "user_contacts_user_id_channel_target_unique" UNIQUE("user_id","channel","target")
97
+ );
98
+ --> statement-breakpoint
99
+ CREATE TABLE "user_segments" (
100
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
101
+ "user_id" uuid NOT NULL,
102
+ "segment" varchar NOT NULL,
103
+ CONSTRAINT "user_segments_user_id_segment_unique" UNIQUE("user_id","segment")
104
+ );
105
+ --> statement-breakpoint
106
+ CREATE TABLE "user_topic_preferences" (
107
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
108
+ "user_id" uuid NOT NULL,
109
+ "topic" varchar NOT NULL,
110
+ "enabled" boolean NOT NULL,
111
+ CONSTRAINT "user_topic_preferences_user_id_topic_unique" UNIQUE("user_id","topic")
112
+ );
113
+ --> statement-breakpoint
114
+ CREATE TABLE "users" (
115
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
116
+ "project_id" uuid NOT NULL,
117
+ "external_id" text NOT NULL,
118
+ "attributes" jsonb DEFAULT '{}'::jsonb NOT NULL,
119
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
120
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
121
+ CONSTRAINT "users_project_id_external_id_unique" UNIQUE("project_id","external_id")
122
+ );
123
+ --> statement-breakpoint
124
+ CREATE TABLE "workflow_definitions" (
125
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
126
+ "project_id" uuid NOT NULL,
127
+ "name" varchar NOT NULL,
128
+ "steps" jsonb NOT NULL,
129
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
130
+ CONSTRAINT "workflow_definitions_project_id_name_unique" UNIQUE("project_id","name")
131
+ );
132
+ --> statement-breakpoint
133
+ CREATE TABLE "workflow_instances" (
134
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
135
+ "project_id" uuid NOT NULL,
136
+ "name" varchar NOT NULL,
137
+ "status" "workflow_status" DEFAULT 'pending' NOT NULL,
138
+ "input" jsonb DEFAULT '{}'::jsonb,
139
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
140
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL
141
+ );
142
+ --> statement-breakpoint
143
+ CREATE TABLE "workflow_steps" (
144
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
145
+ "project_id" uuid NOT NULL,
146
+ "instance_id" uuid NOT NULL,
147
+ "step_index" varchar NOT NULL,
148
+ "action" varchar NOT NULL,
149
+ "output" jsonb,
150
+ "error" text,
151
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
152
+ CONSTRAINT "workflow_steps_instance_id_step_index_unique" UNIQUE("instance_id","step_index")
153
+ );
154
+ --> statement-breakpoint
155
+ CREATE TABLE "workflow_waiters" (
156
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
157
+ "project_id" uuid NOT NULL,
158
+ "instance_id" uuid NOT NULL,
159
+ "event_name" varchar NOT NULL,
160
+ "match_criteria" jsonb NOT NULL,
161
+ "expires_at" timestamp with time zone NOT NULL,
162
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL
163
+ );
164
+ --> statement-breakpoint
165
+ ALTER TABLE "contact_topic_preferences" ADD CONSTRAINT "contact_topic_preferences_contact_id_user_contacts_id_fk" FOREIGN KEY ("contact_id") REFERENCES "public"."user_contacts"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
166
+ ALTER TABLE "project_api_keys" ADD CONSTRAINT "project_api_keys_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
167
+ ALTER TABLE "quiet_hours" ADD CONSTRAINT "quiet_hours_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
168
+ ALTER TABLE "quiet_hours" ADD CONSTRAINT "quiet_hours_contact_id_user_contacts_id_fk" FOREIGN KEY ("contact_id") REFERENCES "public"."user_contacts"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
169
+ ALTER TABLE "templates" ADD CONSTRAINT "templates_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
170
+ ALTER TABLE "user_channel_preferences" ADD CONSTRAINT "user_channel_preferences_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
171
+ ALTER TABLE "user_contacts" ADD CONSTRAINT "user_contacts_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
172
+ ALTER TABLE "user_segments" ADD CONSTRAINT "user_segments_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
173
+ ALTER TABLE "user_topic_preferences" ADD CONSTRAINT "user_topic_preferences_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
174
+ ALTER TABLE "workflow_steps" ADD CONSTRAINT "workflow_steps_instance_id_workflow_instances_id_fk" FOREIGN KEY ("instance_id") REFERENCES "public"."workflow_instances"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
175
+ ALTER TABLE "workflow_waiters" ADD CONSTRAINT "workflow_waiters_instance_id_workflow_instances_id_fk" FOREIGN KEY ("instance_id") REFERENCES "public"."workflow_instances"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
176
+ CREATE INDEX "message_logs_project_idx" ON "message_logs" USING btree ("project_id");--> statement-breakpoint
177
+ CREATE INDEX "task_idx" ON "message_logs" USING btree ("task_id");--> statement-breakpoint
178
+ CREATE INDEX "message_logs_project_task_idx" ON "message_logs" USING btree ("project_id","task_id");--> statement-breakpoint
179
+ CREATE INDEX "provider_msg_idx" ON "message_logs" USING btree ("provider_message_id");--> statement-breakpoint
180
+ CREATE INDEX "msg_log_proj_time_idx" ON "message_logs" USING btree ("project_id","timestamp");--> statement-breakpoint
181
+ CREATE INDEX "msg_log_template_idx" ON "message_logs" USING btree ("project_id","template_id");--> statement-breakpoint
182
+ CREATE INDEX "msg_log_workflow_idx" ON "message_logs" USING btree ("project_id","workflow_instance_id");--> statement-breakpoint
183
+ CREATE INDEX "quiet_hours_user_idx" ON "quiet_hours" USING btree ("user_id");--> statement-breakpoint
184
+ CREATE INDEX "segment_idx" ON "user_segments" USING btree ("segment");--> statement-breakpoint
185
+ CREATE INDEX "workflow_name_idx" ON "workflow_instances" USING btree ("name");--> statement-breakpoint
186
+ CREATE INDEX "waiter_event_idx" ON "workflow_waiters" USING btree ("event_name");--> statement-breakpoint
187
+ CREATE INDEX "waiter_instance_idx" ON "workflow_waiters" USING btree ("instance_id");--> statement-breakpoint
188
+ CREATE INDEX "waiter_comp_idx" ON "workflow_waiters" USING btree ("event_name","project_id","expires_at");--> statement-breakpoint
189
+ CREATE INDEX "waiter_match_idx" ON "workflow_waiters" USING gin ("match_criteria");
@@ -0,0 +1,17 @@
1
+ CREATE TABLE "suppressions" (
2
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
3
+ "project_id" uuid NOT NULL,
4
+ "channel" "channel" NOT NULL,
5
+ "target" varchar NOT NULL,
6
+ "reason" varchar NOT NULL,
7
+ "source" varchar,
8
+ "task_id" varchar,
9
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
10
+ CONSTRAINT "suppression_project_channel_target_uidx" UNIQUE("project_id","channel","target")
11
+ );
12
+ --> statement-breakpoint
13
+ ALTER TABLE "message_logs" ADD COLUMN "campaign_id" varchar;--> statement-breakpoint
14
+ ALTER TABLE "message_logs" ADD COLUMN "metadata" jsonb;--> statement-breakpoint
15
+ CREATE INDEX "suppression_project_idx" ON "suppressions" USING btree ("project_id");--> statement-breakpoint
16
+ CREATE INDEX "suppression_lookup_idx" ON "suppressions" USING btree ("project_id","channel","target");--> statement-breakpoint
17
+ CREATE INDEX "msg_log_campaign_idx" ON "message_logs" USING btree ("project_id","campaign_id");