ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 7m0s
ci / test (pull_request) Successful in 12m1s
ci / build (pull_request) Successful in 18m14s
ci / image (pull_request) Successful in 5m9s
Accounts open tickets under Support and admins answer them under Admin → Support tickets. - A ticket is open while it waits for the admins and answered while it waits for the account. Either side can close or reopen it, and a reply reopens it. - The admins are mailed about new tickets and replies, and the account about answers. - A ticket can name the active organization and point at a monitor, notification channel, alert group, status page or incident in it. Each must be something the account can read. - Next to the conversation, admins see the account at a glance: state, sign-in, organizations with their limits and usage, and open tickets. - Admins switch support off and limit how many tickets an account has open at once. - Suspended accounts and those yet to accept the terms reach support too; a suspended account opens one ticket. - Tickets are part of the account export and are deleted with the account. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
82 lines
2.5 KiB
Go
82 lines
2.5 KiB
Go
package migrations
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/jackc/pgx/v5"
|
|
)
|
|
|
|
func TestAlertGroupsBackfill(t *testing.T) {
|
|
dsn := os.Getenv("UPTIME_TEST_DATABASE_URL")
|
|
if dsn == "" {
|
|
t.Skip("UPTIME_TEST_DATABASE_URL not set")
|
|
}
|
|
ctx := context.Background()
|
|
if _, err := Up(ctx, dsn); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
conn, err := pgx.Connect(ctx, dsn)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer func() { _ = conn.Close(ctx) }()
|
|
tx, err := conn.Begin(ctx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// Exercise both directions inside a transaction; existing test data and
|
|
// goose's migration history remain unchanged after rollback.
|
|
defer func() { _ = tx.Rollback(ctx) }()
|
|
if _, err := tx.Exec(ctx, "SET LOCAL app.scope = 'system'"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// Support tickets point at alert groups; take them back first.
|
|
later, err := files.ReadFile("sql/00051_support_tickets.sql")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
_, laterDown, _ := strings.Cut(string(later), "-- +goose Down")
|
|
if _, err := tx.Exec(ctx, laterDown); err != nil {
|
|
t.Fatalf("down 00051: %v", err)
|
|
}
|
|
raw, err := files.ReadFile("sql/00039_alert_groups.sql")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
up, down, ok := strings.Cut(string(raw), "-- +goose Down")
|
|
if !ok {
|
|
t.Fatal("missing down migration")
|
|
}
|
|
if _, err := tx.Exec(ctx, down); err != nil {
|
|
t.Fatalf("down: %v", err)
|
|
}
|
|
orgID := uuid.New()
|
|
if _, err := tx.Exec(ctx, `INSERT INTO orgs (id,slug,name) VALUES ($1,$2,'Existing organization')`, orgID, "migration-"+orgID.String()); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := tx.Exec(ctx, `INSERT INTO monitors (org_id,name,type,target,interval_seconds,timeout_ms) VALUES ($1,'Existing monitor','tcp','example.test:443',60,1000)`, orgID); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := tx.Exec(ctx, `INSERT INTO notification_channels (org_id,name,type,config) VALUES ($1,'Existing channel','webhook','{}')`, orgID); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := tx.Exec(ctx, up); err != nil {
|
|
t.Fatalf("up: %v", err)
|
|
}
|
|
var groups, monitors, channels int
|
|
err = tx.QueryRow(ctx, `SELECT
|
|
(SELECT count(*) FROM alert_groups WHERE org_id=$1 AND is_default),
|
|
(SELECT count(*) FROM monitor_alert_groups WHERE org_id=$1),
|
|
(SELECT count(*) FROM alert_group_channels WHERE org_id=$1)`, orgID).Scan(&groups, &monitors, &channels)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if groups != 1 || monitors != 1 || channels != 1 {
|
|
t.Fatalf("backfilled groups/monitors/channels = %d/%d/%d, want 1/1/1", groups, monitors, channels)
|
|
}
|
|
}
|