first commit
This commit is contained in:
parent
315d1ca80a
commit
d40024bad6
2
db/.gitkeep
Normal file
2
db/.gitkeep
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
// Empty file - db directory is created at runtime
|
||||||
|
// This file ensures the directory exists in git
|
||||||
@ -1,5 +1,6 @@
|
|||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import fs from 'fs';
|
||||||
import { initDatabase } from '../src/db.js';
|
import { initDatabase } from '../src/db.js';
|
||||||
import config from '../src/config.js';
|
import config from '../src/config.js';
|
||||||
|
|
||||||
@ -8,11 +9,20 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|||||||
async function main() {
|
async function main() {
|
||||||
try {
|
try {
|
||||||
console.log('🚀 Initializing database...');
|
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);
|
await initDatabase(config.db.path);
|
||||||
console.log('✓ Database initialized successfully!');
|
console.log('✓ Database initialized successfully!');
|
||||||
|
console.log(`✓ Database location: ${config.db.path}`);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('✗ Database initialization failed:', error);
|
console.error('✗ Database initialization failed:', error.message);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,10 +2,19 @@ import { getDatabase } from '../src/db.js';
|
|||||||
import { initDatabase } from '../src/db.js';
|
import { initDatabase } from '../src/db.js';
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import config from '../src/config.js';
|
import config from '../src/config.js';
|
||||||
|
import path from 'path';
|
||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
try {
|
try {
|
||||||
console.log('🚀 Initializing and seeding database...');
|
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);
|
await initDatabase(config.db.path);
|
||||||
const db = await getDatabase();
|
const db = await getDatabase();
|
||||||
|
|
||||||
|
|||||||
2
sessions/.gitkeep
Normal file
2
sessions/.gitkeep
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
// Empty file - sessions directory is created at runtime
|
||||||
|
// This file ensures the directory exists in git
|
||||||
@ -2,6 +2,7 @@ import sqlite3 from 'sqlite3';
|
|||||||
import { open } from 'sqlite';
|
import { open } from 'sqlite';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
@ -10,6 +11,12 @@ let db = null;
|
|||||||
export async function initDatabase(dbPath) {
|
export async function initDatabase(dbPath) {
|
||||||
if (db) return db;
|
if (db) return db;
|
||||||
|
|
||||||
|
// Ensure directory exists
|
||||||
|
const dir = path.dirname(dbPath);
|
||||||
|
if (!fs.existsSync(dir)) {
|
||||||
|
fs.mkdirSync(dir, { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
db = await open({
|
db = await open({
|
||||||
filename: dbPath,
|
filename: dbPath,
|
||||||
driver: sqlite3.Database,
|
driver: sqlite3.Database,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user