2026-01-13 22:22:01 +01:00
|
|
|
import {boolean, pgTable, uuid} from "drizzle-orm/pg-core";
|
|
|
|
|
import {timestamps} from "@/db/schema/00_common";
|
|
|
|
|
import {relations} from "drizzle-orm";
|
2026-04-10 18:37:35 +02:00
|
|
|
import {database} from "@/db/schema/07_database";
|
2026-01-13 22:22:01 +01:00
|
|
|
import {createSelectSchema} from "drizzle-zod";
|
|
|
|
|
import {z} from "zod";
|
2026-02-08 20:42:42 +01:00
|
|
|
import {StorageChannel, storageChannel} from "@/db/schema/12_storage-channel";
|
2026-01-13 22:22:01 +01:00
|
|
|
|
|
|
|
|
export const storagePolicy = pgTable('storage_policy', {
|
|
|
|
|
id: uuid('id').defaultRandom().primaryKey(),
|
|
|
|
|
storageChannelId: uuid('storage_channel_id')
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => storageChannel.id, {onDelete: 'cascade'}),
|
|
|
|
|
enabled: boolean('enabled').default(true).notNull(),
|
|
|
|
|
databaseId: uuid('database_id')
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => database.id, {onDelete: 'cascade'}),
|
|
|
|
|
...timestamps
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const storagePolicyRelations = relations(storagePolicy, ({one}) => ({
|
|
|
|
|
storageChannel: one(storageChannel, {
|
|
|
|
|
fields: [storagePolicy.storageChannelId],
|
|
|
|
|
references: [storageChannel.id],
|
|
|
|
|
}),
|
|
|
|
|
database: one(database, {
|
|
|
|
|
fields: [storagePolicy.databaseId],
|
|
|
|
|
references: [database.id],
|
|
|
|
|
}),
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
export const storagePolicySchema = createSelectSchema(storagePolicy);
|
|
|
|
|
export type StoragePolicy = z.infer<typeof storagePolicySchema>;
|
2026-02-08 20:42:42 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
export type StoragePolicyWith = StoragePolicy & {
|
|
|
|
|
storageChannel: StorageChannel;
|
|
|
|
|
};
|