카테고리 관련 DB 스키마/코드를 Kysely 기반으로 마이그레이션

This commit is contained in:
static
2025-01-21 10:57:32 +09:00
parent 698d2455ff
commit 2a2d01b50e
8 changed files with 281 additions and 187 deletions

View File

@@ -1,9 +1,5 @@
import type { ColumnType, Generated } from "kysely";
export type Ciphertext = {
ciphertext: string; // Base64
iv: string; // Base64
};
import type { Ciphertext } from "./util";
interface DirectoryTable {
id: Generated<number>;
@@ -45,26 +41,15 @@ interface FileLogTable {
id: Generated<number>;
file_id: number;
timestamp: ColumnType<Date, Date, never>;
action: "create" | "rename";
action: "create" | "rename" | "add-to-category" | "remove-from-category";
new_name: Ciphertext | null;
category_id: number | null;
}
export const fileCategory = sqliteTable(
"file_category",
{
fileId: integer("file_id")
.notNull()
.references(() => file.id, { onDelete: "cascade" }),
categoryId: integer("category_id")
.notNull()
.references(() => category.id, { onDelete: "cascade" }),
},
(t) => ({
pk: primaryKey({
columns: [t.fileId, t.categoryId],
}),
}),
);
interface FileCategoryTable {
file_id: number;
category_id: number;
}
declare module "./index" {
interface Database {
@@ -72,5 +57,6 @@ declare module "./index" {
directory_log: DirectoryLogTable;
file: FileTable;
file_log: FileLogTable;
file_category: FileCategoryTable;
}
}