add UpdateHelper project / add patitioning store procedures #2

Merged
laurentiu.constantin merged 2 commits from add_Update_Helper into master 2024-06-05 13:25:37 +00:00
22 changed files with 3607 additions and 0 deletions
Showing only changes of commit 60262a4db1 - Show all commits

View File

@ -77,6 +77,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SetupProj", "SetupProj\Setu
EndProject EndProject
Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "Setup_SDRTetra", "Setup_SDRTetra\Setup_SDRTetra.vdproj", "{9FCD029D-6924-41FA-A59F-C79633FF6319}" Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "Setup_SDRTetra", "Setup_SDRTetra\Setup_SDRTetra.vdproj", "{9FCD029D-6924-41FA-A59F-C79633FF6319}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpdateHelper", "UpdateHelper\UpdateHelper.csproj", "{316FC545-051D-47AE-BEFA-1E94AC6D5D21}"
EndProject
Global Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution GlobalSection(SharedMSBuildProjectFiles) = preSolution
SharedUI\SharedUI.projitems*{2292ade7-adac-40d0-866c-8a712f2137f7}*SharedItemsImports = 4 SharedUI\SharedUI.projitems*{2292ade7-adac-40d0-866c-8a712f2137f7}*SharedItemsImports = 4
@ -3195,6 +3197,90 @@ Global
{9FCD029D-6924-41FA-A59F-C79633FF6319}.Repeater|x64.Build.0 = Release {9FCD029D-6924-41FA-A59F-C79633FF6319}.Repeater|x64.Build.0 = Release
{9FCD029D-6924-41FA-A59F-C79633FF6319}.Repeater|x86.ActiveCfg = Release {9FCD029D-6924-41FA-A59F-C79633FF6319}.Repeater|x86.ActiveCfg = Release
{9FCD029D-6924-41FA-A59F-C79633FF6319}.Repeater|x86.Build.0 = Release {9FCD029D-6924-41FA-A59F-C79633FF6319}.Repeater|x86.Build.0 = Release
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.Debug|Any CPU.Build.0 = Debug|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.Debug|x64.ActiveCfg = Debug|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.Debug|x64.Build.0 = Debug|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.Debug|x86.ActiveCfg = Debug|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.Debug|x86.Build.0 = Debug|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.Kit2.0|Any CPU.ActiveCfg = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.Kit2.0|Any CPU.Build.0 = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.Kit2.0|x64.ActiveCfg = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.Kit2.0|x64.Build.0 = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.Kit2.0|x86.ActiveCfg = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.Kit2.0|x86.Build.0 = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KitExcera|Any CPU.ActiveCfg = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KitExcera|Any CPU.Build.0 = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KitExcera|x64.ActiveCfg = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KitExcera|x64.Build.0 = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KitExcera|x86.ActiveCfg = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KitExcera|x86.Build.0 = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KitHytera|Any CPU.ActiveCfg = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KitHytera|Any CPU.Build.0 = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KitHytera|x64.ActiveCfg = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KitHytera|x64.Build.0 = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KitHytera|x86.ActiveCfg = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KitHytera|x86.Build.0 = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.kitLINX|Any CPU.ActiveCfg = kitLINXB|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.kitLINX|Any CPU.Build.0 = kitLINXB|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.kitLINX|x64.ActiveCfg = kitLINXB|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.kitLINX|x64.Build.0 = kitLINXB|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.kitLINX|x86.ActiveCfg = kitLINXB|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.kitLINX|x86.Build.0 = kitLINXB|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.kitLINXB|Any CPU.ActiveCfg = kitLINXB|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.kitLINXB|Any CPU.Build.0 = kitLINXB|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.kitLINXB|x64.ActiveCfg = kitLINXB|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.kitLINXB|x64.Build.0 = kitLINXB|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.kitLINXB|x86.ActiveCfg = kitLINXB|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.kitLINXB|x86.Build.0 = kitLINXB|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KittATLAS|Any CPU.ActiveCfg = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KittATLAS|Any CPU.Build.0 = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KittATLAS|x64.ActiveCfg = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KittATLAS|x64.Build.0 = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KittATLAS|x86.ActiveCfg = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KittATLAS|x86.Build.0 = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KittHARRIS|Any CPU.ActiveCfg = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KittHARRIS|Any CPU.Build.0 = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KittHARRIS|x64.ActiveCfg = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KittHARRIS|x64.Build.0 = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KittHARRIS|x86.ActiveCfg = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KittHARRIS|x86.Build.0 = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KittMotorola|Any CPU.ActiveCfg = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KittMotorola|Any CPU.Build.0 = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KittMotorola|x64.ActiveCfg = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KittMotorola|x64.Build.0 = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KittMotorola|x86.ActiveCfg = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KittMotorola|x86.Build.0 = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KittSimoco|Any CPU.ActiveCfg = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KittSimoco|Any CPU.Build.0 = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KittSimoco|x64.ActiveCfg = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KittSimoco|x64.Build.0 = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KittSimoco|x86.ActiveCfg = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.KittSimoco|x86.Build.0 = KitExcera|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.LINX|Any CPU.ActiveCfg = kitLINXB|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.LINX|Any CPU.Build.0 = kitLINXB|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.LINX|x64.ActiveCfg = kitLINXB|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.LINX|x64.Build.0 = kitLINXB|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.LINX|x86.ActiveCfg = kitLINXB|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.LINX|x86.Build.0 = kitLINXB|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.LISF|Any CPU.ActiveCfg = LISF|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.LISF|Any CPU.Build.0 = LISF|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.LISF|x64.ActiveCfg = LISF|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.LISF|x64.Build.0 = LISF|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.LISF|x86.ActiveCfg = LISF|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.LISF|x86.Build.0 = LISF|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.Release|Any CPU.ActiveCfg = Release|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.Release|Any CPU.Build.0 = Release|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.Release|x64.ActiveCfg = Release|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.Release|x64.Build.0 = Release|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.Release|x86.ActiveCfg = Release|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.Release|x86.Build.0 = Release|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.Repeater|Any CPU.ActiveCfg = Repeater|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.Repeater|Any CPU.Build.0 = Repeater|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.Repeater|x64.ActiveCfg = Repeater|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.Repeater|x64.Build.0 = Repeater|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.Repeater|x86.ActiveCfg = Repeater|Any CPU
{316FC545-051D-47AE-BEFA-1E94AC6D5D21}.Repeater|x86.Build.0 = Repeater|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

15
UpdateHelper/4to5.sql Normal file
View File

@ -0,0 +1,15 @@
CREATE TABLE public.user_radio (radio_id integer NOT NULL DEFAULT 0,user_id integer NOT NULL DEFAULT 0) WITH (OIDS=FALSE);
ALTER TABLE public.user_radio OWNER TO postgres;
CREATE TABLE public.reports(startdate integer NOT NULL DEFAULT 0, stopdate integer NOT NULL DEFAULT 0, unit_ids character varying(4096), geofence_id integer NOT NULL DEFAULT 0, type_stat integer NOT NULL DEFAULT 0, report_id integer NOT NULL DEFAULT 0, email character varying(255),idletime integer, idx serial NOT NULL) WITH (OIDS = FALSE);
ALTER TABLE public.reports OWNER TO postgres;
ALTER TABLE zonename ADD COLUMN useridx integer NOT NULL DEFAULT 0;
ALTER TABLE place ADD COLUMN useridx integer NOT NULL DEFAULT 0;
ALTER TABLE zonename ADD COLUMN alarmtype integer NOT NULL DEFAULT 3;
ALTER TABLE zonename ADD COLUMN sentmsg boolean NOT NULL DEFAULT false;
ALTER TABLE zonename ADD COLUMN msgbody character varying(255) NOT NULL DEFAULT '';
ALTER TABLE zonename ADD COLUMN unitids character varying(255) NOT NULL DEFAULT '';
ALTER TABLE zonename ADD COLUMN sentemail boolean NOT NULL DEFAULT false;
ALTER TABLE zonename ADD COLUMN email character varying(255) NOT NULL DEFAULT '';
ALTER TABLE zonename ADD COLUMN subj character varying(255) NOT NULL DEFAULT '';
ALTER TABLE zonename ADD COLUMN body character varying(255) NOT NULL DEFAULT '';
ALTER TABLE zonename ADD COLUMN imeilist character varying(255) NOT NULL DEFAULT '';

33
UpdateHelper/5to6.sql Normal file
View File

@ -0,0 +1,33 @@
ALTER TABLE \"VoiceRecordings\" ADD COLUMN calltype integer NOT NULL DEFAULT 0;
ALTER TABLE \"VoiceRecordings\" ADD COLUMN group_id integer NOT NULL DEFAULT 0;
ALTER TABLE zonename ADD COLUMN sentmsg2 boolean NOT NULL DEFAULT false;
ALTER TABLE zonename ADD COLUMN msgbody2 character varying(255) NOT NULL DEFAULT '';
ALTER TABLE speedalarm ADD COLUMN lat double precision NOT NULL DEFAULT 0;
ALTER TABLE speedalarm ADD COLUMN lng double precision NOT NULL DEFAULT 0;
ALTER TABLE telemetry_history ADD COLUMN lat double precision NOT NULL DEFAULT 0;
ALTER TABLE telemetry_history ADD COLUMN lng double precision NOT NULL DEFAULT 0;
ALTER TABLE emergalarm ADD COLUMN lat double precision NOT NULL DEFAULT 0;
ALTER TABLE emergalarm ADD COLUMN lng double precision NOT NULL DEFAULT 0;
ALTER TABLE reports ADD COLUMN latlng boolean NOT NULL DEFAULT false;
UPDATE emergalarm SET address='no address' WHERE address = '';
UPDATE telemetry_history SET address='no address' WHERE address = '';
UPDATE speedalarm SET address='no address' WHERE address = '';
ALTER TABLE vehicle ADD COLUMN gps_poor integer NOT NULL DEFAULT 0;
ALTER TABLE vehicle ADD COLUMN gps_off integer NOT NULL DEFAULT 0;
ALTER TABLE vehicle ADD COLUMN made_off integer NOT NULL DEFAULT 0;
UPDATE vehicle SET gps_poor=\"GPS_reporting_interval\"*2, gps_off=\"GPS_reporting_interval\"*4, made_off=\"GPS_reporting_interval\"*10;
UPDATE lastpos SET status=0;
ALTER TABLE gateways ADD COLUMN peer_id integer NOT NULL DEFAULT 0;
ALTER TABLE radio_gw DROP CONSTRAINT unique_radio_gw;
ALTER TABLE sms ADD COLUMN lat double precision NOT NULL DEFAULT 0;
ALTER TABLE sms ADD COLUMN lng double precision NOT NULL DEFAULT 0;
ALTER TABLE sms ADD COLUMN address character varying(255) NOT NULL DEFAULT 'no address';
INSERT INTO emailservice(id, \"user\", pass, enable) VALUES (2,'poll', 'poll', 0);
ALTER TABLE zonename ADD COLUMN speed integer NOT NULL DEFAULT 0;
ALTER TABLE emailservice ADD COLUMN pop_server text NOT NULL DEFAULT 'pop.gmail.com';
ALTER TABLE emailservice ADD COLUMN pop_port integer NOT NULL DEFAULT 995;
ALTER TABLE emailservice ADD COLUMN smtp_server text NOT NULL DEFAULT 'smtp.gmail.com';
ALTER TABLE emailservice ADD COLUMN smtp_port integer NOT NULL DEFAULT 587;
ALTER TABLE emailservice ADD COLUMN is_pop_ssl boolean NOT NULL DEFAULT true;
ALTER TABLE emailservice ADD COLUMN is_smtp_ssl boolean NOT NULL DEFAULT true;
ALTER TABLE emailservice ADD COLUMN last_email_time integer NOT NULL DEFAULT 0;

279
UpdateHelper/6to7.sql Normal file
View File

@ -0,0 +1,279 @@
ALTER TABLE lastpos ADD COLUMN altitude double precision NOT NULL DEFAULT 0;
DROP TABLE IF EXISTS jobtickets;
CREATE TABLE jobtickets (ticket_id serial,name text,job_status integer,sc_id integer,comment text,dispatcher text,priority text,end_time_planned integer,creation_time integer,start_time integer,end_time integer,is_expired boolean DEFAULT false NOT NULL,deleted integer,share_with text,seq_id character varying(40),status integer DEFAULT 0 NOT NULL,sched_timegmt integer DEFAULT 0);
ALTER TABLE public.jobtickets OWNER TO postgres;
DROP TABLE IF EXISTS jobtickets_log;
CREATE TABLE jobtickets_log ( id serial, ticket_id integer, modified_date integer,job_status integer, sc_id integer, comment text) WITH ( OIDS=FALSE);
ALTER TABLE jobtickets_log OWNER TO postgres;
DROP TABLE IF EXISTS jobticketstatusesset;
CREATE TABLE jobticketstatusesset ( status_id serial, status character varying(45), color character varying(45), sound_on integer, sound_file character varying(250), is_first_state integer, is_last_state integer, CONSTRAINT jobticketstatusesset_pkey PRIMARY KEY (status_id))WITH ( OIDS=FALSE);
ALTER TABLE jobticketstatusesset OWNER TO postgres;
DROP TABLE IF EXISTS definejobticket;
CREATE TABLE definejobticket ( name character varying(200) NOT NULL, text character varying(200) NOT NULL, comment character varying(200), priority character varying(200), expire_date integer, idx serial NOT NULL, CONSTRAINT definejobticket_pkey PRIMARY KEY (idx))WITH ( OIDS=FALSE);
ALTER TABLE definejobticket OWNER TO postgres;
ALTER TABLE registration ADD COLUMN has_ticketing boolean NOT NULL DEFAULT false;
DELETE FROM jobticketstatusesset;
INSERT INTO jobticketstatusesset (status_id, status, color, sound_on, sound_file, is_first_state, is_last_state) VALUES (1, 'Assigned', '3D8584', 0, '', 1, 0);
INSERT INTO jobticketstatusesset (status_id, status, color, sound_on, sound_file, is_first_state, is_last_state) VALUES (2, 'Accepted', '3D7171', 0, '', 0, 0);
INSERT INTO jobticketstatusesset (status_id, status, color, sound_on, sound_file, is_first_state, is_last_state) VALUES (3, 'In progress', '3D5B85', 0, '', 0, 0);
INSERT INTO jobticketstatusesset (status_id, status, color, sound_on, sound_file, is_first_state, is_last_state) VALUES (4, 'Completed', '5E853D', 0, '', 0, 1);
INSERT INTO jobticketstatusesset (status_id, status, color, sound_on, sound_file, is_first_state, is_last_state) VALUES (5, 'Rejected', 'A93D47', 0, '', 0, 0);
INSERT INTO jobticketstatusesset (status_id, status, color, sound_on, sound_file, is_first_state, is_last_state) VALUES (6, 'Overdue', 'B29F3D', 0, '', 0, 0);
ALTER TABLE definejobticket ADD COLUMN handled_by text;
ALTER TABLE definejobticket ADD COLUMN schedule_date integer;
ALTER TABLE definejobticket ADD COLUMN share_with text;
DROP TABLE IF EXISTS sequences;
CREATE TABLE sequences( name character varying(32) NOT NULL, value integer NOT NULL DEFAULT 0, idx serial NOT NULL, CONSTRAINT sequences_pkey PRIMARY KEY (idx))WITH ( OIDS=FALSE);
ALTER TABLE sequences OWNER TO postgres;
INSERT INTO sequences(name, value) VALUES('jobticketing',1);
DROP TABLE IF EXISTS icon_theme;
CREATE TABLE icon_theme( id serial NOT NULL, \"name\" text, prefix text) WITH ( OIDS=FALSE);
ALTER TABLE icon_theme OWNER TO postgres;
INSERT INTO icon_theme(id, \"name\", prefix)VALUES (1, 'Classic', 'classic'),(2, 'Pin', 'pin');
DROP TABLE IF EXISTS car;
CREATE TABLE car(\"name\" character varying(100) NOT NULL, id serial NOT NULL, pattern text, displayed_name text, CONSTRAINT car_pkey PRIMARY KEY (id))WITH ( OIDS=FALSE);
ALTER TABLE car OWNER TO postgres;
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('minibus', 102, 'minibus_01', 'Van 1');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('Minicar', 103, 'minicar_01', 'MiniCar 1');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('people_08', 35, 'people_08', 'People 8');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('Minicar2', 104, 'minicar_02', 'MiniCar 2');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('police', 105, 'police_01', 'Police 1');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('Police1', 106, 'police_02', 'Police 2');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('schoolbus', 107, 'school_bus_01', 'School Bus 1');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('taxi_02', 131, 'taxi_02', 'Taxi 2');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('schoolbus2', 108, 'school_bus_02', 'School Bus 2');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('moto_01', 132, 'moto_01', 'Moto 1');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('moto_02', 133, 'moto_02', 'Moto 2');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('TowTruckYellow', 110, 'tow_truck_01', 'Tow Truck');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('TractorUnitBlack', 111, 'tractor_unit', 'Tractor Unit');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('moto_03', 134, 'moto_03', 'Moto 3');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('moto_04', 135, 'moto_04', 'Moto 4');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('Classic-Car-66', 92, 'classic_car_01', 'Classic Car 1');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('truck0', 112, 'truck_01', 'Truck 1');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('classycar', 93, 'classic_car_02', 'Classic Car 2');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('peopleblue', 1, 'people_01', 'People 1');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('peoplegreen', 2, 'people_02', 'People 2');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('peoplegrey', 3, 'people_03', 'People 3');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('peoplepink', 4, 'people_04', 'People 4');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('peoplepurple', 5, 'people_05', 'People 5');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('peoplered', 6, 'people_06', 'People 6');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('army', 79, 'army_01', 'Army');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('bigcar0', 80, 'car_01', 'Car 1');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('bigcar1', 81, 'car_02', 'Car 2');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('bigcar2', 82, 'car_03', 'Car 3');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('moto_05', 136, 'moto_05', 'Moto 5');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('bicycle_01', 137, 'bicycle_01', 'Bicycle');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('car0', 87, 'car_04', 'Car 4');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('car1', 88, 'car_05', 'Car 5');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('car2', 89, 'car_06', 'Car 6');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('car3', 90, 'car_07', 'Car 7');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('CarGrey', 91, 'car_08', 'Car 8');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('dodge', 94, 'dodge_01', 'Dodge');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('FireEscape', 95, 'firetruck_01', 'FireTruck 1');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('truck1', 113, 'truck_02', 'Truck 2');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('firefighters2', 96, 'firetruck_02', 'Fire Truck 2');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('ambulance_01', 36, 'ambulance_01', 'Ambulance 1');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('firetruck1', 97, 'firetruck_03', 'Fire Truck 3');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('truck2', 114, 'truck_03', 'Truck 3');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('firetruck2', 98, 'firetruck_04', 'Fire Truck 4');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('Jeep', 99, 'jeep_01', 'Jeep');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('CabrioletRed', 86, 'cabriolet_01', 'Carbriolet');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('truck3', 115, 'truck_04', 'Truck 4');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('Longhaul', 100, 'longhaul_01', 'Long Haul');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('truck4', 116, 'truck_05', 'Truck 5');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('LorryGreen', 101, 'lorry_01', 'Lorry');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('ambulance_02', 78, 'ambulance_02', 'Ambulance 2');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('truck5', 117, 'truck_06', 'Truck 6');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('truck6', 118, 'truck_07', 'Truck 7');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('TruckYellow', 119, 'truck_08', 'Truck 8');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('wagon', 120, 'wagon_01', 'Wagon');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('bus', 83, 'tour_bus_01', 'Tour Bus 1');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('bus0', 84, 'bus_01', 'Bus 1');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('bus2', 85, 'bus_02', 'Bus 2');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('number_01', 121, 'number_01', '1');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('number_02', 122, 'number_02', '2');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('number_04', 124, 'number_04', '4');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('number_03', 123, 'number_03', '3');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('number_05', 125, 'number_05', '5');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('number_06', 126, 'number_06', '6');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('number_07', 127, 'number_07', '7');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('number_08', 128, 'number_08', '8');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('number_09', 129, 'number_09', '9');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('number_10', 130, 'number_10', '10');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('taxi', 109, 'taxi_01', 'Taxi 1');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('people_07', 34, 'people_07', 'People 7');
insert into \"userSettings\" (user_id, key, value) select userid, 'reportTime', '0' from users where userid not in (select user_id from \"userSettings\" where key = 'reportTime') order by userid;
insert into \"userSettings\" (user_id, key, value) select userid, 'iconTheme', 'pin' from users where userid not in (select user_id from \"userSettings\" where key = 'iconTheme') order by userid;
ALTER TABLE reports ADD COLUMN userid integer;
UPDATE reports SET userid = (SELECT MAX(userid) FROM users);
ALTER TABLE reports ADD COLUMN ticket_status character varying(250);
ALTER TABLE reports ADD COLUMN ticket_date_type character varying(250);
ALTER TABLE reports ADD COLUMN type text;
ALTER TABLE reports ADD COLUMN day text;
ALTER TABLE reports ADD COLUMN is_activated boolean;
ALTER TABLE sms ADD COLUMN color character varying(7);
ALTER TABLE sms ALTER COLUMN color SET STORAGE EXTENDED;
DROP TABLE IF EXISTS placetype;
CREATE TABLE placetype ( type_name character varying(100) NOT NULL,type_id integer NOT NULL,icon_name character varying(70));
ALTER TABLE public.placetype OWNER TO postgres;
CREATE SEQUENCE placetype_type_id_seq START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1;
ALTER TABLE public.placetype_type_id_seq OWNER TO postgres;
ALTER SEQUENCE placetype_type_id_seq OWNED BY placetype.type_id;
SELECT pg_catalog.setval('placetype_type_id_seq', 156, true);
ALTER TABLE place ADD COLUMN icon_size character varying(20);
ALTER TABLE place ADD COLUMN color character varying(7);
ALTER TABLE zonename ADD COLUMN fill_color character varying(7);
ALTER TABLE zonename ADD COLUMN fill_opacity double precision;
ALTER TABLE zonename ADD COLUMN border_color character varying(7);
ALTER TABLE zonename ADD COLUMN border_opacity double precision;
ALTER TABLE zonename ADD COLUMN border_width integer;
ALTER TABLE placetype ALTER COLUMN type_id SET DEFAULT nextval('placetype_type_id_seq'::regclass);
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('calculator', 45, 'calculator.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('calendar', 46, 'calendar.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('camera', 47, 'camera.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('cancel', 48, 'cancel.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('factory', 4, 'factory.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('airport', 1, 'airport.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('cd', 49, 'cd.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('hospital', 6, 'hospital.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('bank', 2, 'bank.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('school', 15, 'school.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('supermarket', 17, 'supermarket.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('shopping', 16, 'shopping.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('office', 18, 'office.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('post_office', 13, 'post_office.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('restaurant', 14, 'restaurant.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('home', 9, 'home.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('fire_department', 7, 'fire_department.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('repair_shop', 3, 'repair_shop.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('garage', 5, 'garage.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('hotel', 10, 'hotel.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('gas_station', 8, 'gas_station.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('military_base', 11, 'military_base.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('police_station', 12, 'police_station.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('chair', 50, 'chair.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('check', 51, 'check.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('cinema', 52, 'cinema.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('add', 20, 'add.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('coffee', 53, 'coffee.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('alert', 22, 'alert.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('anchor', 23, 'anchor.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('announce', 24, 'announce.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('antivirus', 25, 'antivirus.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('arrow_down', 26, 'arrow_down.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('compass', 54, 'compass.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('arrow_down_left', 27, 'arrow_down_left.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('computer', 55, 'computer.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('arrow_down_right', 28, 'arrow_down_right.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('arrow_left', 29, 'arrow_left.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('construction', 56, 'construction.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('repair_shop_2', 102, 'repair_shop_2.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('rip', 103, 'rip.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('roundabout', 104, 'roundabout.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('ruby', 105, 'ruby.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('save', 106, 'save.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('arrow_right', 30, 'arrow_right.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('arrow_up', 31, 'arrow_up.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('arrow_up_left', 32, 'arrow_up_left.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('arrow_up_right', 33, 'arrow_up_right.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('baggage', 34, 'baggage.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('banned', 35, 'banned.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('science', 107, 'science.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('search', 108, 'search.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('servers', 109, 'servers.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('settings', 110, 'settings.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('shape_circle', 111, 'shape_circle.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('shape_ellipse', 112, 'shape_ellipse.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('shape_hexagon', 113, 'shape_hexagon.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('shape_kite', 114, 'shape_kite.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('shape_parallelogram', 115, 'shape_parallelogram.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('battery', 36, 'battery.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('bicycle', 37, 'bicycle.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('bluetooth', 38, 'bluetooth.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('book', 39, 'book.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('bookmark', 40, 'bookmark.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('brush', 41, 'brush.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('bug', 42, 'bug.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('bussiness_card', 43, 'bussiness_card.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('cake', 44, 'cake.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('credit_card', 57, 'credit_card.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('cross', 58, 'cross.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('database', 59, 'database.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('directions', 60, 'directions.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('directions_2', 61, 'directions_2.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('doctor', 62, 'doctor.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('drill', 63, 'drill.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('elevator', 64, 'elevator.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('facebook', 65, 'facebook.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('fan', 66, 'fan.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('favorite', 67, 'favorite.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('flag', 68, 'flag.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('food', 69, 'food.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('gameboy', 70, 'gameboy.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('shape_pentagon', 116, 'shape_pentagon.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('shape_rhombus', 117, 'shape_rhombus.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('shape_square', 118, 'shape_square.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('shape_trapezoid', 119, 'shape_trapezoid.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('shape_triangle', 120, 'shape_triangle.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('pool_game', 98, 'pool_game.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('alarm', 21, 'alarm.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('games', 71, 'games.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('gift', 72, 'gift.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('glasses', 73, 'glasses.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('grid', 74, 'grid.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('hairdresser', 75, 'hairdresser.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('hammer', 76, 'hammer.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('hardware', 77, 'hardware.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('headphones', 78, 'headphones.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('hedge', 79, 'hedge.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('help', 80, 'help.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('help_2', 81, 'help_2.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('icecream', 82, 'icecream.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('info', 83, 'info.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('key', 84, 'key.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('map', 85, 'map.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('marker', 86, 'marker.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('microphone', 87, 'microphone.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('moon', 88, 'moon.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('newspaper', 89, 'newspaper.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('padlock_closed', 90, 'padlock_closed.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('padlock_open', 91, 'padlock_open.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('paintroller', 92, 'paintroller.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('park_bench', 93, 'park_bench.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('phone', 94, 'phone.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('pill', 95, 'pill.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('pinetree', 96, 'pinetree.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('pollution', 97, 'pollution.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('print', 99, 'print.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('refreshment', 100, 'refreshment.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('remote_control', 101, 'remote_control.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('stamp', 121, 'stamp.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('star', 122, 'star.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('stop', 123, 'stop.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('stop_2', 124, 'stop_2.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('stopwatch', 125, 'stopwatch.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('store', 126, 'store.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('tag', 127, 'tag.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('tent', 128, 'tent.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('tie', 129, 'tie.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('time', 130, 'time.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('trafficlight', 131, 'trafficlight.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('trafficlight_green', 132, 'trafficlight_green.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('trafficlight_red', 133, 'trafficlight_red.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('trafficlight_yellow', 134, 'trafficlight_yellow.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('trash', 135, 'trash.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('trophy', 136, 'trophy.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('truck', 137, 'truck.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('typewritter', 138, 'typewritter.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('user', 139, 'user.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('users', 140, 'users.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('water', 141, 'water.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('weather_cloud', 142, 'weather_cloud.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('weather_clouds', 144, 'weather_clouds.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('weather_rain', 145, 'weather_rain.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('weather_sun', 146, 'weather_sun.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('weather_snow', 147, 'weather_snow.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('weather_thunder', 148, 'weather_thunder.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('wi_fi', 149, 'wi_fi.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('weather_cloud_sun', 143, 'weather_cloud_sun.png');
ALTER TABLE messages ADD COLUMN altitude double precision;

100
UpdateHelper/7toLatest7.sql Normal file
View File

@ -0,0 +1,100 @@
CREATE TABLE public.newicons (icontype integer NOT NULL DEFAULT 0, id integer NOT NULL DEFAULT 0, imagedata bytea);
ALTER TABLE groups ADD COLUMN type integer;
UPDATE groups SET type = 0;
ALTER TABLE vehicle ADD COLUMN type integer;
UPDATE vehicle SET type = 0;
ALTER TABLE vehicle ADD COLUMN active boolean;
UPDATE vehicle SET active = TRUE;
ALTER TABLE radio_gw ADD COLUMN name character varying(30);
UPDATE radio_gw SET name = 'unnamed' || \"ID\";
ALTER TABLE radio_gw ADD COLUMN gw_type integer;
UPDATE radio_gw SET gw_type = 0;
ALTER TABLE groups ADD COLUMN r_gw_id integer;
UPDATE groups SET r_gw_id = ( CASE WHEN ((select count(*) from radio_gw ) = 0) THEN 0 ELSE (select min(\"ID\") from radio_gw) END);
update subs_gateway set gateway_id = (CASE WHEN ((select count(*) from radio_gw where \"ID\" = 1 and \"GW_ID\" = 1) = 0) THEN (select min(\"GW_ID\") from radio_gw) ELSE 1 END ), radio_gw_id = (CASE WHEN ((select count(*) from radio_gw where \"ID\" = 1 and \"GW_ID\" = 1) = 0) THEN (select min(\"ID\") from radio_gw) ELSE 1 END) where gateway_id = 1 and radio_gw_id = 1;
CREATE TABLE subscriber_mobile( sc_id serial NOT NULL, phone_imei character varying(20), first_name character varying(50), last_name character varying(50), company character varying(30), os character varying(20), phone_type character varying(20), sip_pswd character varying(30), CONSTRAINT subscriber_mobile_pkey PRIMARY KEY (sc_id)) WITH ( OIDS=FALSE);
ALTER TABLE subscriber_mobile OWNER TO postgres;
CREATE TABLE mobile_contacts(idx serial NOT NULL, sc_id integer NOT NULL, contact_id integer NOT NULL, contact_type character varying(30), contact_type_id integer) WITH ( OIDS=FALSE);
ALTER TABLE mobile_contacts OWNER TO postgres;
ALTER TABLE sms ADD COLUMN user_id integer;
ALTER TABLE sms ALTER COLUMN user_id SET STORAGE PLAIN;
ALTER TABLE users ADD COLUMN backup_user_id integer default 0;
ALTER TABLE users ALTER COLUMN backup_user_id SET STORAGE PLAIN;
UPDATE users SET backup_user_id = -1;
ALTER TABLE subscriber_mobile ADD COLUMN has_gps boolean DEFAULT false;
ALTER TABLE subscriber_mobile ADD COLUMN has_voice boolean DEFAULT false;
ALTER TABLE subscriber_mobile ADD COLUMN has_text boolean DEFAULT false;
ALTER TABLE subscriber_mobile ADD COLUMN has_ticketing boolean DEFAULT false;
ALTER TABLE subscriber_mobile ADD COLUMN email text;
ALTER TABLE subscriber_mobile ADD COLUMN login text;
ALTER TABLE users ADD COLUMN sip_id integer;
ALTER TABLE users ALTER COLUMN sip_id SET STORAGE PLAIN;
ALTER TABLE subscriber_mobile ADD COLUMN lone_worker boolean DEFAULT false;
ALTER TABLE subscriber_mobile ADD COLUMN lone_worker_interval integer DEFAULT 0;
ALTER TABLE emergalarm ADD COLUMN user_id integer;
ALTER TABLE emergalarm ADD COLUMN timegmt_ack integer;
ALTER TABLE geozoneinout ADD COLUMN user_id integer;
ALTER TABLE geozoneinout ADD COLUMN timegmt_ack integer;
ALTER TABLE speedalarm ADD COLUMN user_id integer;
ALTER TABLE speedalarm ADD COLUMN timegmt_ack integer;
ALTER TABLE telemetry_history ADD COLUMN user_id integer;
ALTER TABLE telemetry_history ADD COLUMN timegmt_ack integer;
ALTER TABLE emergalarm ADD COLUMN emergency_type integer;
create table call_patch(idx serial not null, type integer, incoming text, outgoing text, userid integer);
CREATE INDEX msg_sc_id_idx ON messages USING btree (sc_id);
CREATE INDEX secv_idx ON messages USING btree (scevtime);
CREATE INDEX speed_idx ON messages USING btree (speed);
CREATE INDEX timegmt_idx ON messages USING btree (timegmt);
CREATE TABLE users_group(idx serial not null, userid integer not null, grp_id integer not null);
CREATE TABLE sip_manager(sip_id serial not null primary key, id integer not null, type integer not null);
CREATE UNIQUE INDEX unique_idx ON sip_manager (id, type);
ALTER SEQUENCE sip_manager_sip_id_seq RESTART WITH 10;
insert into sip_manager(id, type) select userid, 0 from users where user_type <> 1;
insert into sip_manager(id, type) select id, 1 from groups where type <> 0;
insert into sip_manager(id, type) select sc_id, 2 from subscriber;
insert into sip_manager(id, type) select \"ID\", 4 from radio_gw;
ALTER TABLE users DROP COLUMN sip_id;
insert into \"userSettings\" (user_id, key, value) SELECT 0,'lanLinxServer','' where not exists (select * from \"userSettings\" where user_id = 0 and key = 'lanLinxServer');
insert into \"userSettings\" (user_id, key, value) SELECT 0,'natLinxServer','' where not exists (select * from \"userSettings\" where user_id = 0 and key = 'natLinxServer');
insert into \"userSettings\" (user_id, key, value) SELECT 0,'lanSipPort','' where not exists (select * from \"userSettings\" where user_id = 0 and key = 'lanSipPort');
insert into \"userSettings\" (user_id, key, value) SELECT 0,'natSipPort','' where not exists (select * from \"userSettings\" where user_id = 0 and key = 'natSipPort');
insert into \"userSettings\" (user_id, key, value) SELECT 0,'lanSigPort','41414' where not exists (select * from \"userSettings\" where user_id = 0 and key = 'lanSigPort');
insert into \"userSettings\" (user_id, key, value) SELECT 0,'natSigPort','' where not exists (select * from \"userSettings\" where user_id = 0 and key = 'natSigPort');
insert into \"userSettings\" (user_id, key, value) SELECT 0,'rtpStart','' where not exists (select * from \"userSettings\" where user_id = 0 and key = 'rtpStart');
insert into \"userSettings\" (user_id, key, value) SELECT 0,'rtpEnd','' where not exists (select * from \"userSettings\" where user_id = 0 and key = 'rtpEnd');
INSERT INTO car(\"name\", id, pattern, displayed_name) VALUES ('linx_01', 138, 'linx_01', 'Linx 1'), ('linx_02', 139, 'linx_02', 'Linx 2');
ALTER TABLE subscriber_mobile ADD COLUMN has_man_down boolean DEFAULT false;
ALTER TABLE gateways ADD COLUMN active boolean default false;
UPDATE gateways SET active = true WHERE \"IP\" IN (SELECT ip FROM reg_gateway);
DROP TABLE reg_gateway;
ALTER TABLE subscriber_mobile RENAME lone_worker TO has_lone_worker;
ALTER TABLE subscriber_mobile ADD COLUMN has_emergency boolean DEFAULT true;
UPDATE subscriber_mobile SET lone_worker_interval = 1 WHERE lone_worker_interval = 0;
ALTER TABLE subscriber_mobile ALTER COLUMN lone_worker_interval SET DEFAULT 1;
ALTER TABLE sms ALTER COLUMN mess TYPE text;
ALTER TABLE alarm ALTER COLUMN mess TYPE text;
CREATE SEQUENCE radio_mobile_idx_seq START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1;
CREATE TABLE public.radio_mobile(idx integer NOT NULL DEFAULT nextval('radio_mobile_idx_seq'::regclass), radio_grp_id integer NOT NULL, mobile_grp_id integer NOT NULL);
insert into \"userSettings\" (user_id, key, value) SELECT 0,'sampleRate','8000' where not exists (select * from \"userSettings\" where user_id = 0 and key = 'sampleRate');
insert into \"userSettings\" (user_id, key, value) SELECT 0,'bufferMilliseconds','32' where not exists (select * from \"userSettings\" where user_id = 0 and key = 'bufferMilliseconds');
insert into \"userSettings\" (user_id, key, value) SELECT 0,'bitDepth','16' where not exists (select * from \"userSettings\" where user_id = 0 and key = 'bitDepth');
alter table definesms add column user_id integer NOT NULL DEFAULT 0;
CREATE TABLE msg(idx serial, message text NOT NULL, dest_id int NOT NULL, seq_id text, sched_timegmt integer DEFAULT 0, email text NOT NULL, CONSTRAINT msg_pkey PRIMARY KEY (idx));
CREATE TABLE msg_details(idx serial, msg_id int NOT NULL, sip_id int, timegmt integer, lat double precision NOT NULL DEFAULT 0, lng double precision NOT NULL DEFAULT 0, speed double precision NOT NULL DEFAULT 0, altitude double precision NOT NULL DEFAULT 0, address character varying(255) NOT NULL DEFAULT 'no address'::character varying, is_sent boolean DEFAULT false, is_read boolean DEFAULT false, is_deleted boolean DEFAULT false, CONSTRAINT msg_det_pkey PRIMARY KEY (idx));
ALTER TABLE msg_details ADD CONSTRAINT msg_fk FOREIGN KEY (msg_id) REFERENCES msg (idx) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE CASCADE;
ALTER TABLE msg_details ADD CONSTRAINT sip_manager_msg_det_fk FOREIGN KEY (sip_id) REFERENCES sip_manager (sip_id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION;
ALTER TABLE msg ADD CONSTRAINT sip_manager_msg_fk FOREIGN KEY (dest_id) REFERENCES sip_manager (sip_id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION;
CREATE INDEX msg_sip_id_idx ON msg_details USING btree (sip_id);
CREATE INDEX msg_timegmt_idx ON msg_details USING btree (timegmt);
ALTER TABLE msg_details ADD COLUMN msg_type integer not null default 0;
ALTER TABLE messages ADD COLUMN tallysman_log_id integer;
ALTER TABLE registration ADD COLUMN has_recordings boolean NOT NULL DEFAULT false;
ALTER TABLE \"userSettings\" alter column key type text;
CREATE INDEX idx_geozone_1 ON public.geozoneinout USING btree (sc_id, preview);
CREATE INDEX idx_emergalarm ON public.emergalarm USING btree (sc_id, preview);
CREATE INDEX idx_speedalarm ON public.speedalarm USING btree (sc_id, preview);
CREATE INDEX idx_telemetryalarm ON public.telemetry_history USING btree (sc_id, ack, alarm);
ALTER TABLE zonename ADD COLUMN \"callout\" BOOLEAN DEFAULT FALSE;
ALTER TABLE zonename ADD COLUMN \"callout_severity\" int DEFAULT 3;
ALTER TABLE place ADD COLUMN \"callout\" BOOLEAN DEFAULT FALSE;
ALTER TABLE place ADD COLUMN \"callout_severity\" int DEFAULT 3;

56
UpdateHelper/App.config Normal file
View File

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
<appSettings>
<add key="pg_path" value="C:\Program Files (x86)\SafeMobile\postgresql\pgsql\bin\" />
<add key="cmd_sleep" value="10" />
<add key="db_ip" value="10" />
<add key="hostname" value="127.0.0.1" />
<add key="username" value="postgres" />
<add key="dbname" value="safedispatchdb" />
<add key="port" value="5432" />
<add key="ClientSettingsProvider.ServiceUri" value="" />
</appSettings>
<system.web>
<membership defaultProvider="ClientAuthenticationMembershipProvider">
<providers>
<add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
</providers>
</membership>
<roleManager defaultProvider="ClientRoleProvider" enabled="true">
<providers>
<add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
</providers>
</roleManager>
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="CommandLine" publicKeyToken="de6f01bd326f8c32" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.9.71.2" newVersion="1.9.71.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.5.0" newVersion="4.0.5.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Text.Encodings.Web" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

View File

@ -0,0 +1,696 @@
CREATE OR REPLACE FUNCTION public.CreateMissingForeignKeys()
RETURNS void AS
$BODY$
BEGIN
--===================
--VoiceRecordings
--===================
if NOT exists (select * from information_schema.table_constraints where table_name = 'VoiceRecordings' and constraint_type = 'FOREIGN KEY' and constraint_name = 'voice_recordings_subscriber_fk')
and exists (select * from information_schema.columns where table_name = 'VoiceRecordings' and column_name = 'subscriber_id') then
ALTER TABLE public."VoiceRecordings"
ADD CONSTRAINT voice_recordings_subscriber_fk FOREIGN KEY (subscriber_id)
REFERENCES public.subscriber (sc_id) MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : voice_recordings_subscriber_fk !';
else
RAISE NOTICE '%', 'Foreign key voice_recordings_subscriber_fk already exists between tables (VoiceRecordings, subscriber) !';
end if;
if NOT exists (select * from information_schema.table_constraints where table_name = 'VoiceRecordings' and constraint_type = 'FOREIGN KEY' and constraint_name = 'voice_recordings_gateway_fk')
and exists (select * from information_schema.columns where table_name = 'VoiceRecordings' and column_name = 'gw_id') then
ALTER TABLE public."VoiceRecordings"
ADD CONSTRAINT voice_recordings_gateway_fk FOREIGN KEY (gw_id)
REFERENCES public.gateways ("ID") MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : voice_recordings_gateway_fk !';
else
RAISE NOTICE '%', 'Foreign key voice_recordings_gateway_fk already exists between tables (VoiceRecordings, gateways) !';
end if;
if NOT exists (select * from information_schema.table_constraints where table_name = 'VoiceRecordings' and constraint_type = 'FOREIGN KEY' and constraint_name = 'voice_recordings_groups_fk')
and exists (select * from information_schema.columns where table_name = 'VoiceRecordings' and column_name = 'group_id') then
ALTER TABLE public."VoiceRecordings"
ADD CONSTRAINT voice_recordings_groups_fk FOREIGN KEY (group_id)
REFERENCES public.groups (id) MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : voice_recordings_groups_fk !';
else
RAISE NOTICE '%', 'Foreign key voice_recordings_groups_fk already exists between tables (VoiceRecordings, groups) !';
end if;
if NOT exists (select * from information_schema.table_constraints where table_name = 'VoiceRecordings' and constraint_type = 'FOREIGN KEY' and constraint_name = 'voice_recordings_dispatchers_fk')
and exists (select * from information_schema.columns where table_name = 'VoiceRecordings' and column_name = 'dispatcher_id') then
ALTER TABLE public."VoiceRecordings"
ADD CONSTRAINT voice_recordings_dispatchers_fk FOREIGN KEY (dispatcher_id)
REFERENCES public.users (userid) MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : voice_recordings_dispatchers_fk !';
else
RAISE NOTICE '%', 'Foreign key voice_recordings_dispatchers_fk already exists between tables (VoiceRecordings, users) !';
end if;
--===================
--alarm
--===================
if NOT exists (select * from information_schema.table_constraints where table_name = 'alarm' and constraint_type = 'FOREIGN KEY' and constraint_name = 'alarm_subscriber_fk')
and exists (select * from information_schema.columns where table_name = 'alarm' and column_name = 'sc_id') then
ALTER TABLE public.alarm
ADD CONSTRAINT alarm_subscriber_fk FOREIGN KEY (sc_id)
REFERENCES public.subscriber (sc_id) MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : alarm_subscriber_fk !';
else
RAISE NOTICE '%', 'Foreign key alarm_subscriber_fk exists between tables (alarm, subscriber) !';
end if;
--===================
--call_patch
--===================
if NOT exists (select * from information_schema.table_constraints where table_name = 'call_patch' and constraint_type = 'FOREIGN KEY' and constraint_name = 'call_patch_user_fk')
and exists (select * from information_schema.columns where table_name = 'call_patch' and column_name = 'userid') then
ALTER TABLE public.call_patch
ADD CONSTRAINT call_patch_user_fk FOREIGN KEY (userid)
REFERENCES public.users (userid) MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : call_patch_user_fk !';
else
RAISE NOTICE '%', 'Foreign key call_patch_user_fk exists between tables (call_patch, user) !';
end if;
--===================
--definesms
--===================
if NOT exists (select * from information_schema.table_constraints where table_name = 'definesms' and constraint_type = 'FOREIGN KEY' and constraint_name = 'definesms_user_fk')
and exists (select * from information_schema.columns where table_name = 'definesms' and column_name = 'user_id') then
if exists (select * from public.definesms where user_id = 0) then
UPDATE public.definesms SET user_id = 1
WHERE user_id = 0;
end if;
ALTER TABLE public.definesms
ADD CONSTRAINT definesms_user_fk FOREIGN KEY (user_id)
REFERENCES public.users (userid) MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : definesms_user_fk !';
else
RAISE NOTICE '%', 'Foreign key definesms_user_fk exists between tables (definesms, user) !';
end if;
--===================
--emergalarm
--===================
if NOT exists (select * from information_schema.table_constraints where table_name = 'emergalarm' and constraint_type = 'FOREIGN KEY' and constraint_name = 'emergalarm_subscriber_fk')
and exists (select * from information_schema.columns where table_name = 'emergalarm' and column_name = 'sc_id') then
ALTER TABLE public.emergalarm
ADD CONSTRAINT emergalarm_subscriber_fk FOREIGN KEY (sc_id)
REFERENCES public.subscriber (sc_id) MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : emergalarm_subscriber_fk !';
else
RAISE NOTICE '%', 'Foreign key emergalarm_subscriber_fk exists between tables (emergalarm, subscriber)!';
end if;
if NOT exists (select * from information_schema.table_constraints where table_name = 'emergalarm' and constraint_type = 'FOREIGN KEY' and constraint_name = 'emergalarm_user_fk')
and exists (select * from information_schema.columns where table_name = 'emergalarm' and column_name = 'user_id') then
ALTER TABLE public.emergalarm
ADD CONSTRAINT emergalarm_user_fk FOREIGN KEY (user_id)
REFERENCES public.users (userid) MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : emergalarm_user_fk !';
else
RAISE NOTICE '%', 'Foreign key emergalarm_user_fk exists between tables (emergalarm, user) !';
end if;
--===================
--emergdi
--===================
if NOT exists (select * from information_schema.table_constraints where table_name = 'emergdi' and constraint_type = 'FOREIGN KEY' and constraint_name = 'emergdi_subscriber_fk')
and exists (select * from information_schema.columns where table_name = 'emergdi' and column_name = 'sc_id') then
ALTER TABLE public.emergdi
ADD CONSTRAINT emergdi_subscriber_fk FOREIGN KEY (sc_id)
REFERENCES public.subscriber (sc_id) MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : emergdi_subscriber_fk !';
else
RAISE NOTICE '%', 'Foreign key emergdi_subscriber_fk exists between tables (emergdi, subscriber) !';
end if;
--===================
--geozoneinout
--===================
if NOT exists (select * from information_schema.table_constraints where table_name = 'geozoneinout' and constraint_type = 'FOREIGN KEY' and constraint_name = 'geozoneinout_user_fk')
and exists (select * from information_schema.columns where table_name = 'geozoneinout' and column_name = 'user_id') then
ALTER TABLE public.geozoneinout
ADD CONSTRAINT geozoneinout_user_fk FOREIGN KEY (user_id)
REFERENCES public.users (userid) MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : geozoneinout_user_fk !';
else
RAISE NOTICE '%', 'Foreign key geozoneinout_user_fk exists between tables (geozoneinout, user) !';
end if;
if NOT exists (select * from information_schema.table_constraints where table_name = 'geozoneinout' and constraint_type = 'FOREIGN KEY' and constraint_name = 'geozoneinout_subscriber_fk')
and exists (select * from information_schema.columns where table_name = 'geozoneinout' and column_name = 'sc_id') then
ALTER TABLE public.geozoneinout
ADD CONSTRAINT geozoneinout_subscriber_fk FOREIGN KEY (sc_id)
REFERENCES public.subscriber (sc_id) MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : geozoneinout_subscriber_fk !';
else
RAISE NOTICE '%', 'Foreign key geozoneinout_subscriber_fk exists between tables (geozoneinout, subscriber) !';
end if;
--===================
--groups
--===================
if NOT exists (select * from information_schema.table_constraints where table_name = 'groups' and constraint_type = 'FOREIGN KEY' and constraint_name = 'groups_radio_gw_fk')
and exists (select * from information_schema.columns where table_name = 'groups' and column_name = 'r_gw_id') then
ALTER TABLE public.groups
ADD CONSTRAINT groups_radio_gw_fk FOREIGN KEY (r_gw_id)
REFERENCES public.radio_gw ("ID") MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : groups_radio_gw_fk !';
else
RAISE NOTICE '%', 'Foreign key groups_radio_gw_fk exists between tables (groups, radio_gw)!';
end if;
--===================
--jobtickets
--===================
if NOT exists (select * from information_schema.table_constraints where table_name = 'jobtickets' and constraint_type = 'FOREIGN KEY' and constraint_name = 'jobtickets_subscriber_fk')
and exists (select * from information_schema.columns where table_name = 'jobtickets' and column_name = 'sc_id') then
ALTER TABLE public.jobtickets
ADD CONSTRAINT jobtickets_subscriber_fk FOREIGN KEY (sc_id)
REFERENCES public.subscriber (sc_id) MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : jobtickets_subscriber_fk !';
else
RAISE NOTICE '%', 'Foreign key jobtickets_subscriber_fk exists between tables (jobtickets, subscriber)!';
end if;
--===================
--jobtickets_log
--===================
if NOT exists (select * from information_schema.table_constraints where table_name = 'jobtickets_log' and constraint_type = 'FOREIGN KEY' and constraint_name = 'jobtickets_log_jobtickets_fk')
and exists (select * from information_schema.columns where table_name = 'jobtickets_log' and column_name = 'ticket_id') then
ALTER TABLE public.jobtickets_log
ADD CONSTRAINT jobtickets_log_jobtickets_fk FOREIGN KEY (ticket_id)
REFERENCES public.jobtickets (ticket_id) MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : jobtickets_log_jobtickets_fk !';
else
RAISE NOTICE '%', 'Foreign key jobtickets_log_jobtickets_fk exists between tables (jobtickets_log, jobtickets)!';
end if;
if NOT exists (select * from information_schema.table_constraints where table_name = 'jobtickets_log' and constraint_type = 'FOREIGN KEY' and constraint_name = 'jobtickets_log_subscriber_fk')
and exists (select * from information_schema.columns where table_name = 'jobtickets_log' and column_name = 'sc_id') then
ALTER TABLE public.jobtickets_log
ADD CONSTRAINT jobtickets_log_subscriber_fk FOREIGN KEY (sc_id)
REFERENCES public.subscriber (sc_id) MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : jobtickets_log_subscriber_fk !';
else
RAISE NOTICE '%', 'Foreign key jobtickets_log_subscriber_fk exists between tables (jobtickets_log, subscriber)!';
end if;
--===================
--messages
--===================
if NOT exists (select * from information_schema.table_constraints where table_name = 'messages' and constraint_type = 'FOREIGN KEY' and constraint_name = 'messages_subscriber_fk')
and exists (select * from information_schema.columns where table_name = 'messages' and column_name = 'sc_id') then
ALTER TABLE public.messages
ADD CONSTRAINT messages_subscriber_fk FOREIGN KEY (sc_id)
REFERENCES public.subscriber (sc_id) MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : messages_subscriber_fk !';
else
RAISE NOTICE '%', 'Foreign key messages_subscriber_fk exists between tables (messages, subscriber)!';
end if;
--===================
--mobile_contacts
--===================
if NOT exists (select * from information_schema.table_constraints where table_name = 'mobile_contacts' and constraint_type = 'FOREIGN KEY' and constraint_name = 'mobile_contacts_subscriber_dest_fk')
and exists (select * from information_schema.columns where table_name = 'mobile_contacts' and column_name = 'sc_id') then
ALTER TABLE public.mobile_contacts
ADD CONSTRAINT mobile_contacts_subscriber_dest_fk FOREIGN KEY (sc_id)
REFERENCES public.subscriber (sc_id) MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : mobile_contacts_subscriber_dest_fk !';
else
RAISE NOTICE '%', 'Foreign key mobile_contacts_subscriber_dest_fk exists between tables (mobile_contacts, subscriber)!';
end if;
--===================
--passenger
--===================
if NOT exists (select * from information_schema.table_constraints where table_name = 'passenger' and constraint_type = 'FOREIGN KEY' and constraint_name = 'passenger_subscriber_dest_fk')
and exists (select * from information_schema.columns where table_name = 'passenger' and column_name = 'sc_id') then
ALTER TABLE public.passenger
ADD CONSTRAINT passenger_subscriber_dest_fk FOREIGN KEY (sc_id)
REFERENCES public.subscriber (sc_id) MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : passenger_subscriber_dest_fk !';
else
RAISE NOTICE '%', 'Foreign key passenger_subscriber_dest_fk exists between tables (passenger, subscriber)!';
end if;
--===================
--sms
--===================
if NOT exists (select * from information_schema.table_constraints where table_name = 'sms' and constraint_type = 'FOREIGN KEY' and constraint_name = 'sms_user_fk')
and exists (select * from information_schema.columns where table_name = 'sms' and column_name = 'user_id') then
ALTER TABLE public.sms
ADD CONSTRAINT sms_user_fk FOREIGN KEY (user_id)
REFERENCES public.users (userid) MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : sms_user_fk !';
else
RAISE NOTICE '%', 'Foreign key sms_user_fk exists between tables (sms, user)!';
end if;
--if NOT exists (select * from information_schema.table_constraints where table_name = 'sms' and constraint_type = 'FOREIGN KEY' and constraint_name = 'sms_subscriber_source_fk')
-- and exists (select * from information_schema.columns where table_name = 'sms' and column_name = 'sc_id_sour') then
--
--ALTER TABLE public.sms
-- ADD CONSTRAINT sms_subscriber_source_fk FOREIGN KEY (sc_id_sour)
-- REFERENCES public.subscriber (sc_id) MATCH SIMPLE
-- ON DELETE CASCADE;
--
-- RAISE NOTICE '%', 'Created foreign key : sms_subscriber_source_fk !';
--else
-- RAISE NOTICE '%', 'Foreign key sms_subscriber_source_fk exists between tables (sms, subscriber)!';
--
--end if;
--
--if NOT exists (select * from information_schema.table_constraints where table_name = 'sms' and constraint_type = 'FOREIGN KEY' and constraint_name = 'sms_subscriber_dest_fk')
-- and exists (select * from information_schema.columns where table_name = 'sms' and column_name = 'sc_id_dest') then
--ALTER TABLE public.sms
-- ADD CONSTRAINT sms_subscriber_dest_fk FOREIGN KEY (sc_id_dest)
-- REFERENCES public.subscriber (sc_id) MATCH SIMPLE
-- ON DELETE CASCADE;
--
-- RAISE NOTICE '%', 'Created foreign key : sms_subscriber_dest_fk !';
--else
-- RAISE NOTICE '%', 'Foreign key sms_subscriber_dest_fk exists between tables (sms, subscriber)!';
--
--end if;
--===================
--soundcards
--===================
if NOT exists (select * from information_schema.table_constraints where table_name = 'soundcards' and constraint_type = 'FOREIGN KEY' and constraint_name = 'soundcards_user_fk')
and exists (select * from information_schema.columns where table_name = 'soundcards' and column_name = 'user_id') then
ALTER TABLE public.soundcards
ADD CONSTRAINT soundcards_user_fk FOREIGN KEY (user_id)
REFERENCES public.users (userid) MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : soundcards_user_fk !';
else
RAISE NOTICE '%', 'Foreign key soundcards_user_fk exists between tables (soundcards, user)!';
end if;
--===================
--speedalarm
--===================
if NOT exists (select * from information_schema.table_constraints where table_name = 'speedalarm' and constraint_type = 'FOREIGN KEY' and constraint_name = 'speedalarm_subscriber_fk')
and exists (select * from information_schema.columns where table_name = 'speedalarm' and column_name = 'sc_id') then
ALTER TABLE public.speedalarm
ADD CONSTRAINT speedalarm_subscriber_fk FOREIGN KEY (sc_id)
REFERENCES public.subscriber (sc_id) MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : speedalarm_subscriber_fk !';
else
RAISE NOTICE '%', 'Foreign key speedalarm_subscriber_fk exists between tables (speedalarm, subscriber)!';
end if;
if NOT exists (select * from information_schema.table_constraints where table_name = 'speedalarm' and constraint_type = 'FOREIGN KEY' and constraint_name = 'speedalarm_user_fk')
and exists (select * from information_schema.columns where table_name = 'speedalarm' and column_name = 'user_id') then
ALTER TABLE public.speedalarm
ADD CONSTRAINT speedalarm_user_fk FOREIGN KEY (user_id)
REFERENCES public.users (userid) MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : speedalarm_user_fk !';
else
RAISE NOTICE '%', 'Foreign key speedalarm_user_fk exists between tables (speedalarm, user)!';
end if;
--===================
--subs_gateway
--===================
if NOT exists (select * from information_schema.table_constraints where table_name = 'subs_gateway' and constraint_type = 'FOREIGN KEY' and constraint_name = 'subs_gateway_subscriber_fk')
and exists (select * from information_schema.columns where table_name = 'subs_gateway' and column_name = 'sc_id') then
ALTER TABLE public.subs_gateway
ADD CONSTRAINT subs_gateway_subscriber_fk FOREIGN KEY (sc_id)
REFERENCES public.subscriber (sc_id) MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : subs_gateway_subscriber_fk !';
else
RAISE NOTICE '%', 'Foreign key subs_gateway_subscriber_fk exists between tables (subs_gateway, subscriber)!';
end if;
if NOT exists (select * from information_schema.table_constraints where table_name = 'subs_gateway' and constraint_type = 'FOREIGN KEY' and constraint_name = 'subs_gateway_radio_gw_fk')
and exists (select * from information_schema.columns where table_name = 'subs_gateway' and column_name = 'radio_gw_id') then
ALTER TABLE public.subs_gateway
ADD CONSTRAINT subs_gateway_radio_gw_fk FOREIGN KEY (radio_gw_id)
REFERENCES public.radio_gw ("ID") MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : subs_gateway_radio_gw_fk !';
else
RAISE NOTICE '%', 'Foreign key subs_gateway_radio_gw_fk exists between tables (subs_gateway, radio_gw)!';
end if;
if NOT exists (select * from information_schema.table_constraints where table_name = 'subs_gateway' and constraint_type = 'FOREIGN KEY' and constraint_name = 'subs_gateway_gateways_fk')
and exists (select * from information_schema.columns where table_name = 'subs_gateway' and column_name = 'gateway_id') then
ALTER TABLE public.subs_gateway
ADD CONSTRAINT subs_gateway_gateways_fk FOREIGN KEY (gateway_id)
REFERENCES public.gateways ("ID") MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : subs_gateway_gateways_fk !';
else
RAISE NOTICE '%', 'Foreign key subs_gateway_gateways_fk exists between tables (subs_gateway, gateways)!';
end if;
--===================
--subscriber_history
--===================
if NOT exists (select * from information_schema.table_constraints where table_name = 'subscriber_history' and constraint_type = 'FOREIGN KEY' and constraint_name = 'subscriber_history_subscriber_fk')
and exists (select * from information_schema.columns where table_name = 'subscriber_history' and column_name = 'sc_id') then
ALTER TABLE public.subscriber_history
ADD CONSTRAINT subscriber_history_subscriber_fk FOREIGN KEY (sc_id)
REFERENCES public.subscriber (sc_id) MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : subscriber_history_subscriber_fk !';
else
RAISE NOTICE '%', 'Foreign key subscriber_history_subscriber_fk exists between tables (subscriber_history, subscriber)!';
end if;
if NOT exists (select * from information_schema.table_constraints where table_name = 'subscriber_history' and constraint_type = 'FOREIGN KEY' and constraint_name = 'subscriber_history_vehicle_fk')
and exists (select * from information_schema.columns where table_name = 'subscriber_history' and column_name = 'veh_id') then
ALTER TABLE public.subscriber_history
ADD CONSTRAINT subscriber_history_vehicle_fk FOREIGN KEY (veh_id)
REFERENCES public.vehicle (id) MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : subscriber_history_vehicle_fk !';
else
RAISE NOTICE '%', 'Foreign key subscriber_history_vehicle_fk exists between tables (subscriber_history, vehicle)!';
end if;
--================
--telemetry_pos
--================
if NOT exists (select * from information_schema.table_constraints where table_name = 'telemetry_pos' and constraint_type = 'FOREIGN KEY' and constraint_name = 'telemetry_pos_subscriber_fk')
and exists (select * from information_schema.columns where table_name = 'telemetry_pos' and column_name = 'sc_id') then
ALTER TABLE public.telemetry_pos
ADD CONSTRAINT telemetry_pos_subscriber_fk FOREIGN KEY (sc_id)
REFERENCES public.subscriber (sc_id) MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : telemetry_pos_subscriber_fk !';
else
RAISE NOTICE '%', 'Foreign key telemetry_pos_subscriber_fk exists between tables (telemetry_pos, subscriber)!';
end if;
--================
-- users_radio
--================
if NOT exists (select * from information_schema.table_constraints where table_name = 'user_radio' and constraint_type = 'FOREIGN KEY' and constraint_name = 'user_radio_users_fk')
and exists (select * from information_schema.columns where table_name = 'user_radio' and column_name = 'user_id') then
ALTER TABLE public.user_radio
ADD CONSTRAINT user_radio_users_fk FOREIGN KEY (user_id)
REFERENCES public.users (userid) MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : users_radio_user_fk !';
else
RAISE NOTICE '%', 'Foreign key users_radio_user_fk exists between tables (user_radio, users)!';
end if;
if NOT exists (select * from information_schema.table_constraints where table_name = 'user_radio' and constraint_type = 'FOREIGN KEY' and constraint_name = 'user_radio_radio_gw_fk')
and exists (select * from information_schema.columns where table_name = 'user_radio' and column_name = 'radio_id') then
ALTER TABLE public.user_radio
ADD CONSTRAINT user_radio_radio_gw_fk FOREIGN KEY (radio_id)
REFERENCES public.radio_gw ("ID") MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : user_radio_radio_gw_fk !';
else
RAISE NOTICE '%', 'Foreign key user_radio_radio_gw_fk exists between tables (user_radio, radio_gw)!';
end if;
--================
-- users_group
--================
if NOT exists (select * from information_schema.table_constraints where table_name = 'users_group' and constraint_type = 'FOREIGN KEY' and constraint_name = 'users_group_user_fk')
and exists (select * from information_schema.columns where table_name = 'users_group' and column_name = 'userid') then
ALTER TABLE public.users_group
ADD CONSTRAINT users_group_user_fk FOREIGN KEY (userid)
REFERENCES public.users (userid) MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : users_group_user_fk !';
else
RAISE NOTICE '%', 'Foreign key users_group_user_fk exists between tables (users_group, users)!';
end if;
if NOT exists (select * from information_schema.table_constraints where table_name = 'users_group' and constraint_type = 'FOREIGN KEY' and constraint_name = 'users_group_groups_fk')
and exists (select * from information_schema.columns where table_name = 'users_group' and column_name = 'grp_id') then
ALTER TABLE public.users_group
ADD CONSTRAINT users_group_groups_fk FOREIGN KEY (grp_id)
REFERENCES public.groups (id) MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : users_group_groups_fk !';
else
RAISE NOTICE '%', 'Foreign key users_group_groups_fk exists between tables (users_group, groups)!';
end if;
--================
-- vehicle_group
--================
if NOT exists (select * from information_schema.table_constraints where table_name = 'vehicle_group' and constraint_type = 'FOREIGN KEY' and constraint_name = 'vehicle_group_subscriber_fk')
and exists (select * from information_schema.columns where table_name = 'vehicle_group' and column_name = 'sc_id') then
ALTER TABLE public.vehicle_group
ADD CONSTRAINT vehicle_group_subscriber_fk FOREIGN KEY (sc_id)
REFERENCES public.subscriber (sc_id) MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : vehicle_group_subscriber_fk !';
else
RAISE NOTICE '%', 'Foreign key vehicle_group_subscriber_fk exists between tables (vehicle_group, subscriber)!';
end if;
if NOT exists (select * from information_schema.table_constraints where table_name = 'vehicle_group' and constraint_type = 'FOREIGN KEY' and constraint_name = 'vehicle_group_groups_fk')
and exists (select * from information_schema.columns where table_name = 'vehicle_group' and column_name = 'grp_ip') then
ALTER TABLE public.vehicle_group
ADD CONSTRAINT vehicle_group_groups_fk FOREIGN KEY (grp_ip)
REFERENCES public.groups (id) MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : vehicle_group_groups_fk !';
else
RAISE NOTICE '%', 'Foreign key vehicle_group_groups_fk exists between tables (vehicle_group, groups)!';
end if;
--================
-- vehicle_user
--================
if NOT exists (select * from information_schema.table_constraints where table_name = 'vehicle_user' and constraint_type = 'FOREIGN KEY' and constraint_name = 'vehicle_user_users_fk')
and exists (select * from information_schema.columns where table_name = 'vehicle_user' and column_name = 'user_id') then
ALTER TABLE public.vehicle_user
ADD CONSTRAINT vehicle_user_users_fk FOREIGN KEY (user_id)
REFERENCES public.users (userid) MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : vehicle_user_users_fk !';
else
RAISE NOTICE '%', 'Foreign key vehicle_user_users_fk exists between tables (vehicle_group, users)!';
end if;
if NOT exists (select * from information_schema.table_constraints where table_name = 'vehicle_user' and constraint_type = 'FOREIGN KEY' and constraint_name = 'vehicle_user_vehicule_fk')
and exists (select * from information_schema.columns where table_name = 'vehicle_user' and column_name = 'veh_id') then
ALTER TABLE public.vehicle_user
ADD CONSTRAINT vehicle_user_vehicule_fk FOREIGN KEY (veh_id)
REFERENCES public.vehicle (id) MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : vehicle_user_vehicule_fk !';
else
RAISE NOTICE '%', 'Foreign key vehicle_user_vehicule_fk exists between tables (vehicle_group, vehicle)!';
end if;
--================
-- zonepoints
--================
if NOT exists (select * from information_schema.table_constraints where table_name = 'zonepoints' and constraint_type = 'FOREIGN KEY' and constraint_name = 'zonepoints_zone_fk')
and exists (select * from information_schema.columns where table_name = 'zonepoints' and column_name = 'zone_id') then
ALTER TABLE public.zonepoints
ADD CONSTRAINT zonepoints_zone_fk FOREIGN KEY (zone_id)
REFERENCES public.zonename (idx) MATCH SIMPLE
ON DELETE CASCADE;
RAISE NOTICE '%', 'Created foreign key : zonepoints_zone_fk !';
else
RAISE NOTICE '%', 'Foreign key zonepoints_zone_fk exists between tables (zonepoints, zonename)!';
end if;
END;
$BODY$
LANGUAGE plpgsql VOLATILE

View File

@ -0,0 +1,333 @@
CREATE OR REPLACE FUNCTION public.CreateMissingIndexes()
RETURNS void AS
$BODY$
BEGIN
--================
-- VoiceRecordings
--================
if not exists ( SELECT * FROM pg_indexes WHERE tablename = 'VoiceRecordings' and schemaname = 'public' and indexname = 'voicerecordings_time_start_idx' ) then
CREATE INDEX voicerecordings_time_start_idx ON public."VoiceRecordings" USING btree (time_start);
RAISE NOTICE '%', 'Created index : ''voicerecordings_time_start_idx'' !';
else
RAISE NOTICE '%', 'Index ''voicerecordings_time_start_idx'' already exists for table_name = ''VoiceRecordings'' !';
end if;
--================
-- car
--================
if not exists ( SELECT * FROM pg_indexes WHERE tablename = 'car' and schemaname = 'public' and indexname = 'car_name_idx' ) then
CREATE INDEX car_name_idx ON public.car USING btree (name);
RAISE NOTICE '%', 'Created index : ''car_name_idx'' !';
else
RAISE NOTICE '%', 'Index ''car_name_idx'' already exists for table_name = ''car'' !';
end if;
--================
-- geozoneinout
--================
if not exists ( SELECT * FROM pg_indexes WHERE tablename = 'geozoneinout' and schemaname = 'public' and indexname = 'geozoneinout_sc_id_timegmt_idx' ) then
CREATE INDEX geozoneinout_sc_id_timegmt_idx ON public.geozoneinout USING btree (sc_id, timegmt);
RAISE NOTICE '%', 'Created index : ''geozoneinout_sc_id_timegmt_idx'' !';
else
RAISE NOTICE '%', 'Index ''geozoneinout_sc_id_timegmt_idx'' already exists for table_name = ''geozoneinout'' !';
end if;
--================
-- groups
--================
if not exists ( SELECT * FROM pg_indexes WHERE tablename = 'groups' and schemaname = 'public' and indexname = 'groups_name_idx' ) then
CREATE INDEX groups_name_idx ON public.groups USING btree (name);
RAISE NOTICE '%', 'Created index : ''groups_name_idx'' !';
else
RAISE NOTICE '%', 'Index ''groups_name_idx'' already exists for table_name = ''groups'' !';
end if;
--================
-- passenger
--================
if not exists ( SELECT * FROM pg_indexes WHERE tablename = 'passenger' and schemaname = 'public' and indexname = 'passenger_name_idx' ) then
CREATE INDEX passenger_name_idx ON public.passenger USING btree (name);
RAISE NOTICE '%', 'Created index : ''passenger_name_idx'' !';
else
RAISE NOTICE '%', 'Index ''passenger_name_idx'' already exists for table_name = ''passenger'' !';
end if;
--================
-- placetype
--================
if not exists ( SELECT * FROM pg_indexes WHERE tablename = 'placetype' and schemaname = 'public' and indexname = 'placetype_type_name_idx' ) then
CREATE INDEX placetype_type_name_idx ON public.placetype USING btree (type_name);
RAISE NOTICE '%', 'Created index : ''placetype_type_name_idx'' !';
else
RAISE NOTICE '%', 'Index ''placetype_type_name_idx'' already exists for table_name = ''placetype'' !';
end if;
--================
-- radio_gw
--================
if not exists ( SELECT * FROM pg_indexes WHERE tablename = 'radio_gw' and schemaname = 'public' and indexname = 'radio_gw_name_idx' ) then
CREATE INDEX radio_gw_name_idx ON public.radio_gw USING btree (name);
RAISE NOTICE '%', 'Created index : ''radio_gw_name_idx'' !';
else
RAISE NOTICE '%', 'Index ''radio_gw_name_idx'' already exists for table_name = ''radio_gw'' !';
end if;
if not exists ( SELECT * FROM pg_indexes WHERE tablename = 'radio_gw' and schemaname = 'public' and indexname = 'radio_gw_type_idx' ) then
CREATE INDEX radio_gw_type_idx ON public.radio_gw USING btree (gw_type);
RAISE NOTICE '%', 'Created index : ''radio_gw_type_idx'' !';
else
RAISE NOTICE '%', 'Index ''radio_gw_type_idx'' already exists for table_name = ''radio_gw'' !';
end if;
--================
-- sms
--================
if not exists ( SELECT * FROM pg_indexes WHERE tablename = 'sms' and schemaname = 'public' and indexname = 'sms_timegmt_idx' ) then
CREATE INDEX sms_timegmt_idx ON public.sms USING btree (timegmt);
RAISE NOTICE '%', 'Created index : ''sms_timegmt_idx'' !';
else
RAISE NOTICE '%', 'Index ''sms_timegmt_idx'' already exists for table_name = ''sms'' !';
end if;
--================
-- subscriber
--================
if not exists ( SELECT * FROM pg_indexes WHERE tablename = 'subscriber' and schemaname = 'public' and indexname = 'subscriber_imei_idx' ) then
CREATE INDEX subscriber_imei_idx ON public.subscriber USING btree (imei);
RAISE NOTICE '%', 'Created index : ''subscriber_imei_idx'' !';
else
RAISE NOTICE '%', 'Index ''subscriber_imei_idx'' already exists for table_name = ''subscriber'' !';
end if;
--================
-- subscriber_alarm
--================
if not exists ( SELECT * FROM pg_indexes WHERE tablename = 'subscriber_alarm' and schemaname = 'public' and indexname = 'subscriber_alarm_sc_id_idx' ) then
CREATE INDEX subscriber_alarm_sc_id_idx ON public.subscriber_alarm USING btree (sc_id);
RAISE NOTICE '%', 'Created index : ''subscriber_alarm_sc_id_idx'' !';
else
RAISE NOTICE '%', 'Index ''subscriber_alarm_sc_id_idx'' already exists for table_name = ''subscriber_alarm'' !';
end if;
--================
-- subscriber_stun
--================
if not exists ( SELECT * FROM pg_indexes WHERE tablename = 'subscriber_stun' and schemaname = 'public' and indexname = 'subscriber_stun_sc_id_idx' ) then
CREATE INDEX subscriber_stun_sc_id_idx ON public.subscriber_stun USING btree (sc_id);
RAISE NOTICE '%', 'Created index : ''subscriber_stun_sc_id_idx'' !';
else
RAISE NOTICE '%', 'Index ''subscriber_stun_sc_id_idx'' already exists for table_name = ''subscriber_stun'' !';
end if;
--================
-- telemetry
--================
if not exists ( SELECT * FROM pg_indexes WHERE tablename = 'telemetry' and schemaname = 'public' and indexname = 'telemetry_alarm_idx' ) then
CREATE INDEX telemetry_alarm_idx ON public.telemetry USING btree (alarm);
RAISE NOTICE '%', 'Created index : ''telemetry_alarm_idx'' !';
else
RAISE NOTICE '%', 'Index ''telemetry_alarm_idx'' already exists for table_name = ''telemetry'' !';
end if;
if not exists ( SELECT * FROM pg_indexes WHERE tablename = 'telemetry' and schemaname = 'public' and indexname = 'telemetry_name_idx' ) then
CREATE INDEX telemetry_name_idx ON public.telemetry USING btree (name);
RAISE NOTICE '%', 'Created index : ''telemetry_name_idx'' !';
else
RAISE NOTICE '%', 'Index ''telemetry_name_idx'' already exists for table_name = ''telemetry'' !';
end if;
if not exists ( SELECT * FROM pg_indexes WHERE tablename = 'telemetry' and schemaname = 'public' and indexname = 'telemetry_sc_id_idx' ) then
CREATE INDEX telemetry_sc_id_idx ON public.telemetry USING btree (sc_id);
RAISE NOTICE '%', 'Created index : ''telemetry_sc_id_idx'' !';
else
RAISE NOTICE '%', 'Index ''telemetry_sc_id_idx'' already exists for table_name = ''telemetry'' !';
end if;
if not exists ( SELECT * FROM pg_indexes WHERE tablename = 'telemetry' and schemaname = 'public' and indexname = 'telemetry_sc_id__digital_nr_idx' ) then
CREATE INDEX telemetry_sc_id__digital_nr_idx ON public.telemetry USING btree (sc_id, digital_nr);
RAISE NOTICE '%', 'Created index : ''telemetry_sc_id__digital_nr_idx'' !';
else
RAISE NOTICE '%', 'Index ''telemetry_sc_id__digital_nr_idx'' already exists for table_name = ''telemetry'' !';
end if;
--====================
-- telemetry history
--====================
if not exists ( SELECT * FROM pg_indexes WHERE tablename = 'telemetry_history' and schemaname = 'public' and indexname = 'telemetry_history_sc_id_idx' ) then
CREATE INDEX telemetry_history_sc_id_idx ON public.telemetry_history USING btree (sc_id);
RAISE NOTICE '%', 'Created index : ''telemetry_history_sc_id_idx'' !';
else
RAISE NOTICE '%', 'Index ''telemetry_history_sc_id_idx'' already exists for table_name = ''telemetry_history'' !';
end if;
--================
-- user_radio
--================
if not exists ( SELECT * FROM pg_indexes WHERE tablename = 'user_radio' and schemaname = 'public' and indexname = 'user_radio_userid_idx' ) then
CREATE INDEX user_radio_userid_idx ON public.user_radio USING btree (user_id);
RAISE NOTICE '%', 'Created index : ''user_radio_userid_idx'' !';
else
RAISE NOTICE '%', 'Index ''user_radio_userid_idx'' already exists for table_name = ''user_radio'' !';
end if;
if not exists ( SELECT * FROM pg_indexes WHERE tablename = 'user_radio' and schemaname = 'public' and indexname = 'user_radio_radioid_idx' ) then
CREATE INDEX user_radio_radioid_idx ON public.user_radio USING btree (radio_id);
RAISE NOTICE '%', 'Created index : ''user_radio_radioid_idx'' !';
else
RAISE NOTICE '%', 'Index ''user_radio_radioid_idx'' already exists for table_name = ''user_radio'' !';
end if;
--================
-- users
--================
if not exists ( SELECT * FROM pg_indexes WHERE tablename = 'users' and schemaname = 'public' and indexname = 'user_login_idx' ) then
CREATE INDEX user_login_idx ON public.users USING btree (login);
RAISE NOTICE '%', 'Created index : ''user_login_idx'' !';
else
RAISE NOTICE '%', 'Index ''user_login_idx'' already exists for table_name = ''users'' !';
end if;
if not exists ( SELECT * FROM pg_indexes WHERE tablename = 'users' and schemaname = 'public' and indexname = 'user_usertype_idx' ) then
CREATE INDEX user_usertype_idx ON public.users USING btree (user_type);
RAISE NOTICE '%', 'Created index : ''user_usertype_idx'' !';
else
RAISE NOTICE '%', 'Index ''user_usertype_idx'' already exists for table_name = ''users'' !';
end if;
--================
-- userSettings
--================
if not exists ( SELECT * FROM pg_indexes WHERE tablename = 'userSettings' and schemaname = 'public' and indexname = 'usersettings_userid_idx' ) then
CREATE INDEX usersettings_userid_idx ON public."userSettings" USING btree (user_id);
RAISE NOTICE '%', 'Created index : ''usersettings_userid_idx'' !';
else
RAISE NOTICE '%', 'Index ''usersettings_userid_idx'' already exists for table_name = ''userSettings'' !';
end if;
if not exists ( SELECT * FROM pg_indexes WHERE tablename = 'userSettings' and schemaname = 'public' and indexname = 'usersettings_key_idx' ) then
CREATE INDEX usersettings_key_idx ON public."userSettings" USING btree (key);
RAISE NOTICE '%', 'Created index : ''usersettings_key_idx'' !';
else
RAISE NOTICE '%', 'Index ''usersettings_key_idx'' already exists for table_name = ''userSettings'' !';
end if;
if not exists ( SELECT * FROM pg_indexes WHERE tablename = 'userSettings' and schemaname = 'public' and indexname = 'usersettings_userid_key_idx' ) then
CREATE INDEX usersettings_userid_key_idx ON public."userSettings" USING btree (user_id, key);
RAISE NOTICE '%', 'Created index : ''usersettings_userid_key_idx'' !';
else
RAISE NOTICE '%', 'Index ''usersettings_userid_key_idx'' already exists for table_name = ''userSettings'' !';
end if;
--================
-- vehicle_group
--================
if not exists ( SELECT * FROM pg_indexes WHERE tablename = 'vehicle_group' and schemaname = 'public' and indexname = 'vehicle_group_sc_id_grp_ip_idx' ) then
CREATE INDEX vehicle_group_sc_id_grp_ip_idx ON public.vehicle_group USING btree (sc_id, grp_ip);
RAISE NOTICE '%', 'Created index : ''vehicle_group_sc_id_grp_ip_idx'' !';
else
RAISE NOTICE '%', 'Index ''vehicle_group_sc_id_grp_ip_idx'' already exists for table_name = ''vehicle_group'' !';
end if;
--================
-- zonepoints
--================
if not exists ( SELECT * FROM pg_indexes WHERE tablename = 'zonepoints' and schemaname = 'public' and indexname = 'zonepoints_zoneid_idx' ) then
CREATE INDEX zonepoints_zoneid_idx ON public.zonepoints USING btree (zone_id);
RAISE NOTICE '%', 'Created index : ''zonepoints_zoneid_idx'' !';
else
RAISE NOTICE '%', 'Index ''zonepoints_zoneid_idx'' already exists for table_name = ''zonepoints'' !';
end if;
END;
$BODY$
LANGUAGE plpgsql VOLATILE

View File

@ -0,0 +1,275 @@
CREATE OR REPLACE FUNCTION CreateMissingPrimaryKeys()
RETURNS void
LANGUAGE 'plpgsql'
AS
$$
BEGIN
--============
--call_patch
--============
if NOT exists (select constraint_name from information_schema.table_constraints where table_name = 'call_patch' and constraint_type = 'PRIMARY KEY') then
ALTER TABLE public.call_patch
ADD CONSTRAINT call_patch_pkey PRIMARY KEY(idx);
RAISE NOTICE '%', 'Created primary key : call_patch_pkey!';
else
RAISE NOTICE '%', 'Primary key already exists for table_name = call_patch!';
end if;
--============
--emailservice ( duplicate row )
--============
if NOT exists (select constraint_name from information_schema.table_constraints where table_name = 'emailservice' and constraint_type = 'PRIMARY KEY') then
ALTER TABLE public.emailservice
ADD CONSTRAINT emailservice_pkey PRIMARY KEY(id);
RAISE NOTICE '%', 'Created primary key : emailservice_pkey !';
else
RAISE NOTICE '%', 'Primary key already exists for table_name = emailservice !';
end if;
--============
--emergdi
--============
if NOT exists (select constraint_name from information_schema.table_constraints where table_name = 'emergdi' and constraint_type = 'PRIMARY KEY') then
ALTER TABLE public.emergdi
ADD CONSTRAINT emergdi_pkey PRIMARY KEY(idx);
RAISE NOTICE '%', 'Created primary key : emergdi_pkey !';
else
RAISE NOTICE '%', 'Primary key already exists for table_name = emergdi !';
end if;
--========
--groups
--========
if NOT exists (select constraint_name from information_schema.table_constraints where table_name = 'groups' and constraint_type = 'PRIMARY KEY') then
ALTER TABLE public.groups
ADD CONSTRAINT groups_pkey PRIMARY KEY(id);
RAISE NOTICE '%', 'Created primary key : groups_pkey !';
else
RAISE NOTICE '%', 'Primary key already exists for table_name = groups !';
end if;
--============
-- icon_theme
--============
if NOT exists (select constraint_name from information_schema.table_constraints where table_name = 'icon_theme' and constraint_type = 'PRIMARY KEY') then
ALTER TABLE public.icon_theme
ADD CONSTRAINT icon_theme_pkey PRIMARY KEY(id);
RAISE NOTICE '%', 'Created primary key : icon_theme_pkey !';
else
RAISE NOTICE '%', 'Primary key already exists for table_name = icon_theme !';
end if;
--============
-- jobtickets
--============
if NOT exists (select constraint_name from information_schema.table_constraints where table_name = 'jobtickets' and constraint_type = 'PRIMARY KEY') then
ALTER TABLE public.jobtickets
ADD CONSTRAINT jobtickets_pkey PRIMARY KEY(ticket_id);
RAISE NOTICE '%', 'Created primary key : jobtickets_pkey !';
else
RAISE NOTICE '%', 'Primary key already exists for table_name = jobtickets !';
end if;
--================
-- jobtickets_log
--================
if NOT exists (select constraint_name from information_schema.table_constraints where table_name = 'jobtickets_log' and constraint_type = 'PRIMARY KEY') then
ALTER TABLE public.jobtickets_log
ADD CONSTRAINT jobtickets_log_pkey PRIMARY KEY(id);
RAISE NOTICE '%', 'Created primary key : jobtickets_log_pkey !';
else
RAISE NOTICE '%', 'Primary key already exists for table_name = jobtickets_log !';
end if;
--================
-- mobile_contacts
--================
if NOT exists (select constraint_name from information_schema.table_constraints where table_name = 'mobile_contacts' and constraint_type = 'PRIMARY KEY') then
ALTER TABLE public.mobile_contacts
ADD CONSTRAINT mobile_contacts_pkey PRIMARY KEY(idx);
RAISE NOTICE '%', 'Created primary key : mobile_contacts_pkey !';
else
RAISE NOTICE '%', 'Primary key already exists for table_name = mobile_contacts !';
end if;
--================
-- placetype
--================
if NOT exists (select constraint_name from information_schema.table_constraints where table_name = 'placetype' and constraint_type = 'PRIMARY KEY') then
ALTER TABLE public.placetype
ADD CONSTRAINT placetype_pkey PRIMARY KEY(type_id);
RAISE NOTICE '%', 'Created primary key : placetype_pkey !';
else
RAISE NOTICE '%', 'Primary key already exists for table_name = placetype !';
end if;
--================
-- radio_mobile
--================
if NOT exists (select constraint_name from information_schema.table_constraints where table_name = 'radio_mobile' and constraint_type = 'PRIMARY KEY') then
ALTER TABLE public.radio_mobile
ADD CONSTRAINT radio_mobile_pkey PRIMARY KEY(idx);
RAISE NOTICE '%', 'Created primary key : radio_mobile_pkey !';
else
RAISE NOTICE '%', 'Primary key already exists for table_name = radio_mobile !';
end if;
--================
-- reports
--================
if NOT exists (select constraint_name from information_schema.table_constraints where table_name = 'reports' and constraint_type = 'PRIMARY KEY') then
ALTER TABLE public.reports
ADD CONSTRAINT reports_pkey PRIMARY KEY(idx);
RAISE NOTICE '%', 'Created primary key : reports_pkey !';
else
RAISE NOTICE '%', 'Primary key already exists for table_name = reports !';
end if;
--================
-- sd_list
--================
if NOT exists (select constraint_name from information_schema.table_constraints where table_name = 'sd_list' and constraint_type = 'PRIMARY KEY') then
ALTER TABLE public.sd_list
ADD CONSTRAINT sd_list_pkey PRIMARY KEY(sd_id);
RAISE NOTICE '%', 'Created primary key : sd_list_pkey !';
else
RAISE NOTICE '%', 'Primary key already exists for table_name = sd_list !';
end if;
--============
-- users_group
--============
if NOT exists (select constraint_name from information_schema.table_constraints where table_name = 'users_group' and constraint_type = 'PRIMARY KEY') then
ALTER TABLE public.users_group
ADD CONSTRAINT users_group_pkey PRIMARY KEY(idx);
RAISE NOTICE '%', 'Created primary key : users_group_pkey !';
else
RAISE NOTICE '%', 'Primary key already exists for table_name = users_group !';
end if;
--============
-- user_radio
--============
if NOT exists (select constraint_name from information_schema.table_constraints where table_name = 'user_radio' and constraint_type = 'PRIMARY KEY') then
ALTER TABLE public.user_radio
ADD CONSTRAINT user_radio_pkey PRIMARY KEY(radio_id, user_id);
RAISE NOTICE '%', 'Created primary key : user_radio_pkey !';
else
RAISE NOTICE '%', 'Primary key already exists for table_name = user_radio !';
end if;
--============
-- vehicle_group
--============
if NOT exists (select constraint_name from information_schema.table_constraints where table_name = 'vehicle_group' and constraint_type = 'PRIMARY KEY') then
ALTER TABLE public.vehicle_group
ADD CONSTRAINT vehicle_group_pkey PRIMARY KEY(idx);
RAISE NOTICE '%', 'Created primary key : vehicle_group_pkey !';
else
RAISE NOTICE '%', 'Primary key already exists for table_name = vehicle_group !';
end if;
--============
-- vehicle_user
--============
if NOT exists (select constraint_name from information_schema.table_constraints where table_name = 'vehicle_user' and constraint_type = 'PRIMARY KEY') then
ALTER TABLE public.vehicle_user
ADD CONSTRAINT vehicle_user_pkey PRIMARY KEY(veh_id, user_id);
RAISE NOTICE '%', 'Created primary key : vehicle_user_pkey !';
else
RAISE NOTICE '%', 'Primary key already exists for table_name = vehicle_user !';
end if;
--============
-- zonenames
--============
if NOT exists (select constraint_name from information_schema.table_constraints where table_name = 'zonename' and constraint_type = 'PRIMARY KEY') then
ALTER TABLE public.zonename
ADD CONSTRAINT zonename_pkey PRIMARY KEY(idx);
RAISE NOTICE '%', 'Created primary key : zonename_pkey !';
else
RAISE NOTICE '%', 'Primary key already exists for table_name = zonename !';
end if;
--============
-- zonepoints
--============
if NOT exists (select constraint_name from information_schema.table_constraints where table_name = 'zonepoints' and constraint_type = 'PRIMARY KEY') then
ALTER TABLE public.zonepoints
ADD CONSTRAINT zonepoints_pkey PRIMARY KEY(idx);
RAISE NOTICE '%', 'Created primary key : zonepoints_pkey!';
else
RAISE NOTICE '%', 'Primary key already exists for table_name = zonepoints !';
end if;
END;
$$;

121
UpdateHelper/NewFields.sql Normal file
View File

@ -0,0 +1,121 @@
CREATE OR REPLACE FUNCTION public.AddNewFields()
RETURNS void
LANGUAGE 'plpgsql'
AS
$BODY$
BEGIN
IF NOT EXISTS (SELECT * FROM information_schema.columns WHERE table_name = 'radio_gw' AND column_name = 'deleted') THEN
ALTER TABLE public.radio_gw ADD COLUMN deleted boolean NOT NULL DEFAULT false;
RAISE NOTICE '%', 'ADD COLUMN : deleted in table radio_gw !';
ELSE
RAISE NOTICE '%', 'COLUMN deleted already exists in table radio_gw !';
END IF;
IF EXISTS ( SELECT * FROM pg_constraint WHERE conname = 'uniqueKey_radio_gw' ) THEN
ALTER TABLE public.radio_gw DROP CONSTRAINT "uniqueKey_radio_gw";
RAISE NOTICE '%', 'DROP CONSTRAINT uniqueKey_radio_gw in table radio_gw !';
END IF;
IF NOT EXISTS ( SELECT * FROM pg_indexes WHERE tablename = 'radio_gw' and schemaname = 'public' and indexname = 'uniqueKey_radio_gw' ) THEN
CREATE UNIQUE INDEX "uniqueKey_radio_gw" ON radio_gw ("IP", "GW_ID", deleted) WHERE deleted = false;
RAISE NOTICE '%', 'CREATE UNIQUE INDEX uniqueKey_radio_gw in table radio_gw !';
ELSE
RAISE NOTICE '%', 'UNIQUE INDEX uniqueKey_radio_gw already exists in table radio_gw !';
END IF;
IF NOT EXISTS (SELECT * FROM information_schema.columns WHERE table_name = 'gateways' AND column_name='deleted') THEN
ALTER TABLE public.gateways ADD COLUMN deleted boolean NOT NULL DEFAULT false;
RAISE NOTICE '%', 'ADD COLUMN : deleted in table gateways !';
ELSE
RAISE NOTICE '%', 'COLUMN deleted already exists in table gateways !';
END IF;
IF EXISTS ( SELECT * FROM pg_constraint WHERE conname = 'uniqueKey_gateways' ) THEN
ALTER TABLE public.gateways DROP CONSTRAINT "uniqueKey_gateways";
RAISE NOTICE '%', 'DROP CONSTRAINT uniqueKey_gateways in table gateways !';
END IF ;
IF NOT EXISTS ( SELECT * FROM pg_indexes WHERE tablename = 'gateways' and schemaname = 'public' and indexname = 'uniqueKey_gateways' ) THEN
CREATE UNIQUE INDEX "uniqueKey_gateways" ON gateways ("IP", deleted) WHERE deleted = false ;
RAISE NOTICE '%', 'CREATE UNIQUE INDEX uniqueKey_gateways in table gateways !';
ELSE
RAISE NOTICE '%', 'UNIQUE INDEX uniqueKey_gateways already exists in table gateways !';
END IF;
IF NOT EXISTS (SELECT * FROM information_schema.columns WHERE table_name = 'subs_gateway' AND column_name = 'id') THEN
CREATE SEQUENCE IF NOT EXISTS subs_gateway_seq;
ALTER TABLE public.subs_gateway ADD COLUMN id INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('subs_gateway_seq'::regclass) ;
RAISE NOTICE '%', 'ADD COLUMN : id in table subs_gateway and set it as primary key!';
ELSE
RAISE NOTICE '%', 'COLUMN id already exists in table subs_gateway !';
END IF;
IF EXISTS (SELECT * FROM information_schema.columns WHERE table_name = 'subs_gateway' AND column_name = 'gateway_id' AND is_nullable = 'NO') THEN
ALTER TABLE public.subs_gateway ALTER COLUMN gateway_id DROP NOT NULL;
RAISE NOTICE '%', 'DROP NOT NULL attribute FOR COLUMN : gateway_id in the table subs_gateway !';
ELSE
RAISE NOTICE '%', 'The attribute NULL already exists for the column : gateway_id in the table subs_gateway !';
END IF;
IF EXISTS (SELECT * FROM information_schema.columns WHERE table_name = 'subs_gateway' AND column_name = 'radio_gw_id' AND is_nullable = 'NO') THEN
ALTER TABLE public.subs_gateway ALTER COLUMN radio_gw_id DROP NOT NULL;
RAISE NOTICE '%', 'DROP NOT NULL attribute FOR COLUMN : radio_gw_id in the table subs_gateway !';
ELSE
RAISE NOTICE '%', 'The attribute NULL already exists for the column : radio_gw_id in the table subs_gateway !';
END IF;
IF NOT EXISTS (SELECT * FROM information_schema.columns WHERE table_name = 'VoiceRecordings' AND column_name = 'dispatcher_id') THEN
ALTER TABLE public."VoiceRecordings" ADD COLUMN dispatcher_id integer NULL;
RAISE NOTICE '%', 'ADD COLUMN : dispatcher_id in table VoiceRecordings !';
END IF;
IF EXISTS (SELECT * FROM information_schema.columns WHERE table_name = 'VoiceRecordings' AND column_name = 'subscriber_id' AND is_nullable = 'NO') THEN
ALTER TABLE public."VoiceRecordings" ALTER COLUMN subscriber_id DROP NOT NULL;
RAISE NOTICE '%', 'DROP NOT NULL attribute FOR COLUMN : subscriber_id in the table VoiceRecordings !';
ELSE
RAISE NOTICE '%', 'The attribute NULL already exists for the column : subscriber_id in the table VoiceRecordings !';
END IF;
IF EXISTS (SELECT * FROM information_schema.columns WHERE table_name = 'VoiceRecordings' AND column_name = 'group_id' AND is_nullable = 'NO') THEN
ALTER TABLE public."VoiceRecordings" ALTER COLUMN group_id DROP NOT NULL;
RAISE NOTICE '%', 'DROP NOT NULL attribute FOR COLUMN : group_id in the table VoiceRecordings !';
ELSE
RAISE NOTICE '%', 'The attribute NULL already exists for the column : group_id in the table VoiceRecordings !';
END IF;
IF NOT EXISTS (SELECT * FROM information_schema.columns WHERE table_name = 'vehicle' AND column_name = 'is_deleted' AND is_nullable = 'NO') THEN
ALTER TABLE vehicle ADD COLUMN is_deleted BOOLEAN NOT NULL DEFAULT FALSE;
RAISE NOTICE '%', 'ADD COLUMN : is_deleted in table vehicle and set it to FALSE!';
ELSE
RAISE NOTICE '%', 'COLUMN is_deleted already exists in table vehicle !';
END IF;
END;
$BODY$;

218
UpdateHelper/Program.cs Normal file
View File

@ -0,0 +1,218 @@
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace UpdateHelper
{
class Program
{
static void Main(string[] args)
{
#region filename argument
var sql_path = "";
try
{
switch(args[0])
{
case "-f":
case "-w":
sql_path = AppDomain.CurrentDomain.BaseDirectory + args[1];
break;
case "-h":
case "--help":
WriteLine("-w <SQL Func filename>", ConsoleColor.Yellow); // run whole file
WriteLine("-f <SQL Query filename>", ConsoleColor.Yellow); // run line by line
WriteLine("-h help", ConsoleColor.Yellow);
WriteLine("--help help", ConsoleColor.Yellow);
WriteLine("NOTE: If you wish to set the pgsql password, please execute: SET PGPASSWORD=<PGPASSWORD STRING>", ConsoleColor.Cyan);
Console.WriteLine("\nPress any key to exit...");
Console.ReadKey();
return;
}
}
catch
{
WriteLine("Invalid argument exception", ConsoleColor.Red);
Console.WriteLine("\nPress any key to exit...");
Console.ReadLine();
return;
}
#endregion
#region readfile & config
string pg_path = ConfigurationManager.AppSettings["pg_path"];
if (!pg_path.EndsWith("\\"))
pg_path += "\\";
string hostname = ConfigurationManager.AppSettings["hostname"];
string username = ConfigurationManager.AppSettings["username"];
string dbname = ConfigurationManager.AppSettings["dbname"];
string port = ConfigurationManager.AppSettings["port"];
string PGPASSWORD = ConfigurationManager.AppSettings["PGPASSWORD"];
int cntOK = 0, cntKO = 0, cntWarning = 0, total = 0, cmd_sleep = 100;
int.TryParse(ConfigurationManager.AppSettings["cmd_sleep"], out cmd_sleep);
if(!File.Exists(sql_path))
{
WriteLine("Invalid sql_path", ConsoleColor.Red);
Console.ReadLine();
return;
}
if (!File.Exists(pg_path + "psql.exe"))
{
WriteLine("Invalid pg_path", ConsoleColor.Red);
Console.ReadLine();
return;
}
#endregion
string arguments = string.Empty;
if (args[0] == "-w")
{
arguments = string.Format("-h {0} -U {1} -d {2} -p {3} -w -f \"{4}\" ", hostname, username, dbname, port, sql_path);
RunFile(pg_path, arguments);
Console.WriteLine(pg_path + "psql.exe " + arguments);
Console.ReadKey();
return;
}
if (args[0] == "-f")
{
var reader = File.ReadLines(sql_path);
StringBuilder fileOK = new StringBuilder();
StringBuilder fileKO = new StringBuilder();
StringBuilder fileWarning = new StringBuilder();
StreamWriter swOK = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "\\Succes.txt", false);
StreamWriter swKO = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "\\Failed.txt", false);
StreamWriter swWarning = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "\\Warning.txt", false);
Process p = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
arguments = string.Empty;
#region execute commands
foreach (string line in reader)
{
if (!line.StartsWith("--"))
{
total++;
arguments = string.Format("-h {0} -U {1} -d {2} -p {3} -c \"{4}\" -w", hostname, username, dbname, port, line);
p.StartInfo = RunQuery(startInfo, pg_path, arguments);
p.Start();
// add statistics
string output = p.StandardOutput.ReadToEnd();
string error = p.StandardError.ReadToEnd();
if (output == "")
{
if (error.Contains("already"))
{
WriteLine(line, ConsoleColor.Yellow);
WriteLine(error.Trim(), ConsoleColor.White);
fileWarning.AppendLine(line);
cntWarning++;
}
else
{
WriteLine(line, ConsoleColor.Red);
WriteLine(error, ConsoleColor.White);
fileKO.AppendLine(line);
cntKO++;
}
}
else
{
WriteLine(line, ConsoleColor.Green);
fileOK.AppendLine(line);
cntOK++;
}
Thread.Sleep(cmd_sleep);
}
}
#endregion
#region statistics
WriteLine("-------------------------", ConsoleColor.Cyan);
WriteLine("| Finish |", ConsoleColor.Cyan);
WriteLine("-------------------------", ConsoleColor.Cyan);
WriteLine(string.Format("| Total | {0,10}|", total), ConsoleColor.Cyan);
WriteLine(string.Format("| Succes | {0,10}|", cntOK), ConsoleColor.Cyan);
WriteLine(string.Format("| Warning | {0,10}|", cntWarning), ConsoleColor.Cyan);
WriteLine(string.Format("| Failed | {0,10}|", cntKO), ConsoleColor.Cyan);
WriteLine("-------------------------", ConsoleColor.Cyan);
#endregion
#region write streams
swOK.Write(fileOK.ToString());
swOK.Close();
swKO.Write(fileKO.ToString());
swKO.Close();
swWarning.Write(fileWarning.ToString());
swWarning.Close();
#endregion
Console.ReadKey();
}
}
static void RunFile(string path, string arguments)
{
Process p = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
p.StartInfo = RunQuery(startInfo, path, arguments);
p.Start();
string output = p.StandardOutput.ReadToEnd();
string error = p.StandardError.ReadToEnd();
Console.WriteLine(output);
Console.WriteLine(error);
}
static ProcessStartInfo RunQuery(ProcessStartInfo startInfo, string path, string arguments)
{
startInfo.FileName = path + "psql.exe";
startInfo.Arguments = arguments;
startInfo.Verb = "runas";
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
return startInfo;
}
static void WriteLine(string str, ConsoleColor color)
{
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.Write(String.Format("[### {0:H:mm:ss} ###] ", DateTime.Now));
Console.ForegroundColor = color;
Console.Write(String.Format("{0}\n", str));
Console.ForegroundColor = ConsoleColor.Gray;
}
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("UpdateHelper")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("UpdateHelper")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("5e9a06be-0b35-444f-8f1d-714e6f12d8ee")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("8.1.0.10898")]
[assembly: AssemblyFileVersion("8.1.0.10898")]

View File

@ -0,0 +1,278 @@

-- in order to add foreign keys is mandatory to have right values for related data.
-- so we should remove the records without related data
CREATE OR REPLACE FUNCTION RemoveRecordsWithoutRelatedData()
RETURNS void
LANGUAGE 'plpgsql'
AS
$$
BEGIN
if ( (select count(*) from emailservice where id = 2) > 1 ) then
delete from public.emailservice where id = 2;
INSERT INTO public.emailservice(
id, "user", pass, enable, pop_server, pop_port, smtp_server, smtp_port, is_pop_ssl, is_smtp_ssl, last_email_time)
VALUES (2, 'poll', 'poll', 0, 'pop.gmail.com', 995, 'smtp.gmail.com', 587, true, true, 0);
end if;
--=============================================
-- insert a dummy user if it doesn't exist
--=============================================
if not exists ( select * from public.users where userid = 0) then
INSERT INTO users(userid, firstname, lastname, login, password, user_type, ison,backup_user_id) VALUES (0, 'anything', 'anything', 'anything', 'anything', 100, 0, -1 );
end if;
--=============================================
-- insert a dummy suscriber if it doesn't exist
--=============================================
if not exists ( select * from subscriber where sc_id = 0 ) then
insert into subscriber (sc_id, imei) values ( 0, '0');
end if;
--==========================================================
-- replace the invalid user ids to the id of the dummy user
--==========================================================
if exists ( select * from public.sms where user_id < 0) then
update sms set user_id = 0 where user_id = -1;
end if;
--========================================
-- remove the emergalarm records
-- whose subscriber doesn't exists any more
--========================================
delete from public.emergalarm
where sc_id in ( select distinct sc_id from public.emergalarm
except
select sc_id from public.subscriber
)
or user_id in ( select distinct user_id from public.emergalarm
except
select userid from public.users
);
--========================================
-- remove the groups
-- whose radio_gw doesn't exists any more
--========================================
delete from public.groups
where r_gw_id in ( select distinct r_gw_id from public.groups
except
select "ID" from public.radio_gw
);
--========================================
-- remove the passenger
-- whose subscriber doesn't exists any more
--========================================
delete from public.passenger
where sc_id in ( select distinct sc_id from public.passenger
except
select sc_id from public.subscriber
);
--========================================
-- remove the subs_gateway
-- whose subscriber doesn't exists any more
--========================================
delete from public.subs_gateway
where gateway_id in ( select distinct gateway_id from public.subs_gateway
except
select "ID" from public.gateways
)
or radio_gw_id in ( select distinct radio_gw_id from public.subs_gateway
except
select "ID" from public.radio_gw
)
or sc_id in ( select distinct sc_id from public.subs_gateway
except
select sc_id from public.subscriber
);
--========================================
-- remove the speedalarm records
-- whose subscriber doesn't exists any more
--========================================
delete from public.speedalarm
where sc_id in ( select distinct sc_id from public.speedalarm
except
select sc_id from public.subscriber
)
or user_id in ( select distinct user_id from public.speedalarm
except
select userid from public.users
);
--========================================
-- remove the soundcard records
-- whose user doesn't exists any more
--========================================
delete from public.soundcards
where user_id in ( select distinct user_id from public.soundcards
except
select userid from public.users
);
--========================================
-- remove the emergdi records
-- whose subscriber doesn't exists any more
--========================================
delete from public.emergdi
where sc_id in ( select distinct sc_id from public.emergdi
except
select sc_id from public.subscriber
);
--========================================
-- remove the sms records
-- whose subscriber doesn't exists any more
--========================================
delete from public.sms
where sc_id_sour in ( select distinct sc_id_sour from public.sms
except
select sc_id from public.subscriber
)
or sc_id_dest in ( select distinct sc_id_dest from public.sms
except
select sc_id from public.subscriber
);
--========================================
-- remove the messages records
-- whose subscriber doesn't exists any more
--========================================
delete from public.messages
where sc_id in ( select distinct sc_id from public.messages
except
select sc_id from public.subscriber
);
--========================================
-- remove the geozoneinout records
-- whose subscriber doesn't exists any more
--========================================
delete from public.geozoneinout
where sc_id in ( select distinct sc_id from public.geozoneinout
except
select sc_id from public.subscriber
);
--========================================
-- remove the subscriber_history records
-- whose subscriber/ vehicle doesn't exists any more
--========================================
delete from public.subscriber_history
where sc_id in ( select distinct sc_id from public.subscriber_history
except
select sc_id from public.subscriber
)
or veh_id in ( select distinct veh_id from public.subscriber_history
except
select id from public.vehicle
);
--========================================
-- remove the user_radio records
-- whose user_id / radio_id doesn't exists any more
--========================================
delete from public.user_radio
where user_id in ( select distinct user_id from public.user_radio
except
select userid from public.users
)
or radio_id in ( select distinct radio_id from public.user_radio
except
select "ID" from public.radio_gw
);
--========================================
-- remove the user_group records
-- whose user doesn't exists any more
--========================================
delete from public.users_group
where userid in ( select distinct userid from public.users_group
except
select userid from public.users
)
or grp_id in ( select distinct grp_id from public.users_group
except
select id from public.groups
);
--========================================
-- remove the vehicle_group
-- whose group_id doesn't exists any more
--========================================
delete from public.vehicle_group
where grp_ip in ( select distinct grp_ip from public.vehicle_group
except
select id from groups
)
or sc_id in ( select distinct sc_id from public.vehicle_group
except
select sc_id from public.subscriber
);
--========================================
-- remove the vehicle_user
-- whose user_id doesn't exists any more
--========================================
delete from public.vehicle_user
where user_id in ( select distinct user_id from public.vehicle_user
except
select userid from users
)
or veh_id in ( select distinct veh_id from public.vehicle_user
except
select id from public.vehicle
);
--========================================
-- remove the zonepoints records
-- whose zone_id doesn't exists any more
--========================================
delete from public.zonepoints
where zone_id in ( select distinct zone_id from public.zonepoints
except
select idx from public.zonename
);
--========================================
-- remove sc_id=0 from all records
--========================================
delete from public.subscriber_stun
where sc_id = 0;
delete from public.subscriber_alarm
where sc_id = 0;
delete from public.emergdi
where sc_id = 0;
delete from public.messages
where sc_id = 0;
delete from public.subs_gateway
where sc_id = 0;
delete from public.subscriber
where sc_id = 0;
END;
$$

View File

@ -0,0 +1,5 @@
SELECT AddNewFields();
SELECT RemoveRecordsWithoutRelatedData();
SELECT CreateMissingPrimaryKeys();
SELECT CreateMissingForeignKeys();
SELECT CreateMissingIndexes();

View File

@ -0,0 +1,3 @@
UpdateHelper.exe -w generate_partitioning_of_an_existing_table_by_date_unix_time.sql
UpdateHelper.exe -w get_query_partitioning_of_an_existing_table_by_date_unix_time.sql
UpdateHelper.exe -f call_messsages_partitioning.sql

View File

@ -0,0 +1,194 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{316FC545-051D-47AE-BEFA-1E94AC6D5D21}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>UpdateHelper</RootNamespace>
<AssemblyName>UpdateHelper</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'kitLINXB|AnyCPU'">
<OutputPath>bin\kitLINXB\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'KitExcera|AnyCPU'">
<OutputPath>bin\KitExcera\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'LISF|AnyCPU'">
<OutputPath>bin\LISF\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Repeater|AnyCPU'">
<OutputPath>bin\Repeater\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config">
<SubType>Designer</SubType>
</None>
<None Include="functions.bat">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="prebuild.sh" />
<None Include="RunMessagesPartitioning.bat" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.5">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.5 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Content Include="4to5.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="5to6.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="6to7.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="7toLatest7.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="call_messages_partitioning.sql" />
<Content Include="CreateMissingForeignKeys.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="CreateMissingIndexes.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="CreateMissingPrimaryKeys.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="generate_partitioning_of_an_existing_table_by_date_unix_time.sql" />
<Content Include="get_query_partitioning_of_an_existing_table_by_date_unix_time.sql" />
<Content Include="NewFields.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="RemoveRecordsWithoutRelatedData.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="RunAllMissingFiles.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="sql.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SafeMobileLIB_DLL\safemobilelib.csproj">
<Project>{f7a15710-ee5c-4374-b9c7-aed367e36f16}</Project>
<Name>safemobilelib</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
<PropertyGroup>
<PreBuildEvent>$(ProjectDir)prebuild.sh</PreBuildEvent>
</PropertyGroup>
</Project>

View File

@ -0,0 +1 @@
SELECT generate_partitioning_of_an_existing_table_by_date_unix_time( 'messages', 'timegmt', 2020, 2035, 'half-yearly', false);

View File

@ -0,0 +1,6 @@
UpdateHelper.exe -w NewFields.sql
UpdateHelper.exe -w RemoveRecordsWithoutRelatedData.sql
UpdateHelper.exe -w CreateMissingPrimaryKeys.sql
UpdateHelper.exe -w CreateMissingForeignKeys.sql
UpdateHelper.exe -w CreateMissingIndexes.sql
UpdateHelper.exe -f RunAllMissingFiles.sql

View File

@ -0,0 +1,252 @@
DROP FUNCTION IF EXISTS public.generate_partitioning_of_an_existing_table_by_date_unix_time(text, text, integer, integer, text, boolean);
CREATE OR REPLACE FUNCTION public.generate_partitioning_of_an_existing_table_by_date_unix_time(
tablename text,
columnname text,
start_year integer,
end_year integer,
step text,
droptable boolean DEFAULT false)
RETURNS void
LANGUAGE 'plpgsql'
VOLATILE PARALLEL UNSAFE
AS $BODY$
declare old_tablename TEXT;
new_tablename TEXT;
partition_tablename TEXT;
start_interval TEXT;
end_interval TEXT;
interations INTEGER;
i INTEGER;
sql_str TEXT = '';
receive_constraints TEXT;
receive_triggers TEXT;
toBeDeleted_constraints TEXT;
lastvalue INTEGER;
exists_sequence TEXT;
tmp_sql VARCHAR;
renamed_indexes TEXT;
renamed_constraints TEXT;
toBeCreated_indexes TEXT;
start_unix_time TEXT;
end_unix_time TEXT;
primary_key TEXT;
sequence_id TEXT;
BEGIN
IF start_year > end_year THEN
RAISE NOTICE '%', 'start_year > end_year';
RETURN;
END IF;
primary_key := '"posID"';
sequence_id := '_posID_seq';
new_tablename := 'new_' || tablename;
sql_str := format('-- create a new table having the same structure with specified table ' || CHR(13) ||
'CREATE TABLE ' || new_tablename || '(LIKE ' || tablename || ' INCLUDING DEFAULTS INCLUDING CONSTRAINTS) PARTITION BY RANGE(' || columnname || ');' || CHR(13) || CHR(13) ||
'-- create partiton for all other records that dont match with the partition condition' || CHR(13) ||
'CREATE TABLE ' || tablename || '_default PARTITION OF ' || new_tablename || ' DEFAULT; ') || CHR(13);
sql_str := sql_str || CHR(13) || get_query_partitioning_of_an_existing_table_by_date_unix_time(tablename , new_tablename, start_year, end_year, step);
sql_str := sql_str || CHR(13) ||
'-- copy data into the new table ' || CHR(13) ||
'INSERT INTO ' || new_tablename || '(SELECT * FROM ' || tablename || '); ' || CHR(13) ;
RAISE NOTICE '%', sql_str;
-- execute the query
EXECUTE sql_str;
--===========================================================
-- build the commands to rename the indexes
--===========================================================
old_tablename := tablename;
SELECT string_agg( 'ALTER INDEX IF EXISTS "' || indexname || '" RENAME TO "old_' || indexname || '";' , CHR(13)) INTO renamed_indexes
FROM pg_indexes pg
WHERE pg.tablename = old_tablename
AND indexname NOT LIKE '%pkey%';
SELECT string_agg( CASE WHEN contype = 'p' THEN -- primary key
'ALTER INDEX IF EXISTS "' || conname || '" RENAME TO "old_' || conname || '";'
ELSE
'ALTER TABLE ' || old_tablename || ' RENAME CONSTRAINT "' || conname || '" TO "old_' || conname || '";'
END
, CHR(13)) INTO renamed_constraints
FROM pg_catalog.pg_constraint con
INNER JOIN pg_catalog.pg_class rel ON rel.oid = con.conrelid
WHERE rel.relname = old_tablename;
--======================================================================
-- build the commands to recreate the indexes on the partitioned table
--======================================================================
SELECT string_agg( indexdef || ';' , CHR(13)) INTO toBeCreated_indexes
FROM pg_indexes pg
WHERE pg.tablename = old_tablename
AND indexname NOT LIKE '%pkey%'
AND indexname NOT LIKE '%' || primary_key || '%'
AND indexdef NOT LIKE '%UNIQUE%';
--===========================================================
-- save the foreign key into receive_constraints variable
--===========================================================
SELECT string_agg(command , CHR(13) ) INTO receive_constraints
FROM ( SELECT format('ALTER TABLE IF EXISTS "%s" ADD CONSTRAINT "%s" FOREIGN KEY ("%s") REFERENCES "%s"("%s");',
tablename,
tc.constraint_name,
string_agg(distinct kcu.column_name, ','),
ccu.table_name,
string_agg(distinct ccu.column_name, ',')) command
FROM information_schema.table_constraints AS tc
JOIN information_schema.key_column_usage AS kcu
ON tc.constraint_name = kcu.constraint_name
JOIN information_schema.constraint_column_usage AS ccu
ON ccu.constraint_name = tc.constraint_name
WHERE constraint_type = 'FOREIGN KEY'
AND tc.table_name = tablename
GROUP BY tc.constraint_name, tc.table_name, ccu.table_name
)x;
--===========================================================
-- save the triggers into receive_triggers variable
--===========================================================
SELECT string_agg(command , CHR(13) ) INTO receive_triggers
FROM ( SELECT format( 'CREATE TRIGGER %s %s %s ON "%s" FOR EACH ROW %s ;',
t1.trigger_name
,t1.action_timing
,t2.event_manipulation
,t1.event_object_table
,t1.action_statement ) as command
FROM ( SELECT DISTINCT
trigger_name
,action_timing
,event_object_table
,action_statement
FROM information_schema.triggers
WHERE event_object_table = tablename
) t1
INNER JOIN (SELECT trigger_name, string_agg(event_manipulation, ' OR ') as event_manipulation
FROM information_schema.triggers
WHERE event_object_table = tablename
GROUP BY trigger_name
) t2 ON t1.trigger_name = t2.trigger_name
)x;
--===================================================================================================================
-- save the constraints which refereces the specified tablename into toBeDeleted_constraints variable
--===================================================================================================================
SELECT string_agg( 'ALTER TABLE IF EXISTS "' || foreign_table || '" DROP CONSTRAINT IF EXISTS "' || constraint_name || '";' , CHR(13) ) INTO toBeDeleted_constraints
FROM (
select kcu.table_name as foreign_table,
'>-' as rel,
rel_tco.table_schema || '.' || rel_tco.table_name as primary_table,
string_agg(kcu.column_name, ', ') as fk_columns,
kcu.constraint_name
from information_schema.table_constraints tco
join information_schema.key_column_usage kcu
on tco.constraint_schema = kcu.constraint_schema
and tco.constraint_name = kcu.constraint_name
join information_schema.referential_constraints rco
on tco.constraint_schema = rco.constraint_schema
and tco.constraint_name = rco.constraint_name
join information_schema.table_constraints rel_tco
on rco.unique_constraint_schema = rel_tco.constraint_schema
and rco.unique_constraint_name = rel_tco.constraint_name
where tco.constraint_type = 'FOREIGN KEY'
and rel_tco.table_name = tablename
group by kcu.table_schema,
kcu.table_name,
rel_tco.table_name,
rel_tco.table_schema,
kcu.constraint_name
)x;
tmp_sql = ' SELECT ''exists'' FROM pg_class WHERE relname = ''' || tablename || sequence_id || ''';';
EXECUTE tmp_sql INTO exists_sequence;
--RAISE NOTICE '%', COALESCE( exists_sequence, 'not exists');
IF exists_sequence = 'exists' THEN
EXECUTE format(' SELECT last_value FROM "%s";', tablename || sequence_id) INTO lastvalue;
END IF;
IF ( dropTable ) THEN
sql_str := '--====== dropTable = true ======-- ' || CHR(13) || CHR(13) ||
'-- drop old table with cascade ' || CHR(13) ||
'DROP TABLE IF EXISTS ' || tablename || ' CASCADE; ' || CHR(13) ||
'-- rename the new table to old table ' || CHR(13) ||
'ALTER TABLE IF EXISTS ' || new_tablename || ' RENAME TO ' || tablename || ';' || CHR(13) ||
'-- create primary key ' || CHR(13) ||
'ALTER TABLE IF EXISTS ' || tablename || ' ADD CONSTRAINT ' || tablename || '_pkey PRIMARY KEY (' || primary_key || ',' || columnname || ');' || CHR(13) ||
'-- create sequence ' || CHR(13) ||
'CREATE SEQUENCE IF NOT EXISTS "' || tablename || sequence_id || '" INCREMENT 1 START ' || COALESCE(lastvalue,0) + 1 || ';' || CHR(13) ||
'-- set id to be taken from sequence ' || CHR(13) ||
'ALTER TABLE IF EXISTS ' || tablename || ' ALTER COLUMN ' || primary_key || ' SET DEFAULT nextval(''"' || tablename || sequence_id || '"'');' || CHR(13);
ELSE
sql_str := COALESCE( renamed_constraints, '') || CHR(13) ||
COALESCE( renamed_indexes, '') || CHR(13);
EXECUTE sql_str;
sql_str := '--====== dropTable = false ( rename table )======-- ' || CHR(13) || CHR(13) ||
'-- rename the current table to *_old ' || CHR(13) ||
'ALTER TABLE IF EXISTS ' || tablename || ' RENAME TO ' || tablename || '_old; ' || CHR(13) ||
'-- rename the new table ' || CHR(13) ||
'ALTER TABLE IF EXISTS ' || new_tablename || ' RENAME TO ' || tablename || ';' || CHR(13) ||
'-- create primary key ' || CHR(13) ||
'ALTER TABLE IF EXISTS ' || tablename || ' ADD CONSTRAINT ' || tablename || '_pkey PRIMARY KEY (' || primary_key || ',' || columnname || ');' || CHR(13) ||
'-- rename existing sequence as old ' || CHR(13) ||
'ALTER SEQUENCE IF EXISTS "' || tablename || sequence_id || '" RENAME TO "' || tablename || '_old' || sequence_id || '";' || CHR(13) ||
'-- create sequence ' || CHR(13) ||
'CREATE SEQUENCE IF NOT EXISTS "' || tablename || sequence_id || '" INCREMENT 1 START ' || COALESCE(lastvalue,0) + 1 || ';' || CHR(13) ||
'-- set id to be taken from sequence ' || CHR(13) ||
'ALTER TABLE IF EXISTS ' || tablename || '_old' || ' ALTER COLUMN ' || primary_key || ' SET DEFAULT nextval(''"' || tablename || '_old' || sequence_id || '"'');' || CHR(13) ||
'-- set id to be taken from sequence ' || CHR(13) ||
'ALTER TABLE IF EXISTS ' || tablename || ' ALTER COLUMN ' || primary_key || ' SET DEFAULT nextval(''"' || tablename || sequence_id || '"'');' || CHR(13);
END IF;
sql_str := sql_str || COALESCE(toBeDeleted_constraints, '') || CHR(13) || COALESCE(receive_constraints, '') || CHR(13) || CHR(13) || COALESCE(receive_triggers, '');
RAISE NOTICE '%', sql_str;
-- execute the query
EXECUTE sql_str;
sql_str := COALESCE(toBeCreated_indexes, '');
RAISE NOTICE '%', sql_str;
EXECUTE sql_str;
END;
$BODY$;

View File

@ -0,0 +1,130 @@
DROP FUNCTION IF EXISTS public.get_query_partitioning_of_an_existing_table_by_date_unix_time(text, text, integer, integer, text);
CREATE OR REPLACE FUNCTION public.get_query_partitioning_of_an_existing_table_by_date_unix_time(
old_tablename text,
new_tablename text,
start_year integer,
end_year integer,
step text)
RETURNS character varying
LANGUAGE 'plpgsql'
VOLATILE PARALLEL UNSAFE
AS $BODY$
DECLARE partition_tablename TEXT;
start_interval TEXT;
end_interval TEXT;
i INTEGER;
sql_str TEXT;
start_unix_time TEXT;
end_unix_time TEXT;
BEGIN
IF start_year > end_year THEN
RAISE NOTICE '%', 'start_year > end_year';
RETURN '';
END IF;
WHILE start_year <= end_year LOOP -- loop through years
-- set the initial month
CASE step
WHEN 'monthly' THEN i:= 1;
WHEN 'quaterly' THEN i:= 3;
WHEN 'half-yearly' THEN i:= 6;
WHEN 'yearly' THEN i:= 12;
ELSE
RAISE NOTICE '%', 'Invalid step parameter. Valid values are : monthly, quaterly, half-yearly, yearly';
EXIT;
END CASE;
WHILE i <= 12 LOOP -- loop through month
partition_tablename := '';
CASE step
WHEN 'monthly' THEN
partition_tablename := old_tablename || '_' || lpad(i::text, 2, '0') || '_' || start_year::text;
start_interval = start_year::text || '-' || lpad(i::text, 2, '0') || '-01';
end_interval = (date_trunc('month', start_interval::date) + interval '1 months')::date;
i := i + 1;
start_unix_time = extract(epoch from (start_interval)::timestamp);
end_unix_time = extract(epoch from (end_interval::date - Interval'1 sec')::timestamp);
WHEN 'quaterly' THEN
IF (i % 3 = 0) THEN
partition_tablename := old_tablename || '_Q' || i/3 || '_' || start_year::text;
start_interval = start_year::text || '-' || case i/3
when 1 then '01-01'
when 2 then '04-01'
when 3 then '07-01'
when 4 then '10-01'
end;
end_interval = (date_trunc('quarter', start_interval::date) + interval '3 months')::date;
i := i + 3;
start_unix_time = extract(epoch from (start_interval)::timestamp);
end_unix_time = extract(epoch from (end_interval::date - Interval'1 sec')::timestamp);
END IF;
WHEN 'half-yearly' THEN
IF (i % 6 = 0) THEN
partition_tablename := old_tablename || '_S' || i/6 || '_' || start_year::text;
start_interval = start_year::text || case i/6 when 1 then '-01-01' else '-07-01' end ;
end_interval = (start_interval::date + interval '6 months')::date;
i := i + 6;
start_unix_time = extract(epoch from (start_interval)::timestamp);
end_unix_time = extract(epoch from (end_interval::date - Interval'1 sec')::timestamp);
END IF;
WHEN 'yearly' THEN
IF (i % 12 = 0) THEN
partition_tablename := old_tablename || '_' || start_year::text;
start_interval = start_year::text || '-01-01';
end_interval = (date_trunc('year', start_interval::date) + interval '1 year')::date;
i := i + 12;
start_unix_time = extract(epoch from (start_interval)::timestamp);
end_unix_time = extract(epoch from (end_interval::date - Interval'1 sec')::timestamp);
END IF;
ELSE
RAISE NOTICE '%', 'Invalid step parameter. Valid values are : monthly, quaterly, half-yearly, yearly';
EXIT;
END CASE;
IF ( partition_tablename <> '') THEN
sql_str := COALESCE(sql_str, '') || CHR(13) || 'CREATE TABLE ' || partition_tablename || ' PARTITION OF ' || new_tablename ||
' FOR VALUES FROM (' || start_unix_time || ') TO (' || end_unix_time || ');';
END IF;
END LOOP;
start_year := start_year + 1;
sql_str := COALESCE(sql_str, '') || CHR(13);
END LOOP;
--RAISE NOTICE '%', sql_str;
RETURN COALESCE(sql_str, '');
END;
$BODY$;

39
UpdateHelper/prebuild.sh Normal file
View File

@ -0,0 +1,39 @@
#/!bin/bash
echo .................
echo . Prebuild step $(pwd)
echo .................
version=$(git describe)
# (
# echo namespace SafeDispatch-git
# echo {
# echo public class VersionInfo
# echo {
# echo public string Version{ get; set; } = "%VersionGIT%";
# echo }
# echo }
# )> "$(ProjectDir)\Properties\VersionInfo.cs"
[ -f ../../../Properties/VersionInfo.cs ] && rm ../../../Properties/VersionInfo.cs
cat > ../../../Properties/VersionInfo.cs << ENDOFFILE
// Generated on $(date) by prebuild script
namespace SafeDispatch-git
{
public class VersionInfo
{
public string Version{ get; set; } = "$version";
}
}
ENDOFFILE
echo Generated 'Properties/VersionInfo.cs' with the content below:
cat ../../../Properties/VersionInfo.cs
echo ............................
#read -p 'Press Enter to continue...' var

451
UpdateHelper/sql.sql Normal file
View File

@ -0,0 +1,451 @@
---
-- Below is v4 to v5
---
CREATE TABLE public.user_radio (radio_id integer NOT NULL DEFAULT 0,user_id integer NOT NULL DEFAULT 0) WITH (OIDS=FALSE);
ALTER TABLE public.user_radio OWNER TO postgres;
CREATE TABLE public.reports(startdate integer NOT NULL DEFAULT 0, stopdate integer NOT NULL DEFAULT 0, unit_ids character varying(4096), geofence_id integer NOT NULL DEFAULT 0, type_stat integer NOT NULL DEFAULT 0, report_id integer NOT NULL DEFAULT 0, email character varying(255),idletime integer, idx serial NOT NULL) WITH (OIDS = FALSE);
ALTER TABLE public.reports OWNER TO postgres;
ALTER TABLE zonename ADD COLUMN useridx integer NOT NULL DEFAULT 0;
ALTER TABLE place ADD COLUMN useridx integer NOT NULL DEFAULT 0;
ALTER TABLE zonename ADD COLUMN alarmtype integer NOT NULL DEFAULT 3;
ALTER TABLE zonename ADD COLUMN sentmsg boolean NOT NULL DEFAULT false;
ALTER TABLE zonename ADD COLUMN msgbody character varying(255) NOT NULL DEFAULT '';
ALTER TABLE zonename ADD COLUMN unitids character varying(255) NOT NULL DEFAULT '';
ALTER TABLE zonename ADD COLUMN sentemail boolean NOT NULL DEFAULT false;
ALTER TABLE zonename ADD COLUMN email character varying(255) NOT NULL DEFAULT '';
ALTER TABLE zonename ADD COLUMN subj character varying(255) NOT NULL DEFAULT '';
ALTER TABLE zonename ADD COLUMN body character varying(255) NOT NULL DEFAULT '';
ALTER TABLE zonename ADD COLUMN imeilist character varying(255) NOT NULL DEFAULT '';
---
-- Below is v5 to v6
---
ALTER TABLE \"VoiceRecordings\" ADD COLUMN calltype integer NOT NULL DEFAULT 0;
ALTER TABLE \"VoiceRecordings\" ADD COLUMN group_id integer NOT NULL DEFAULT 0;
ALTER TABLE zonename ADD COLUMN sentmsg2 boolean NOT NULL DEFAULT false;
ALTER TABLE zonename ADD COLUMN msgbody2 character varying(255) NOT NULL DEFAULT '';
ALTER TABLE speedalarm ADD COLUMN lat double precision NOT NULL DEFAULT 0;
ALTER TABLE speedalarm ADD COLUMN lng double precision NOT NULL DEFAULT 0;
ALTER TABLE telemetry_history ADD COLUMN lat double precision NOT NULL DEFAULT 0;
ALTER TABLE telemetry_history ADD COLUMN lng double precision NOT NULL DEFAULT 0;
ALTER TABLE emergalarm ADD COLUMN lat double precision NOT NULL DEFAULT 0;
ALTER TABLE emergalarm ADD COLUMN lng double precision NOT NULL DEFAULT 0;
ALTER TABLE reports ADD COLUMN latlng boolean NOT NULL DEFAULT false;
UPDATE emergalarm SET address='no address' WHERE address = '';
UPDATE telemetry_history SET address='no address' WHERE address = '';
UPDATE speedalarm SET address='no address' WHERE address = '';
ALTER TABLE vehicle ADD COLUMN gps_poor integer NOT NULL DEFAULT 0;
ALTER TABLE vehicle ADD COLUMN gps_off integer NOT NULL DEFAULT 0;
ALTER TABLE vehicle ADD COLUMN made_off integer NOT NULL DEFAULT 0;
UPDATE vehicle SET gps_poor=\"GPS_reporting_interval\"*2, gps_off=\"GPS_reporting_interval\"*4, made_off=\"GPS_reporting_interval\"*10;
UPDATE lastpos SET status=0;
---
-- Below is v6 with for recordings.
---
ALTER TABLE gateways ADD COLUMN peer_id integer NOT NULL DEFAULT 0;
ALTER TABLE radio_gw DROP CONSTRAINT unique_radio_gw;
ALTER TABLE sms ADD COLUMN lat double precision NOT NULL DEFAULT 0;
ALTER TABLE sms ADD COLUMN lng double precision NOT NULL DEFAULT 0;
ALTER TABLE sms ADD COLUMN address character varying(255) NOT NULL DEFAULT 'no address';
INSERT INTO emailservice(id, \"user\", pass, enable) VALUES (2,'poll', 'poll', 0);
ALTER TABLE zonename ADD COLUMN speed integer NOT NULL DEFAULT 0;
ALTER TABLE emailservice ADD COLUMN pop_server text NOT NULL DEFAULT 'pop.gmail.com';
ALTER TABLE emailservice ADD COLUMN pop_port integer NOT NULL DEFAULT 995;
ALTER TABLE emailservice ADD COLUMN smtp_server text NOT NULL DEFAULT 'smtp.gmail.com';
ALTER TABLE emailservice ADD COLUMN smtp_port integer NOT NULL DEFAULT 587;
ALTER TABLE emailservice ADD COLUMN is_pop_ssl boolean NOT NULL DEFAULT true;
ALTER TABLE emailservice ADD COLUMN is_smtp_ssl boolean NOT NULL DEFAULT true;
ALTER TABLE emailservice ADD COLUMN last_email_time integer NOT NULL DEFAULT 0;
---
-- Below is v6 to v7
---
ALTER TABLE lastpos ADD COLUMN altitude double precision NOT NULL DEFAULT 0;
DROP TABLE IF EXISTS jobtickets;
CREATE TABLE jobtickets (ticket_id serial,name text,job_status integer,sc_id integer,comment text,dispatcher text,priority text,end_time_planned integer,creation_time integer,start_time integer,end_time integer,is_expired boolean DEFAULT false NOT NULL,deleted integer,share_with text,seq_id character varying(40),status integer DEFAULT 0 NOT NULL,sched_timegmt integer DEFAULT 0);
ALTER TABLE public.jobtickets OWNER TO postgres;
DROP TABLE IF EXISTS jobtickets_log;
CREATE TABLE jobtickets_log ( id serial, ticket_id integer, modified_date integer,job_status integer, sc_id integer, comment text) WITH ( OIDS=FALSE);
ALTER TABLE jobtickets_log OWNER TO postgres;
DROP TABLE IF EXISTS jobticketstatusesset;
CREATE TABLE jobticketstatusesset ( status_id serial, status character varying(45), color character varying(45), sound_on integer, sound_file character varying(250), is_first_state integer, is_last_state integer, CONSTRAINT jobticketstatusesset_pkey PRIMARY KEY (status_id))WITH ( OIDS=FALSE);
ALTER TABLE jobticketstatusesset OWNER TO postgres;
DROP TABLE IF EXISTS definejobticket;
CREATE TABLE definejobticket ( name character varying(200) NOT NULL, text character varying(200) NOT NULL, comment character varying(200), priority character varying(200), expire_date integer, idx serial NOT NULL, CONSTRAINT definejobticket_pkey PRIMARY KEY (idx))WITH ( OIDS=FALSE);
ALTER TABLE definejobticket OWNER TO postgres;
ALTER TABLE registration ADD COLUMN has_ticketing boolean NOT NULL DEFAULT false;
DELETE FROM jobticketstatusesset;
INSERT INTO jobticketstatusesset (status_id, status, color, sound_on, sound_file, is_first_state, is_last_state) VALUES (1, 'Assigned', '3D8584', 0, '', 1, 0);
INSERT INTO jobticketstatusesset (status_id, status, color, sound_on, sound_file, is_first_state, is_last_state) VALUES (2, 'Accepted', '3D7171', 0, '', 0, 0);
INSERT INTO jobticketstatusesset (status_id, status, color, sound_on, sound_file, is_first_state, is_last_state) VALUES (3, 'In progress', '3D5B85', 0, '', 0, 0);
INSERT INTO jobticketstatusesset (status_id, status, color, sound_on, sound_file, is_first_state, is_last_state) VALUES (4, 'Completed', '5E853D', 0, '', 0, 1);
INSERT INTO jobticketstatusesset (status_id, status, color, sound_on, sound_file, is_first_state, is_last_state) VALUES (5, 'Rejected', 'A93D47', 0, '', 0, 0);
INSERT INTO jobticketstatusesset (status_id, status, color, sound_on, sound_file, is_first_state, is_last_state) VALUES (6, 'Overdue', 'B29F3D', 0, '', 0, 0);
ALTER TABLE definejobticket ADD COLUMN handled_by text;
ALTER TABLE definejobticket ADD COLUMN schedule_date integer;
ALTER TABLE definejobticket ADD COLUMN share_with text;
DROP TABLE IF EXISTS sequences;
CREATE TABLE sequences( name character varying(32) NOT NULL, value integer NOT NULL DEFAULT 0, idx serial NOT NULL, CONSTRAINT sequences_pkey PRIMARY KEY (idx))WITH ( OIDS=FALSE);
ALTER TABLE sequences OWNER TO postgres;
INSERT INTO sequences(name, value) VALUES('jobticketing',1);
DROP TABLE IF EXISTS icon_theme;
CREATE TABLE icon_theme( id serial NOT NULL, \"name\" text, prefix text) WITH ( OIDS=FALSE);
ALTER TABLE icon_theme OWNER TO postgres;
INSERT INTO icon_theme(id, \"name\", prefix)VALUES (1, 'Classic', 'classic'),(2, 'Pin', 'pin');
DROP TABLE IF EXISTS car;
CREATE TABLE car(\"name\" character varying(100) NOT NULL, id serial NOT NULL, pattern text, displayed_name text, CONSTRAINT car_pkey PRIMARY KEY (id))WITH ( OIDS=FALSE);
ALTER TABLE car OWNER TO postgres;
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('minibus', 102, 'minibus_01', 'Van 1');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('Minicar', 103, 'minicar_01', 'MiniCar 1');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('people_08', 35, 'people_08', 'People 8');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('Minicar2', 104, 'minicar_02', 'MiniCar 2');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('police', 105, 'police_01', 'Police 1');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('Police1', 106, 'police_02', 'Police 2');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('schoolbus', 107, 'school_bus_01', 'School Bus 1');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('taxi_02', 131, 'taxi_02', 'Taxi 2');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('schoolbus2', 108, 'school_bus_02', 'School Bus 2');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('moto_01', 132, 'moto_01', 'Moto 1');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('moto_02', 133, 'moto_02', 'Moto 2');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('TowTruckYellow', 110, 'tow_truck_01', 'Tow Truck');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('TractorUnitBlack', 111, 'tractor_unit', 'Tractor Unit');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('moto_03', 134, 'moto_03', 'Moto 3');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('moto_04', 135, 'moto_04', 'Moto 4');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('Classic-Car-66', 92, 'classic_car_01', 'Classic Car 1');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('truck0', 112, 'truck_01', 'Truck 1');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('classycar', 93, 'classic_car_02', 'Classic Car 2');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('peopleblue', 1, 'people_01', 'People 1');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('peoplegreen', 2, 'people_02', 'People 2');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('peoplegrey', 3, 'people_03', 'People 3');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('peoplepink', 4, 'people_04', 'People 4');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('peoplepurple', 5, 'people_05', 'People 5');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('peoplered', 6, 'people_06', 'People 6');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('army', 79, 'army_01', 'Army');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('bigcar0', 80, 'car_01', 'Car 1');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('bigcar1', 81, 'car_02', 'Car 2');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('bigcar2', 82, 'car_03', 'Car 3');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('moto_05', 136, 'moto_05', 'Moto 5');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('bicycle_01', 137, 'bicycle_01', 'Bicycle');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('car0', 87, 'car_04', 'Car 4');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('car1', 88, 'car_05', 'Car 5');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('car2', 89, 'car_06', 'Car 6');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('car3', 90, 'car_07', 'Car 7');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('CarGrey', 91, 'car_08', 'Car 8');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('dodge', 94, 'dodge_01', 'Dodge');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('FireEscape', 95, 'firetruck_01', 'FireTruck 1');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('truck1', 113, 'truck_02', 'Truck 2');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('firefighters2', 96, 'firetruck_02', 'Fire Truck 2');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('ambulance_01', 36, 'ambulance_01', 'Ambulance 1');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('firetruck1', 97, 'firetruck_03', 'Fire Truck 3');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('truck2', 114, 'truck_03', 'Truck 3');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('firetruck2', 98, 'firetruck_04', 'Fire Truck 4');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('Jeep', 99, 'jeep_01', 'Jeep');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('CabrioletRed', 86, 'cabriolet_01', 'Carbriolet');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('truck3', 115, 'truck_04', 'Truck 4');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('Longhaul', 100, 'longhaul_01', 'Long Haul');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('truck4', 116, 'truck_05', 'Truck 5');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('LorryGreen', 101, 'lorry_01', 'Lorry');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('ambulance_02', 78, 'ambulance_02', 'Ambulance 2');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('truck5', 117, 'truck_06', 'Truck 6');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('truck6', 118, 'truck_07', 'Truck 7');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('TruckYellow', 119, 'truck_08', 'Truck 8');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('wagon', 120, 'wagon_01', 'Wagon');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('bus', 83, 'tour_bus_01', 'Tour Bus 1');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('bus0', 84, 'bus_01', 'Bus 1');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('bus2', 85, 'bus_02', 'Bus 2');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('number_01', 121, 'number_01', '1');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('number_02', 122, 'number_02', '2');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('number_04', 124, 'number_04', '4');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('number_03', 123, 'number_03', '3');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('number_05', 125, 'number_05', '5');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('number_06', 126, 'number_06', '6');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('number_07', 127, 'number_07', '7');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('number_08', 128, 'number_08', '8');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('number_09', 129, 'number_09', '9');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('number_10', 130, 'number_10', '10');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('taxi', 109, 'taxi_01', 'Taxi 1');
INSERT INTO car (name, id, pattern, displayed_name) VALUES ('people_07', 34, 'people_07', 'People 7');
insert into \"userSettings\" (user_id, key, value) select userid, 'reportTime', '0' from users where userid not in (select user_id from \"userSettings\" where key = 'reportTime') order by userid;
insert into \"userSettings\" (user_id, key, value) select userid, 'iconTheme', 'pin' from users where userid not in (select user_id from \"userSettings\" where key = 'iconTheme') order by userid;
ALTER TABLE reports ADD COLUMN userid integer;
UPDATE reports SET userid = (SELECT MAX(userid) FROM users);
ALTER TABLE reports ADD COLUMN ticket_status character varying(250);
ALTER TABLE reports ADD COLUMN ticket_date_type character varying(250);
ALTER TABLE reports ADD COLUMN type text;
ALTER TABLE reports ADD COLUMN day text;
ALTER TABLE reports ADD COLUMN is_activated boolean;
ALTER TABLE sms ADD COLUMN color character varying(7);
ALTER TABLE sms ALTER COLUMN color SET STORAGE EXTENDED;
DROP TABLE IF EXISTS placetype;
CREATE TABLE placetype ( type_name character varying(100) NOT NULL,type_id integer NOT NULL,icon_name character varying(70));
ALTER TABLE public.placetype OWNER TO postgres;
CREATE SEQUENCE placetype_type_id_seq START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1;
ALTER TABLE public.placetype_type_id_seq OWNER TO postgres;
ALTER SEQUENCE placetype_type_id_seq OWNED BY placetype.type_id;
SELECT pg_catalog.setval('placetype_type_id_seq', 156, true);
ALTER TABLE place ADD COLUMN icon_size character varying(20);
ALTER TABLE place ADD COLUMN color character varying(7);
ALTER TABLE zonename ADD COLUMN fill_color character varying(7);
ALTER TABLE zonename ADD COLUMN fill_opacity double precision;
ALTER TABLE zonename ADD COLUMN border_color character varying(7);
ALTER TABLE zonename ADD COLUMN border_opacity double precision;
ALTER TABLE zonename ADD COLUMN border_width integer;
ALTER TABLE placetype ALTER COLUMN type_id SET DEFAULT nextval('placetype_type_id_seq'::regclass);
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('calculator', 45, 'calculator.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('calendar', 46, 'calendar.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('camera', 47, 'camera.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('cancel', 48, 'cancel.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('factory', 4, 'factory.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('airport', 1, 'airport.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('cd', 49, 'cd.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('hospital', 6, 'hospital.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('bank', 2, 'bank.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('school', 15, 'school.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('supermarket', 17, 'supermarket.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('shopping', 16, 'shopping.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('office', 18, 'office.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('post_office', 13, 'post_office.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('restaurant', 14, 'restaurant.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('home', 9, 'home.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('fire_department', 7, 'fire_department.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('repair_shop', 3, 'repair_shop.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('garage', 5, 'garage.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('hotel', 10, 'hotel.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('gas_station', 8, 'gas_station.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('military_base', 11, 'military_base.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('police_station', 12, 'police_station.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('chair', 50, 'chair.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('check', 51, 'check.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('cinema', 52, 'cinema.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('add', 20, 'add.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('coffee', 53, 'coffee.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('alert', 22, 'alert.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('anchor', 23, 'anchor.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('announce', 24, 'announce.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('antivirus', 25, 'antivirus.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('arrow_down', 26, 'arrow_down.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('compass', 54, 'compass.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('arrow_down_left', 27, 'arrow_down_left.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('computer', 55, 'computer.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('arrow_down_right', 28, 'arrow_down_right.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('arrow_left', 29, 'arrow_left.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('construction', 56, 'construction.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('repair_shop_2', 102, 'repair_shop_2.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('rip', 103, 'rip.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('roundabout', 104, 'roundabout.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('ruby', 105, 'ruby.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('save', 106, 'save.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('arrow_right', 30, 'arrow_right.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('arrow_up', 31, 'arrow_up.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('arrow_up_left', 32, 'arrow_up_left.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('arrow_up_right', 33, 'arrow_up_right.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('baggage', 34, 'baggage.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('banned', 35, 'banned.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('science', 107, 'science.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('search', 108, 'search.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('servers', 109, 'servers.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('settings', 110, 'settings.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('shape_circle', 111, 'shape_circle.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('shape_ellipse', 112, 'shape_ellipse.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('shape_hexagon', 113, 'shape_hexagon.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('shape_kite', 114, 'shape_kite.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('shape_parallelogram', 115, 'shape_parallelogram.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('battery', 36, 'battery.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('bicycle', 37, 'bicycle.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('bluetooth', 38, 'bluetooth.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('book', 39, 'book.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('bookmark', 40, 'bookmark.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('brush', 41, 'brush.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('bug', 42, 'bug.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('bussiness_card', 43, 'bussiness_card.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('cake', 44, 'cake.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('credit_card', 57, 'credit_card.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('cross', 58, 'cross.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('database', 59, 'database.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('directions', 60, 'directions.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('directions_2', 61, 'directions_2.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('doctor', 62, 'doctor.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('drill', 63, 'drill.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('elevator', 64, 'elevator.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('facebook', 65, 'facebook.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('fan', 66, 'fan.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('favorite', 67, 'favorite.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('flag', 68, 'flag.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('food', 69, 'food.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('gameboy', 70, 'gameboy.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('shape_pentagon', 116, 'shape_pentagon.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('shape_rhombus', 117, 'shape_rhombus.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('shape_square', 118, 'shape_square.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('shape_trapezoid', 119, 'shape_trapezoid.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('shape_triangle', 120, 'shape_triangle.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('pool_game', 98, 'pool_game.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('alarm', 21, 'alarm.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('games', 71, 'games.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('gift', 72, 'gift.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('glasses', 73, 'glasses.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('grid', 74, 'grid.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('hairdresser', 75, 'hairdresser.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('hammer', 76, 'hammer.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('hardware', 77, 'hardware.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('headphones', 78, 'headphones.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('hedge', 79, 'hedge.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('help', 80, 'help.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('help_2', 81, 'help_2.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('icecream', 82, 'icecream.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('info', 83, 'info.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('key', 84, 'key.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('map', 85, 'map.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('marker', 86, 'marker.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('microphone', 87, 'microphone.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('moon', 88, 'moon.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('newspaper', 89, 'newspaper.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('padlock_closed', 90, 'padlock_closed.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('padlock_open', 91, 'padlock_open.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('paintroller', 92, 'paintroller.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('park_bench', 93, 'park_bench.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('phone', 94, 'phone.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('pill', 95, 'pill.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('pinetree', 96, 'pinetree.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('pollution', 97, 'pollution.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('print', 99, 'print.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('refreshment', 100, 'refreshment.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('remote_control', 101, 'remote_control.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('stamp', 121, 'stamp.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('star', 122, 'star.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('stop', 123, 'stop.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('stop_2', 124, 'stop_2.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('stopwatch', 125, 'stopwatch.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('store', 126, 'store.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('tag', 127, 'tag.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('tent', 128, 'tent.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('tie', 129, 'tie.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('time', 130, 'time.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('trafficlight', 131, 'trafficlight.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('trafficlight_green', 132, 'trafficlight_green.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('trafficlight_red', 133, 'trafficlight_red.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('trafficlight_yellow', 134, 'trafficlight_yellow.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('trash', 135, 'trash.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('trophy', 136, 'trophy.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('truck', 137, 'truck.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('typewritter', 138, 'typewritter.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('user', 139, 'user.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('users', 140, 'users.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('water', 141, 'water.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('weather_cloud', 142, 'weather_cloud.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('weather_clouds', 144, 'weather_clouds.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('weather_rain', 145, 'weather_rain.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('weather_sun', 146, 'weather_sun.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('weather_snow', 147, 'weather_snow.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('weather_thunder', 148, 'weather_thunder.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('wi_fi', 149, 'wi_fi.png');
INSERT INTO placetype (type_name, type_id, icon_name) VALUES ('weather_cloud_sun', 143, 'weather_cloud_sun.png');
ALTER TABLE messages ADD COLUMN altitude double precision;
---
-- Below if v7 to LINX
---
CREATE TABLE public.newicons (icontype integer NOT NULL DEFAULT 0, id integer NOT NULL DEFAULT 0, imagedata bytea);
ALTER TABLE groups ADD COLUMN type integer;
UPDATE groups SET type = 0;
ALTER TABLE vehicle ADD COLUMN type integer;
UPDATE vehicle SET type = 0;
ALTER TABLE vehicle ADD COLUMN active boolean;
UPDATE vehicle SET active = TRUE;
ALTER TABLE radio_gw ADD COLUMN name character varying(30);
UPDATE radio_gw SET name = 'unnamed' || \"ID\";
ALTER TABLE radio_gw ADD COLUMN gw_type integer;
UPDATE radio_gw SET gw_type = 0;
ALTER TABLE groups ADD COLUMN r_gw_id integer;
UPDATE groups SET r_gw_id = ( CASE WHEN ((select count(*) from radio_gw ) = 0) THEN 0 ELSE (select min(\"ID\") from radio_gw) END);
update subs_gateway set gateway_id = (CASE WHEN ((select count(*) from radio_gw where \"ID\" = 1 and \"GW_ID\" = 1) = 0) THEN (select min(\"GW_ID\") from radio_gw) ELSE 1 END ), radio_gw_id = (CASE WHEN ((select count(*) from radio_gw where \"ID\" = 1 and \"GW_ID\" = 1) = 0) THEN (select min(\"ID\") from radio_gw) ELSE 1 END) where gateway_id = 1 and radio_gw_id = 1;
CREATE TABLE subscriber_mobile( sc_id serial NOT NULL, phone_imei character varying(20), first_name character varying(50), last_name character varying(50), company character varying(30), os character varying(20), phone_type character varying(20), sip_pswd character varying(30), CONSTRAINT subscriber_mobile_pkey PRIMARY KEY (sc_id)) WITH ( OIDS=FALSE);
ALTER TABLE subscriber_mobile OWNER TO postgres;
CREATE TABLE mobile_contacts(idx serial NOT NULL, sc_id integer NOT NULL, contact_id integer NOT NULL, contact_type character varying(30), contact_type_id integer) WITH ( OIDS=FALSE);
ALTER TABLE mobile_contacts OWNER TO postgres;
ALTER TABLE sms ADD COLUMN user_id integer;
ALTER TABLE sms ALTER COLUMN user_id SET STORAGE PLAIN;
ALTER TABLE users ADD COLUMN backup_user_id integer default 0;
ALTER TABLE subscriber_mobile ADD COLUMN has_gps boolean DEFAULT false;
ALTER TABLE subscriber_mobile ADD COLUMN has_voice boolean DEFAULT false;
ALTER TABLE subscriber_mobile ADD COLUMN has_text boolean DEFAULT false;
ALTER TABLE subscriber_mobile ADD COLUMN has_ticketing boolean DEFAULT false;
ALTER TABLE subscriber_mobile ADD COLUMN email text;
ALTER TABLE subscriber_mobile ADD COLUMN login text;
ALTER TABLE users ADD COLUMN sip_id integer;
ALTER TABLE users ALTER COLUMN sip_id SET STORAGE PLAIN;
ALTER TABLE subscriber_mobile ADD COLUMN lone_worker boolean DEFAULT false;
ALTER TABLE subscriber_mobile ADD COLUMN lone_worker_interval integer DEFAULT 0;
ALTER TABLE emergalarm ADD COLUMN user_id integer;
ALTER TABLE emergalarm ADD COLUMN timegmt_ack integer;
ALTER TABLE geozoneinout ADD COLUMN user_id integer;
ALTER TABLE geozoneinout ADD COLUMN timegmt_ack integer;
ALTER TABLE speedalarm ADD COLUMN user_id integer;
ALTER TABLE speedalarm ADD COLUMN timegmt_ack integer;
ALTER TABLE telemetry_history ADD COLUMN user_id integer;
ALTER TABLE telemetry_history ADD COLUMN timegmt_ack integer;
ALTER TABLE emergalarm ADD COLUMN emergency_type integer;
create table call_patch(idx serial not null, type integer, incoming text, outgoing text, userid integer);
CREATE INDEX msg_sc_id_idx ON messages USING btree (sc_id);
CREATE INDEX secv_idx ON messages USING btree (scevtime);
CREATE INDEX speed_idx ON messages USING btree (speed);
CREATE INDEX timegmt_idx ON messages USING btree (timegmt);
CREATE TABLE users_group(idx serial not null, userid integer not null, grp_id integer not null);
CREATE TABLE sip_manager(sip_id serial not null primary key, id integer not null, type integer not null);
CREATE UNIQUE INDEX unique_idx ON sip_manager (id, type);
ALTER SEQUENCE sip_manager_sip_id_seq RESTART WITH 10;
insert into sip_manager(id, type) select userid, 0 from users where user_type <> 1;
insert into sip_manager(id, type) select id, 1 from groups where type <> 0;
insert into sip_manager(id, type) select sc_id, 2 from subscriber;
insert into sip_manager(id, type) select \"ID\", 4 from radio_gw;
ALTER TABLE users DROP COLUMN sip_id;
insert into \"userSettings\" (user_id, key, value) SELECT 0,'lanLinxServer','' where not exists (select * from \"userSettings\" where user_id = 0 and key = 'lanLinxServer');
insert into \"userSettings\" (user_id, key, value) SELECT 0,'natLinxServer','' where not exists (select * from \"userSettings\" where user_id = 0 and key = 'natLinxServer');
insert into \"userSettings\" (user_id, key, value) SELECT 0,'lanSipPort','' where not exists (select * from \"userSettings\" where user_id = 0 and key = 'lanSipPort');
insert into \"userSettings\" (user_id, key, value) SELECT 0,'natSipPort','' where not exists (select * from \"userSettings\" where user_id = 0 and key = 'natSipPort');
insert into \"userSettings\" (user_id, key, value) SELECT 0,'lanSigPort','41414' where not exists (select * from \"userSettings\" where user_id = 0 and key = 'lanSigPort');
insert into \"userSettings\" (user_id, key, value) SELECT 0,'natSigPort','' where not exists (select * from \"userSettings\" where user_id = 0 and key = 'natSigPort');
insert into \"userSettings\" (user_id, key, value) SELECT 0,'rtpStart','' where not exists (select * from \"userSettings\" where user_id = 0 and key = 'rtpStart');
insert into \"userSettings\" (user_id, key, value) SELECT 0,'rtpEnd','' where not exists (select * from \"userSettings\" where user_id = 0 and key = 'rtpEnd');
INSERT INTO car(\"name\", id, pattern, displayed_name) VALUES ('linx_01', 138, 'linx_01', 'Linx 1'), ('linx_02', 139, 'linx_02', 'Linx 2');
ALTER TABLE subscriber_mobile ADD COLUMN has_man_down boolean DEFAULT false;
ALTER TABLE gateways ADD COLUMN active boolean default false;
UPDATE gateways SET active = true WHERE \"IP\" IN (SELECT ip FROM reg_gateway);
DROP TABLE reg_gateway;
ALTER TABLE subscriber_mobile RENAME lone_worker TO has_lone_worker;
ALTER TABLE subscriber_mobile ADD COLUMN has_emergency boolean DEFAULT true;
UPDATE subscriber_mobile SET lone_worker_interval = 1 WHERE lone_worker_interval = 0;
ALTER TABLE subscriber_mobile ALTER COLUMN lone_worker_interval SET DEFAULT 1;
ALTER TABLE sms ALTER COLUMN mess TYPE text;
ALTER TABLE alarm ALTER COLUMN mess TYPE text;
CREATE SEQUENCE radio_mobile_idx_seq START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1;
CREATE TABLE public.radio_mobile(idx integer NOT NULL DEFAULT nextval('radio_mobile_idx_seq'::regclass), radio_grp_id integer NOT NULL, mobile_grp_id integer NOT NULL);
insert into \"userSettings\" (user_id, key, value) SELECT 0,'sampleRate','8000' where not exists (select * from \"userSettings\" where user_id = 0 and key = 'sampleRate');
insert into \"userSettings\" (user_id, key, value) SELECT 0,'bufferMilliseconds','32' where not exists (select * from \"userSettings\" where user_id = 0 and key = 'bufferMilliseconds');
insert into \"userSettings\" (user_id, key, value) SELECT 0,'bitDepth','16' where not exists (select * from \"userSettings\" where user_id = 0 and key = 'bitDepth');
alter table definesms add column user_id integer NOT NULL DEFAULT 0;
CREATE TABLE msg(idx serial, message text NOT NULL, dest_id int NOT NULL, seq_id text, sched_timegmt integer DEFAULT 0, email text NOT NULL, CONSTRAINT msg_pkey PRIMARY KEY (idx));
CREATE TABLE msg_details(idx serial, msg_id int NOT NULL, sip_id int, timegmt integer, lat double precision NOT NULL DEFAULT 0, lng double precision NOT NULL DEFAULT 0, speed double precision NOT NULL DEFAULT 0, altitude double precision NOT NULL DEFAULT 0, address character varying(255) NOT NULL DEFAULT 'no address'::character varying, is_sent boolean DEFAULT false, is_read boolean DEFAULT false, is_deleted boolean DEFAULT false, CONSTRAINT msg_det_pkey PRIMARY KEY (idx));
ALTER TABLE msg_details ADD CONSTRAINT msg_fk FOREIGN KEY (msg_id) REFERENCES msg (idx) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE CASCADE;
ALTER TABLE msg_details ADD CONSTRAINT sip_manager_msg_det_fk FOREIGN KEY (sip_id) REFERENCES sip_manager (sip_id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION;
ALTER TABLE msg ADD CONSTRAINT sip_manager_msg_fk FOREIGN KEY (dest_id) REFERENCES sip_manager (sip_id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION;
CREATE INDEX msg_sip_id_idx ON msg_details USING btree (sip_id);
CREATE INDEX msg_timegmt_idx ON msg_details USING btree (timegmt);
ALTER TABLE msg_details ADD COLUMN msg_type integer not null default 0;
ALTER TABLE messages ADD COLUMN tallysman_log_id integer;
ALTER TABLE registration ADD COLUMN has_recordings boolean NOT NULL DEFAULT false;
ALTER TABLE \"userSettings\" alter column key type text;
---
-- Fix long context menu when to many alerts
---
CREATE INDEX idx_geozone_1 ON public.geozoneinout USING btree (sc_id, preview);
CREATE INDEX idx_emergalarm ON public.emergalarm USING btree (sc_id, preview);
CREATE INDEX idx_speedalarm ON public.speedalarm USING btree (sc_id, preview);
CREATE INDEX idx_telemetryalarm ON public.telemetry_history USING btree (sc_id, ack, alarm);
---
-- Callout for TetraSDR
---
ALTER TABLE zonename ADD COLUMN \"callout\" BOOLEAN DEFAULT FALSE;
ALTER TABLE zonename ADD COLUMN \"callout_severity\" int DEFAULT 3;
ALTER TABLE place ADD COLUMN \"callout\" BOOLEAN DEFAULT FALSE;
ALTER TABLE place ADD COLUMN \"callout_severity\" int DEFAULT 3;