Rustelo/resources/auth/migrations/006_service_tokens_sqlite.sql
Jesús Pérez f1010e9d07
chore: update
2026-07-18 20:16:16 +01:00

17 lines
936 B
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- Migration: 006 Service tokens for external notification senders
-- Database: SQLite
CREATE TABLE IF NOT EXISTS service_tokens (
id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(4))) || '-' || lower(hex(randomblob(2))) || '-4' || substr(lower(hex(randomblob(2))),2) || '-' || substr('89ab',abs(random()) % 4 + 1, 1) || substr(lower(hex(randomblob(2))),2) || '-' || lower(hex(randomblob(6)))),
name TEXT NOT NULL,
token_hash TEXT NOT NULL UNIQUE,
created_by TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
scopes TEXT NOT NULL DEFAULT '["notify"]',
is_active INTEGER NOT NULL DEFAULT 1,
last_used_at DATETIME,
expires_at DATETIME,
created_at DATETIME NOT NULL DEFAULT (datetime('now'))
);
CREATE INDEX IF NOT EXISTS idx_service_tokens_hash ON service_tokens(token_hash);
CREATE INDEX IF NOT EXISTS idx_service_tokens_creator ON service_tokens(created_by);