feat(alerting): V12 flyway migration for alerting tables
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package com.cameleer.server.app.alerting.storage;
|
||||
|
||||
import com.cameleer.server.app.AbstractPostgresIT;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class V12MigrationIT extends AbstractPostgresIT {
|
||||
|
||||
@Test
|
||||
void allAlertingTablesAndEnumsExist() {
|
||||
var tables = jdbcTemplate.queryForList(
|
||||
"SELECT table_name FROM information_schema.tables WHERE table_schema='public' " +
|
||||
"AND table_name IN ('alert_rules','alert_rule_targets','alert_instances'," +
|
||||
"'alert_silences','alert_notifications','alert_reads')",
|
||||
String.class);
|
||||
assertThat(tables).containsExactlyInAnyOrder(
|
||||
"alert_rules","alert_rule_targets","alert_instances",
|
||||
"alert_silences","alert_notifications","alert_reads");
|
||||
|
||||
var enums = jdbcTemplate.queryForList(
|
||||
"SELECT typname FROM pg_type WHERE typname IN " +
|
||||
"('severity_enum','condition_kind_enum','alert_state_enum'," +
|
||||
"'target_kind_enum','notification_status_enum')",
|
||||
String.class);
|
||||
assertThat(enums).hasSize(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
void deletingEnvironmentCascadesAlertingRows() {
|
||||
var envId = java.util.UUID.randomUUID();
|
||||
jdbcTemplate.update(
|
||||
"INSERT INTO environments (id, slug, display_name) VALUES (?, ?, ?)",
|
||||
envId, "test-cascade-env", "Test Cascade Env");
|
||||
jdbcTemplate.update(
|
||||
"INSERT INTO users (user_id, provider, email) " +
|
||||
"VALUES (?, ?, ?)", "u1", "local", "a@b.test");
|
||||
var ruleId = java.util.UUID.randomUUID();
|
||||
jdbcTemplate.update(
|
||||
"INSERT INTO alert_rules (id, environment_id, name, severity, condition_kind, condition, " +
|
||||
"notification_title_tmpl, notification_message_tmpl, created_by, updated_by) " +
|
||||
"VALUES (?, ?, 'r', 'WARNING', 'AGENT_STATE', '{}'::jsonb, 't', 'm', 'u1', 'u1')",
|
||||
ruleId, envId);
|
||||
var instanceId = java.util.UUID.randomUUID();
|
||||
jdbcTemplate.update(
|
||||
"INSERT INTO alert_instances (id, rule_id, rule_snapshot, environment_id, state, severity, " +
|
||||
"fired_at, context, title, message) VALUES (?, ?, '{}'::jsonb, ?, 'FIRING', 'WARNING', " +
|
||||
"now(), '{}'::jsonb, 't', 'm')",
|
||||
instanceId, ruleId, envId);
|
||||
|
||||
jdbcTemplate.update("DELETE FROM environments WHERE id = ?", envId);
|
||||
|
||||
assertThat(jdbcTemplate.queryForObject(
|
||||
"SELECT count(*) FROM alert_rules WHERE environment_id = ?",
|
||||
Integer.class, envId)).isZero();
|
||||
assertThat(jdbcTemplate.queryForObject(
|
||||
"SELECT count(*) FROM alert_instances WHERE environment_id = ?",
|
||||
Integer.class, envId)).isZero();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user