diff --git a/lib/management/mng_db.js b/lib/management/mng_db.js index 428403b..baae549 100644 --- a/lib/management/mng_db.js +++ b/lib/management/mng_db.js @@ -1166,7 +1166,10 @@ db_utils.prototype.changeBoardWampStatus = function (board_id, session, status, message: '', result: '' }; - connection.query("UPDATE boards SET board_id=" + mysql.escape(board_id) + ", session_id=" + mysql.escape(session) + ", status=" + mysql.escape(status) + " WHERE board_id=" + mysql.escape(board_id), function (err, result) { + + var conn_time = new Date().toISOString().replace(/\..+/, ''); + + connection.query("UPDATE boards SET conn_time=" + mysql.escape(conn_time) + ", board_id=" + mysql.escape(board_id) + ", session_id=" + mysql.escape(session) + ", status=" + mysql.escape(status) + " WHERE board_id=" + mysql.escape(board_id), function (err, result) { if (err != null) { response.result = "ERROR"; response.message = err; diff --git a/lib/modules/plugin_manager.js b/lib/modules/plugin_manager.js index b63afa1..6acced1 100644 --- a/lib/modules/plugin_manager.js +++ b/lib/modules/plugin_manager.js @@ -386,12 +386,18 @@ plugin_utils = function (session, rest) { * plugin_id: * type: integer * description: "The IoTronic plugin ID" - * latest_change: + * plugin_name: * type: string - * description: "Timestamp of the latest plugin state update." + * description: "Plugin name" * state: * type: string * description: "Plugin status: 'injected', 'executed', 'running', 'killed'" + * latest_change: + * type: string + * description: "Timestamp of the latest plugin state update." + * parameters: + * type: object + * description: "latest JSON parameters injected" * 403: * description: "Wrong, expired or not specified token in request header." * 500: @@ -2634,49 +2640,6 @@ plugin_utils.prototype.managePlugins = function (board, request_id, args) { } -/* - - computeParameters(board, plugin, parameters, parameters_set, plugin_defaults, - function (cparams) { - - console.log("FFFFFFFFFFFFFFFFFFFFF\nPARAMS COMPUTED: " + cparams.message + "\nFFFFFFFFFFFFFFFFFFFFF"); - - - } - ); - - - - - computeParameters(board, plugin, parameters, parameters_set, plugin_defaults, - function (cparams) { - - if(cparams.result == "ERROR"){ - - if(res != false){ - logger.warn("[PLUGIN] --> " + cparams.message); - res.status(500).send(cparams); - }else{ - request_utils.updateResult(request_id, board, cparams.result, cparams.message); - } - - } - else{ - - console.log("FFFFFFFFFFFFFFFFFFFFF\nPARAMS COMPUTED: " + cparams.message + "\nFFFFFFFFFFFFFFFFFFFFF"); - - - } - - - - } - ); - - */ - - - switch (plugin_operation) { case 'run': @@ -2833,149 +2796,6 @@ plugin_utils.prototype.managePlugins = function (board, request_id, args) { } ); - - /* - if (parameters == "" || parameters == undefined) { - - response.message = "WARNING - ASYNC PLUGIN '" + plugin_name + "' has not parameters!"; - response.result = "ERROR"; - if(res != false){ - logger.warn("[PLUGIN] --> " + response.message); - res.status(500).send(response); - }else{ - request_utils.updateResult(request_id, board, response.result, response.message); - } - - } - else { - - if(res != false) - logger.debug("[PLUGIN] --> Plugin '" + plugin_name + "' parameters:\n " + parameters); - - //I need to read the category of the plugin from the DB - db.getPluginCategory(plugin_name, function (data) { - - if (data.result == "ERROR") { - response.message = data.message; - response.result = "ERROR"; - if(res != false){ - logger.warn("[PLUGIN] --> " + response.message); - res.status(500).send(response); - }else{ - request_utils.updateResult(request_id, board, response.result, response.message); - } - - - } else { - - var plugincategory = data.message[0].category; - if(res != false) - logger.debug("[PLUGIN] --> Plugin category: " + plugincategory); - - if (plugincategory === "async") { - - session_wamp.call('s4t.'+ board + '.plugin.run', [plugin_name, parameters, plugin_checksum]).then( - - function (rpc_response) { - - if (rpc_response.result == "ERROR") { - - response.message = rpc_response.message; - response.result = "ERROR"; - - db.updatePluginStatus(board, plugin, "failed", function (out) { - - if(res != false){ - logger.debug("[PLUGIN] ----> " + out.message); - logger.warn("[PLUGIN] --> Start plugin error for '" + plugin_name + "': " + JSON.stringify(response.message, null, "\t")); - res.status(500).send(response); - }else{ - request_utils.updateResult(request_id, board, response.result, response.message); - } - - }); - - - } - else if (rpc_response.result == "SUCCESS"){ - - response.message = rpc_response.message; - response.result = "SUCCESS"; - - db.updatePluginStatus(board, plugin, "running", function (out) { - - if(res != false){ - logger.debug("[PLUGIN] ----> " + out.message); - logger.info("[PLUGIN] --> Start plugin result for '" + plugin_name + "': " + response.message); - res.status(200).send(response); - }else{ - request_utils.updateResult(request_id, board, response.result, response.message); - } - - }); - - - }else { - - response.message = rpc_response.message; - response.result = rpc_response.result; - if(res != false){ - logger.warn("[PLUGIN] --> Running warning result for '" + plugin_name + "' plugin: " + response.message); - res.status(500).send(response); - }else{ - request_utils.updateResult(request_id, board, response.result, response.message); - } - - } - - - }, - function (error) { - - response.message = error.args[0].message; - response.result = "ERROR"; - if(res != false) - logger.error("[PLUGIN] --> Plugin error '" + plugin_name + "': " + JSON.stringify(response.message)); - - db.updatePluginStatus(board, plugin, "failed", function (out) { - - if(res != false){ - logger.debug("[PLUGIN] ----> " + out.message); - logger.info("[PLUGIN] --> Error starting plugin '" + plugin_name + "': " + response.message); - res.status(500).send(response); - }else{ - request_utils.updateResult(request_id, board, response.result, response.message); - } - - }); - - } - ); - - } else { - - response.message = "Operation 'run' not supported for this plugin category!"; - response.result = "ERROR"; - if(res != false){ - logger.warn("[PLUGIN] ----> " + response.message); - res.status(500).send(response); - }else{ - request_utils.updateResult(request_id, board, response.result, response.message); - } - - - } - - - } - - - - }); - - } - */ - break; diff --git a/lib/modules/service_manager.js b/lib/modules/service_manager.js index 2a5ca02..2851602 100644 --- a/lib/modules/service_manager.js +++ b/lib/modules/service_manager.js @@ -43,7 +43,7 @@ services_utils = function (session, rest) { // SERVICES MANAGEMENT APIs //--------------------------------------------------------------------------------------------------- - + //GET services list /** * @swagger @@ -447,7 +447,7 @@ services_utils = function (session, rest) { if (check.result == "ERROR") { res.status(500).send(check); } else { - + var subject = "service action: "+ service_action + " " +service; request_utils.insertRequest(project, subject).then( @@ -653,7 +653,7 @@ services_utils = function (session, rest) { } ); - + } }); @@ -910,7 +910,7 @@ services_utils = function (session, rest) { message: '', result: '' }; - + db.getProjectBoardsPerService(project, service, function (data) { if(data.result=="ERROR"){ @@ -930,7 +930,7 @@ services_utils = function (session, rest) { }); - + //RESTORE all services on board /** * @swagger @@ -1006,7 +1006,7 @@ services_utils = function (session, rest) { // Register RPC methods this.exportCommands(session_wamp) - + }; @@ -1097,15 +1097,15 @@ services_utils.prototype.updateService = function (service, service_name, port, } else { if (data.message[0] === undefined) { - + response.message = "Service '" + service + "' does not exist!"; response.result = "ERROR"; logger.warn("[SERVICE] --> " + response.message); res.status(500).send(response); - + } else { - + db.updateService(service, service_name, port, protocol, function (result_db) { if (result_db.result == "ERROR") { @@ -1212,7 +1212,7 @@ services_utils.prototype.manageService = function (board_id, service, service_ac getServiceInfo(service, function (service_info) { if (service_info.result == "ERROR") { - + if(res != false){ logger.error("[SERVICE] --> getServiceInfo error: " + service_info.message); res.status(500).send(service_info.message); @@ -1314,10 +1314,10 @@ services_utils.prototype.manageService = function (board_id, service, service_ac } }); - + } else if (service_result.result === "WARNING") { - + if(res != false){ logger.warn("[SERVICE] --> " + service_result.message); res.status(500).send(service_result); @@ -1406,7 +1406,7 @@ services_utils.prototype.manageService = function (board_id, service, service_ac response.result = data_p.result; response.message = "DB getActiveService error for '" + service_name + "': " + data_p.message; - + if(res != false){ logger.error("[SERVICE] --> " + response.message); res.status(500).send(response); @@ -1528,7 +1528,10 @@ services_utils.prototype.manageService = function (board_id, service, service_ac ); - } else { + } + else { + + //newPort function is used because we need a TCP port not already used newPort(function (publicPort) { @@ -1655,13 +1658,13 @@ services_utils.prototype.manageService = function (board_id, service, service_ac } - + } - + }); - + break; @@ -1813,16 +1816,16 @@ services_utils.prototype.manageService = function (board_id, service, service_ac else logger.info("[SYSTEM] --> " + service_result.message); } - + } }); - + } } - + } }, @@ -1844,9 +1847,9 @@ services_utils.prototype.manageService = function (board_id, service, service_ac } } - + ); - + } @@ -1881,7 +1884,7 @@ services_utils.prototype.manageService = function (board_id, service, service_ac } - + }); @@ -1993,38 +1996,53 @@ function newPort(callback) { } else { - for(var key=0; key < busy.message.length; key++) { + if (busy.message.length == 0){ - (function(key) { + free = all_ports; + logger.debug("[SERVICE] --> Free ports (all): " + free); + var rand_selected_port = free[Math.floor(Math.random()*free.length)]; - busy_list.push(busy.message[key].public_port); + response.message = rand_selected_port; + response.result = "SUCCESS"; + callback(response); - if (key == busy.message.length - 1) { + } + else{ - logger.debug("[SERVICE] --> Busy ports: " + busy_list); + for(var key=0; key < busy.message.length; key++) { - if(busy.message.length < n_ports ) { + (function(key) { - free = all_ports.filter(n => !busy_list.includes(n)) + busy_list.push(busy.message[key].public_port); - logger.debug("[SERVICE] --> Free ports: " + free); + if (key == busy.message.length - 1) { - var rand_selected_port = free[Math.floor(Math.random()*free.length)]; + logger.debug("[SERVICE] --> Busy ports: " + busy_list); - response.message = rand_selected_port; - response.result = "SUCCESS"; - callback(response); - } - else{ - response.message = "No more ports available!"; - response.result = "ERROR"; - callback(response); - } + if(busy.message.length < n_ports ) { + free = all_ports.filter(n => !busy_list.includes(n)) - } + logger.debug("[SERVICE] --> Free ports: " + free); - })(key); + var rand_selected_port = free[Math.floor(Math.random()*free.length)]; + + response.message = rand_selected_port; + response.result = "SUCCESS"; + callback(response); + } + else{ + response.message = "No more ports available!"; + response.result = "ERROR"; + callback(response); + } + + + } + + })(key); + + } } @@ -2033,6 +2051,8 @@ function newPort(callback) { + + } }); diff --git a/package.json b/package.json index f80874a..9bd3b2d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@mdslab/iotronic-standalone", - "version": "2.3.4", + "version": "2.3.5", "description": "IoTronic-standalone is the implementation of a personal Cloud to remote manage embedded devices (Arduino YUN/Linino One, Raspberry Pi 2/3, etc)", "main": "lib/iotronic_standalone.js", "scripts": { diff --git a/utils/plugin-exec/plugin_async.js b/utils/plugin-exec/plugin_async.js new file mode 100644 index 0000000..95ef028 --- /dev/null +++ b/utils/plugin-exec/plugin_async.js @@ -0,0 +1,139 @@ +var fs = require("fs"); +const {PythonShell} = require('python-shell'); +var net = require('net'); + +var LIGHTNINGROD_HOME = process.env.LIGHTNINGROD_HOME; + +var PLUGINS_STORE = process.env.IOTRONIC_HOME + '/plugins/'; + +console.log("LR Home:",LIGHTNINGROD_HOME) + +const args = process.argv; +//console.log(args); + +// Inputs +plugin_source = args[1] +plugin_name = args[2] +version = args[3] +plugin_json = args[4] + + +console.log(plugin_source,plugin_name,version,plugin_json); + + +var pyshell = null; +var s_server = null; +var socketPath = '/tmp/plugin-'+plugin_name; + +var response = { + message: '', + result: '' +}; + + +// Callback for socket +var handler = function(socket){ + + // Listen for data from client + socket.on('data',function(bytes){ + + var data = bytes.toString(); // Decode byte string + var data_parsed = JSON.parse(data); // Parse JSON response + + if(data_parsed.result == "ERROR"){ + + response.result = "ERROR"; + response.message = data_parsed.payload; + console.log('[PLUGIN] - Error in '+plugin_name + ':\n'+JSON.stringify(response.message, null, "\t")); + + }else{ + + response.result = "SUCCESS"; + response.message = data_parsed.payload; + console.log('[PLUGIN] - '+plugin_name + ': '+ JSON.stringify(response.message, null, "\t")); + + } + + }); + + // On client close + socket.on('end', function() { + console.log('[PLUGIN-SOCKET] - Socket disconnected'); + s_server.close(function(){ + console.log('[PLUGIN-SOCKET] - Server socket closed'); + }); + + }); + + +}; + + + +// Remove an existing socket +fs.unlink(socketPath, function(){ + // Create the server, give it our callback handler and listen at the path + + s_server = net.createServer(handler).listen(socketPath, function(){ + console.log('[PLUGIN-SOCKET] - Socket in listening...'); + console.log('[PLUGIN-SOCKET] --> socket: '+socketPath); + }) + +}); + + +var options = { + mode: 'text', + pythonPath: '/usr/bin/python3', + pythonOptions: ['-u'], + //scriptPath: __dirname, + args: [plugin_name, version, plugin_json] +}; + + +//var pyshell = new PythonShell('./python/async-wrapper.py', options); +pyshell = new PythonShell('/usr/lib/node_modules/@mdslab/iotronic-lightning-rod/modules/plugins-manager/python/async-wrapper.py', options); + +PY_PID = pyshell.childProcess.pid; +console.log("[PLUGIN-SHELL] - PID wrapper: "+ PY_PID); + + + +pyshell.on('message', function (message) { + // received a message sent from the Python script (a simple "print" statement) + console.log("[PLUGIN-WRAPPER] - PYTHON: "+message); +}); + +// end the input stream and allow the process to exit +pyshell.end(function (err, code, signal) { + + if (err){ + + //console.log("Plugin '"+plugin_name+"' error logs: \n" + JSON.stringify(err, null, "\t")); + + response.result = "ERROR"; + response.message = "Error plugin execution: please check plugin logs: \n" + err.traceback; + + console.log(response) + + + } + else{ + + console.log('[PLUGIN-SHELL] - Python shell of "'+plugin_name+'" plugin terminated: {signal: '+ signal+', code: '+code+'}'); + + if(signal == null && code == 0){ + + console.log("[PLUGIN-SHELL] --> unexpected '"+plugin_name+"' plugin termination!"); + + }else{ + console.log("[PLUGIN-SHELL] --> Python plugin '"+plugin_name+"' terminated!") + } + + } + + + +}); + + diff --git a/utils/plugin-exec/plugin_sync.js b/utils/plugin-exec/plugin_sync.js new file mode 100644 index 0000000..bf1dc0a --- /dev/null +++ b/utils/plugin-exec/plugin_sync.js @@ -0,0 +1,141 @@ +var fs = require("fs"); +const {PythonShell} = require('python-shell'); +var net = require('net'); + +var LIGHTNINGROD_HOME = process.env.LIGHTNINGROD_HOME; + +var PLUGINS_STORE = process.env.IOTRONIC_HOME + '/plugins/'; + +console.log("LR Home:",LIGHTNINGROD_HOME) + +const args = process.argv; +//console.log(args); + +// Inputs +plugin_source = args[1] +plugin_name = args[2] +version = args[3] +plugin_json = args[4] + + +console.log(plugin_source,plugin_name,version,plugin_json); + + +var pyshell = null; +var s_server = null; +var socketPath = '/tmp/plugin-'+plugin_name; + +var response = { + message: '', + result: '' +}; + + +// Callback for socket +var handler = function(socket){ + + // Listen for data from client + socket.on('data', function(bytes){ + + var data = bytes.toString(); // Decode byte string + var data_parsed = JSON.parse(data); // Parse JSON response + + if(data_parsed.result == "ERROR"){ + + response.result = "ERROR"; + response.message = "Error in plugin execution: " + data_parsed.payload; + console.log('[PLUGIN] - Error in '+plugin_name + ':\n'+JSON.stringify(response.message, null, "\t")); + + }else{ + + try{ + + response.result = "SUCCESS"; + response.message = data_parsed.payload; + console.log('[PLUGIN] - '+plugin_name + ': '+ JSON.stringify(response.message, null, "\t")); + + } + catch(err){ + response.result = "ERROR"; + response.message = JSON.stringify(err); + console.log('Error parsing '+plugin_name + ' plugin response: '+ response.message); + } + + + } + + + }); + + // On client close + socket.on('end', function() { + + console.log('[PLUGIN-SOCKET] - Socket disconnected'); + + s_server.close(function(){ + + console.log('[PLUGIN-SOCKET] - Server socket closed'); + + }); + + }); + +}; + +// Remove an existing plugin socket +fs.unlink(socketPath, function(){ + + var plugin_folder = PLUGINS_STORE + plugin_name; + var schema_outputFilename = plugin_folder + "/" + plugin_name + '.json'; + + // Create the server, give it our callback handler and listen at the path + s_server = net.createServer(handler).listen(socketPath, function() { + console.log('[PLUGIN-SOCKET] - Socket in listening...'); + console.log('[PLUGIN-SOCKET] --> socket: '+socketPath); + + + // after socket creation we will start the plugin wrapper + var options = { + mode: 'text', + pythonPath: '/usr/bin/python3', + pythonOptions: ['-u'], + //scriptPath: __dirname, + args: [plugin_name, version, plugin_json] + }; + + let pyshell = new PythonShell('/usr/lib/node_modules/@mdslab/iotronic-lightning-rod/modules/plugins-manager/python/sync-wrapper.py', options); + // it will create a python instance like this: + // python -u /opt/stack4things/lightning-rod/modules/plugins-manager/python/sync-wrapper.py py_sync {"name":"S4T"} + + console.log("[PLUGIN-SHELL] - PID wrapper: "+pyshell.childProcess.pid); + + // listening 'print' output + pyshell.on('message', function (message) { + // received a message sent from the Python script (a simple "print" statement) + console.log("[PLUGIN-WRAPPER] - PYTHON: "+message); + }); + + + // end the input stream and allow the process to exit + pyshell.end(function (err, code, signal) { + + if (err){ + + response.result = "ERROR"; + response.message = err; + console.log(response); + + }else{ + console.log('[PLUGIN-SHELL] - Python shell terminated: {signal: '+ signal+', code: '+code+'}'); + } + + }); + + + + }) + + + } + +); \ No newline at end of file diff --git a/utils/s4t-mariadb.sql b/utils/s4t-mariadb.sql new file mode 100644 index 0000000..984971e --- /dev/null +++ b/utils/s4t-mariadb.sql @@ -0,0 +1,709 @@ +-- MySQL Script generated by MySQL Workbench +-- gio 13 set 2018 09:45:52 CEST +-- Model: New Model Version: 1.0 +-- MySQL Workbench Forward Engineering + +SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; +SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; +SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES'; + +-- ----------------------------------------------------- +-- Schema s4t-iotronic +-- ----------------------------------------------------- +DROP SCHEMA IF EXISTS `s4t-iotronic` ; + +-- ----------------------------------------------------- +-- Schema s4t-iotronic +-- ----------------------------------------------------- +CREATE SCHEMA IF NOT EXISTS `s4t-iotronic` DEFAULT CHARACTER SET latin1 ; +USE `s4t-iotronic` ; + +-- ----------------------------------------------------- +-- Table `s4t-iotronic`.`layouts` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `s4t-iotronic`.`layouts` ; + +CREATE TABLE IF NOT EXISTS `s4t-iotronic`.`layouts` ( + `id_layout` INT NOT NULL AUTO_INCREMENT, + `model` VARCHAR(45) NULL, + `manufacturer` VARCHAR(45) NULL, + `image` VARCHAR(45) NULL, + `layout` VARCHAR(45) NOT NULL, + `distro` VARCHAR(45) NOT NULL, + PRIMARY KEY (`id_layout`)) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `s4t-iotronic`.`projects` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `s4t-iotronic`.`projects` ; + +CREATE TABLE IF NOT EXISTS `s4t-iotronic`.`projects` ( + `uuid` VARCHAR(36) NOT NULL, + `name` VARCHAR(50) NOT NULL, + `description` VARCHAR(255) NULL DEFAULT NULL, + PRIMARY KEY (`uuid`)) +ENGINE = InnoDB +AUTO_INCREMENT = 2 +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `s4t-iotronic`.`users` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `s4t-iotronic`.`users` ; + +CREATE TABLE IF NOT EXISTS `s4t-iotronic`.`users` ( + `uuid` VARCHAR(36) NOT NULL, + `username` VARCHAR(50) NOT NULL, + `password` VARCHAR(60) NULL DEFAULT NULL, + `email` VARCHAR(50) NOT NULL, + `first_name` VARCHAR(45) NULL DEFAULT NULL, + `last_name` VARCHAR(45) NULL DEFAULT NULL, + `latest_update` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`uuid`), + UNIQUE INDEX `username_UNIQUE` (`username` ASC)) +ENGINE = InnoDB +AUTO_INCREMENT = 2 +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `s4t-iotronic`.`boards` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `s4t-iotronic`.`boards` ; + +CREATE TABLE IF NOT EXISTS `s4t-iotronic`.`boards` ( + `board_id` VARCHAR(36) NOT NULL, + `label` VARCHAR(100) NOT NULL, + `session_id` VARCHAR(255) NULL DEFAULT NULL, + `status` VARCHAR(15) NULL DEFAULT NULL, + `latest_update` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `layout_id` INT NULL, + `description` VARCHAR(255) NULL DEFAULT NULL, + `net_enabled` TINYINT(1) NOT NULL, + `projects_id` VARCHAR(36) NULL, + `users_id` VARCHAR(36) NULL, + `mobile` TINYINT(1) NOT NULL, + `position_refresh_time` INT NULL, + `notify` TINYINT(1) NOT NULL, + `notify_rate` VARCHAR(45) NULL, + `notify_retry` INT NULL, + `extra` LONGTEXT NULL, + `state` VARCHAR(45) NOT NULL, + `pubkey` LONGTEXT NULL, + `password` VARCHAR(60) NULL, + `lr_version` VARCHAR(10) NULL, + PRIMARY KEY (`board_id`), + INDEX `fk_boards_layout1_idx` (`layout_id` ASC), + INDEX `fk_boards_projects1_idx` (`projects_id` ASC), + INDEX `fk_boards_users1_idx` (`users_id` ASC), + CONSTRAINT `fk_boards_layout1` + FOREIGN KEY (`layout_id`) + REFERENCES `s4t-iotronic`.`layouts` (`id_layout`) + ON DELETE SET NULL + ON UPDATE CASCADE, + CONSTRAINT `fk_boards_projects1` + FOREIGN KEY (`projects_id`) + REFERENCES `s4t-iotronic`.`projects` (`uuid`) + ON DELETE SET NULL + ON UPDATE CASCADE, + CONSTRAINT `fk_boards_users1` + FOREIGN KEY (`users_id`) + REFERENCES `s4t-iotronic`.`users` (`uuid`) + ON DELETE SET NULL + ON UPDATE CASCADE) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `s4t-iotronic`.`plugin_types` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `s4t-iotronic`.`plugin_types` ; + +CREATE TABLE IF NOT EXISTS `s4t-iotronic`.`plugin_types` ( + `id` INT NOT NULL, + `type` VARCHAR(45) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE INDEX `tag_UNIQUE` (`type` ASC)) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `s4t-iotronic`.`plugin_tags` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `s4t-iotronic`.`plugin_tags` ; + +CREATE TABLE IF NOT EXISTS `s4t-iotronic`.`plugin_tags` ( + `id` INT NOT NULL, + `tag` VARCHAR(45) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE INDEX `tag_UNIQUE` (`tag` ASC)) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `s4t-iotronic`.`plugins` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `s4t-iotronic`.`plugins` ; + +CREATE TABLE IF NOT EXISTS `s4t-iotronic`.`plugins` ( + `id` INT(11) NOT NULL AUTO_INCREMENT, + `name` VARCHAR(100) NOT NULL, + `category` VARCHAR(20) NOT NULL, + `version` VARCHAR(45) NOT NULL, + `checksum` VARCHAR(100) NOT NULL, + `type_id` INT NOT NULL, + `tag_id` INT NOT NULL, + `code` LONGTEXT NOT NULL, + `defaults` LONGTEXT NULL, + `updated_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `created_at` TIMESTAMP NULL DEFAULT NULL, + `description` VARCHAR(255) NULL DEFAULT 'no description', + PRIMARY KEY (`id`, `type_id`, `tag_id`), + UNIQUE INDEX `name-ver-cat-type` (`name` ASC, `version` ASC, `category` ASC, `type_id` ASC), + INDEX `fk_plugins_plugin_type1_idx` (`type_id` ASC), + INDEX `fk_plugins_plugin_tags1_idx` (`tag_id` ASC), + CONSTRAINT `fk_plugins_plugin_type1` + FOREIGN KEY (`type_id`) + REFERENCES `s4t-iotronic`.`plugin_types` (`id`) + ON DELETE NO ACTION + ON UPDATE CASCADE, + CONSTRAINT `fk_plugins_plugin_tags1` + FOREIGN KEY (`tag_id`) + REFERENCES `s4t-iotronic`.`plugin_tags` (`id`) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB +AUTO_INCREMENT = 10 +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `s4t-iotronic`.`plugins_injected` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `s4t-iotronic`.`plugins_injected` ; + +CREATE TABLE IF NOT EXISTS `s4t-iotronic`.`plugins_injected` ( + `board_id` VARCHAR(36) NOT NULL, + `plugin_id` INT(11) NOT NULL, + `plugin_name` VARCHAR(100) NULL, + `state` VARCHAR(20) NOT NULL, + `latest_change` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `parameters` LONGTEXT NULL, + INDEX `fk_plugins_injected_plugins1_idx` (`plugin_id` ASC), + PRIMARY KEY (`board_id`, `plugin_id`), + INDEX `fk_plugins_injected_boards1_idx` (`board_id` ASC), + CONSTRAINT `fk_plugins_injected_plugins1` + FOREIGN KEY (`plugin_id`) + REFERENCES `s4t-iotronic`.`plugins` (`id`) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT `fk_plugins_injected_boards1` + FOREIGN KEY (`board_id`) + REFERENCES `s4t-iotronic`.`boards` (`board_id`) + ON DELETE CASCADE + ON UPDATE CASCADE) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `s4t-iotronic`.`vlans` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `s4t-iotronic`.`vlans` ; + +CREATE TABLE IF NOT EXISTS `s4t-iotronic`.`vlans` ( + `id` INT NOT NULL AUTO_INCREMENT, + `vlan_name` VARCHAR(45) NOT NULL, + `vlan_ip` VARCHAR(45) NOT NULL, + `vlan_mask` VARCHAR(45) NOT NULL, + `net_uuid` VARCHAR(45) NOT NULL, + PRIMARY KEY (`id`)) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `s4t-iotronic`.`socat_connections` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `s4t-iotronic`.`socat_connections` ; + +CREATE TABLE IF NOT EXISTS `s4t-iotronic`.`socat_connections` ( + `id` INT NOT NULL AUTO_INCREMENT, + `id_board` VARCHAR(36) NOT NULL, + `port` INT(6) NULL, + `ip_board` VARCHAR(45) NULL, + `ip_server` VARCHAR(45) NULL, + `status` VARCHAR(45) NOT NULL, + PRIMARY KEY (`id`, `id_board`), + INDEX `fk_socat_connections_boards1_idx` (`id_board` ASC), + CONSTRAINT `fk_socat_connections_boards1` + FOREIGN KEY (`id_board`) + REFERENCES `s4t-iotronic`.`boards` (`board_id`) + ON DELETE CASCADE + ON UPDATE CASCADE) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `s4t-iotronic`.`vlans_connection` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `s4t-iotronic`.`vlans_connection` ; + +CREATE TABLE IF NOT EXISTS `s4t-iotronic`.`vlans_connection` ( + `id` INT NOT NULL AUTO_INCREMENT, + `id_vlan` INT NOT NULL, + `id_socat_connection` INT NOT NULL, + `ip_vlan` VARCHAR(45) NOT NULL, + PRIMARY KEY (`id`), + INDEX `fk_vlans_connection_vlans1_idx` (`id_vlan` ASC), + INDEX `fk_vlans_connection_socat_connections1_idx` (`id_socat_connection` ASC), + CONSTRAINT `fk_vlans_connection_vlans1` + FOREIGN KEY (`id_vlan`) + REFERENCES `s4t-iotronic`.`vlans` (`id`) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT `fk_vlans_connection_socat_connections1` + FOREIGN KEY (`id_socat_connection`) + REFERENCES `s4t-iotronic`.`socat_connections` (`id`) + ON DELETE CASCADE + ON UPDATE CASCADE) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `s4t-iotronic`.`sensors` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `s4t-iotronic`.`sensors` ; + +CREATE TABLE IF NOT EXISTS `s4t-iotronic`.`sensors` ( + `id` INT NOT NULL, + `type` VARCHAR(45) NOT NULL, + `unit` VARCHAR(45) NOT NULL, + `fabric_name` VARCHAR(45) NULL, + `model` VARCHAR(45) NULL, + PRIMARY KEY (`id`)) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `s4t-iotronic`.`sensors_on_board` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `s4t-iotronic`.`sensors_on_board` ; + +CREATE TABLE IF NOT EXISTS `s4t-iotronic`.`sensors_on_board` ( + `id_sensor` INT NOT NULL, + `id_board` VARCHAR(36) NOT NULL, + PRIMARY KEY (`id_sensor`, `id_board`), + INDEX `fk_sensors_on_board_boards_connected1_idx` (`id_board` ASC), + CONSTRAINT `fk_sensors_on_board_sensors1` + FOREIGN KEY (`id_sensor`) + REFERENCES `s4t-iotronic`.`sensors` (`id`) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT `fk_sensors_on_board_boards1` + FOREIGN KEY (`id_board`) + REFERENCES `s4t-iotronic`.`boards` (`board_id`) + ON DELETE CASCADE + ON UPDATE CASCADE) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `s4t-iotronic`.`plugin_sensors` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `s4t-iotronic`.`plugin_sensors` ; + +CREATE TABLE IF NOT EXISTS `s4t-iotronic`.`plugin_sensors` ( + `plugins_id` INT(11) NOT NULL, + `sensors_id` INT NOT NULL, + INDEX `fk_plugin_sensors_plugins1_idx` (`plugins_id` ASC), + INDEX `fk_plugin_sensors_sensors1_idx` (`sensors_id` ASC), + PRIMARY KEY (`plugins_id`, `sensors_id`), + CONSTRAINT `fk_plugin_sensors_plugins1` + FOREIGN KEY (`plugins_id`) + REFERENCES `s4t-iotronic`.`plugins` (`id`) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT `fk_plugin_sensors_sensors1` + FOREIGN KEY (`sensors_id`) + REFERENCES `s4t-iotronic`.`sensors` (`id`) + ON DELETE NO ACTION + ON UPDATE CASCADE) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `s4t-iotronic`.`free_addresses` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `s4t-iotronic`.`free_addresses` ; + +CREATE TABLE IF NOT EXISTS `s4t-iotronic`.`free_addresses` ( + `ip` VARCHAR(45) NOT NULL, + `vlans_id` INT NOT NULL, + `insert_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + INDEX `fk_free_addresses_vlans1_idx` (`vlans_id` ASC), + PRIMARY KEY (`ip`, `vlans_id`), + CONSTRAINT `fk_free_addresses_vlans1` + FOREIGN KEY (`vlans_id`) + REFERENCES `s4t-iotronic`.`vlans` (`id`) + ON DELETE CASCADE + ON UPDATE CASCADE) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `s4t-iotronic`.`drivers` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `s4t-iotronic`.`drivers` ; + +CREATE TABLE IF NOT EXISTS `s4t-iotronic`.`drivers` ( + `id` INT(11) NOT NULL AUTO_INCREMENT, + `name` VARCHAR(20) NOT NULL, + `jsonschema` LONGTEXT NOT NULL, + `code` LONGTEXT NOT NULL, + PRIMARY KEY (`id`), + UNIQUE INDEX `name_UNIQUE` (`name` ASC)) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `s4t-iotronic`.`drivers_injected` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `s4t-iotronic`.`drivers_injected` ; + +CREATE TABLE IF NOT EXISTS `s4t-iotronic`.`drivers_injected` ( + `driver_id` INT NOT NULL, + `board_id` VARCHAR(36) NOT NULL, + `state` VARCHAR(20) NOT NULL, + `latest_change` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`driver_id`, `board_id`), + INDEX `fk_drivers_injected_boards1_idx` (`board_id` ASC), + CONSTRAINT `fk_drivers_injected_drivers1` + FOREIGN KEY (`driver_id`) + REFERENCES `s4t-iotronic`.`drivers` (`id`) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT `fk_drivers_injected_boards_connected1` + FOREIGN KEY (`board_id`) + REFERENCES `s4t-iotronic`.`boards` (`board_id`) + ON DELETE CASCADE + ON UPDATE CASCADE) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `s4t-iotronic`.`mountpoints` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `s4t-iotronic`.`mountpoints` ; + +CREATE TABLE IF NOT EXISTS `s4t-iotronic`.`mountpoints` ( + `src_board` VARCHAR(36) NOT NULL, + `dst_board` VARCHAR(36) NOT NULL, + `src_path` VARCHAR(255) NOT NULL, + `dst_path` VARCHAR(255) NOT NULL, + `status` VARCHAR(45) NOT NULL, + PRIMARY KEY (`src_board`, `dst_board`, `src_path`, `dst_path`), + INDEX `fk_mountpoints_boards_connected1_idx` (`src_board` ASC), + INDEX `fk_mountpoints_boards_connected2_idx` (`dst_board` ASC), + CONSTRAINT `fk_mountpoints_boards1` + FOREIGN KEY (`src_board`) + REFERENCES `s4t-iotronic`.`boards` (`board_id`) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT `fk_mountpoints_boards2` + FOREIGN KEY (`dst_board`) + REFERENCES `s4t-iotronic`.`boards` (`board_id`) + ON DELETE CASCADE + ON UPDATE CASCADE) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `s4t-iotronic`.`services` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `s4t-iotronic`.`services` ; + +CREATE TABLE IF NOT EXISTS `s4t-iotronic`.`services` ( + `id` INT(11) NOT NULL AUTO_INCREMENT, + `name` VARCHAR(45) NOT NULL, + `port` INT NOT NULL, + `protocol` VARCHAR(10) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE INDEX `name_UNIQUE` (`name` ASC)) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `s4t-iotronic`.`active_services` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `s4t-iotronic`.`active_services` ; + +CREATE TABLE IF NOT EXISTS `s4t-iotronic`.`active_services` ( + `service_id` INT NOT NULL, + `board_id` VARCHAR(36) NOT NULL, + `public_port` INT NOT NULL, + `last_update` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `pid` INT NULL, + PRIMARY KEY (`service_id`, `board_id`, `public_port`), + INDEX `fk_active_services_services1_idx` (`service_id` ASC), + INDEX `fk_active_services_boards1_idx` (`board_id` ASC), + UNIQUE INDEX `public_port_UNIQUE` (`public_port` ASC), + CONSTRAINT `fk_active_services_services1` + FOREIGN KEY (`service_id`) + REFERENCES `s4t-iotronic`.`services` (`id`) + ON DELETE NO ACTION + ON UPDATE CASCADE, + CONSTRAINT `fk_active_services_boards1` + FOREIGN KEY (`board_id`) + REFERENCES `s4t-iotronic`.`boards` (`board_id`) + ON DELETE CASCADE + ON UPDATE CASCADE) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `s4t-iotronic`.`coordinates` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `s4t-iotronic`.`coordinates` ; + +CREATE TABLE IF NOT EXISTS `s4t-iotronic`.`coordinates` ( + `coordinates_id` INT NOT NULL AUTO_INCREMENT, + `board_id` VARCHAR(36) NOT NULL, + `altitude` VARCHAR(45) NOT NULL, + `longitude` VARCHAR(45) NOT NULL, + `latitude` VARCHAR(45) NOT NULL, + `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`coordinates_id`), + CONSTRAINT `fk_coordinates_boards1` + FOREIGN KEY (`board_id`) + REFERENCES `s4t-iotronic`.`boards` (`board_id`) + ON DELETE CASCADE + ON UPDATE CASCADE) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `s4t-iotronic`.`modules` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `s4t-iotronic`.`modules` ; + +CREATE TABLE IF NOT EXISTS `s4t-iotronic`.`modules` ( + `id` INT(11) NOT NULL AUTO_INCREMENT, + `name` VARCHAR(45) NOT NULL, + `description` VARCHAR(255) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE INDEX `name_UNIQUE` (`name` ASC)) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `s4t-iotronic`.`active_modules` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `s4t-iotronic`.`active_modules` ; + +CREATE TABLE IF NOT EXISTS `s4t-iotronic`.`active_modules` ( + `module_id` INT NOT NULL, + `board_id` VARCHAR(36) NOT NULL, + `latest_update` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`module_id`, `board_id`), + INDEX `fk_active_services_services1_idx` (`module_id` ASC), + INDEX `fk_active_services_boards1_idx` (`board_id` ASC), + CONSTRAINT `fk_active_services_services10` + FOREIGN KEY (`module_id`) + REFERENCES `s4t-iotronic`.`modules` (`id`) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT `fk_active_services_boards10` + FOREIGN KEY (`board_id`) + REFERENCES `s4t-iotronic`.`boards` (`board_id`) + ON DELETE CASCADE + ON UPDATE CASCADE) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `s4t-iotronic`.`flows` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `s4t-iotronic`.`flows` ; + +CREATE TABLE IF NOT EXISTS `s4t-iotronic`.`flows` ( + `id` INT NOT NULL AUTO_INCREMENT, + `name` VARCHAR(45) NOT NULL, + `description` VARCHAR(255) NULL, + `checksum` VARCHAR(45) NOT NULL, + `code` VARCHAR(45) NOT NULL, + `updated_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `created_at` TIMESTAMP NULL DEFAULT NULL, + PRIMARY KEY (`id`)) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `s4t-iotronic`.`flows_injected` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `s4t-iotronic`.`flows_injected` ; + +CREATE TABLE IF NOT EXISTS `s4t-iotronic`.`flows_injected` ( + `flow_id` INT NOT NULL, + `board_id` VARCHAR(36) NOT NULL, + INDEX `fk_flows_injected_flows1_idx` (`flow_id` ASC), + PRIMARY KEY (`flow_id`, `board_id`), + INDEX `fk_flows_injected_boards1_idx` (`board_id` ASC), + CONSTRAINT `fk_flows_injected_flows1` + FOREIGN KEY (`flow_id`) + REFERENCES `s4t-iotronic`.`flows` (`id`) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT `fk_flows_injected_boards1` + FOREIGN KEY (`board_id`) + REFERENCES `s4t-iotronic`.`boards` (`board_id`) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `s4t-iotronic`.`requests` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `s4t-iotronic`.`requests` ; + +CREATE TABLE IF NOT EXISTS `s4t-iotronic`.`requests` ( + `id_request` VARCHAR(36) NOT NULL, + `project_id` VARCHAR(36) NOT NULL, + `subject` VARCHAR(100) NOT NULL, + `result` VARCHAR(45) NULL DEFAULT NULL, + `timestamp` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`id_request`), + INDEX `fk_requests_projects1_idx` (`project_id` ASC), + CONSTRAINT `fk_requests_projects1` + FOREIGN KEY (`project_id`) + REFERENCES `s4t-iotronic`.`projects` (`uuid`) + ON DELETE CASCADE + ON UPDATE CASCADE) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +-- ----------------------------------------------------- +-- Table `s4t-iotronic`.`results` +-- ----------------------------------------------------- +DROP TABLE IF EXISTS `s4t-iotronic`.`results` ; + +CREATE TABLE IF NOT EXISTS `s4t-iotronic`.`results` ( + `request_id` VARCHAR(36) NOT NULL, + `board_id` VARCHAR(36) NOT NULL, + `result` VARCHAR(45) NULL DEFAULT NULL, + `message` LONGTEXT NULL DEFAULT NULL, + `timestamp` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + INDEX `fk_results_requests1_idx` (`request_id` ASC), + INDEX `fk_results_boards1_idx` (`board_id` ASC), + PRIMARY KEY (`request_id`, `board_id`), + UNIQUE INDEX `request_board_UNIQUE` (`request_id` ASC, `board_id` ASC), + CONSTRAINT `fk_results_requests1` + FOREIGN KEY (`request_id`) + REFERENCES `s4t-iotronic`.`requests` (`id_request`) + ON DELETE CASCADE + ON UPDATE CASCADE, + CONSTRAINT `fk_results_boards1` + FOREIGN KEY (`board_id`) + REFERENCES `s4t-iotronic`.`boards` (`board_id`) + ON DELETE CASCADE + ON UPDATE CASCADE) +ENGINE = InnoDB +DEFAULT CHARACTER SET = utf8; + + +SET SQL_MODE=@OLD_SQL_MODE; +SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; +SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS; + +-- ----------------------------------------------------- +-- Data for table `s4t-iotronic`.`layouts` +-- ----------------------------------------------------- +START TRANSACTION; +USE `s4t-iotronic`; +INSERT INTO `s4t-iotronic`.`layouts` (`id_layout`, `model`, `manufacturer`, `image`, `layout`, `distro`) VALUES (1, 'YUN', 'Arduino', 'Linino', 'arduino_yun', 'openwrt'); +INSERT INTO `s4t-iotronic`.`layouts` (`id_layout`, `model`, `manufacturer`, `image`, `layout`, `distro`) VALUES (2, 'server', 'generic', 'Ubuntu', 'server', 'debian'); +INSERT INTO `s4t-iotronic`.`layouts` (`id_layout`, `model`, `manufacturer`, `image`, `layout`, `distro`) VALUES (3, 'Raspberry Pi 3', 'Raspberry', 'LEDE', 'raspberry_pi', 'openwrt'); +INSERT INTO `s4t-iotronic`.`layouts` (`id_layout`, `model`, `manufacturer`, `image`, `layout`, `distro`) VALUES (4, 'Raspberry Pi 3', 'Raspberry', 'Raspbian', 'raspberry_pi', 'debian'); +INSERT INTO `s4t-iotronic`.`layouts` (`id_layout`, `model`, `manufacturer`, `image`, `layout`, `distro`) VALUES (5, 'Orange Pi Zero', 'Orange', 'Armbian', 'raspberry_pi', 'debian'); +INSERT INTO `s4t-iotronic`.`layouts` (`id_layout`, `model`, `manufacturer`, `image`, `layout`, `distro`) VALUES (6, 'Artik', 'Samsung', 'Ubuntu-16.04', 'artik', 'debian'); + +COMMIT; + + +-- ----------------------------------------------------- +-- Data for table `s4t-iotronic`.`plugin_types` +-- ----------------------------------------------------- +START TRANSACTION; +USE `s4t-iotronic`; +INSERT INTO `s4t-iotronic`.`plugin_types` (`id`, `type`) VALUES (1, 'nodejs'); +INSERT INTO `s4t-iotronic`.`plugin_types` (`id`, `type`) VALUES (2, 'python'); + +COMMIT; + + +-- ----------------------------------------------------- +-- Data for table `s4t-iotronic`.`plugin_tags` +-- ----------------------------------------------------- +START TRANSACTION; +USE `s4t-iotronic`; +INSERT INTO `s4t-iotronic`.`plugin_tags` (`id`, `tag`) VALUES (1, 'released'); +INSERT INTO `s4t-iotronic`.`plugin_tags` (`id`, `tag`) VALUES (2, 'unreleased'); +INSERT INTO `s4t-iotronic`.`plugin_tags` (`id`, `tag`) VALUES (3, 'stable'); +INSERT INTO `s4t-iotronic`.`plugin_tags` (`id`, `tag`) VALUES (4, 'unstable'); + +COMMIT; + + +-- ----------------------------------------------------- +-- Data for table `s4t-iotronic`.`sensors` +-- ----------------------------------------------------- +START TRANSACTION; +USE `s4t-iotronic`; +INSERT INTO `s4t-iotronic`.`sensors` (`id`, `type`, `unit`, `fabric_name`, `model`) VALUES (1, 'temperature', '°C', 'TinkerKit', 'Thermistor'); +INSERT INTO `s4t-iotronic`.`sensors` (`id`, `type`, `unit`, `fabric_name`, `model`) VALUES (2, 'brightness', 'lux', 'TinkerKit', 'LDR'); +INSERT INTO `s4t-iotronic`.`sensors` (`id`, `type`, `unit`, `fabric_name`, `model`) VALUES (3, 'humidity', '%', 'Honeywell', 'HIH-4030'); +INSERT INTO `s4t-iotronic`.`sensors` (`id`, `type`, `unit`, `fabric_name`, `model`) VALUES (4, 'sound_detect', 'db', 'Keyes', 'HY-038'); +INSERT INTO `s4t-iotronic`.`sensors` (`id`, `type`, `unit`, `fabric_name`, `model`) VALUES (5, 'gas', 'ppm', 'Grove', 'MQ9'); +INSERT INTO `s4t-iotronic`.`sensors` (`id`, `type`, `unit`, `fabric_name`, `model`) VALUES (6, 'barometer', 'hPa', 'TinkerKit', 'mpl3115'); + +COMMIT; + + +-- ----------------------------------------------------- +-- Data for table `s4t-iotronic`.`services` +-- ----------------------------------------------------- +START TRANSACTION; +USE `s4t-iotronic`; +INSERT INTO `s4t-iotronic`.`services` (`id`, `name`, `port`, `protocol`) VALUES (1, 'SSH', 22, 'SSH'); +INSERT INTO `s4t-iotronic`.`services` (`id`, `name`, `port`, `protocol`) VALUES (2, 'WEB', 80, 'HTTP'); +INSERT INTO `s4t-iotronic`.`services` (`id`, `name`, `port`, `protocol`) VALUES (3, 'WEB SSL', 443, 'HTTPS'); +INSERT INTO `s4t-iotronic`.`services` (`id`, `name`, `port`, `protocol`) VALUES (4, 'Node-RED', 1880, 'HTTP'); +INSERT INTO `s4t-iotronic`.`services` (`id`, `name`, `port`, `protocol`) VALUES (5, 'Mosquitto', 1883, 'HTTP'); + +COMMIT; +