mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-12 21:08:46 +00:00
DB에 thumbnail 테이블 추가
This commit is contained in:
31
src/lib/server/db/migrations/1738409340-AddThumbnail.ts
Normal file
31
src/lib/server/db/migrations/1738409340-AddThumbnail.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { Kysely, sql } from "kysely";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export const up = async (db: Kysely<any>) => {
|
||||
// media.ts
|
||||
await db.schema
|
||||
.createTable("thumbnail")
|
||||
.addColumn("id", "integer", (col) => col.primaryKey().generatedAlwaysAsIdentity())
|
||||
.addColumn("directory_id", "integer", (col) =>
|
||||
col.references("directory.id").onDelete("cascade").unique(),
|
||||
)
|
||||
.addColumn("file_id", "integer", (col) =>
|
||||
col.references("file.id").onDelete("cascade").unique(),
|
||||
)
|
||||
.addColumn("category_id", "integer", (col) =>
|
||||
col.references("category.id").onDelete("cascade").unique(),
|
||||
)
|
||||
.addColumn("path", "text", (col) => col.unique().notNull())
|
||||
.addColumn("created_at", "timestamp(3)", (col) => col.notNull())
|
||||
.addColumn("encrypted_content_iv", "text", (col) => col.notNull())
|
||||
.addCheckConstraint(
|
||||
"thumbnail_ck01",
|
||||
sql`(file_id IS NOT NULL)::integer + (directory_id IS NOT NULL)::integer + (category_id IS NOT NULL)::integer = 1`,
|
||||
)
|
||||
.execute();
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export const down = async (db: Kysely<any>) => {
|
||||
await db.schema.dropTable("thumbnail").execute();
|
||||
};
|
||||
@@ -1,7 +1,9 @@
|
||||
import * as Initial1737357000 from "./1737357000-Initial";
|
||||
import * as AddFileCategory1737422340 from "./1737422340-AddFileCategory";
|
||||
import * as AddThumbnail1738409340 from "./1738409340-AddThumbnail";
|
||||
|
||||
export default {
|
||||
"1737357000-Initial": Initial1737357000,
|
||||
"1737422340-AddFileCategory": AddFileCategory1737422340,
|
||||
"1738409340-AddThumbnail": AddThumbnail1738409340,
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@ export * from "./category";
|
||||
export * from "./client";
|
||||
export * from "./file";
|
||||
export * from "./hsk";
|
||||
export * from "./media";
|
||||
export * from "./mek";
|
||||
export * from "./session";
|
||||
export * from "./user";
|
||||
|
||||
17
src/lib/server/db/schema/media.ts
Normal file
17
src/lib/server/db/schema/media.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import type { ColumnType, Generated } from "kysely";
|
||||
|
||||
interface ThumbnailTable {
|
||||
id: Generated<number>;
|
||||
directory_id: number | null;
|
||||
file_id: number | null;
|
||||
category_id: number | null;
|
||||
path: string;
|
||||
created_at: ColumnType<Date, Date, never>;
|
||||
encrypted_content_iv: string; // Base64
|
||||
}
|
||||
|
||||
declare module "./index" {
|
||||
interface Database {
|
||||
thumbnail: ThumbnailTable;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user