2011-02-27 Miguel de Dios <miguel.dedios@artica.es>

* pandoradb_data.sql, pandoradb.data.postgreSQL.sql: in the table "tgrupo"
	reordered the last field, this field is "custom_id" with '' value.

	* pandoradb.postgreSQL.sql: commented the first lines before it was for
	make manuallity the schema. Fixed in the "talert_templates" the column
	"id_alert_action" can be null, and fixed the type of column "id_language"
	in table "tlanguage". And move to empty lines some end line comments and
	group in one line the functions for avoid the error in the install.

	* include/db/postgresql.php: fixed in the function "postgresql_get_db_row"
	the quotes for the field, the correct quotes is " for PostgreSQL.
	
	* include/auth/mysql.php, include/functions_db.php: cleaned source code
	style.
	
	* install.php: now the installer can install a schema and data in PostgreSQL
	database.
	
	* extensions/update_manager.php: added some code and TODO comment to fix or
	develop the method to use postgreSQL.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4021 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2011-02-27 05:25:53 +00:00
parent 935a7a5afc
commit 836b2a7a01
9 changed files with 345 additions and 121 deletions

View File

@ -1,3 +1,26 @@
2011-02-27 Miguel de Dios <miguel.dedios@artica.es>
* pandoradb_data.sql, pandoradb.data.postgreSQL.sql: in the table "tgrupo"
reordered the last field, this field is "custom_id" with '' value.
* pandoradb.postgreSQL.sql: commented the first lines before it was for
make manuallity the schema. Fixed in the "talert_templates" the column
"id_alert_action" can be null, and fixed the type of column "id_language"
in table "tlanguage". And move to empty lines some end line comments and
group in one line the functions for avoid the error in the install.
* include/db/postgresql.php: fixed in the function "postgresql_get_db_row"
the quotes for the field, the correct quotes is " for PostgreSQL.
* include/auth/mysql.php, include/functions_db.php: cleaned source code
style.
* install.php: now the installer can install a schema and data in PostgreSQL
database.
* extensions/update_manager.php: added some code and TODO comment to fix or
develop the method to use postgreSQL.
2011-02-24 Miguel de Dios <miguel.dedios@artica.es> 2011-02-24 Miguel de Dios <miguel.dedios@artica.es>
* include/db/postgresql.php: in function "postgresql_connect_db" added * include/db/postgresql.php: in function "postgresql_connect_db" added

View File

@ -134,6 +134,12 @@ if(isset($config['id_user'])) {
} }
$db = NULL; $db = NULL;
switch ($config['dbtype']) {
pandora_update_manager_install (); case 'mysql':
pandora_update_manager_install ();
break;
case 'postgresql':
//TODO MAKE THE UPDATE MANAGER FOR POSTGRESQL
break;
}
?> ?>

View File

@ -232,7 +232,7 @@ function get_user_id ($user) {
* @return bool True if the user exists. * @return bool True if the user exists.
*/ */
function is_user ($user) { function is_user ($user) {
$user = get_db_row ('tusuario', 'id_user', get_user_id ($user)); $user = get_db_row('tusuario', 'id_user', get_user_id ($user));
if (! $user) if (! $user)
return false; return false;
return true; return true;

View File

@ -103,15 +103,15 @@ function postgresql_get_db_row ($table, $field_search, $condition, $fields = fal
} }
if (is_int ($condition)) { if (is_int ($condition)) {
$sql = sprintf ('SELECT %s FROM "%s" WHERE \'%s\' = %d LIMIT 1', $sql = sprintf ('SELECT %s FROM "%s" WHERE "%s" = %d LIMIT 1',
$fields, $table, $field_search, $condition); $fields, $table, $field_search, $condition);
} }
else if (is_float ($condition) || is_double ($condition)) { else if (is_float ($condition) || is_double ($condition)) {
$sql = sprintf ("SELECT %s FROM \"%s\" WHERE '%s' = %f LIMIT 1", $sql = sprintf ("SELECT %s FROM \"%s\" WHERE \"%s\" = %f LIMIT 1",
$fields, $table, $field_search, $condition); $fields, $table, $field_search, $condition);
} }
else { else {
$sql = sprintf ("SELECT %s FROM \"%s\" WHERE '%s' = '%s' LIMIT 1", $sql = sprintf ("SELECT %s FROM \"%s\" WHERE \"%s\" = '%s' LIMIT 1",
$fields, $table, $field_search, $condition); $fields, $table, $field_search, $condition);
} }
$result = get_db_all_rows_sql ($sql); $result = get_db_all_rows_sql ($sql);

View File

@ -71,7 +71,7 @@ function check_login () {
} }
if ((isset($_SESSION["id_usuario"])) AND ($_SESSION["id_usuario"] != "")) { if ((isset($_SESSION["id_usuario"])) AND ($_SESSION["id_usuario"] != "")) {
if (is_user ($_SESSION["id_usuario"])) { if (is_user($_SESSION["id_usuario"])) {
return 0; return 0;
} }
} }

View File

@ -170,20 +170,46 @@ function parse_mysql_dump($url){
return 0; return 0;
} }
function parse_postgresql_dump($url) { function parse_postgresql_dump($connection, $url, $debug = false) {
if (file_exists($url)) { if (file_exists($url)) {
$file_content = file($url); $file_content = file($url);
$query = ""; $query = "";
foreach($file_content as $sql_line){ foreach($file_content as $sql_line){
$comment = preg_match("/^(\s|\t)*--.*$/", $line); $clean_line = trim($sql_line);
$comment = preg_match("/^(\s|\t)*--.*$/", $clean_line);
if ($comment) { if ($comment) {
continue; continue;
} }
$clean_line = $sql_line; if (empty($clean_line)) {
var_dump($clean_line); continue;
}
$query .= $clean_line;
//Check if the end of query with the the semicolon and any returns in the end of line
if(preg_match("/;[\040]*\$/", $clean_line)) {
//And execute and clean buffer
pg_send_query($connection, $query);
$result = pg_get_result($connection);
if ($debug) {
var_dump($query);
var_dump(pg_result_error($result));
}
if (pg_result_status($result) == PGSQL_FATAL_ERROR) {
echo pg_result_error($result);
echo "<i><br>$query<br></i>";
return 0;
}
$query = "";
}
} }
return 1; return 1;
@ -527,8 +553,9 @@ function install_step4() {
check_generic ( 1, "Connection with Database"); check_generic ( 1, "Connection with Database");
// Drop database if needed // Drop database if needed
if ($dbdrop == 1) if ($dbdrop == 1) {
mysql_query ("DROP DATABASE IF EXISTS $dbname"); mysql_query ("DROP DATABASE IF EXISTS $dbname");
}
// Create schema // Create schema
$step1 = mysql_query ("CREATE DATABASE $dbname"); $step1 = mysql_query ("CREATE DATABASE $dbname");
@ -558,10 +585,10 @@ function install_step4() {
$cfgin = fopen ("include/config.inc.php","r"); $cfgin = fopen ("include/config.inc.php","r");
$cfgout = fopen ($pandora_config,"w"); $cfgout = fopen ($pandora_config,"w");
$config_contents = fread ($cfgin, filesize("include/config.inc.php")); $config_contents = fread ($cfgin, filesize("include/config.inc.php"));
$dbtype = 'mysql'; //TODO set other types $dbtype = 'mysql';
$config_new = '<?php $config_new = '<?php
// Begin of automatic config file // Begin of automatic config file
$config["dbtype"] = "' . $dbtype . '"; //DB type (mysql, postgres) $config["dbtype"] = "' . $dbtype . '"; //DB type (mysql, postgresql...in future others)
$config["dbname"]="'.$dbname.'"; // MySQL DataBase name $config["dbname"]="'.$dbname.'"; // MySQL DataBase name
$config["dbuser"]="pandora"; // DB User $config["dbuser"]="pandora"; // DB User
$config["dbpass"]="'.$random_password.'"; // DB Password $config["dbpass"]="'.$random_password.'"; // DB Password
@ -597,7 +624,7 @@ function install_step4() {
// Drop database if needed // Drop database if needed
if ($dbdrop == 1) { if ($dbdrop == 1) {
pg_query($connection, "DROP DATABASE \"" . $dbname . "\";"); $result = pg_query($connection, "DROP DATABASE \"" . $dbname . "\";");
} }
pg_send_query($connection, "CREATE DATABASE \"" . $dbname . "\" WITH ENCODING 'utf8';"); pg_send_query($connection, "CREATE DATABASE \"" . $dbname . "\" WITH ENCODING 'utf8';");
@ -623,8 +650,127 @@ function install_step4() {
check_generic ($step2, "Opening database '$dbname'"); check_generic ($step2, "Opening database '$dbname'");
if ($step2) { if ($step2) {
$step3 = parse_postgresql_dump("pandoradb.postgreSQL.sql"); $step3 = parse_postgresql_dump($connection, "pandoradb.postgreSQL.sql");
check_generic ($step3, "Creating schema"); }
check_generic($step3, "Creating schema");
if ($step3) {
$step4 = parse_postgresql_dump($connection, "pandoradb.data.postgreSQL.sql");
}
check_generic ($step4, "Populating database");
if ($step4) {
$random_password = random_name (8);
pg_query($connection, "DROP USER pandora");
pg_send_query($connection, "CREATE USER pandora WITH PASSWORD '" . $random_password . "'");
$result = pg_get_result($connection);
if (pg_result_status($result) != PGSQL_FATAL_ERROR) {
//Set the privileges for DB
pg_send_query($connection, "GRANT ALL PRIVILEGES ON DATABASE pandora to pandora;");
$result = pg_get_result($connection);
$setDBPrivileges = 0;
if (pg_result_status($result) != PGSQL_FATAL_ERROR) {
$setDBPrivileges = 1;
}
if ($setDBPrivileges) {
//Set the privileges for each tables.
pg_send_query($connection, "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';");
$result = pg_get_result($connection);
$tables = array();
while ($row = pg_fetch_assoc($result)) {
$tables[] = $row['table_name'];
}
$correct = 1;
foreach ($tables as $table) {
pg_send_query($connection, "GRANT ALL PRIVILEGES ON TABLE " . $table . " to pandora;");
$result = pg_get_result($connection);
if (pg_result_status($result) == PGSQL_FATAL_ERROR) {
$correct = 0;
break;
}
//INI ----- Grant for secuences
pg_send_query($connection, "SELECT column_name FROM information_schema.columns WHERE table_name = '" . $table . "';");
$result2 = pg_get_result($connection);
$columns = array();
while ($row = pg_fetch_assoc($result2)) {
$columns[] = $row['column_name'];
}
//Check for each column if it have a sequence to grant
foreach ($columns as $column) {
pg_send_query($connection, "SELECT pg_get_serial_sequence('" . $table . "', '" . $column . "');");
$result3 = pg_get_result($connection);
$sequence = pg_fetch_assoc($result3);
if (!empty($sequence['pg_get_serial_sequence'])) {
pg_send_query($connection, "GRANT ALL PRIVILEGES ON SEQUENCE " . $sequence['pg_get_serial_sequence'] . " to pandora;");
$result4 = pg_get_result($connection);
if (pg_result_status($result4) == PGSQL_FATAL_ERROR) {
$correct = 0;
break;
}
}
}
//END ----- Grant for secuences
}
if ($correct) {
$step5 = 1;
}
}
}
}
check_generic ($step5, "Established privileges for user pandora. A new random password has been generated: <b>$random_password</b><div class='warn'>Please write it down, you will need to setup your Pandora FMS server, editing the </i>/etc/pandora/pandora_server.conf</i> file</div>");
if ($step5) {
$step6 = is_writable("include");
}
check_generic ($step6, "Write permissions to save config file in './include'");
if ($step6) {
$cfgin = fopen ("include/config.inc.php","r");
$cfgout = fopen ($pandora_config,"w");
$config_contents = fread ($cfgin, filesize("include/config.inc.php"));
$dbtype = 'postgresql';
$config_new = '<?php
// Begin of automatic config file
$config["dbtype"] = "' . $dbtype . '"; //DB type (mysql, postgresql...in future others)
$config["dbname"]="'.$dbname.'"; // MySQL DataBase name
$config["dbuser"]="pandora"; // DB User
$config["dbpass"]="'.$random_password.'"; // DB Password
$config["dbhost"]="'.$dbhost.'"; // DB Host
$config["homedir"]="'.$path.'"; // Config homedir
$config["homeurl"]="'.$url.'"; // Base URL
// End of automatic config file
?>';
$step7 = fputs ($cfgout, $config_new);
$step7 = $step7 + fputs ($cfgout, $config_contents);
if ($step7 > 0)
$step7 = 1;
fclose ($cfgin);
fclose ($cfgout);
chmod ($pandora_config, 0600);
}
check_generic ($step7, "Created new config file at '".$pandora_config."'");
if (($step7 + $step6 + $step5 + $step4 + $step3 + $step2 + $step1) == 7) {
$everything_ok = 1;
} }
} }
break; break;
@ -704,19 +850,20 @@ function install_step5() {
if (! isset($_GET["step"])){ if (! isset($_GET["step"])){
install_step1(); install_step1();
} else { }
else {
$step = $_GET["step"]; $step = $_GET["step"];
switch ($step) { switch ($step) {
case 11: install_step1_licence(); case 11: install_step1_licence();
break; break;
case 2: install_step2(); case 2: install_step2();
break; break;
case 3: install_step3(); case 3: install_step3();
break; break;
case 4: install_step4(); case 4: install_step4();
break; break;
case 5: install_step5(); case 5: install_step5();
break; break;
} }
} }

View File

@ -105,15 +105,16 @@ COMMIT WORK;
-- --
BEGIN WORK; BEGIN WORK;
LOCK TABLE "tgrupo"; LOCK TABLE "tgrupo";
INSERT INTO "tgrupo" VALUES INSERT INTO "tgrupo" ("id_grupo", "nombre", "icon", "parent", "propagate", "disabled", "custom_id")
(2,'Servers','server_database',0,0,'',0), VALUES
(4,'Firewalls','firewall',0,0,'',0), (2,'Servers','server_database',0,0,0,''),
(8,'Databases','database_gear',0,0,'',0), (4,'Firewalls','firewall',0,0,0,''),
(9,'Network','transmit',0,0,'',0), (8,'Databases','database_gear',0,0,0,''),
(10,'Unknown','world',0,0,'',0), (9,'Network','transmit',0,0,0,''),
(11,'Workstations','computer',0,0,'',0), (10,'Unknown','world',0,0,0,''),
(12,'Applications','applications',0,0,'',0), (11,'Workstations','computer',0,0,0,''),
(13,'Web','world',0,0,'',0); (12,'Applications','applications',0,0,0,''),
(13,'Web','world',0,0,0,'');
COMMIT WORK; COMMIT WORK;
-- --

View File

@ -22,9 +22,9 @@
-- ----------------------------------------------------------- -- -----------------------------------------------------------
-- The charset is for all DB not only table. -- The charset is for all DB not only table.
CREATE DATABASE "pandora" WITH ENCODING 'utf8'; --CREATE DATABASE "pandora" WITH ENCODING 'utf8';
\c "pandora" --\c "pandora"
CREATE LANGUAGE plpgsql; CREATE LANGUAGE plpgsql;
@ -60,9 +60,12 @@ CREATE TABLE "tagente" (
"custom_id" varchar(255) default '', "custom_id" varchar(255) default '',
"server_name" varchar(100) default '', "server_name" varchar(100) default '',
"cascade_protection" SMALLINT NOT NULL default 0, "cascade_protection" SMALLINT NOT NULL default 0,
"timezone_offset" SMALLINT NULL DEFAULT 0, --number of hours of diference with the server timezone --number of hours of diference with the server timezone
"icon_path" VARCHAR(127) NULL DEFAULT NULL, --path in the server to the image of the icon representing the agent "timezone_offset" SMALLINT NULL DEFAULT 0,
"update_gis_data" SMALLINT NOT NULL DEFAULT 1 --set it to one to update the position data (altitude, longitude, latitude) when getting information from the agent or to 0 to keep the last value and don\'t update it --path in the server to the image of the icon representing the agent
"icon_path" VARCHAR(127) NULL DEFAULT NULL,
--set it to one to update the position data (altitude, longitude, latitude) when getting information from the agent or to 0 to keep the last value and don\'t update it
"update_gis_data" SMALLINT NOT NULL DEFAULT 1
); );
CREATE INDEX "tagente_nombre_idx" ON "tagente"("nombre"); CREATE INDEX "tagente_nombre_idx" ON "tagente"("nombre");
CREATE INDEX "tagente_direccion_idx" ON "tagente"("direccion"); CREATE INDEX "tagente_direccion_idx" ON "tagente"("direccion");
@ -239,7 +242,7 @@ CREATE TABLE "talert_templates" (
"id" SERIAL NOT NULL PRIMARY KEY, "id" SERIAL NOT NULL PRIMARY KEY,
"name" text default '', "name" text default '',
"description" TEXT, "description" TEXT,
"id_alert_action" INTEGER NOT NULL REFERENCES talert_actions("id") ON DELETE SET NULL ON UPDATE CASCADE, "id_alert_action" INTEGER REFERENCES talert_actions("id") ON DELETE SET NULL ON UPDATE CASCADE,
"field1" text default '', "field1" text default '',
"field2" text default '', "field2" text default '',
"field3" text NOT NULL, "field3" text NOT NULL,
@ -419,17 +422,12 @@ CREATE TABLE "tincidencia" (
CREATE INDEX "tincidencia_id_1_idx" ON "tincidencia"("id_usuario","id_incidencia"); CREATE INDEX "tincidencia_id_1_idx" ON "tincidencia"("id_usuario","id_incidencia");
CREATE INDEX "tincidencia_id_agente_modulo_idx" ON "tincidencia"("id_agente_modulo"); CREATE INDEX "tincidencia_id_agente_modulo_idx" ON "tincidencia"("id_agente_modulo");
--This function is for to tranlate "on update CURRENT_TIMESTAMP" of MySQL. --This function is for to tranlate "on update CURRENT_TIMESTAMP" of MySQL.
CREATE OR REPLACE FUNCTION update_tincidencia_actualizacion() --It is in only one line because the parser of Pandora installer execute the code at the end with ;
RETURNS TRIGGER AS $$ CREATE OR REPLACE FUNCTION update_tincidencia_actualizacion() RETURNS TRIGGER AS $$ BEGIN NEW.actualizacion = now(); RETURN NEW; END; $$ language 'plpgsql';
BEGIN
NEW.actualizacion = now();
RETURN NEW;
END;
$$ language 'plpgsql';
CREATE TRIGGER trigger_tincidencia_actualizacion BEFORE UPDATE ON tincidencia FOR EACH ROW EXECUTE PROCEDURE update_tincidencia_actualizacion(); CREATE TRIGGER trigger_tincidencia_actualizacion BEFORE UPDATE ON tincidencia FOR EACH ROW EXECUTE PROCEDURE update_tincidencia_actualizacion();
CREATE TABLE "tlanguage" ( CREATE TABLE "tlanguage" (
"id_language" SERIAL NOT NULL PRIMARY KEY, "id_language" varchar(6) NOT NULL default '',
"name" varchar(100) NOT NULL default '' "name" varchar(100) NOT NULL default ''
); );
@ -662,7 +660,7 @@ CREATE TABLE "tusuario" (
"language" varchar(10) default NULL, "language" varchar(10) default NULL,
"timezone" varchar(50) default '', "timezone" varchar(50) default '',
"block_size" INTEGER NOT NULL default 20, "block_size" INTEGER NOT NULL default 20,
"flash_chart" INTEGER NOT NULL default 1, "flash_chart" INTEGER NOT NULL default 1
); );
CREATE TABLE "tusuario_perfil" ( CREATE TABLE "tusuario_perfil" (
@ -823,7 +821,8 @@ CREATE TABLE "tserver_export" (
"port" INTEGER NOT NULL default 0, "port" INTEGER NOT NULL default 0,
"directory" varchar(100) NOT NULL default '', "directory" varchar(100) NOT NULL default '',
"options" varchar(100) NOT NULL default '', "options" varchar(100) NOT NULL default '',
"timezone_offset" SMALLINT NOT NULL default 0 --Number of hours of diference with the server timezone --Number of hours of diference with the server timezone
"timezone_offset" SMALLINT NOT NULL default 0
); );
-- id_export_server is real pandora fms export server process that manages this server -- id_export_server is real pandora fms export server process that manages this server
@ -861,16 +860,23 @@ CREATE TABLE "tplanned_downtime_agents" (
-- ----------------------------------------------------- -- -----------------------------------------------------
--Table to store historical GIS information of the agents --Table to store historical GIS information of the agents
CREATE TABLE "tgis_data_history" ( CREATE TABLE "tgis_data_history" (
"id_tgis_data" SERIAL NOT NULL PRIMARY KEY, --key of the table --key of the table
"id_tgis_data" SERIAL NOT NULL PRIMARY KEY,
"longitude" DOUBLE PRECISION NOT NULL, "longitude" DOUBLE PRECISION NOT NULL,
"latitude" DOUBLE PRECISION NOT NULL, "latitude" DOUBLE PRECISION NOT NULL,
"altitude" DOUBLE PRECISION NOT NULL, "altitude" DOUBLE PRECISION NOT NULL,
"start_timestamp" TIMESTAMP without time zone DEFAULT CURRENT_TIMESTAMP, --timestamp on wich the agente started to be in this position --timestamp on wich the agente started to be in this position
"end_timestamp" TIMESTAMP without time zone default NULL, --timestamp on wich the agent was placed for last time on this position "start_timestamp" TIMESTAMP without time zone DEFAULT CURRENT_TIMESTAMP,
"description" TEXT DEFAULT NULL, --description of the region correoponding to this placemnt --timestamp on wich the agent was placed for last time on this position
"manual_placement" SMALLINT NOT NULL default 0, --0 to show that the position cames from the agent, 1 to show that the position was established manualy "end_timestamp" TIMESTAMP without time zone default NULL,
"number_of_packages" INTEGER NOT NULL default 1, --Number of data packages received with this position from the start_timestampa to the_end_timestamp --description of the region correoponding to this placemnt
"tagente_id_agente" INTEGER NOT NULL --reference to the agent "description" TEXT DEFAULT NULL,
-- 0 to show that the position cames from the agent, 1 to show that the position was established manualy
"manual_placement" SMALLINT NOT NULL default 0,
-- Number of data packages received with this position from the start_timestampa to the_end_timestamp
"number_of_packages" INTEGER NOT NULL default 1,
--reference to the agent
"tagente_id_agente" INTEGER NOT NULL
); );
CREATE INDEX "tgis_data_history_start_timestamp_idx" ON "tgis_data_history"("start_timestamp"); CREATE INDEX "tgis_data_history_start_timestamp_idx" ON "tgis_data_history"("start_timestamp");
CREATE INDEX "tgis_data_history_end_timestamp_idx" ON "tgis_data_history"("end_timestamp"); CREATE INDEX "tgis_data_history_end_timestamp_idx" ON "tgis_data_history"("end_timestamp");
@ -880,17 +886,28 @@ CREATE INDEX "tgis_data_history_end_timestamp_idx" ON "tgis_data_history"("end_t
-- ----------------------------------------------------- -- -----------------------------------------------------
--Table to store last GIS information of the agents --Table to store last GIS information of the agents
CREATE TABLE "tgis_data_status" ( CREATE TABLE "tgis_data_status" (
"tagente_id_agente" INTEGER NOT NULL REFERENCES "tagente"("id_agente") ON DELETE CASCADE ON UPDATE NO ACTION, --Reference to the agent --Reference to the agent
"current_longitude" DOUBLE PRECISION NOT NULL, --Last received longitude "tagente_id_agente" INTEGER NOT NULL REFERENCES "tagente"("id_agente") ON DELETE CASCADE ON UPDATE NO ACTION,
"current_latitude" DOUBLE PRECISION NOT NULL, --Last received latitude --Last received longitude
"current_altitude" DOUBLE PRECISION NOT NULL, --Last received altitude "current_longitude" DOUBLE PRECISION NOT NULL,
"stored_longitude" DOUBLE PRECISION NOT NULL, --Reference longitude to see if the agent has moved --Last received latitude
"stored_latitude" DOUBLE PRECISION NOT NULL, --Reference latitude to see if the agent has moved "current_latitude" DOUBLE PRECISION NOT NULL,
"stored_altitude" DOUBLE PRECISION DEFAULT NULL, --Reference altitude to see if the agent has moved --Last received altitude
"number_of_packages" INTEGER NOT NULL default 1, --Number of data packages received with this position since start_timestampa "current_altitude" DOUBLE PRECISION NOT NULL,
"start_timestamp" TIMESTAMP without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, --Timestamp on wich the agente started to be in this position --Reference longitude to see if the agent has moved
"manual_placement" SMALLINT NOT NULL default 0, --0 to show that the position cames from the agent, 1 to show that the position was established manualy "stored_longitude" DOUBLE PRECISION NOT NULL,
"description" TEXT NULL, --description of the region correoponding to this placemnt --Reference latitude to see if the agent has moved
"stored_latitude" DOUBLE PRECISION NOT NULL,
--Reference altitude to see if the agent has moved
"stored_altitude" DOUBLE PRECISION DEFAULT NULL,
--Number of data packages received with this position since start_timestampa
"number_of_packages" INTEGER NOT NULL default 1,
--Timestamp on wich the agente started to be in this position
"start_timestamp" TIMESTAMP without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
--0 to show that the position cames from the agent, 1 to show that the position was established manualy
"manual_placement" SMALLINT NOT NULL default 0,
--description of the region correoponding to this placemnt
"description" TEXT NULL,
PRIMARY KEY("tagente_id_agente") PRIMARY KEY("tagente_id_agente")
); );
CREATE INDEX "tgis_data_status_start_timestamp_idx" ON "tgis_data_status"("start_timestamp"); CREATE INDEX "tgis_data_status_start_timestamp_idx" ON "tgis_data_status"("start_timestamp");
@ -901,18 +918,30 @@ CREATE INDEX "tgis_data_status_tagente_id_agente_idx" ON "tgis_data_status"("tag
-- ----------------------------------------------------- -- -----------------------------------------------------
--Table containing information about a gis map --Table containing information about a gis map
CREATE TABLE "tgis_map" ( CREATE TABLE "tgis_map" (
"id_tgis_map" SERIAL NOT NULL PRIMARY KEY, --table identifier --table identifier
"map_name" VARCHAR(63) NOT NULL, --Name of the map "id_tgis_map" SERIAL NOT NULL PRIMARY KEY,
"initial_longitude" DOUBLE PRECISION DEFAULT NULL, --longitude of the center of the map when it\'s loaded --Name of the map
"initial_latitude" DOUBLE PRECISION DEFAULT NULL, --latitude of the center of the map when it\'s loaded "map_name" VARCHAR(63) NOT NULL,
"initial_altitude" DOUBLE PRECISION DEFAULT NULL, --altitude of the center of the map when it\'s loaded --longitude of the center of the map when it\'s loaded
"zoom_level" SMALLINT NOT NULL default 1, --Zoom level to show when the map is loaded. "initial_longitude" DOUBLE PRECISION DEFAULT NULL,
"map_background" VARCHAR(127) DEFAULT NULL, --path on the server to the background image of the map --latitude of the center of the map when it\'s loaded
"default_longitude" DOUBLE PRECISION DEFAULT NULL, --default longitude for the agents placed on the map "initial_latitude" DOUBLE PRECISION DEFAULT NULL,
"default_latitude" DOUBLE PRECISION DEFAULT NULL, --default latitude for the agents placed on the map --altitude of the center of the map when it\'s loaded
"default_altitude" DOUBLE PRECISION DEFAULT NULL, --default altitude for the agents placed on the map "initial_altitude" DOUBLE PRECISION DEFAULT NULL,
"group_id" INTEGER NOT NULL default 0, --Group that owns the map --Zoom level to show when the map is loaded.
"default_map" SMALLINT NOT NULL default 0 --1 if this is the default map, 0 in other case "zoom_level" SMALLINT NOT NULL default 1,
--path on the server to the background image of the map
"map_background" VARCHAR(127) DEFAULT NULL,
--default longitude for the agents placed on the map
"default_longitude" DOUBLE PRECISION DEFAULT NULL,
--default latitude for the agents placed on the map
"default_latitude" DOUBLE PRECISION DEFAULT NULL,
--default altitude for the agents placed on the map
"default_altitude" DOUBLE PRECISION DEFAULT NULL,
--Group that owns the map
"group_id" INTEGER NOT NULL default 0,
--1 if this is the default map, 0 in other case
"default_map" SMALLINT NOT NULL default 0
); );
CREATE INDEX "tgis_map_tagente_map_name_idx" ON "tgis_map"("map_name"); CREATE INDEX "tgis_map_tagente_map_name_idx" ON "tgis_map"("map_name");
@ -921,19 +950,32 @@ CREATE INDEX "tgis_map_tagente_map_name_idx" ON "tgis_map"("map_name");
-- ----------------------------------------------------- -- -----------------------------------------------------
--Table to store the map connection information --Table to store the map connection information
CREATE TABLE "tgis_map_connection" ( CREATE TABLE "tgis_map_connection" (
"id_tmap_connection" SERIAL NOT NULL PRIMARY KEY, --table id --table id
"conection_name" VARCHAR(45) DEFAULT NULL, --Name of the connection (name of the base layer) "id_tmap_connection" SERIAL NOT NULL PRIMARY KEY,
"connection_type" VARCHAR(45) DEFAULT NULL, --Type of map server to connect --Name of the connection (name of the base layer)
"conection_data" TEXT DEFAULT NULL, --connection information (this can probably change to fit better the possible connection parameters) "conection_name" VARCHAR(45) DEFAULT NULL,
"num_zoom_levels" SMALLINT DEFAULT NULL, --Number of zoom levels available --Type of map server to connect
"default_zoom_level" SMALLINT NOT NULL default 16, --Default Zoom Level for the connection "connection_type" VARCHAR(45) DEFAULT NULL,
"default_longitude" DOUBLE PRECISION DEFAULT NULL, --default longitude for the agents placed on the map --connection information (this can probably change to fit better the possible connection parameters)
"default_latitude" DOUBLE PRECISION DEFAULT NULL, --default latitude for the agents placed on the map "conection_data" TEXT DEFAULT NULL,
"default_altitude" DOUBLE PRECISION DEFAULT NULL, --default altitude for the agents placed on the map --Number of zoom levels available
"initial_longitude" DOUBLE PRECISION DEFAULT NULL, --longitude of the center of the map when it\'s loaded "num_zoom_levels" SMALLINT DEFAULT NULL,
"initial_latitude" DOUBLE PRECISION DEFAULT NULL, --latitude of the center of the map when it\'s loaded --Default Zoom Level for the connection
"initial_altitude" DOUBLE PRECISION DEFAULT NULL, --altitude of the center of the map when it\'s loaded "default_zoom_level" SMALLINT NOT NULL default 16,
"group_id" INTEGER NOT NULL default 0 --Group that owns the map --default longitude for the agents placed on the map
"default_longitude" DOUBLE PRECISION DEFAULT NULL,
--default latitude for the agents placed on the map
"default_latitude" DOUBLE PRECISION DEFAULT NULL,
--default altitude for the agents placed on the map
"default_altitude" DOUBLE PRECISION DEFAULT NULL,
--longitude of the center of the map when it\'s loaded
"initial_longitude" DOUBLE PRECISION DEFAULT NULL,
--latitude of the center of the map when it\'s loaded
"initial_latitude" DOUBLE PRECISION DEFAULT NULL,
--altitude of the center of the map when it\'s loaded
"initial_altitude" DOUBLE PRECISION DEFAULT NULL,
--Group that owns the map
"group_id" INTEGER NOT NULL default 0
); );
-- ----------------------------------------------------- -- -----------------------------------------------------
@ -941,22 +983,21 @@ CREATE TABLE "tgis_map_connection" (
-- ----------------------------------------------------- -- -----------------------------------------------------
--Table to asociate a connection to a gis map --Table to asociate a connection to a gis map
CREATE TABLE "tgis_map_has_tgis_map_connection" ( CREATE TABLE "tgis_map_has_tgis_map_connection" (
"tgis_map_id_tgis_map" INTEGER NOT NULL REFERENCES "tgis_map"("id_tgis_map") ON DELETE CASCADE ON UPDATE NO ACTION, --reference to tgis_map --reference to tgis_map
"tgis_map_connection_id_tmap_connection" INTEGER NOT NULL REFERENCES "tgis_map_connection" ("id_tmap_connection") ON DELETE CASCADE ON UPDATE NO ACTION, --reference to tgis_map_connection "tgis_map_id_tgis_map" INTEGER NOT NULL REFERENCES "tgis_map"("id_tgis_map") ON DELETE CASCADE ON UPDATE NO ACTION,
"modification_time" TIMESTAMP without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, --Last Modification Time of the Connection --reference to tgis_map_connection
"default_map_connection" SMALLINT NOT NULL default 0, --Flag to mark the default map connection of a map "tgis_map_connection_id_tmap_connection" INTEGER NOT NULL REFERENCES "tgis_map_connection" ("id_tmap_connection") ON DELETE CASCADE ON UPDATE NO ACTION,
--Last Modification Time of the Connection
"modification_time" TIMESTAMP without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
--Flag to mark the default map connection of a map
"default_map_connection" SMALLINT NOT NULL default 0,
PRIMARY KEY ("tgis_map_id_tgis_map", "tgis_map_connection_id_tmap_connection") PRIMARY KEY ("tgis_map_id_tgis_map", "tgis_map_connection_id_tmap_connection")
); );
CREATE INDEX "tgis_map_has_tgis_map_connection_map_tgis_map_id_tgis_map_idx" ON "tgis_map_has_tgis_map_connection"("tgis_map_id_tgis_map"); CREATE INDEX "tgis_map_has_tgis_map_connection_map_tgis_map_id_tgis_map_idx" ON "tgis_map_has_tgis_map_connection"("tgis_map_id_tgis_map");
CREATE INDEX "tgis_map_has_tgis_map_connection_map_tgis_map_connection_id_tmap_connection_idx" ON "tgis_map_has_tgis_map_connection"("tgis_map_connection_id_tmap_connection"); CREATE INDEX "tgis_map_has_tgis_map_connection_map_tgis_map_connection_id_tmap_connection_idx" ON "tgis_map_has_tgis_map_connection"("tgis_map_connection_id_tmap_connection");
--This function is for to tranlate "ON UPDATE CURRENT_TIMESTAMP" of MySQL. --This function is for to tranlate "ON UPDATE CURRENT_TIMESTAMP" of MySQL.
CREATE OR REPLACE FUNCTION update_tgis_map_has_tgis_map_connection_modification_time() --It is in only one line because the parser of Pandora installer execute the code at the end with ;
RETURNS TRIGGER AS $$ CREATE OR REPLACE FUNCTION update_tgis_map_has_tgis_map_connection_modification_time() RETURNS TRIGGER AS $$ BEGIN NEW.modification_time = now(); RETURN NEW; END; $$ language 'plpgsql';
BEGIN
NEW.modification_time = now();
RETURN NEW;
END;
$$ language 'plpgsql';
CREATE TRIGGER trigger_tgis_map_has_tgis_map_connection_modification_time BEFORE UPDATE ON tgis_map_has_tgis_map_connection FOR EACH ROW EXECUTE PROCEDURE update_tgis_map_has_tgis_map_connection_modification_time(); CREATE TRIGGER trigger_tgis_map_has_tgis_map_connection_modification_time BEFORE UPDATE ON tgis_map_has_tgis_map_connection FOR EACH ROW EXECUTE PROCEDURE update_tgis_map_has_tgis_map_connection_modification_time();
-- ----------------------------------------------------- -- -----------------------------------------------------
@ -964,12 +1005,18 @@ CREATE TRIGGER trigger_tgis_map_has_tgis_map_connection_modification_time BEFORE
-- ----------------------------------------------------- -- -----------------------------------------------------
--Table containing information about the map layers --Table containing information about the map layers
CREATE TABLE "tgis_map_layer" ( CREATE TABLE "tgis_map_layer" (
"id_tmap_layer" SERIAL NOT NULL PRIMARY KEY, --table id --table id
"layer_name" VARCHAR(45) NOT NULL, --Name of the layer "id_tmap_layer" SERIAL NOT NULL PRIMARY KEY,
"view_layer" SMALLINT NOT NULL default 1, --True if the layer must be shown --Name of the layer
"layer_stack_order" SMALLINT NOT NULL default 0, --Number of order of the layer in the layer stack, bigger means upper on the stack.\n "layer_name" VARCHAR(45) NOT NULL,
"tgis_map_id_tgis_map" INTEGER NOT NULL default 0 REFERENCES "tgis_map"("id_tgis_map") ON DELETE CASCADE ON UPDATE NO ACTION, --reference to the map containing the layer --True if the layer must be shown
"tgrupo_id_grupo" BIGINT NOT NULL --reference to the group shown in the layer "view_layer" SMALLINT NOT NULL default 1,
--Number of order of the layer in the layer stack, bigger means upper on the stack.\n
"layer_stack_order" SMALLINT NOT NULL default 0,
--reference to the map containing the layer
"tgis_map_id_tgis_map" INTEGER NOT NULL default 0 REFERENCES "tgis_map"("id_tgis_map") ON DELETE CASCADE ON UPDATE NO ACTION,
--reference to the group shown in the layer
"tgrupo_id_grupo" BIGINT NOT NULL
); );
CREATE INDEX "tgis_map_layer_id_tmap_layer_idx" ON "tgis_map_layer"("id_tmap_layer"); CREATE INDEX "tgis_map_layer_id_tmap_layer_idx" ON "tgis_map_layer"("id_tmap_layer");

View File

@ -108,14 +108,14 @@ UNLOCK TABLES;
LOCK TABLES `tgrupo` WRITE; LOCK TABLES `tgrupo` WRITE;
INSERT INTO `tgrupo` VALUES INSERT INTO `tgrupo` VALUES
(2,'Servers','server_database',0,0,'',0), (2,'Servers','server_database',0,0,0,''),
(4,'Firewalls','firewall',0,0,'',0), (4,'Firewalls','firewall',0,0,0,''),
(8,'Databases','database_gear',0,0,'',0), (8,'Databases','database_gear',0,0,0,''),
(9,'Network','transmit',0,0,'',0), (9,'Network','transmit',0,0,0,''),
(10,'Unknown','world',0,0,'',0), (10,'Unknown','world',0,0,0,''),
(11,'Workstations','computer',0,0,'',0), (11,'Workstations','computer',0,0,0,''),
(12,'Applications','applications',0,0,'',0), (12,'Applications','applications',0,0,0,''),
(13,'Web','world',0,0,'',0); (13,'Web','world',0,0,0,'');
UNLOCK TABLES; UNLOCK TABLES;