chore: scaffold Next.js + Prisma schema + dev MariaDB

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
YugonitoandClaude Opus 5.5 committed 2026-10-27 17:57:05 +01:00
1 parent c4cee91ed7
commit 8d41c2fffe
27 files changed
+9616

No files matched your search

@@ -0,0 +1,210 @@
-- CreateTable
CREATE TABLE `User` (
`id` VARCHAR(191) NOT NULL,
`firstName` VARCHAR(191) NOT NULL,
`login` VARCHAR(191) NOT NULL,
`passwordHash` VARCHAR(191) NOT NULL,
`color` VARCHAR(191) NOT NULL,
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
UNIQUE INDEX `User_login_key`(`login`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `Setting` (
`id` INTEGER NOT NULL DEFAULT 1,
`defaultSplit` JSON NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `Category` (
`id` VARCHAR(191) NOT NULL,
`name` VARCHAR(191) NOT NULL,
`emoji` VARCHAR(191) NOT NULL,
`kind` ENUM('INCOME', 'EXPENSE') NOT NULL,
`archived` BOOLEAN NOT NULL DEFAULT false,
`sortOrder` INTEGER NOT NULL DEFAULT 0,
UNIQUE INDEX `Category_name_kind_key`(`name`, `kind`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `Operation` (
`id` VARCHAR(191) NOT NULL,
`kind` ENUM('INCOME', 'EXPENSE') NOT NULL,
`amount` DECIMAL(12, 2) NOT NULL,
`date` DATE NOT NULL,
`label` VARCHAR(191) NOT NULL,
`note` TEXT NULL,
`categoryId` VARCHAR(191) NOT NULL,
`accountUserId` VARCHAR(191) NOT NULL,
`status` ENUM('PLANNED', 'ACTUAL', 'SKIPPED') NOT NULL,
`recurringId` VARCHAR(191) NULL,
`occurrenceDate` DATE NULL,
`allocatedToRecurringId` VARCHAR(191) NULL,
`allocatedToOperationId` VARCHAR(191) NULL,
`allocationMode` ENUM('REDUCE_SHARED', 'BENEFICIARY_ONLY', 'CUSTOM') NULL,
`createdById` VARCHAR(191) NOT NULL,
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`updatedAt` DATETIME(3) NOT NULL,
INDEX `Operation_date_idx`(`date`),
UNIQUE INDEX `Operation_recurringId_occurrenceDate_key`(`recurringId`, `occurrenceDate`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `OperationSplit` (
`operationId` VARCHAR(191) NOT NULL,
`userId` VARCHAR(191) NOT NULL,
`basisPoints` INTEGER NOT NULL,
PRIMARY KEY (`operationId`, `userId`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `Recurring` (
`id` VARCHAR(191) NOT NULL,
`kind` ENUM('INCOME', 'EXPENSE') NOT NULL,
`amount` DECIMAL(12, 2) NOT NULL,
`label` VARCHAR(191) NOT NULL,
`categoryId` VARCHAR(191) NOT NULL,
`accountUserId` VARCHAR(191) NOT NULL,
`frequency` ENUM('MONTHLY', 'QUARTERLY', 'YEARLY') NOT NULL,
`dayOfMonth` INTEGER NOT NULL,
`startDate` DATE NOT NULL,
`endDate` DATE NULL,
`paused` BOOLEAN NOT NULL DEFAULT false,
`loanId` VARCHAR(191) NULL,
`allocatedToRecurringId` VARCHAR(191) NULL,
`allocationMode` ENUM('REDUCE_SHARED', 'BENEFICIARY_ONLY', 'CUSTOM') NULL,
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
UNIQUE INDEX `Recurring_loanId_key`(`loanId`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `RecurringSplit` (
`recurringId` VARCHAR(191) NOT NULL,
`userId` VARCHAR(191) NOT NULL,
`basisPoints` INTEGER NOT NULL,
PRIMARY KEY (`recurringId`, `userId`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `Settlement` (
`id` VARCHAR(191) NOT NULL,
`fromUserId` VARCHAR(191) NOT NULL,
`toUserId` VARCHAR(191) NOT NULL,
`amount` DECIMAL(12, 2) NOT NULL,
`date` DATE NOT NULL,
`note` VARCHAR(191) NULL,
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `Budget` (
`id` VARCHAR(191) NOT NULL,
`categoryId` VARCHAR(191) NOT NULL,
`monthlyAmount` DECIMAL(12, 2) NOT NULL,
`startMonth` CHAR(7) NOT NULL,
`endMonth` CHAR(7) NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `Loan` (
`id` VARCHAR(191) NOT NULL,
`name` VARCHAR(191) NOT NULL,
`lender` VARCHAR(191) NULL,
`principal` DECIMAL(12, 2) NOT NULL,
`annualRate` DECIMAL(6, 3) NOT NULL,
`durationMonths` INTEGER NOT NULL,
`startDate` DATE NOT NULL,
`insuranceMonthly` DECIMAL(12, 2) NOT NULL DEFAULT 0,
`accountUserId` VARCHAR(191) NOT NULL,
`paymentOverride` DECIMAL(12, 2) NULL,
`referenceDate` DATE NULL,
`referenceRemainingCapital` DECIMAL(12, 2) NULL,
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `LoanSplit` (
`loanId` VARCHAR(191) NOT NULL,
`userId` VARCHAR(191) NOT NULL,
`basisPoints` INTEGER NOT NULL,
PRIMARY KEY (`loanId`, `userId`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- AddForeignKey
ALTER TABLE `Operation` ADD CONSTRAINT `Operation_categoryId_fkey` FOREIGN KEY (`categoryId`) REFERENCES `Category`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Operation` ADD CONSTRAINT `Operation_accountUserId_fkey` FOREIGN KEY (`accountUserId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Operation` ADD CONSTRAINT `Operation_recurringId_fkey` FOREIGN KEY (`recurringId`) REFERENCES `Recurring`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Operation` ADD CONSTRAINT `Operation_allocatedToRecurringId_fkey` FOREIGN KEY (`allocatedToRecurringId`) REFERENCES `Recurring`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Operation` ADD CONSTRAINT `Operation_allocatedToOperationId_fkey` FOREIGN KEY (`allocatedToOperationId`) REFERENCES `Operation`(`id`) ON DELETE SET NULL ON UPDATE NO ACTION;
-- AddForeignKey
ALTER TABLE `Operation` ADD CONSTRAINT `Operation_createdById_fkey` FOREIGN KEY (`createdById`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `OperationSplit` ADD CONSTRAINT `OperationSplit_operationId_fkey` FOREIGN KEY (`operationId`) REFERENCES `Operation`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `OperationSplit` ADD CONSTRAINT `OperationSplit_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Recurring` ADD CONSTRAINT `Recurring_categoryId_fkey` FOREIGN KEY (`categoryId`) REFERENCES `Category`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Recurring` ADD CONSTRAINT `Recurring_accountUserId_fkey` FOREIGN KEY (`accountUserId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Recurring` ADD CONSTRAINT `Recurring_loanId_fkey` FOREIGN KEY (`loanId`) REFERENCES `Loan`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Recurring` ADD CONSTRAINT `Recurring_allocatedToRecurringId_fkey` FOREIGN KEY (`allocatedToRecurringId`) REFERENCES `Recurring`(`id`) ON DELETE SET NULL ON UPDATE NO ACTION;
-- AddForeignKey
ALTER TABLE `RecurringSplit` ADD CONSTRAINT `RecurringSplit_recurringId_fkey` FOREIGN KEY (`recurringId`) REFERENCES `Recurring`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `RecurringSplit` ADD CONSTRAINT `RecurringSplit_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Settlement` ADD CONSTRAINT `Settlement_fromUserId_fkey` FOREIGN KEY (`fromUserId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Settlement` ADD CONSTRAINT `Settlement_toUserId_fkey` FOREIGN KEY (`toUserId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Budget` ADD CONSTRAINT `Budget_categoryId_fkey` FOREIGN KEY (`categoryId`) REFERENCES `Category`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `Loan` ADD CONSTRAINT `Loan_accountUserId_fkey` FOREIGN KEY (`accountUserId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `LoanSplit` ADD CONSTRAINT `LoanSplit_loanId_fkey` FOREIGN KEY (`loanId`) REFERENCES `Loan`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `LoanSplit` ADD CONSTRAINT `LoanSplit_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
+3
View File
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (e.g., Git)
provider = "mysql"
+201
View File
@@ -0,0 +1,201 @@
generator client {
provider = "prisma-client-js"
binaryTargets = ["native", "linux-musl-openssl-3.0.x"]
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
enum OpKind {
INCOME
EXPENSE
}
enum OpStatus {
PLANNED
ACTUAL
SKIPPED
}
enum AllocationMode {
REDUCE_SHARED
BENEFICIARY_ONLY
CUSTOM
}
enum Frequency {
MONTHLY
QUARTERLY
YEARLY
}
model User {
id String @id @default(cuid())
firstName String
login String @unique
passwordHash String
color String
createdAt DateTime @default(now())
accountOperations Operation[] @relation("OperationAccount")
createdOperations Operation[] @relation("OperationCreator")
operationSplits OperationSplit[]
recurrings Recurring[]
recurringSplits RecurringSplit[]
settlementsFrom Settlement[] @relation("SettlementFrom")
settlementsTo Settlement[] @relation("SettlementTo")
loans Loan[]
loanSplits LoanSplit[]
}
model Setting {
id Int @id @default(1)
defaultSplit Json
}
model Category {
id String @id @default(cuid())
name String
emoji String
kind OpKind
archived Boolean @default(false)
sortOrder Int @default(0)
operations Operation[]
recurrings Recurring[]
budgets Budget[]
@@unique([name, kind])
}
model Operation {
id String @id @default(cuid())
kind OpKind
amount Decimal @db.Decimal(12, 2)
date DateTime @db.Date
label String
note String? @db.Text
categoryId String
category Category @relation(fields: [categoryId], references: [id], onDelete: Restrict)
accountUserId String
accountUser User @relation("OperationAccount", fields: [accountUserId], references: [id])
status OpStatus
recurringId String?
recurring Recurring? @relation("RecurringOccurrences", fields: [recurringId], references: [id], onDelete: SetNull)
occurrenceDate DateTime? @db.Date
allocatedToRecurringId String?
allocatedToRecurring Recurring? @relation("OperationAllocatedToRecurring", fields: [allocatedToRecurringId], references: [id], onDelete: SetNull)
allocatedToOperationId String?
allocatedToOperation Operation? @relation("OperationAllocatedToOperation", fields: [allocatedToOperationId], references: [id], onDelete: SetNull, onUpdate: NoAction)
allocatedFrom Operation[] @relation("OperationAllocatedToOperation")
allocationMode AllocationMode?
splits OperationSplit[]
createdById String
createdBy User @relation("OperationCreator", fields: [createdById], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([recurringId, occurrenceDate])
@@index([date])
}
model OperationSplit {
operationId String
operation Operation @relation(fields: [operationId], references: [id], onDelete: Cascade)
userId String
user User @relation(fields: [userId], references: [id])
basisPoints Int
@@id([operationId, userId])
}
model Recurring {
id String @id @default(cuid())
kind OpKind
amount Decimal @db.Decimal(12, 2)
label String
categoryId String
category Category @relation(fields: [categoryId], references: [id], onDelete: Restrict)
accountUserId String
accountUser User @relation(fields: [accountUserId], references: [id])
frequency Frequency
dayOfMonth Int
startDate DateTime @db.Date
endDate DateTime? @db.Date
paused Boolean @default(false)
loanId String? @unique
loan Loan? @relation(fields: [loanId], references: [id], onDelete: Cascade)
allocatedToRecurringId String?
allocatedToRecurring Recurring? @relation("RecurringAllocatedToRecurring", fields: [allocatedToRecurringId], references: [id], onDelete: SetNull, onUpdate: NoAction)
allocatedFrom Recurring[] @relation("RecurringAllocatedToRecurring")
allocationMode AllocationMode?
splits RecurringSplit[]
occurrences Operation[] @relation("RecurringOccurrences")
allocatedOperations Operation[] @relation("OperationAllocatedToRecurring")
createdAt DateTime @default(now())
}
model RecurringSplit {
recurringId String
recurring Recurring @relation(fields: [recurringId], references: [id], onDelete: Cascade)
userId String
user User @relation(fields: [userId], references: [id])
basisPoints Int
@@id([recurringId, userId])
}
model Settlement {
id String @id @default(cuid())
fromUserId String
fromUser User @relation("SettlementFrom", fields: [fromUserId], references: [id])
toUserId String
toUser User @relation("SettlementTo", fields: [toUserId], references: [id])
amount Decimal @db.Decimal(12, 2)
date DateTime @db.Date
note String?
createdAt DateTime @default(now())
}
model Budget {
id String @id @default(cuid())
categoryId String
category Category @relation(fields: [categoryId], references: [id], onDelete: Cascade)
monthlyAmount Decimal @db.Decimal(12, 2)
startMonth String @db.Char(7)
endMonth String? @db.Char(7)
}
model Loan {
id String @id @default(cuid())
name String
lender String?
principal Decimal @db.Decimal(12, 2)
annualRate Decimal @db.Decimal(6, 3)
durationMonths Int
startDate DateTime @db.Date
insuranceMonthly Decimal @default(0) @db.Decimal(12, 2)
accountUserId String
accountUser User @relation(fields: [accountUserId], references: [id])
paymentOverride Decimal? @db.Decimal(12, 2)
referenceDate DateTime? @db.Date
referenceRemainingCapital Decimal? @db.Decimal(12, 2)
splits LoanSplit[]
recurring Recurring?
createdAt DateTime @default(now())
}
model LoanSplit {
loanId String
loan Loan @relation(fields: [loanId], references: [id], onDelete: Cascade)
userId String
user User @relation(fields: [userId], references: [id])
basisPoints Int
@@id([loanId, userId])
}
+45
View File
@@ -0,0 +1,45 @@
import { PrismaClient, type OpKind } from "@prisma/client";
// Catégories de départ (spec §10). Upsert idempotent : relancé à chaque démarrage du conteneur.
const CATEGORIES: { name: string; emoji: string; kind: OpKind }[] = [
{ name: "Logement", emoji: "🏠", kind: "EXPENSE" },
{ name: "Courses", emoji: "🛒", kind: "EXPENSE" },
{ name: "Restaurants", emoji: "🍽", kind: "EXPENSE" },
{ name: "Transport", emoji: "⛽", kind: "EXPENSE" },
{ name: "Auto", emoji: "🚗", kind: "EXPENSE" },
{ name: "Crédit", emoji: "🏦", kind: "EXPENSE" },
{ name: "Énergie", emoji: "⚡", kind: "EXPENSE" },
{ name: "Télécom", emoji: "📱", kind: "EXPENSE" },
{ name: "Abonnements", emoji: "📺", kind: "EXPENSE" },
{ name: "Santé", emoji: "💊", kind: "EXPENSE" },
{ name: "Loisirs", emoji: "🎉", kind: "EXPENSE" },
{ name: "Vacances", emoji: "✈️", kind: "EXPENSE" },
{ name: "Vêtements", emoji: "👕", kind: "EXPENSE" },
{ name: "Cadeaux", emoji: "🎁", kind: "EXPENSE" },
{ name: "Maison", emoji: "🛋", kind: "EXPENSE" },
{ name: "Impôts", emoji: "🧾", kind: "EXPENSE" },
{ name: "Divers", emoji: "📦", kind: "EXPENSE" },
{ name: "Salaire", emoji: "💼", kind: "INCOME" },
{ name: "Remboursement employeur", emoji: "🧾", kind: "INCOME" },
{ name: "IK", emoji: "🚗", kind: "INCOME" },
{ name: "Prime", emoji: "💶", kind: "INCOME" },
{ name: "Autres revenus", emoji: "➕", kind: "INCOME" },
];
export async function seed(prisma: PrismaClient) {
for (const [i, c] of CATEGORIES.entries()) {
await prisma.category.upsert({
where: { name_kind: { name: c.name, kind: c.kind } },
update: {},
create: { ...c, sortOrder: i },
});
}
await prisma.setting.upsert({ where: { id: 1 }, update: {}, create: { id: 1, defaultSplit: {} } });
}
if (require.main === module) {
const prisma = new PrismaClient();
seed(prisma)
.then(() => console.log(`Seed OK (${CATEGORIES.length} catégories)`))
.finally(() => prisma.$disconnect());
}