feat(notifications): add custom notification type and enhance notification schema with custom handling

This commit is contained in:
ChristoferMendes
2025-09-26 17:07:52 -03:00
parent b5bc384664
commit 7f3fe52b53
6 changed files with 13612 additions and 275 deletions
+12
View File
@@ -0,0 +1,12 @@
ALTER TYPE "public"."notificationType" ADD VALUE 'custom';--> statement-breakpoint
CREATE TABLE "custom" (
"customId" text PRIMARY KEY NOT NULL,
"endpoint" text NOT NULL,
"httpMethod" text DEFAULT 'POST' NOT NULL,
"headers" text,
"body" text,
"queryParams" text
);
--> statement-breakpoint
ALTER TABLE "notification" ADD COLUMN "customId" text;--> statement-breakpoint
ALTER TABLE "notification" ADD CONSTRAINT "notification_customId_custom_customId_fk" FOREIGN KEY ("customId") REFERENCES "public"."custom"("customId") ON DELETE cascade ON UPDATE no action;
@@ -0,0 +1,3 @@
ALTER TABLE "custom" DROP COLUMN "httpMethod";--> statement-breakpoint
ALTER TABLE "custom" DROP COLUMN "body";--> statement-breakpoint
ALTER TABLE "custom" DROP COLUMN "queryParams";
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+14
View File
@@ -792,6 +792,20 @@
"when": 1758483520214, "when": 1758483520214,
"tag": "0112_freezing_skrulls", "tag": "0112_freezing_skrulls",
"breakpoints": true "breakpoints": true
},
{
"idx": 113,
"version": "7",
"when": 1758913506515,
"tag": "0113_keen_wasp",
"breakpoints": true
},
{
"idx": 114,
"version": "7",
"when": 1758914193619,
"tag": "0114_smart_shape",
"breakpoints": true
} }
] ]
} }
@@ -12,6 +12,7 @@ export const notificationType = pgEnum("notificationType", [
"email", "email",
"gotify", "gotify",
"ntfy", "ntfy",
"custom",
]); ]);
export const notifications = pgTable("notification", { export const notifications = pgTable("notification", {
@@ -48,6 +49,9 @@ export const notifications = pgTable("notification", {
ntfyId: text("ntfyId").references(() => ntfy.ntfyId, { ntfyId: text("ntfyId").references(() => ntfy.ntfyId, {
onDelete: "cascade", onDelete: "cascade",
}), }),
customId: text("customId").references(() => custom.customId, {
onDelete: "cascade",
}),
organizationId: text("organizationId") organizationId: text("organizationId")
.notNull() .notNull()
.references(() => organization.id, { onDelete: "cascade" }), .references(() => organization.id, { onDelete: "cascade" }),
@@ -116,6 +120,15 @@ export const ntfy = pgTable("ntfy", {
priority: integer("priority").notNull().default(3), priority: integer("priority").notNull().default(3),
}); });
export const custom = pgTable("custom", {
customId: text("customId")
.notNull()
.primaryKey()
.$defaultFn(() => nanoid()),
endpoint: text("endpoint").notNull(),
headers: text("headers"), // JSON string
});
export const notificationsRelations = relations(notifications, ({ one }) => ({ export const notificationsRelations = relations(notifications, ({ one }) => ({
slack: one(slack, { slack: one(slack, {
fields: [notifications.slackId], fields: [notifications.slackId],
@@ -141,6 +154,10 @@ export const notificationsRelations = relations(notifications, ({ one }) => ({
fields: [notifications.ntfyId], fields: [notifications.ntfyId],
references: [ntfy.ntfyId], references: [ntfy.ntfyId],
}), }),
custom: one(custom, {
fields: [notifications.customId],
references: [custom.customId],
}),
organization: one(organization, { organization: one(organization, {
fields: [notifications.organizationId], fields: [notifications.organizationId],
references: [organization.id], references: [organization.id],
@@ -339,6 +356,32 @@ export const apiFindOneNotification = notificationsSchema
}) })
.required(); .required();
export const apiCreateCustom = notificationsSchema
.pick({
appBuildError: true,
databaseBackup: true,
dokployRestart: true,
name: true,
appDeploy: true,
dockerCleanup: true,
serverThreshold: true,
})
.extend({
endpoint: z.string().min(1),
headers: z.string().optional(),
});
export const apiUpdateCustom = apiCreateCustom.partial().extend({
notificationId: z.string().min(1),
customId: z.string().min(1),
organizationId: z.string().optional(),
});
export const apiTestCustomConnection = z.object({
endpoint: z.string().min(1),
headers: z.string().optional(),
});
export const apiSendTest = notificationsSchema export const apiSendTest = notificationsSchema
.extend({ .extend({
botToken: z.string(), botToken: z.string(),
@@ -356,5 +399,7 @@ export const apiSendTest = notificationsSchema
appToken: z.string(), appToken: z.string(),
accessToken: z.string(), accessToken: z.string(),
priority: z.number(), priority: z.number(),
endpoint: z.string(),
headers: z.string(),
}) })
.partial(); .partial();