feat: backend storage

This commit is contained in:
charlesgauthereau
2026-01-12 21:16:52 +01:00
parent f3eedf6f30
commit faaa4033bd
42 changed files with 1623 additions and 968 deletions
+3 -1
View File
@@ -12,6 +12,7 @@ import * as notificationChannel from "./schema/09_notification-channel";
import * as organizationNotificationChannel from "./schema/09_notification-channel";
import * as alertPolicy from "./schema/10_alert-policy";
import * as notificationLog from "./schema/11_notification-log";
import * as storageChannel from "./schema/12_storage-channel";
import {Pool} from "pg";
@@ -40,7 +41,8 @@ export const schemas = {
...notificationChannel,
...organizationNotificationChannel,
...alertPolicy,
...notificationLog
...notificationLog,
...storageChannel
};
export const db = drizzle({
+7
View File
@@ -141,6 +141,13 @@
"when": 1767782077775,
"tag": "0019_overjoyed_butterfly",
"breakpoints": true
},
{
"idx": 20,
"version": "7",
"when": 1768248015695,
"tag": "0020_thankful_sunspot",
"breakpoints": true
}
]
}
+3
View File
@@ -8,6 +8,7 @@ import {member, OrganizationMember} from "@/db/schema/04_member";
import {User} from "@/db/schema/02_user";
import {timestamps} from "@/db/schema/00_common";
import {NotificationChannel, organizationNotificationChannel} from "@/db/schema/09_notification-channel";
import {organizationStorageChannel, StorageChannel} from "@/db/schema/12_storage-channel";
export const organization = pgTable("organization", {
id: uuid("id").defaultRandom().primaryKey(),
@@ -24,6 +25,7 @@ export const organizationRelations = relations(organization, ({many}) => ({
invitations: many(invitation),
projects: many(project),
notificationChannels: many(organizationNotificationChannel),
storageChannels: many(organizationStorageChannel),
}));
@@ -48,5 +50,6 @@ export type OrganizationWith = Organization & {
members?: MemberWithUser[] | null;
invitations?: OrganizationInvitation[] | null;
notificationChannels?: NotificationChannel[] | null;
storageChannels?: StorageChannel[] | null;
projects?: Project[] | null;
};
+58
View File
@@ -0,0 +1,58 @@
import {boolean, jsonb, pgEnum, pgTable, 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 providerStorageKindEnum = pgEnum('provider_storage_kind', ['local', 's3']);
export const storageChannel = pgTable('storage_channel', {
id: uuid("id").defaultRandom().primaryKey(),
provider: providerStorageKindEnum('provider').notNull(),
name: varchar('name', {length: 255}).notNull(),
config: jsonb('config').notNull(),
enabled: boolean('enabled').default(false).notNull(),
...timestamps
});
export const organizationStorageChannel = pgTable(
"organization_storage_channels",
{
organizationId: uuid('organization_id')
.notNull()
.references(() => organization.id, {onDelete: 'cascade'}),
storageChannelId: uuid('storage_channel_id')
.notNull()
.references(() => storageChannel.id, {onDelete: 'cascade'}),
},
(t) => [unique().on(t.organizationId, t.storageChannelId)]
);
export const storageChannelRelations = relations(storageChannel, ({many}) => ({
organizations: many(organizationStorageChannel),
}));
export const organizationStorageChannelRelations = relations(organizationStorageChannel, ({one}) => ({
organization: one(organization, {
fields: [organizationStorageChannel.organizationId],
references: [organization.id],
}),
storageChannel: one(storageChannel, {
fields: [organizationStorageChannel.storageChannelId],
references: [storageChannel.id],
}),
}));
export const storageChannelSchema = createSelectSchema(storageChannel);
export type StorageChannel = z.infer<typeof storageChannelSchema>;
export type StorageChannelWith = StorageChannel & {
organizations: {
organizationId: string;
storageChannelId: string;
}[];
};