Working on notifier system.

This commit is contained in:
charlesgauthereau
2025-11-09 16:47:58 +01:00
parent 411e09f452
commit 7dfd9f02e8
27 changed files with 2755 additions and 81 deletions
+5 -1
View File
@@ -8,6 +8,8 @@ import * as member from "./schema/05_invitation";
import * as project from "./schema/06_project";
import * as agent from "./schema/08_agent";
import * as database from "./schema/07_database";
import * as notificationChannel from "./schema/09_notification-channel";
import * as organizationNotificationChannel from "./schema/09_notification-channel";
import {Pool} from "pg";
@@ -32,7 +34,9 @@ export const schemas = {
...member,
...project,
...agent,
...database
...database,
...notificationChannel,
...organizationNotificationChannel
};
export const db = drizzle({
+20
View File
@@ -0,0 +1,20 @@
CREATE TYPE "public"."provider_kind" AS ENUM('curl', 'slack', 'smtp', 'webhook');--> statement-breakpoint
CREATE TABLE "notification_channel" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"provider" "provider_kind" NOT NULL,
"name" varchar(255) NOT NULL,
"config" jsonb NOT NULL,
"enabled" boolean DEFAULT false NOT NULL,
"updated_at" timestamp,
"created_at" timestamp DEFAULT now() NOT NULL,
"deleted_at" timestamp
);
--> statement-breakpoint
CREATE TABLE "organization_notification_channels" (
"organization_id" uuid NOT NULL,
"notification_channel_id" uuid NOT NULL,
CONSTRAINT "organization_notification_channels_organization_id_notification_channel_id_unique" UNIQUE("organization_id","notification_channel_id")
);
--> statement-breakpoint
ALTER TABLE "organization_notification_channels" ADD CONSTRAINT "organization_notification_channels_organization_id_organization_id_fk" FOREIGN KEY ("organization_id") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "organization_notification_channels" ADD CONSTRAINT "organization_notification_channels_notification_channel_id_notification_channel_id_fk" FOREIGN KEY ("notification_channel_id") REFERENCES "public"."notification_channel"("id") ON DELETE cascade ON UPDATE no action;
File diff suppressed because it is too large Load Diff
+7
View File
@@ -50,6 +50,13 @@
"when": 1762028639833,
"tag": "0006_moaning_pete_wisdom",
"breakpoints": true
},
{
"idx": 7,
"version": "7",
"when": 1762685571404,
"tag": "0007_last_umar",
"breakpoints": true
}
]
}
+3 -1
View File
@@ -1,4 +1,4 @@
import { pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core";
import { pgTable, text, uuid } from "drizzle-orm/pg-core";
import { relations } from "drizzle-orm";
import { project } from "./06_project";
import { createSelectSchema } from "drizzle-zod";
@@ -7,6 +7,7 @@ import {invitation, OrganizationInvitation} from "@/db/schema/05_invitation";
import {member, OrganizationMember} from "@/db/schema/04_member";
import {User} from "@/db/schema/02_user";
import {timestamps} from "@/db/schema/00_common";
import {organizationNotificationChannel} from "@/db/schema/09_notification-channel";
export const organization = pgTable("organization", {
id: uuid("id").defaultRandom().primaryKey(),
@@ -22,6 +23,7 @@ export const organizationRelations = relations(organization, ({ many }) => ({
members: many(member),
invitations: many(invitation),
projects: many(project),
notificationChannels: many(organizationNotificationChannel),
}));
+50
View File
@@ -0,0 +1,50 @@
import {boolean, jsonb, pgEnum, pgTable, primaryKey, unique, uuid, varchar} from "drizzle-orm/pg-core";
import {timestamps} from "@/db/schema/00_common";
import {organization} from "@/db/schema/03_organization";
import {relations} from "drizzle-orm";
import {createSelectSchema} from "drizzle-zod";
import {z} from "zod";
export const providerKindEnum = pgEnum('provider_kind', ['curl', 'slack', 'smtp', 'webhook']);
export const notificationChannel = pgTable('notification_channel', {
id: uuid("id").defaultRandom().primaryKey(),
provider: providerKindEnum('provider').notNull(),
name: varchar('name', {length: 255}).notNull(),
config: jsonb('config').notNull(),
enabled: boolean('enabled').default(false).notNull(),
...timestamps
});
export const organizationNotificationChannel = pgTable(
"organization_notification_channels",
{
organizationId: uuid('organization_id')
.notNull()
.references(() => organization.id, {onDelete: 'cascade'}),
notificationChannelId: uuid('notification_channel_id')
.notNull()
.references(() => notificationChannel.id, {onDelete: 'cascade'}),
},
(t) => [unique().on(t.organizationId, t.notificationChannelId)]
);
export const notificationChannelRelations = relations(notificationChannel, ({many}) => ({
organizations: many(organizationNotificationChannel),
}));
export const organizationNotificationChannelRelations = relations(organizationNotificationChannel, ({one}) => ({
organization: one(organization, {
fields: [organizationNotificationChannel.organizationId],
references: [organization.id],
}),
notificationChannel: one(notificationChannel, {
fields: [organizationNotificationChannel.notificationChannelId],
references: [notificationChannel.id],
}),
}));
export const notificationChannelSchema = createSelectSchema(notificationChannel);
export type NotificationChannel = z.infer<typeof notificationChannelSchema>;
+28
View File
@@ -0,0 +1,28 @@
import {desc, eq} from "drizzle-orm";
import {db} from "@/db";
import {
NotificationChannel,
notificationChannel,
organizationNotificationChannel
} from "@/db/schema/09_notification-channel";
export async function getOrganizationChannels(organizationId: string) {
return await db
.select({
id: notificationChannel.id,
name: notificationChannel.name,
provider: notificationChannel.provider,
config: notificationChannel.config,
enabled: notificationChannel.enabled,
updatedAt: notificationChannel.updatedAt,
createdAt: notificationChannel.createdAt,
deletedAt: notificationChannel.deletedAt,
})
.from(organizationNotificationChannel)
.innerJoin(
notificationChannel,
eq(organizationNotificationChannel.notificationChannelId, notificationChannel.id)
)
.orderBy(desc(notificationChannel.createdAt))
.where(eq(organizationNotificationChannel.organizationId, organizationId)) as unknown as NotificationChannel[];
}