diff --git a/db/patch-fix-kafka-producer-booleans.sql b/db/patch-fix-kafka-producer-booleans.sql new file mode 100644 index 000000000..810ec92e3 --- /dev/null +++ b/db/patch-fix-kafka-producer-booleans.sql @@ -0,0 +1,29 @@ +-- You should not modify if this have pushed to Github, unless it does serious wrong with the db. +BEGIN TRANSACTION; + +-- Rename COLUMNs to another one (suffixed by `_old`) +ALTER TABLE monitor + RENAME COLUMN kafka_producer_ssl TO kafka_producer_ssl_old; + +ALTER TABLE monitor + RENAME COLUMN kafka_producer_allow_auto_topic_creation TO kafka_producer_allow_auto_topic_creation_old; + +-- Add correct COLUMNs +ALTER TABLE monitor + ADD COLUMN kafka_producer_ssl BOOLEAN default 0 NOT NULL; + +ALTER TABLE monitor + ADD COLUMN kafka_producer_allow_auto_topic_creation BOOLEAN default 0 NOT NULL; + +-- Set bring old values from `_old` COLUMNs to correct ones +UPDATE monitor set kafka_producer_allow_auto_topic_creation = monitor.kafka_producer_allow_auto_topic_creation_old; +UPDATE monitor set kafka_producer_ssl = monitor.kafka_producer_ssl_old; + +-- Remove old COLUMNs +ALTER TABLE monitor + DROP COLUMN kafka_producer_allow_auto_topic_creation_old; + +ALTER TABLE monitor + DROP COLUMN kafka_producer_ssl_old; + +COMMIT; diff --git a/server/database.js b/server/database.js index af141dda0..29ab3b941 100644 --- a/server/database.js +++ b/server/database.js @@ -82,6 +82,7 @@ class Database { "patch-add-timeout-monitor.sql": true, "patch-add-gamedig-given-port.sql": true, "patch-notification-config.sql": true, + "patch-fix-kafka-producer-booleans.sql": true, }; /** diff --git a/server/model/monitor.js b/server/model/monitor.js index 5cd94aa5d..1e08ccd45 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -143,8 +143,8 @@ class Monitor extends BeanModel { expectedValue: this.expectedValue, kafkaProducerTopic: this.kafkaProducerTopic, kafkaProducerBrokers: JSON.parse(this.kafkaProducerBrokers), - kafkaProducerSsl: this.kafkaProducerSsl === "1" && true || false, - kafkaProducerAllowAutoTopicCreation: this.kafkaProducerAllowAutoTopicCreation === "1" && true || false, + kafkaProducerSsl: this.getKafkaProducerSsl(), + kafkaProducerAllowAutoTopicCreation: this.getKafkaProducerAllowAutoTopicCreation(), kafkaProducerMessage: this.kafkaProducerMessage, screenshot, }; @@ -287,6 +287,22 @@ class Monitor extends BeanModel { return Boolean(this.gamedigGivenPortOnly); } + /** + * Parse to boolean + * @returns {boolean} Kafka Producer Ssl enabled? + */ + getKafkaProducerSsl() { + return Boolean(this.kafkaProducerSsl); + } + + /** + * Parse to boolean + * @returns {boolean} Kafka Producer Allow Auto Topic Creation Enabled? + */ + getKafkaProducerAllowAutoTopicCreation() { + return Boolean(this.kafkaProducerAllowAutoTopicCreation); + } + /** * Start monitor * @param {Server} io Socket server instance diff --git a/server/server.js b/server/server.js index 6baf343e2..605dde325 100644 --- a/server/server.js +++ b/server/server.js @@ -789,6 +789,9 @@ let needSetup = false; bean.kafkaProducerAllowAutoTopicCreation = monitor.kafkaProducerAllowAutoTopicCreation; bean.kafkaProducerSaslOptions = JSON.stringify(monitor.kafkaProducerSaslOptions); bean.kafkaProducerMessage = monitor.kafkaProducerMessage; + bean.kafkaProducerSsl = monitor.kafkaProducerSsl; + bean.kafkaProducerAllowAutoTopicCreation = + monitor.kafkaProducerAllowAutoTopicCreation; bean.gamedigGivenPortOnly = monitor.gamedigGivenPortOnly; bean.validate(); diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index 85687078d..687aa42c7 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -891,6 +891,7 @@ const monitorDefaults = { mechanism: "None", }, kafkaProducerSsl: false, + kafkaProducerAllowAutoTopicCreation: false, gamedigGivenPortOnly: true, };