update first - 84
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { mkdirSync, readFileSync, rmSync } from 'node:fs';
|
||||
import { dirname, resolve } from 'node:path';
|
||||
import { DatabaseSync } from 'node:sqlite';
|
||||
|
||||
function databasePathFromUrl(url) {
|
||||
if (!url?.startsWith('file:')) {
|
||||
throw new Error('DATABASE_URL must use SQLite file: URL');
|
||||
}
|
||||
const rawPath = url.slice('file:'.length);
|
||||
if (rawPath.startsWith('/')) {
|
||||
return rawPath;
|
||||
}
|
||||
return resolve('prisma', rawPath);
|
||||
}
|
||||
|
||||
const databasePath = databasePathFromUrl(process.env.DATABASE_URL ?? 'file:./dev.db');
|
||||
mkdirSync(dirname(databasePath), { recursive: true });
|
||||
rmSync(databasePath, { force: true });
|
||||
rmSync(`${databasePath}-journal`, { force: true });
|
||||
|
||||
const sql = readFileSync(resolve('prisma/migrations/202606280001_init/migration.sql'), 'utf8');
|
||||
const db = new DatabaseSync(databasePath);
|
||||
db.exec('PRAGMA foreign_keys = ON;');
|
||||
db.exec(sql);
|
||||
db.close();
|
||||
|
||||
console.log(`SQLite schema applied to ${databasePath}`);
|
||||
Reference in New Issue
Block a user