feat: prisma schema User + SyncRun + seed admin

Sets up Prisma 7 with SQLite (better-sqlite3 adapter), User and SyncRun models, migration, and admin seed account for mathieu.fort@gmail.com.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-06 17:15:54 +02:00
parent 1b60fd79f7
commit 192def9008
9 changed files with 721 additions and 8 deletions
@@ -0,0 +1,26 @@
-- CreateTable
CREATE TABLE "User" (
"id" TEXT NOT NULL PRIMARY KEY,
"email" TEXT NOT NULL,
"name" TEXT NOT NULL,
"password" TEXT NOT NULL,
"role" TEXT NOT NULL DEFAULT 'gestionnaire',
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
);
-- CreateTable
CREATE TABLE "SyncRun" (
"id" TEXT NOT NULL PRIMARY KEY,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"userId" TEXT NOT NULL,
"status" TEXT NOT NULL,
"created" INTEGER NOT NULL DEFAULT 0,
"updated" INTEGER NOT NULL DEFAULT 0,
"deactivated" INTEGER NOT NULL DEFAULT 0,
"errors" INTEGER NOT NULL DEFAULT 0,
"log" TEXT NOT NULL DEFAULT '[]',
CONSTRAINT "SyncRun_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
-- CreateIndex
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
+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 = "sqlite"
+30
View File
@@ -0,0 +1,30 @@
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "sqlite"
}
model User {
id String @id @default(cuid())
email String @unique
name String
password String
role String @default("gestionnaire")
createdAt DateTime @default(now())
syncRuns SyncRun[]
}
model SyncRun {
id String @id @default(cuid())
createdAt DateTime @default(now())
userId String
user User @relation(fields: [userId], references: [id])
status String
created Int @default(0)
updated Int @default(0)
deactivated Int @default(0)
errors Int @default(0)
log String @default("[]")
}
+33
View File
@@ -0,0 +1,33 @@
import { PrismaClient } from '@prisma/client'
import { PrismaBetterSqlite3 } from '@prisma/adapter-better-sqlite3'
import { hash } from 'bcryptjs'
import path from 'path'
const dbUrl = process.env.DATABASE_URL ?? 'file:./data/dev.db'
const dbPath = dbUrl.startsWith('file:')
? path.resolve(process.cwd(), dbUrl.slice('file:'.length))
: dbUrl
const adapter = new PrismaBetterSqlite3({ url: dbPath })
const prisma = new PrismaClient({ adapter } as any)
async function main() {
const password = process.env.SEED_ADMIN_PASSWORD
if (!password) throw new Error('SEED_ADMIN_PASSWORD env var requis')
await prisma.user.upsert({
where: { email: 'mathieu.fort@gmail.com' },
update: {},
create: {
email: 'mathieu.fort@gmail.com',
name: 'Mathieu',
password: await hash(password, 12),
role: 'admin',
},
})
console.log('✅ Compte admin créé : mathieu.fort@gmail.com')
}
main()
.catch(console.error)
.finally(() => prisma.$disconnect())