192def9008
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>
34 lines
988 B
TypeScript
34 lines
988 B
TypeScript
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())
|