gallery now supports multiple users

This commit is contained in:
2025-12-06 02:07:32 +01:00
parent 2df7625657
commit e7388bbb25
6 changed files with 97 additions and 51 deletions

View File

@@ -36,7 +36,6 @@ async function ensureUserDataDB(dbPath) {
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
);
-- Tabla 2: UserIntegration (✅ ACTUALIZADA)
CREATE TABLE IF NOT EXISTS UserIntegration (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL UNIQUE,
@@ -49,7 +48,6 @@ async function ensureUserDataDB(dbPath) {
FOREIGN KEY (user_id) REFERENCES User(id) ON DELETE CASCADE
);
-- Tabla 3: ListEntry
CREATE TABLE IF NOT EXISTS ListEntry (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
@@ -124,14 +122,16 @@ function ensureFavoritesDB(dbPath) {
if (!exists) {
const schema = `
CREATE TABLE IF NOT EXISTS favorites (
id TEXT PRIMARY KEY,
id TEXT NOT NULL,
user_id INTEGER NOT NULL,
title TEXT NOT NULL,
image_url TEXT NOT NULL,
thumbnail_url TEXT NOT NULL DEFAULT "",
tags TEXT NOT NULL DEFAULT "",
headers TEXT NOT NULL DEFAULT "",
provider TEXT NOT NULL DEFAULT ""
);
provider TEXT NOT NULL DEFAULT "",
PRIMARY KEY (id, user_id)
);
`;
db.exec(schema, (err) => {
@@ -147,6 +147,7 @@ function ensureFavoritesDB(dbPath) {
const hasHeaders = cols.some(c => c.name === "headers");
const hasProvider = cols.some(c => c.name === "provider");
const hasUserId = cols.some(c => c.name === "user_id");
const queries = [];
@@ -158,6 +159,10 @@ function ensureFavoritesDB(dbPath) {
queries.push(`ALTER TABLE favorites ADD COLUMN provider TEXT NOT NULL DEFAULT ""`);
}
if (!hasUserId) {
queries.push(`ALTER TABLE favorites ADD COLUMN user_id INTEGER NOT NULL DEFAULT 1`);
}
if (queries.length === 0) {
return resolve(false);
}