fix various issues
This commit is contained in:
+24
-2
@@ -35,14 +35,12 @@ export async function migrate(sql: any) {
|
||||
cert_alert_days INTEGER NOT NULL DEFAULT 0,
|
||||
max_redirects INTEGER NOT NULL DEFAULT 1,
|
||||
tags TEXT[] NOT NULL DEFAULT '{}',
|
||||
channel_ids UUID[] NOT NULL DEFAULT '{}',
|
||||
created_at TIMESTAMPTZ DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ DEFAULT now()
|
||||
)
|
||||
`;
|
||||
await sql`CREATE INDEX IF NOT EXISTS idx_monitors_account ON monitors(account_id)`;
|
||||
await sql`CREATE INDEX IF NOT EXISTS idx_monitors_tags ON monitors USING GIN(tags)`;
|
||||
await sql`CREATE INDEX IF NOT EXISTS idx_monitors_channel_ids ON monitors USING GIN(channel_ids)`;
|
||||
|
||||
// ── pings ─────────────────────────────────────────────────────────────
|
||||
await sql`
|
||||
@@ -114,10 +112,34 @@ export async function migrate(sql: any) {
|
||||
kind TEXT NOT NULL,
|
||||
config JSONB NOT NULL,
|
||||
enabled BOOLEAN NOT NULL DEFAULT true,
|
||||
monitor_ids TEXT[] NOT NULL DEFAULT '{}',
|
||||
created_at TIMESTAMPTZ DEFAULT now()
|
||||
)
|
||||
`;
|
||||
await sql`CREATE INDEX IF NOT EXISTS idx_notification_channels_account ON notification_channels(account_id)`;
|
||||
await sql`ALTER TABLE notification_channels ADD COLUMN IF NOT EXISTS monitor_ids TEXT[] NOT NULL DEFAULT '{}'`;
|
||||
await sql`CREATE INDEX IF NOT EXISTS idx_notification_channels_monitor_ids ON notification_channels USING GIN(monitor_ids)`;
|
||||
|
||||
// ── one-time flip: monitors.channel_ids → notification_channels.monitor_ids ──
|
||||
const [chanCol] = await sql`
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_name = 'monitors' AND column_name = 'channel_ids'
|
||||
`;
|
||||
if (chanCol) {
|
||||
await sql`
|
||||
UPDATE notification_channels c SET monitor_ids = sub.mids
|
||||
FROM (
|
||||
SELECT m.channel_id::uuid AS cid, array_agg(m.id) AS mids
|
||||
FROM (
|
||||
SELECT id, UNNEST(channel_ids) AS channel_id FROM monitors
|
||||
) m
|
||||
GROUP BY m.channel_id
|
||||
) sub
|
||||
WHERE c.id = sub.cid
|
||||
`;
|
||||
await sql`ALTER TABLE monitors DROP COLUMN IF EXISTS channel_ids`;
|
||||
await sql`DROP INDEX IF EXISTS idx_monitors_channel_ids`;
|
||||
}
|
||||
|
||||
// ── status_pages ──────────────────────────────────────────────────────
|
||||
await sql`
|
||||
|
||||
Reference in New Issue
Block a user