feat: tags personnalisés par utilisateur (user_id)
DB: - tags.user_id REFERENCES users(id) - UNIQUE(name, user_id) au lieu de UNIQUE(name) - Migration v2.6: alter + recreate table API (tous les endpoints tags): - POST/PUT/DELETE /api/settings/tags: filtré par user_id - GET /api/settings/tags/all: retourne uniquement les tags du user - GET/POST /api/local-workspace/*/tags: scope user → Les tags de l'utilisateur 1 ne sont pas visibles par l'utilisateur 2
This commit is contained in:
@@ -306,9 +306,11 @@ def init_db():
|
||||
-- v2.2.0: Tags system
|
||||
CREATE TABLE IF NOT EXISTS tags (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL UNIQUE,
|
||||
name TEXT NOT NULL,
|
||||
color TEXT DEFAULT '#787774',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
user_id INTEGER NOT NULL DEFAULT 0 REFERENCES users(id),
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
UNIQUE(name, user_id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS page_tags (
|
||||
@@ -379,6 +381,19 @@ def init_db():
|
||||
)""")
|
||||
except sqlite3.OperationalError:
|
||||
pass
|
||||
# v2.6: Tags per-user
|
||||
try:
|
||||
conn.execute("ALTER TABLE tags ADD COLUMN user_id INTEGER NOT NULL DEFAULT 0 REFERENCES users(id)")
|
||||
except sqlite3.OperationalError:
|
||||
pass
|
||||
try:
|
||||
# Recreate UNIQUE constraint for per-user tags
|
||||
conn.execute("CREATE TABLE IF NOT EXISTS tags_new (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, color TEXT DEFAULT '#787774', user_id INTEGER NOT NULL DEFAULT 0 REFERENCES users(id), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, UNIQUE(name, user_id))")
|
||||
conn.execute("INSERT OR IGNORE INTO tags_new (id, name, color, user_id, created_at) SELECT id, name, color, COALESCE(user_id,0), created_at FROM tags")
|
||||
conn.execute("DROP TABLE tags")
|
||||
conn.execute("ALTER TABLE tags_new RENAME TO tags")
|
||||
except sqlite3.OperationalError:
|
||||
pass
|
||||
conn.commit()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user