mirror of
https://github.com/Icinga/icingadb.git
synced 2026-05-28 04:35:54 -04:00
Make {NotificationHistory,StateHistory}#Id UUID -> SHA1
This commit is contained in:
parent
c29a70272d
commit
52ae34a6f8
6 changed files with 20 additions and 27 deletions
|
|
@ -314,7 +314,7 @@ func writeMultiEntityStage(entryToEntities func(entry redis.XMessage) ([]v1.Upse
|
|||
// user_notification_history relation table for each user ID.
|
||||
func userNotificationStage(ctx context.Context, s Sync, key string, in <-chan redis.XMessage, out chan<- redis.XMessage) error {
|
||||
type NotificationHistory struct {
|
||||
Id types.UUID `structify:"id"`
|
||||
Id types.Binary `structify:"id"`
|
||||
EnvironmentId types.Binary `structify:"environment_id"`
|
||||
EndpointId types.Binary `structify:"endpoint_id"`
|
||||
UserIds types.String `structify:"users_notified_ids"`
|
||||
|
|
@ -345,7 +345,7 @@ func userNotificationStage(ctx context.Context, s Sync, key string, in <-chan re
|
|||
userNotifications = append(userNotifications, &v1.UserNotificationHistory{
|
||||
EntityWithoutChecksum: v1types.EntityWithoutChecksum{
|
||||
IdMeta: v1types.IdMeta{
|
||||
Id: utils.Checksum(append(append([]byte(nil), notificationHistory.Id.UUID[:]...), user...)),
|
||||
Id: utils.Checksum(append(append([]byte(nil), notificationHistory.Id...), user...)),
|
||||
},
|
||||
},
|
||||
EnvironmentMeta: v1types.EnvironmentMeta{
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package history
|
|||
|
||||
import (
|
||||
"github.com/icinga/icingadb/pkg/contracts"
|
||||
"github.com/icinga/icingadb/pkg/icingadb/v1"
|
||||
"github.com/icinga/icingadb/pkg/types"
|
||||
)
|
||||
|
||||
|
|
@ -13,22 +14,7 @@ type UpserterEntity interface {
|
|||
|
||||
// HistoryTableEntity is embedded by every concrete history type that has its own table.
|
||||
type HistoryTableEntity struct {
|
||||
Id types.UUID `json:"id"`
|
||||
}
|
||||
|
||||
// Fingerprint implements part of the contracts.Entity interface.
|
||||
func (hte HistoryTableEntity) Fingerprint() contracts.Fingerprinter {
|
||||
return hte
|
||||
}
|
||||
|
||||
// ID implements part of the contracts.Entity interface.
|
||||
func (hte HistoryTableEntity) ID() contracts.ID {
|
||||
return hte.Id
|
||||
}
|
||||
|
||||
// SetID implements part of the contracts.Entity interface.
|
||||
func (hte *HistoryTableEntity) SetID(id contracts.ID) {
|
||||
hte.Id = id.(types.UUID)
|
||||
v1.EntityWithoutChecksum `json:",inline"`
|
||||
}
|
||||
|
||||
// Upsert implements the contracts.Upserter interface.
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ type NotificationHistory struct {
|
|||
type UserNotificationHistory struct {
|
||||
v1.EntityWithoutChecksum `json:",inline"`
|
||||
v1.EnvironmentMeta `json:",inline"`
|
||||
NotificationHistoryId types.UUID `json:"notification_history_id"`
|
||||
NotificationHistoryId types.Binary `json:"notification_history_id"`
|
||||
UserId types.Binary `json:"user_id"`
|
||||
}
|
||||
|
||||
|
|
@ -32,7 +32,7 @@ func (u *UserNotificationHistory) Upsert() interface{} {
|
|||
|
||||
type HistoryNotification struct {
|
||||
HistoryMeta `json:",inline"`
|
||||
NotificationHistoryId types.UUID `json:"id"`
|
||||
NotificationHistoryId types.Binary `json:"id"`
|
||||
EventTime types.UnixMilli `json:"send_time"`
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ type StateHistory struct {
|
|||
|
||||
type HistoryState struct {
|
||||
HistoryMeta `json:",inline"`
|
||||
StateHistoryId types.UUID `json:"id"`
|
||||
StateHistoryId types.Binary `json:"id"`
|
||||
EventTime types.UnixMilli `json:"event_time"`
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -916,7 +916,7 @@ CREATE TABLE zone (
|
|||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;
|
||||
|
||||
CREATE TABLE notification_history (
|
||||
id binary(16) NOT NULL COMMENT 'UUID',
|
||||
id binary(20) NOT NULL COMMENT 'sha1(environment.name + notification.name + type + send_time)',
|
||||
environment_id binary(20) NOT NULL COMMENT 'environment.id',
|
||||
endpoint_id binary(20) DEFAULT NULL COMMENT 'endpoint.id',
|
||||
object_type enum('host', 'service') NOT NULL,
|
||||
|
|
@ -940,7 +940,7 @@ CREATE TABLE notification_history (
|
|||
CREATE TABLE user_notification_history (
|
||||
id binary(20) NOT NULL COMMENT 'sha1(notification_history_id + user_id)',
|
||||
environment_id binary(20) NOT NULL COMMENT 'environment.id',
|
||||
notification_history_id binary(16) NOT NULL COMMENT 'UUID notification_history.id',
|
||||
notification_history_id binary(20) NOT NULL COMMENT 'UUID notification_history.id',
|
||||
user_id binary(20) NOT NULL COMMENT 'user.id',
|
||||
|
||||
PRIMARY KEY (id),
|
||||
|
|
@ -949,7 +949,7 @@ CREATE TABLE user_notification_history (
|
|||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;
|
||||
|
||||
CREATE TABLE state_history (
|
||||
id binary(16) NOT NULL COMMENT 'UUID',
|
||||
id binary(20) NOT NULL COMMENT 'sha1(environment.name + host|service.name + event_time)',
|
||||
environment_id binary(20) NOT NULL COMMENT 'environment.id',
|
||||
endpoint_id binary(20) DEFAULT NULL COMMENT 'endpoint.id',
|
||||
object_type enum('host', 'service') NOT NULL,
|
||||
|
|
@ -1067,8 +1067,8 @@ CREATE TABLE history (
|
|||
object_type enum('host', 'service') NOT NULL,
|
||||
host_id binary(20) NOT NULL COMMENT 'host.id',
|
||||
service_id binary(20) DEFAULT NULL COMMENT 'service.id',
|
||||
notification_history_id binary(16) DEFAULT NULL COMMENT 'notification_history.id',
|
||||
state_history_id binary(16) DEFAULT NULL COMMENT 'state_history.id',
|
||||
notification_history_id binary(20) DEFAULT NULL COMMENT 'notification_history.id',
|
||||
state_history_id binary(20) DEFAULT NULL COMMENT 'state_history.id',
|
||||
downtime_history_id binary(20) DEFAULT NULL COMMENT 'downtime_history.downtime_id',
|
||||
comment_history_id binary(20) DEFAULT NULL COMMENT 'comment_history.comment_id',
|
||||
flapping_history_id binary(20) DEFAULT NULL COMMENT 'flapping_history.id',
|
||||
|
|
|
|||
|
|
@ -165,6 +165,7 @@ ALTER TABLE host_state
|
|||
|
||||
ALTER TABLE state_history
|
||||
ADD COLUMN scheduling_source text DEFAULT NULL AFTER check_source,
|
||||
MODIFY id binary(20) NOT NULL COMMENT 'sha1(environment.name + host|service.name + event_time)',
|
||||
MODIFY output longtext DEFAULT NULL,
|
||||
MODIFY long_output longtext DEFAULT NULL;
|
||||
|
||||
|
|
@ -173,10 +174,16 @@ ALTER TABLE service_state
|
|||
MODIFY long_output longtext DEFAULT NULL,
|
||||
MODIFY performance_data longtext DEFAULT NULL;
|
||||
|
||||
ALTER TABLE notification_history
|
||||
MODIFY id binary(20) NOT NULL COMMENT 'sha1(environment.name + notification.name + type + send_time)';
|
||||
|
||||
ALTER TABLE user_notification_history
|
||||
MODIFY id binary(20) NOT NULL COMMENT 'sha1(notification_history_id + user_id)';
|
||||
MODIFY id binary(20) NOT NULL COMMENT 'sha1(notification_history_id + user_id)',
|
||||
MODIFY notification_history_id binary(20) NOT NULL COMMENT 'UUID notification_history.id';
|
||||
|
||||
ALTER TABLE history
|
||||
MODIFY notification_history_id binary(20) DEFAULT NULL COMMENT 'notification_history.id',
|
||||
MODIFY state_history_id binary(20) DEFAULT NULL COMMENT 'state_history.id',
|
||||
ADD CONSTRAINT fk_history_acknowledgement_history FOREIGN KEY (acknowledgement_history_id) REFERENCES acknowledgement_history (id) ON DELETE CASCADE,
|
||||
ADD CONSTRAINT fk_history_comment_history FOREIGN KEY (comment_history_id) REFERENCES comment_history (comment_id) ON DELETE CASCADE,
|
||||
ADD CONSTRAINT fk_history_downtime_history FOREIGN KEY (downtime_history_id) REFERENCES downtime_history (downtime_id) ON DELETE CASCADE,
|
||||
|
|
|
|||
Loading…
Reference in a new issue