chore: init from v0

This commit is contained in:
Julien Froidefond
2025-11-27 09:51:18 +01:00
commit e9e44916fd
109 changed files with 15966 additions and 0 deletions

101
prisma/schema.prisma Normal file
View File

@@ -0,0 +1,101 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}
model Account {
id String @id @default(cuid())
name String
bankId String
accountNumber String
type String // CHECKING | SAVINGS | CREDIT_CARD | OTHER
folderId String?
balance Float @default(0)
currency String @default("EUR")
lastImport String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
folder Folder? @relation(fields: [folderId], references: [id], onDelete: SetNull)
transactions Transaction[]
@@index([folderId])
}
model Transaction {
id String @id @default(cuid())
accountId String
date String
amount Float
description String
type String // DEBIT | CREDIT
categoryId String?
isReconciled Boolean @default(false)
fitId String // OFX unique transaction ID
memo String?
checkNum String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
account Account @relation(fields: [accountId], references: [id], onDelete: Cascade)
category Category? @relation(fields: [categoryId], references: [id], onDelete: SetNull)
@@unique([accountId, fitId])
@@index([accountId])
@@index([categoryId])
@@index([date])
}
model Folder {
id String @id @default(cuid())
name String
parentId String?
color String
icon String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
parent Folder? @relation("FolderHierarchy", fields: [parentId], references: [id], onDelete: Cascade)
children Folder[] @relation("FolderHierarchy")
accounts Account[]
@@index([parentId])
}
model Category {
id String @id @default(cuid())
name String
color String
icon String
keywords String // JSON array stored as string
parentId String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
parent Category? @relation("CategoryHierarchy", fields: [parentId], references: [id], onDelete: Cascade)
children Category[] @relation("CategoryHierarchy")
transactions Transaction[]
rules CategoryRule[]
@@index([parentId])
}
model CategoryRule {
id String @id @default(cuid())
categoryId String
pattern String
isRegex Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
category Category @relation(fields: [categoryId], references: [id], onDelete: Cascade)
@@index([categoryId])
}

116
prisma/seed.ts Normal file
View File

@@ -0,0 +1,116 @@
import { PrismaClient } from "@prisma/client"
const prisma = new PrismaClient()
const defaultCategories = [
{
name: "Alimentation",
color: "#22c55e",
icon: "shopping-cart",
keywords: ["carrefour", "leclerc", "auchan", "lidl", "supermarche", "boulangerie", "restaurant"],
parentId: null,
},
{
name: "Transport",
color: "#3b82f6",
icon: "car",
keywords: ["sncf", "ratp", "uber", "essence", "total", "parking", "peage"],
parentId: null,
},
{
name: "Logement",
color: "#f59e0b",
icon: "home",
keywords: ["loyer", "edf", "engie", "eau", "assurance habitation"],
parentId: null,
},
{
name: "Loisirs",
color: "#ec4899",
icon: "gamepad",
keywords: ["cinema", "netflix", "spotify", "fnac", "amazon"],
parentId: null,
},
{
name: "Santé",
color: "#ef4444",
icon: "heart",
keywords: ["pharmacie", "medecin", "docteur", "hopital", "mutuelle"],
parentId: null,
},
{
name: "Revenus",
color: "#10b981",
icon: "wallet",
keywords: ["salaire", "virement recu", "remboursement"],
parentId: null,
},
{
name: "Abonnements",
color: "#8b5cf6",
icon: "repeat",
keywords: ["free", "orange", "sfr", "bouygues", "internet", "telephone"],
parentId: null,
},
{
name: "Shopping",
color: "#06b6d4",
icon: "bag",
keywords: ["zara", "h&m", "decathlon", "ikea"],
parentId: null,
},
]
async function main() {
console.log("Seeding database...")
// Create root folder if it doesn't exist
const rootFolder = await prisma.folder.upsert({
where: { id: "folder-root" },
update: {},
create: {
id: "folder-root",
name: "Mes Comptes",
parentId: null,
color: "#6366f1",
icon: "folder",
},
})
console.log("Root folder created:", rootFolder.name)
// Create default categories
for (const category of defaultCategories) {
const existing = await prisma.category.findFirst({
where: {
name: category.name,
parentId: category.parentId,
},
})
if (!existing) {
await prisma.category.create({
data: {
name: category.name,
color: category.color,
icon: category.icon,
keywords: JSON.stringify(category.keywords),
parentId: category.parentId,
},
})
console.log(`Created category: ${category.name}`)
}
}
console.log("Seeding completed!")
}
main()
.catch((e) => {
console.error(e)
process.exit(1)
})
.finally(async () => {
await prisma.$disconnect()
})