-- alerts 0001: create_alerts -- Generated by termix-plugin migrations. Review before committing. CREATE TABLE IF NOT EXISTS "p_alerts_channels" ( "id" integer PRIMARY KEY AUTOINCREMENT, "user_id" text NOT NULL, "name" text NOT NULL, "type" text NOT NULL, "config" text, "enabled" integer NOT NULL DEFAULT 1, "created_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP, "updated_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE ); CREATE INDEX IF NOT EXISTS "idx_alerts_channels_user" ON "p_alerts_channels" ("user_id"); CREATE TABLE IF NOT EXISTS "p_alerts_items" ( "id" integer PRIMARY KEY AUTOINCREMENT, "user_id" text NOT NULL, "source" text NOT NULL, "category" text NOT NULL, "severity" text NOT NULL, "title" text NOT NULL, "body" text, "link" text, "context" text, "dedupe_key" text, "deliveries" text, "read_at" text, "created_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE ); CREATE INDEX IF NOT EXISTS "idx_alerts_items_user" ON "p_alerts_items" ("user_id", "created_at"); CREATE INDEX IF NOT EXISTS "idx_alerts_items_unread" ON "p_alerts_items" ("user_id", "read_at"); CREATE INDEX IF NOT EXISTS "idx_alerts_items_dedupe" ON "p_alerts_items" ("user_id", "dedupe_key"); CREATE TABLE IF NOT EXISTS "p_alerts_rules" ( "id" integer PRIMARY KEY AUTOINCREMENT, "user_id" text NOT NULL, "name" text NOT NULL, "pattern" text NOT NULL DEFAULT '*', "min_severity" text NOT NULL DEFAULT 'warning', "channel_ids" text NOT NULL, "enabled" integer NOT NULL DEFAULT 1, "created_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE ); CREATE INDEX IF NOT EXISTS "idx_alerts_rules_user" ON "p_alerts_rules" ("user_id"); CREATE TABLE IF NOT EXISTS "dismissed_alerts" ( "id" integer PRIMARY KEY AUTOINCREMENT, "user_id" text NOT NULL, "alert_id" text NOT NULL, "dismissed_at" text NOT NULL DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE ); CREATE INDEX IF NOT EXISTS "idx_dismissed_alerts_user_id" ON "dismissed_alerts" ("user_id"); ALTER TABLE "dismissed_alerts" RENAME TO "p_alerts_dismissed";