2025-11-23 17:13:07 +01:00
|
|
|
import {pgTable, text, uuid} from "drizzle-orm/pg-core";
|
|
|
|
|
import {relations} from "drizzle-orm";
|
|
|
|
|
import {Project, project} from "./06_project";
|
|
|
|
|
import {createSelectSchema} from "drizzle-zod";
|
|
|
|
|
import {z} from "zod";
|
2025-08-29 15:31:23 +02:00
|
|
|
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";
|
2025-11-23 17:13:07 +01:00
|
|
|
import {NotificationChannel, organizationNotificationChannel} from "@/db/schema/09_notification-channel";
|
2026-01-12 21:16:52 +01:00
|
|
|
import {organizationStorageChannel, StorageChannel} from "@/db/schema/12_storage-channel";
|
2025-05-16 15:54:17 +02:00
|
|
|
|
|
|
|
|
export const organization = pgTable("organization", {
|
|
|
|
|
id: uuid("id").defaultRandom().primaryKey(),
|
|
|
|
|
name: text("name").notNull(),
|
|
|
|
|
slug: text("slug").unique().notNull(),
|
|
|
|
|
logo: text("logo"),
|
|
|
|
|
metadata: text("metadata"),
|
2025-08-29 15:31:23 +02:00
|
|
|
...timestamps
|
2025-05-16 15:54:17 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
2025-11-23 17:13:07 +01:00
|
|
|
export const organizationRelations = relations(organization, ({many}) => ({
|
2025-05-16 15:54:17 +02:00
|
|
|
members: many(member),
|
|
|
|
|
invitations: many(invitation),
|
|
|
|
|
projects: many(project),
|
2025-11-09 16:47:58 +01:00
|
|
|
notificationChannels: many(organizationNotificationChannel),
|
2026-01-12 21:16:52 +01:00
|
|
|
storageChannels: many(organizationStorageChannel),
|
2025-05-16 15:54:17 +02:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const organizationSchema = createSelectSchema(organization);
|
|
|
|
|
export type Organization = z.infer<typeof organizationSchema>;
|
|
|
|
|
|
2025-07-26 14:43:59 +02:00
|
|
|
export type OrganizationWithMembers = Organization & {
|
|
|
|
|
members: OrganizationMember[];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export type MemberWithUser = OrganizationMember & {
|
|
|
|
|
user: User;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export type OrganizationWithMembersAndUsers = Organization & {
|
|
|
|
|
members: MemberWithUser[];
|
|
|
|
|
invitations: OrganizationInvitation[];
|
2025-11-23 17:13:07 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export type OrganizationWith = Organization & {
|
|
|
|
|
user?: User | null;
|
|
|
|
|
members?: MemberWithUser[] | null;
|
|
|
|
|
invitations?: OrganizationInvitation[] | null;
|
|
|
|
|
notificationChannels?: NotificationChannel[] | null;
|
2026-01-12 21:16:52 +01:00
|
|
|
storageChannels?: StorageChannel[] | null;
|
2025-11-23 17:13:07 +01:00
|
|
|
projects?: Project[] | null;
|
|
|
|
|
};
|