Début du projet
This commit is contained in:
commit
e7d4e607f6
23 files changed
+4855
No files matched your search
@@ -0,0 +1,20 @@
|
||||
const Database = require('better-sqlite3');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const dataDir = path.join(__dirname, '..', 'data');
|
||||
if (!fs.existsSync(dataDir)) {
|
||||
fs.mkdirSync(dataDir, { recursive: true });
|
||||
}
|
||||
|
||||
const dbPath = process.env.DB_PATH || path.join(dataDir, 'articles.db');
|
||||
const db = new Database(dbPath);
|
||||
|
||||
function initDb() {
|
||||
const migrationPath = path.join(__dirname, '..', 'migrations', '001_init.sql');
|
||||
const sql = fs.readFileSync(migrationPath, 'utf8');
|
||||
db.exec(sql);
|
||||
console.log('[DB] Base de données initialisée:', dbPath);
|
||||
}
|
||||
|
||||
module.exports = { db, initDb };
|
||||