Centre de notification
This commit is contained in:
@@ -1898,4 +1898,109 @@ console.log('[DB] Migrations 2FA OK');
|
||||
}
|
||||
}
|
||||
|
||||
// ── Table notifications ───────────────────────────────────────────────────
|
||||
{
|
||||
const tables = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='notifications'").get();
|
||||
if (!tables) {
|
||||
db.exec(`
|
||||
CREATE TABLE notifications (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
type TEXT NOT NULL DEFAULT 'system',
|
||||
title TEXT NOT NULL,
|
||||
body TEXT,
|
||||
link TEXT,
|
||||
read INTEGER NOT NULL DEFAULT 0,
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
)
|
||||
`);
|
||||
db.exec('CREATE INDEX IF NOT EXISTS idx_notif_user_id ON notifications(user_id)');
|
||||
db.exec('CREATE INDEX IF NOT EXISTS idx_notif_read ON notifications(user_id, read)');
|
||||
db.exec('CREATE INDEX IF NOT EXISTS idx_notif_created ON notifications(created_at)');
|
||||
console.log('[DB] Table notifications créée');
|
||||
}
|
||||
}
|
||||
|
||||
// ── Tickets support ───────────────────────────────────────────────────────────
|
||||
{
|
||||
const cols = db.prepare("PRAGMA table_info(tickets)").all().map(c => c.name);
|
||||
if (!cols.includes('id')) {
|
||||
db.exec(`
|
||||
CREATE TABLE IF NOT EXISTS tickets (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
ticket_number TEXT NOT NULL UNIQUE,
|
||||
subject TEXT NOT NULL,
|
||||
status TEXT NOT NULL DEFAULT 'open',
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
||||
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
)
|
||||
`);
|
||||
db.exec('CREATE INDEX IF NOT EXISTS idx_tickets_user_id ON tickets(user_id)');
|
||||
db.exec('CREATE INDEX IF NOT EXISTS idx_tickets_status ON tickets(status)');
|
||||
db.exec('CREATE INDEX IF NOT EXISTS idx_tickets_updated ON tickets(updated_at)');
|
||||
console.log('[DB] Table tickets créée');
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const cols = db.prepare("PRAGMA table_info(ticket_messages)").all().map(c => c.name);
|
||||
if (!cols.includes('id')) {
|
||||
db.exec(`
|
||||
CREATE TABLE IF NOT EXISTS ticket_messages (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
ticket_id INTEGER NOT NULL REFERENCES tickets(id) ON DELETE CASCADE,
|
||||
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
body TEXT NOT NULL,
|
||||
is_admin INTEGER NOT NULL DEFAULT 0,
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
)
|
||||
`);
|
||||
db.exec('CREATE INDEX IF NOT EXISTS idx_tmsg_ticket_id ON ticket_messages(ticket_id)');
|
||||
db.exec('CREATE INDEX IF NOT EXISTS idx_tmsg_created ON ticket_messages(created_at)');
|
||||
console.log('[DB] Table ticket_messages créée');
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const cols = db.prepare("PRAGMA table_info(ticket_attachments)").all().map(c => c.name);
|
||||
if (!cols.includes('id')) {
|
||||
db.exec(`
|
||||
CREATE TABLE IF NOT EXISTS ticket_attachments (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
message_id INTEGER NOT NULL REFERENCES ticket_messages(id) ON DELETE CASCADE,
|
||||
filename TEXT NOT NULL,
|
||||
original_name TEXT NOT NULL,
|
||||
size INTEGER NOT NULL DEFAULT 0,
|
||||
mime_type TEXT
|
||||
)
|
||||
`);
|
||||
db.exec('CREATE INDEX IF NOT EXISTS idx_tattach_message_id ON ticket_attachments(message_id)');
|
||||
console.log('[DB] Table ticket_attachments créée');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
// Migration : colonne updated_at sur ticket_messages (édition 5 min)
|
||||
const cols = db.prepare("PRAGMA table_info(ticket_messages)").all().map(c => c.name);
|
||||
if (!cols.includes('updated_at')) {
|
||||
db.exec("ALTER TABLE ticket_messages ADD COLUMN updated_at TEXT");
|
||||
console.log('[DB] ticket_messages: colonne updated_at ajoutée');
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// Migration : ticket_type et ticket_pages sur tickets (qualification)
|
||||
const cols = db.prepare("PRAGMA table_info(tickets)").all().map(c => c.name);
|
||||
if (!cols.includes('ticket_type')) {
|
||||
db.exec("ALTER TABLE tickets ADD COLUMN ticket_type TEXT");
|
||||
console.log('[DB] tickets: colonne ticket_type ajoutée');
|
||||
}
|
||||
if (!cols.includes('ticket_pages')) {
|
||||
db.exec("ALTER TABLE tickets ADD COLUMN ticket_pages TEXT");
|
||||
console.log('[DB] tickets: colonne ticket_pages ajoutée');
|
||||
}
|
||||
}
|
||||
|
||||
export default db;
|
||||
|
||||
Reference in New Issue
Block a user