Fix: Ensure all skills are tracked as files, not submodules
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import Database from 'better-sqlite3';
|
||||
import path from 'path';
|
||||
|
||||
const dbPath = path.join(__dirname, '../../todos.db');
|
||||
|
||||
// Create database connection
|
||||
let db: Database.Database | null = null;
|
||||
|
||||
export function getDatabase(): Database.Database {
|
||||
if (!db) {
|
||||
db = new Database(dbPath);
|
||||
db.pragma('journal_mode = WAL');
|
||||
console.log(`Connected to SQLite database at ${dbPath}`);
|
||||
}
|
||||
return db;
|
||||
}
|
||||
|
||||
export function closeDatabase(): void {
|
||||
if (db) {
|
||||
db.close();
|
||||
db = null;
|
||||
console.log('Database connection closed');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import sqlite3 from 'sqlite3';
|
||||
import path from 'path';
|
||||
|
||||
const dbPath = path.join(__dirname, '../../todos.db');
|
||||
|
||||
const db = new sqlite3.Database(dbPath, (err: Error | null) => {
|
||||
if (err) {
|
||||
console.error('Database connection error:', err);
|
||||
} else {
|
||||
console.log('Connected to SQLite database');
|
||||
}
|
||||
});
|
||||
|
||||
// Initialize database schema
|
||||
export const initDatabase = (): Promise<void> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.run(`
|
||||
CREATE TABLE IF NOT EXISTS todos (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
title TEXT NOT NULL,
|
||||
completed BOOLEAN DEFAULT 0,
|
||||
createdAt TEXT DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
`, (err: Error | null) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
console.log('Database schema initialized');
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export default db;
|
||||
@@ -0,0 +1,2 @@
|
||||
export { getDatabase, closeDatabase } from './database';
|
||||
export { runMigrations, initializeDatabase } from './migrations';
|
||||
@@ -0,0 +1,31 @@
|
||||
import { getDatabase } from './database';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
const schemaPath = path.join(__dirname, './schema.sql');
|
||||
|
||||
export function runMigrations(): void {
|
||||
try {
|
||||
const db = getDatabase();
|
||||
const schema = fs.readFileSync(schemaPath, 'utf-8');
|
||||
|
||||
// Execute the schema SQL
|
||||
db.exec(schema);
|
||||
|
||||
console.log('Database migrations completed successfully');
|
||||
} catch (error) {
|
||||
console.error('Error running migrations:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export function initializeDatabase(): void {
|
||||
try {
|
||||
runMigrations();
|
||||
console.log('Database initialized and ready for use');
|
||||
} catch (error) {
|
||||
console.error('Failed to initialize database:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
CREATE TABLE IF NOT EXISTS todos (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
title TEXT NOT NULL,
|
||||
description TEXT,
|
||||
completed INTEGER DEFAULT 0,
|
||||
createdAt TEXT,
|
||||
updatedAt TEXT
|
||||
);
|
||||
Reference in New Issue
Block a user