mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-13 07:09:20 +00:00
56 lines
2.3 KiB
SQL
56 lines
2.3 KiB
SQL
-- alerts 0001: create_alerts
|
|
-- Generated by termix-plugin migrations. Review before committing.
|
|
|
|
CREATE TABLE IF NOT EXISTS "p_alerts_channels" (
|
|
"id" serial PRIMARY KEY,
|
|
"user_id" varchar(255) NOT NULL,
|
|
"name" text NOT NULL,
|
|
"type" varchar(32) NOT NULL,
|
|
"config" text,
|
|
"enabled" boolean NOT NULL DEFAULT true,
|
|
"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" serial PRIMARY KEY,
|
|
"user_id" varchar(255) NOT NULL,
|
|
"source" varchar(64) NOT NULL,
|
|
"category" varchar(128) NOT NULL,
|
|
"severity" varchar(16) NOT NULL,
|
|
"title" text NOT NULL,
|
|
"body" text,
|
|
"link" text,
|
|
"context" text,
|
|
"dedupe_key" varchar(255),
|
|
"deliveries" text,
|
|
"read_at" varchar(255),
|
|
"created_at" varchar(255) 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" serial PRIMARY KEY,
|
|
"user_id" varchar(255) NOT NULL,
|
|
"name" text NOT NULL,
|
|
"pattern" varchar(128) NOT NULL DEFAULT '*',
|
|
"min_severity" varchar(16) NOT NULL DEFAULT 'warning',
|
|
"channel_ids" text NOT NULL,
|
|
"enabled" boolean NOT NULL DEFAULT true,
|
|
"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" serial PRIMARY KEY,
|
|
"user_id" varchar(255) 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";
|