-- Create tables (DDL)
create table lec_page (id varchar(255) not null, created_at timestamp, deleted boolean not null, updated_at timestamp, configuration TEXT, default_page boolean not null, dynamic boolean not null, lang varchar(255), name varchar(255), path varchar(255), permission_id varchar(255), show_order int4 not null, slug varchar(255), visible boolean not null, primary key (id));

create table lec_permission (id varchar(255) not null, description varchar(255), primary key (id));
create table lec_role (id varchar(255) not null, description varchar(255), primary key (id));
create table lec_role_permission (roles_id varchar(255) not null, permissions_id varchar(255) not null);

alter table lec_page add constraint FKbx6gynj19c7cxod3muvycsjj7 foreign key (permission_id) references lec_permission;
alter table lec_role_permission add constraint FKblxw0vakj6b3no147y484q9yr foreign key (permissions_id) references lec_permission;
alter table lec_role_permission add constraint FKhblu9t37p55oneyq1nccv2wa9 foreign key (roles_id) references lec_role;

-- Dummy data (DML)
INSERT INTO lec_role (id, description) VALUES ('platform-admin', 'platform-admin');
INSERT INTO lec_role (id, description) VALUES ('registered', 'registered');

INSERT INTO lec_permission (id, description) VALUES ('admin', 'Accesso alle funzionalità di amministrazione');
INSERT INTO lec_permission (id, description) VALUES ('view', 'Visualizzazione pagine');

INSERT INTO lec_page (id, lang, name, slug, path, configuration, show_order, default_page, visible, dynamic, deleted, created_at, updated_at, permission_id) VALUES ('508f7865-c3f4-4ad6-8ddc-4532d72b0f60', 'it', 'Consumo', 'my-consumption', 'pages/my-consumption', '{"layout":{"rows":[{"columns":[{"width":0,"widgets":[{"type":"TABLE","datasourceConfiguration":{"parameters":[],"parametricQuery":{"queryid":4,"name":"List users'' communities from user id","description":"Retrieves the list of user''s communities from his/her id","queryType":"sql","admittedqueryvalues":[],"values":{},"metadata":[{"unitOfMeasure":"N/A | N/A","name":"communityid","description":"Id della comunità | id della comunità","type":"Integer","example":"1"},{"unitOfMeasure":"N/A | N/A","name":"communityname","description":"Nome della comunità | Nome della Comunità","type":"String","example":"GECO"},{"unitOfMeasure":"N/A | N/A","name":"description","description":"Descrizione | Descrizione estesa","type":"String","example":"Descrizione di un oggetto"}],"parameters":[]}},"rowSelectable":true,"rowSelectColumn":"communityid","rowSelectParamName":null,"selectedColumns":["communityname"],"editable":false,"formCode":null,"formColumnId":null,"formColumnTitle":null}],"style":{"borderWidth":null,"borderColor":null,"borderStyle":"none","borderRadius":null,"padding":null,"backgroundColor":null,"fontSize":null,"color":null,"fontStyle":null}},{"width":0,"widgets":[{"type":"TABLE","datasourceConfiguration":{"parameters":[{"name":"startDate","type":"any_date","value":"2021-09-01T09:46:11.000Z"},{"name":"endDate","type":"any_date","value":"2021-09-30T09:46:17.000Z"},{"name":"communityid","type":"querystring","value":"communityid"},{"name":"flowid","type":"any_number","value":"8"}],"parametricQuery":{"queryid":2,"name":"Consumption data in a period","description":"Returns the active energy consumption data for a user in a comunnity in a specific period between startDate and endDate","queryType":"sql","admittedqueryvalues":[{"admittedqueryvalueid":1,"type":"period","value":"now","queries":null,"listOfValue":null,"id":1},{"admittedqueryvalueid":3,"type":"period","value":"end_of_the_month","queries":null,"listOfValue":null,"id":3},{"admittedqueryvalueid":4,"type":"period","value":"start_of_the_month","queries":null,"listOfValue":null,"id":4},{"admittedqueryvalueid":5,"type":"period","value":"end_of_the_day","queries":null,"listOfValue":null,"id":5},{"admittedqueryvalueid":6,"type":"period","value":"start_ot_the_day","queries":null,"listOfValue":null,"id":6},{"admittedqueryvalueid":7,"type":"period","value":"end_of_year","queries":null,"listOfValue":null,"id":7},{"admittedqueryvalueid":8,"type":"period","value":"start_of_year","queries":null,"listOfValue":null,"id":8},{"admittedqueryvalueid":9,"type":"period","value":"any value","queries":null,"listOfValue":null,"id":9},{"admittedqueryvalueid":2,"type":"period","value":"start_of_the_week","queries":null,"listOfValue":null,"id":2},{"admittedqueryvalueid":12,"type":"period","value":"end_of_the_week","queries":null,"listOfValue":null,"id":12}],"values":{"period":["now","end_of_the_month","start_of_the_month","end_of_the_day","start_ot_the_day","end_of_year","start_of_year","any value","start_of_the_week","end_of_the_week"]},"metadata":[{"unitOfMeasure":"W | watts","name":"powactive","description":"Energia attiva | Energia attiva misurata dal contatore","type":"Integer","example":"6"},{"unitOfMeasure":"N/A | N/A","name":"timestamp","description":"Tempo | Registrazione del momento di un evento","type":"Date","example":"2021-03-06 00:00:00"}],"parameters":[{"paramId":3,"description":"Data iniziale","name":"startDate","type":"Timestamp","example":"2021-03-01 00:00:00","familytype":"Period","inout":null,"unitofmeasure":"N/A | N/A"},{"paramId":4,"description":"Data finale","name":"endDate","type":"Timestamp","example":"2021-03-06 00:00:00","familytype":"Period","inout":null,"unitofmeasure":"N/A | N/A"},{"paramId":10,"description":"Id della comunità | id della comunità | Community Id | Internal id of the Community","name":"communityid","type":"Integer","example":"1","familytype":"integerInterval","inout":null,"unitofmeasure":"N/A | N/A"},{"paramId":11,"description":"Id del flusso dati | Identificativo numerico del flusso dati | Flow id | Identification number of the data flow","name":"flowid","type":"Integer","example":"8","familytype":"integerinterval","inout":null,"unitofmeasure":"N/A | N/A"}]}},"rowSelectable":false,"rowSelectColumn":null,"rowSelectParamName":null,"selectedColumns":["powactive","timestamp"],"editable":false,"formCode":null,"formColumnId":null,"formColumnTitle":null},{"type":"CHART","chartType":"bar","seriesList":[{"datasourceConfiguration":{"parameters":[{"name":"startDate","type":"any_date","value":"2021-09-01T12:49:40.000Z"},{"name":"endDate","type":"any_date","value":"2021-09-30T12:49:46.000Z"},{"name":"communityid","type":"querystring","value":"communityid"},{"name":"flowid","type":"any_number","value":"8"}],"parametricQuery":{"queryid":3,"name":"Reactive consumption in a period","description":"Returns the reactive energy consumption data for a user in a comunnity in a specific period between startDate and endDate","queryType":"sql","admittedqueryvalues":[{"admittedqueryvalueid":1,"type":"period","value":"now","queries":null,"listOfValue":null,"id":1},{"admittedqueryvalueid":3,"type":"period","value":"end_of_the_month","queries":null,"listOfValue":null,"id":3},{"admittedqueryvalueid":4,"type":"period","value":"start_of_the_month","queries":null,"listOfValue":null,"id":4},{"admittedqueryvalueid":5,"type":"period","value":"end_of_the_day","queries":null,"listOfValue":null,"id":5},{"admittedqueryvalueid":6,"type":"period","value":"start_ot_the_day","queries":null,"listOfValue":null,"id":6},{"admittedqueryvalueid":7,"type":"period","value":"end_of_year","queries":null,"listOfValue":null,"id":7},{"admittedqueryvalueid":8,"type":"period","value":"start_of_year","queries":null,"listOfValue":null,"id":8},{"admittedqueryvalueid":9,"type":"period","value":"any value","queries":null,"listOfValue":null,"id":9},{"admittedqueryvalueid":2,"type":"period","value":"start_of_the_week","queries":null,"listOfValue":null,"id":2},{"admittedqueryvalueid":12,"type":"period","value":"end_of_the_week","queries":null,"listOfValue":null,"id":12}],"values":{"period":["now","end_of_the_month","start_of_the_month","end_of_the_day","start_ot_the_day","end_of_year","start_of_year","any value","start_of_the_week","end_of_the_week"]},"metadata":[{"unitOfMeasure":"W | watts","name":"powreactive","description":"Potenza reattiva | Potenza reattiva misurata dal contatore","type":"Integer","example":"1390"},{"unitOfMeasure":"N/A | N/A","name":"timestamp","description":"Tempo | Registrazione del momento di un evento","type":"Date","example":"2021-03-06 00:00:00"}],"parameters":[{"paramId":3,"description":"Data iniziale","name":"startDate","type":"Timestamp","example":"2021-03-01 00:00:00","familytype":"Period","inout":null,"unitofmeasure":"N/A | N/A"},{"paramId":4,"description":"Data finale","name":"endDate","type":"Timestamp","example":"2021-03-06 00:00:00","familytype":"Period","inout":null,"unitofmeasure":"N/A | N/A"},{"paramId":10,"description":"Id della comunità | id della comunità | Community Id | Internal id of the Community","name":"communityid","type":"Integer","example":"1","familytype":"integerInterval","inout":null,"unitofmeasure":"N/A | N/A"},{"paramId":11,"description":"Id del flusso dati | Identificativo numerico del flusso dati | Flow id | Identification number of the data flow","name":"flowid","type":"Integer","example":"8","familytype":"integerinterval","inout":null,"unitofmeasure":"N/A | N/A"}]}},"selectedColumns":["powreactive"],"styles":[{"column":"powreactive","color":null}],"xaxisColumn":"timestamp"}]}],"style":{"borderWidth":null,"borderColor":null,"borderStyle":"none","borderRadius":null,"padding":null,"backgroundColor":null,"fontSize":null,"color":null,"fontStyle":null}}]}]}}', 0, false, true, true, false, '2021-12-02 11:31:15.190691', '2021-12-02 14:50:31.769170', 'view');
INSERT INTO lec_page (id, lang, name, slug, path, configuration, show_order, default_page, visible, dynamic, deleted, created_at, updated_at, permission_id) VALUES ('7cdbde77-1616-40a5-9d53-357bace5f9d3', 'it', 'I miei dispositivi', 'my-devices', 'pages/my-devices', '{"layout":{"rows":[{"columns":[{"width":0,"widgets":[{"type":"TABLE","datasourceConfiguration":{"parameters":[],"parametricQuery":{"queryid":8,"name":"List of user devices","description":"Returns the list of devices owned by a single user","admittedqueryvalues":[],"values":{},"metadata":[{"unitOfMeasure":"N/A | N/A","name":"deviceid","description":"","type":"List","example":"FF016"},{"unitOfMeasure":"N/A | N/A","name":"supplierid","description":"SupplierId | Identificativo del fornitore del device","type":"String","example":"SINAPSI"},{"unitOfMeasure":"N/A | N/A","name":"userid","description":"Userid | Identificativo dell''utente","type":"Integer","example":"141"},{"unitOfMeasure":"N/A | N/A","name":"identificationmethod","description":"Identification method | Il metodo di identificazione del dispositivo","type":"Integer","example":null},{"unitOfMeasure":"N/A | N/A","name":"altdeviceid","description":"AltdeviceID | Identificativo alternativo del dispositivo","type":"String","example":"Dispositivo di Utente"},{"unitOfMeasure":"N/A | N/A","name":"devicename","description":"DeviceName | Nome del dispositivo","type":"String","example":"Dispositvo 3345"},{"unitOfMeasure":"N/A | N/A","name":"description","description":"Descrizione | Descrizione estesa","type":"String","example":"Descrizione di un oggetto"},{"unitOfMeasure":"N/A | N/A","name":"note","description":"Note | Note allegate al dispositivo","type":"String","example":"Prova di una nota legata al dispositivo 3344"},{"unitOfMeasure":"N/A | N/A","name":"devicetype","description":"DeviceType | Tiplologia del dispositivo","type":"String","example":"Dispositivo Utente"},{"unitOfMeasure":"N/A | N/A","name":"devicestatus","description":"Device Status | Stato del sispositivo","type":"Integer","example":"1"},{"unitOfMeasure":"N/A | N/A","name":"usetype","description":"UseType | Tipologia di utilizzo","type":"Integer","example":"1"},{"unitOfMeasure":"N/A | N/A","name":"georeferenceformat","description":"Georeferenceformat | formato del sistema di georeferenziazione","type":"String","example":"WGS84"},{"unitOfMeasure":"N/A | N/A\\n","name":"georeferencex","description":"Georeferencex | Valore X di georeferenziazione","type":"Double","example":"10.6833813"},{"unitOfMeasure":"N/A | N/A","name":"georeferencey","description":"Georeferencey | Valore Y di georeferenziazione","type":"Double","example":"11.3369464"},{"unitOfMeasure":"N/A | N/A","name":"georeferencez","description":"Georeferencez | Valore Z di georeferenziazione","type":"Double","example":"33.4543544"},{"unitOfMeasure":"N/A | N/A","name":"activationdate","description":"ActiovationDate | Data di attivazione","type":"String","example":"2021-02-23 15:30:45"},{"unitOfMeasure":"N/A | N/A","name":"crudcode","description":"crudCode | codice di gestione dell''oggetto","type":"String","example":"users"}],"parameters":[]}},"rowSelectable":false,"rowSelectColumn":null,"rowSelectParamName":null,"selectedColumns":["userid","devicename","description"],"editable":true,"formCode":"devices","formColumnId":"deviceid","formColumnTitle":"devicename"}],"style":{"borderWidth":null,"borderColor":null,"borderStyle":"none","borderRadius":null,"padding":null,"backgroundColor":null,"fontSize":null,"color":null,"fontStyle":null}}]}]}}', 0, false, true, true, false, '2021-12-02 10:15:23.404520', '2021-12-02 11:17:52.580295', 'view');
INSERT INTO lec_page (id, lang, name, slug, path, configuration, show_order, default_page, visible, dynamic, deleted, created_at, updated_at, permission_id) VALUES ('f67f9714-eaea-45c0-9d8f-e3521014b7ad', 'it', 'Chi siamo', 'chi-siamo', 'pages/chi-siamo',  '{"layout":{"rows":[{"columns":[{"width":0,"widgets":[{"type":"TEXT","content":"<h1>Chi siamo</h1><p class=\\\"ql-align-justify\\\">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut egestas lacus purus, in mollis neque accumsan eu. Mauris et molestie enim, at maximus odio. Quisque ullamcorper pellentesque nisi et ultrices. Aliquam erat volutpat. Vestibulum accumsan justo sed ultricies ullamcorper. Vestibulum aliquam at nulla vitae consequat. Etiam ligula ex, hendrerit nec dui ac, finibus viverra sapien. Suspendisse neque odio, ornare sit amet varius a, facilisis eget lorem. Sed nec sollicitudin ex, vel mattis massa. In purus lectus, iaculis in purus non, mattis interdum quam. Nam vel vehicula nibh. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p><p class=\\\"ql-align-justify\\\">Aliquam ut mauris lacus. Cras lobortis nisi in metus sodales, sit amet tristique sem faucibus. Maecenas quis dolor suscipit, tincidunt nulla in, fringilla diam. Nulla mauris tortor, auctor eget purus facilisis, dignissim sodales justo. Nunc faucibus eget nulla quis hendrerit. Phasellus sed ante fermentum, mattis mauris id, interdum tortor. Duis condimentum nisl nec purus faucibus, nec mattis quam fermentum. Donec fermentum vulputate sem sed lacinia. Praesent eu felis id dui scelerisque suscipit. Sed rutrum lectus ut consectetur interdum. Aenean viverra ullamcorper dolor, et sollicitudin orci convallis non.</p><p class=\\\"ql-align-justify\\\"><br></p><h2 class=\\\"ql-align-justify\\\">Per contattarci:</h2><h4>ENEA</h4><p>Lungotevere Thaon di Revel, 76</p><p class=\\\"ql-align-justify\\\">00196 ROMA Italia</p>"}]}]}]}}', 0, false, true, true, false, '2021-09-13 17:40:23.584005', '2021-09-20 17:42:18.193927', 'view');
INSERT INTO lec_page (id, lang, name, slug, path, configuration, show_order, default_page, visible, dynamic, deleted, created_at, updated_at, permission_id) VALUES ('f7c54e8f-c0bd-416c-9957-383aa6774338', 'it', 'Amministrazione pagine', null, 'pages',  '{"layout":{"rows":[{"columns":[{"width":0,"widgets":[]}]}]}}', 1, false, true, false, false, '2021-08-16 10:19:35.837317', '2021-10-20 16:54:49.146686', 'admin');

INSERT INTO lec_role_permission (roles_id, permissions_id) VALUES ('registered', 'view');
INSERT INTO lec_role_permission (roles_id, permissions_id) VALUES ('platform-admin', 'admin');
INSERT INTO lec_role_permission (roles_id, permissions_id) VALUES ('platform-admin', 'view');
