pretty much ready to 'ship'

This commit is contained in:
cottongin
2025-10-30 17:18:30 -04:00
parent 7bb3aabd72
commit 8f3a12ad76
10 changed files with 518 additions and 190 deletions

View File

@@ -84,6 +84,46 @@ function initializeDatabase() {
// Column already exists, ignore error
}
// Add upvotes and downvotes columns to games if they don't exist
try {
db.exec(`ALTER TABLE games ADD COLUMN upvotes INTEGER DEFAULT 0`);
} catch (err) {
// Column already exists, ignore error
}
try {
db.exec(`ALTER TABLE games ADD COLUMN downvotes INTEGER DEFAULT 0`);
} catch (err) {
// Column already exists, ignore error
}
// Migrate existing popularity_score to upvotes/downvotes if needed
try {
const gamesWithScore = db.prepare(`
SELECT id, popularity_score FROM games
WHERE popularity_score != 0 AND (upvotes = 0 AND downvotes = 0)
`).all();
if (gamesWithScore.length > 0) {
const updateGame = db.prepare(`
UPDATE games
SET upvotes = ?, downvotes = ?
WHERE id = ?
`);
for (const game of gamesWithScore) {
if (game.popularity_score > 0) {
updateGame.run(game.popularity_score, 0, game.id);
} else {
updateGame.run(0, Math.abs(game.popularity_score), game.id);
}
}
console.log(`Migrated popularity scores for ${gamesWithScore.length} games`);
}
} catch (err) {
console.error('Error migrating popularity scores:', err);
}
// Packs table for pack-level favoriting
db.exec(`
CREATE TABLE IF NOT EXISTS packs (
@@ -113,6 +153,20 @@ function initializeDatabase() {
)
`);
// Add message_hash column if it doesn't exist
try {
db.exec(`ALTER TABLE chat_logs ADD COLUMN message_hash TEXT`);
} catch (err) {
// Column already exists, ignore error
}
// Create index on message_hash for fast duplicate checking
try {
db.exec(`CREATE INDEX IF NOT EXISTS idx_chat_logs_hash ON chat_logs(message_hash)`);
} catch (err) {
// Index already exists, ignore error
}
console.log('Database initialized successfully');
}