Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions check_db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const sqlite3 = require('sqlite3');
const path = require('path');

const db = new sqlite3.Database(path.join(__dirname, 'studyplan.db'));

db.all("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name", (err, rows) => {
if (err) {
console.error('Error:', err);
} else {
console.log('Tables in database:');
rows.forEach(row => console.log(` - ${row.name}`));
}
db.close();
});
35 changes: 35 additions & 0 deletions css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -5183,3 +5183,38 @@ body {
.subject-sidebar-item:hover .delete-subject-btn {
opacity: 1;
}

/* Notes Styling */
.note-card {
transition: all 0.2s ease;
background: var(--color-background-primary);
}

.note-card:hover {
border-color: var(--color-border-primary);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.note-card:hover .note-edit-btn {
background: var(--color-background-secondary);
border-color: var(--color-border-primary);
}

#notes-section {
background: var(--color-background-primary);
min-height: 100vh;
}

#notes-search {
background: var(--color-background-secondary) !important;
transition: all 0.2s;
}

#notes-search:focus {
border-color: var(--color-border-primary) !important;
outline: none;
}

#notes-list {
animation: fadeIn 0.3s ease-in-out;
}
67 changes: 20 additions & 47 deletions database.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ const db = new sqlite3.Database(path.join(__dirname, 'studyplan.db'));

function initDb() {
db.serialize(() => {
// Users Table
db.run(`CREATE TABLE IF NOT EXISTS users (
id TEXT PRIMARY KEY,
email TEXT NOT NULL UNIQUE,
password TEXT NOT NULL,
reset_token TEXT,
reset_token_expiry DATETIME,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
)`);

// Subjects Table
db.run(`CREATE TABLE IF NOT EXISTS subjects (
Expand All @@ -15,18 +24,9 @@ function initDb() {
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
)`);

// ================= USERS TABLE =================
db.run(`CREATE TABLE IF NOT EXISTS users (
id TEXT PRIMARY KEY,
email TEXT UNIQUE NOT NULL,
password TEXT NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
)`);

// ================= TASKS TABLE =================
// Tasks Table
db.run(`CREATE TABLE IF NOT EXISTS tasks (
id TEXT PRIMARY KEY,
user_email TEXT,
subject_id TEXT,
title TEXT NOT NULL,
description TEXT,
Expand All @@ -36,8 +36,6 @@ function initDb() {
confidence_score REAL,
notes TEXT,
archived INTEGER DEFAULT 0,
estimated_duration INTEGER,
is_estimated_duration_min BOOLEAN,
labels TEXT DEFAULT '[]',
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (subject_id) REFERENCES subjects(id)
Expand All @@ -46,59 +44,34 @@ function initDb() {
// Add labels column to existing tasks table if it doesn't exist
db.all("PRAGMA table_info(tasks)", (err, rows) => {
if (err) return;

const hasLabels = rows.some(r => r.name === 'labels');
if (!hasLabels) {
db.run("ALTER TABLE tasks ADD COLUMN labels TEXT DEFAULT '[]'");
}

// ================= ADD USER EMAIL COLUMN =================
const hasUserEmail = rows.some(r => r.name === 'user_email');
if (!hasUserEmail) {
db.run("ALTER TABLE tasks ADD COLUMN user_email TEXT");
}
});
db.all("PRAGMA table_info(tasks)", (err, rows) => {
if (err) return;

const columnNames = rows.map((row) => row.name);

// Estimated duration columns
if (!columnNames.includes("estimated_duration")) {
db.run("ALTER TABLE tasks ADD COLUMN estimated_duration INTEGER");
}

if (!columnNames.includes("is_estimated_duration_min")) {
db.run(
"ALTER TABLE tasks ADD COLUMN is_estimated_duration_min BOOLEAN"
);
}

// Labels column
if (!columnNames.includes("labels")) {
db.run("ALTER TABLE tasks ADD COLUMN labels TEXT DEFAULT '[]'");
}
});
// Notes Table
db.run(`CREATE TABLE IF NOT EXISTS notes (
id TEXT PRIMARY KEY,
title TEXT NOT NULL,
content TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
)`);

// Pre-populate some subjects if empty
db.get('SELECT COUNT(*) as count FROM subjects', (err, row) => {
if (row && row.count === 0) {
console.log("Seeding subjects...");

const stmt = db.prepare(
"INSERT INTO subjects (id, name, short_code, color) VALUES (?, ?, ?, ?)"
);

const stmt = db.prepare("INSERT INTO subjects (id, name, short_code, color) VALUES (?, ?, ?, ?)");
stmt.run('sub_1', 'Computer Science', 'CS', 'var(--color-text-info)');
stmt.run('sub_2', 'Mathematics', 'Maths', 'var(--color-text-success)');
stmt.run('sub_3', 'English Lit', 'English', 'var(--color-text-purple)');
stmt.run('sub_4', 'Physics', 'Physics', 'var(--color-text-warning)');

stmt.finalize();
}
});

});
}

module.exports = { db, initDb };
module.exports = { db, initDb };
Loading