diff --git a/nexus/db-model/src/lib.rs b/nexus/db-model/src/lib.rs index 66723e0b18..a5fb4479db 100644 --- a/nexus/db-model/src/lib.rs +++ b/nexus/db-model/src/lib.rs @@ -63,6 +63,7 @@ mod switch_interface; mod switch_port; mod v2p_mapping; mod vmm_state; +mod webhook_msg_delivery; // These actually represent subqueries, not real table. // However, they must be defined in the same crate as our tables // for join-based marker trait generation. @@ -127,6 +128,7 @@ mod db { pub use self::macaddr::*; pub use self::unsigned::*; +pub use self::webhook_msg_delivery::*; pub use address_lot::*; pub use allow_list::*; pub use bfd::*; diff --git a/nexus/db-model/src/schema.rs b/nexus/db-model/src/schema.rs index 399da81ea4..2b5bf1e69a 100644 --- a/nexus/db-model/src/schema.rs +++ b/nexus/db-model/src/schema.rs @@ -2108,3 +2108,78 @@ table! { region_snapshot_snapshot_id -> Nullable, } } + +table! { + webhook_rx (id) { + id -> Uuid, + name -> Text, + endpoint -> Text, + time_created -> Timestamptz, + time_modified -> Nullable, + time_deleted -> Nullable, + } +} + +table! { + webhook_rx_secret (rx_id, signature_id) { + rx_id -> Uuid, + signature_id -> Text, + secret -> Binary, + time_created -> Timestamptz, + time_deleted -> Nullable, + } +} + +allow_tables_to_appear_in_same_query!(webhook_rx, webhook_rx_secret); +joinable!(webhook_rx_secret -> webhook_rx (rx_id)); + +table! { + webhook_rx_subscription (rx_id, event_class) { + rx_id -> Uuid, + event_class -> Text, + time_created -> Timestamptz, + } +} + +allow_tables_to_appear_in_same_query!(webhook_rx, webhook_rx_subscription); +joinable!(webhook_rx_subscription -> webhook_rx (rx_id)); + +table! { + webhook_msg (id) { + id -> Uuid, + time_created -> Timestamptz, + time_dispatched -> Nullable, + event_class -> Text, + event -> Jsonb, + } +} + +table! { + webhook_msg_dispatch (id) { + id -> Uuid, + rx_id -> Uuid, + payload -> Jsonb, + time_created -> Timestamptz, + time_completed -> Nullable, + } +} + +allow_tables_to_appear_in_same_query!(webhook_rx, webhook_msg_dispatch); +joinable!(webhook_msg_dispatch -> webhook_rx (rx_id)); + +table! { + webhook_msg_delivery_attempt (id) { + id -> Uuid, + dispatch_id -> Uuid, + result -> crate::WebhookDeliveryResultEnum, + response_status -> Nullable, + response_duration -> Nullable, + time_created -> Timestamptz, + } +} + +allow_tables_to_appear_in_same_query!( + webhook_msg_dispatch, + webhook_msg_delivery_attempt +); +joinable!(webhook_msg_delivery_attempt -> webhook_msg_dispatch (dispatch_id)); diff --git a/nexus/db-model/src/schema_versions.rs b/nexus/db-model/src/schema_versions.rs index 02646bc6dd..dd5a3218cd 100644 --- a/nexus/db-model/src/schema_versions.rs +++ b/nexus/db-model/src/schema_versions.rs @@ -17,7 +17,7 @@ use std::collections::BTreeMap; /// /// This must be updated when you change the database schema. Refer to /// schema/crdb/README.adoc in the root of this repository for details. -pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(116, 0, 0); +pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(117, 0, 0); /// List of all past database schema versions, in *reverse* order /// @@ -29,6 +29,7 @@ static KNOWN_VERSIONS: Lazy> = Lazy::new(|| { // | leaving the first copy as an example for the next person. // v // KnownVersion::new(next_int, "unique-dirname-with-the-sql-files"), + KnownVersion::new(117, "add-webhooks"), KnownVersion::new(116, "bp-physical-disk-disposition"), KnownVersion::new(115, "inv-omicron-physical-disks-generation"), KnownVersion::new(114, "crucible-ref-count-records"), diff --git a/nexus/db-model/src/webhook_msg_delivery.rs b/nexus/db-model/src/webhook_msg_delivery.rs new file mode 100644 index 0000000000..d9724ef9a5 --- /dev/null +++ b/nexus/db-model/src/webhook_msg_delivery.rs @@ -0,0 +1,30 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +use super::impl_enum_type; +use serde::Deserialize; +use serde::Serialize; + +impl_enum_type!( + #[derive(SqlType, Debug, Clone)] + #[diesel(postgres_type(name = "webhook_msg_delivery_result", schema = "public"))] + pub struct WebhookDeliveryResultEnum; + + #[derive( + Copy, + Clone, + Debug, + PartialEq, + AsExpression, + FromSqlRow, + Serialize, + Deserialize, + )] + #[diesel(sql_type = WebhookDeliveryResultEnum)] + pub enum WebhookDeliveryResult; + + FailedHttpError => b"failed_http_error" + FailedUnreachable => b"failed_unreachable" + Succeeded => b"succeeded" +); diff --git a/schema/crdb/dbinit.sql b/schema/crdb/dbinit.sql index 84e1d0ca5a..224b76e09f 100644 --- a/schema/crdb/dbinit.sql +++ b/schema/crdb/dbinit.sql @@ -4856,7 +4856,7 @@ INSERT INTO omicron.public.db_metadata ( version, target_version ) VALUES - (TRUE, NOW(), NOW(), '116.0.0', NULL) + (TRUE, NOW(), NOW(), '117.0.0', NULL) ON CONFLICT DO NOTHING; COMMIT;