fix: use better-sqlite3 adapter in seed.mjs (Prisma 7 requirement)
This commit is contained in:
+12
-5
@@ -1,23 +1,30 @@
|
|||||||
import { PrismaClient } from '@prisma/client'
|
import { PrismaClient } from '@prisma/client'
|
||||||
|
import { PrismaBetterSQLite3 } from '@prisma/adapter-better-sqlite3'
|
||||||
|
import Database from 'better-sqlite3'
|
||||||
import { hash } from 'bcryptjs'
|
import { hash } from 'bcryptjs'
|
||||||
|
|
||||||
const prisma = new PrismaClient()
|
|
||||||
|
|
||||||
const password = process.env.SEED_ADMIN_PASSWORD
|
const password = process.env.SEED_ADMIN_PASSWORD
|
||||||
if (!password) {
|
if (!password) {
|
||||||
console.error('SEED_ADMIN_PASSWORD requis')
|
console.error('SEED_ADMIN_PASSWORD requis')
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const dbUrl = process.env.DATABASE_URL ?? 'file:./data/app.db'
|
||||||
|
const dbPath = dbUrl.replace(/^file:/, '')
|
||||||
|
const db = new Database(dbPath)
|
||||||
|
const adapter = new PrismaBetterSQLite3(db)
|
||||||
|
const prisma = new PrismaClient({ adapter })
|
||||||
|
|
||||||
await prisma.user.upsert({
|
await prisma.user.upsert({
|
||||||
where: { email: 'mathieu.fort@gmail.com' },
|
where: { email: 'mathieu.fort@gmail.com' },
|
||||||
update: {},
|
update: {},
|
||||||
create: {
|
create: {
|
||||||
email: 'mathieu.fort@gmail.com',
|
email: 'mathieu.fort@gmail.com',
|
||||||
name: 'Mathieu',
|
name: 'Mathieu',
|
||||||
password: await hash(password, 12),
|
password: await hash(password, 12),
|
||||||
role: 'admin',
|
role: 'admin',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
console.log('✅ Compte admin créé : mathieu.fort@gmail.com')
|
console.log('✅ Compte admin créé : mathieu.fort@gmail.com')
|
||||||
await prisma.$disconnect()
|
await prisma.$disconnect()
|
||||||
|
db.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user