first commit

This commit is contained in:
KIENTZ Alexandre 2025-12-03 21:36:55 +01:00
parent 315d1ca80a
commit d40024bad6
5 changed files with 31 additions and 1 deletions

2
db/.gitkeep Normal file
View File

@ -0,0 +1,2 @@
// Empty file - db directory is created at runtime
// This file ensures the directory exists in git

View File

@ -1,5 +1,6 @@
import { fileURLToPath } from 'url';
import path from 'path';
import fs from 'fs';
import { initDatabase } from '../src/db.js';
import config from '../src/config.js';
@ -8,11 +9,20 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
async function main() {
try {
console.log('🚀 Initializing database...');
// Ensure db directory exists
const dbDir = path.dirname(config.db.path);
if (!fs.existsSync(dbDir)) {
fs.mkdirSync(dbDir, { recursive: true });
console.log(`✓ Created directory: ${dbDir}`);
}
await initDatabase(config.db.path);
console.log('✓ Database initialized successfully!');
console.log(`✓ Database location: ${config.db.path}`);
process.exit(0);
} catch (error) {
console.error('✗ Database initialization failed:', error);
console.error('✗ Database initialization failed:', error.message);
process.exit(1);
}
}

View File

@ -2,10 +2,19 @@ import { getDatabase } from '../src/db.js';
import { initDatabase } from '../src/db.js';
import { v4 as uuidv4 } from 'uuid';
import config from '../src/config.js';
import path from 'path';
import fs from 'fs';
async function main() {
try {
console.log('🚀 Initializing and seeding database...');
// Ensure db directory exists
const dbDir = path.dirname(config.db.path);
if (!fs.existsSync(dbDir)) {
fs.mkdirSync(dbDir, { recursive: true });
}
await initDatabase(config.db.path);
const db = await getDatabase();

2
sessions/.gitkeep Normal file
View File

@ -0,0 +1,2 @@
// Empty file - sessions directory is created at runtime
// This file ensures the directory exists in git

View File

@ -2,6 +2,7 @@ import sqlite3 from 'sqlite3';
import { open } from 'sqlite';
import path from 'path';
import { fileURLToPath } from 'url';
import fs from 'fs';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
@ -10,6 +11,12 @@ let db = null;
export async function initDatabase(dbPath) {
if (db) return db;
// Ensure directory exists
const dir = path.dirname(dbPath);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
db = await open({
filename: dbPath,
driver: sqlite3.Database,