feat: backup + restore

This commit is contained in:
Vasily Zubarev
2025-03-28 23:36:27 +01:00
parent 61da617f68
commit 54a892ddb0
11 changed files with 340 additions and 63 deletions

46
models/backups.ts Normal file
View File

@@ -0,0 +1,46 @@
import { prisma } from "@/lib/db"
type ModelEntry = {
filename: string
model: any
idField: string
}
// Ordering is important here
export const MODEL_BACKUP: ModelEntry[] = [
{
filename: "settings.json",
model: prisma.setting,
idField: "code",
},
{
filename: "currencies.json",
model: prisma.currency,
idField: "code",
},
{
filename: "categories.json",
model: prisma.category,
idField: "code",
},
{
filename: "projects.json",
model: prisma.project,
idField: "code",
},
{
filename: "fields.json",
model: prisma.field,
idField: "code",
},
{
filename: "files.json",
model: prisma.file,
idField: "id",
},
{
filename: "transactions.json",
model: prisma.transaction,
idField: "id",
},
]

View File

@@ -16,7 +16,7 @@ export type ExportImportFieldSettings = {
import?: (value: any) => Promise<any>
}
export const exportImportFieldsMapping: Record<string, ExportImportFieldSettings> = {
export const EXPORT_AND_IMPORT_FIELD_MAP: Record<string, ExportImportFieldSettings> = {
name: {
code: "name",
type: "string",