DELETE FROM ENTRY_ENTITY WHERE OWNER = 'default';
DELETE FROM ENTRY_PATH WHERE OWNER = 'default';
DELETE FROM ENTRY_DATASET_RELATIONSHIPS WHERE OWNER = 'default';
DELETE FROM ENTRY_ORDER WHERE OWNER = 'default';
DELETE FROM ENTRY_FILTERS WHERE OWNER = 'default';
DELETE FROM ENTRY_HAVING WHERE OWNER = 'default';
delete from ENTRY_AGGREGATORS where OWNER='default';
DELETE FROM ENTRY_DATASET_MAPPINGS where OWNER = 'default';

INSERT INTO ENTRY_ENTITY(COD_ENTITY, TABLE_NAME, ENTITY_TYPE, COD_PATH, STRATEGY, OWNER) VALUES
-- Sources
('ET_AIRCRAFTS', 'AIRCRAFTS','SRC', 'PSA', NULL, 'default'),
('ET_AIRPORTS', 'AIRPORTS','SRC', 'PSA', NULL, 'default'),
('ET_CARRIERS', 'CARRIERS','SRC', 'PSA', NULL, 'default'),
('ET_FLIGHTS', 'FLIGHTS','SRC', 'PSA', NULL, 'default'),
('ET_CUSTOMERS', 'CUSTOMERS','SRC', 'PSA', NULL, 'default'),
('ET_USERS_WEB', 'USERS_WEB','SRC', 'PSA', NULL, 'default'),
-- Transformation
('ET_USERS_WEB_TMP', 'USERS_WEB_TMP', 'WITH', 'NPSA',NULL, 'default'),
('ET_FLIGHTS_TMP', 'FLIGHTS_TMP','TB', 'NPSA', 'INSERT', 'default'),
('ET_AIRCRAFTS_TMP', 'AIRCRAFTS_TMP','TB', 'NPSA', 'INSERT', 'default'),
('ET_CUSTOMERS_TMP', 'CUSTOMERS_TMP', 'TB', 'NPSA', 'INSERT', 'default');

INSERT INTO ENTRY_PATH (COD_PATH, DATABASE_NAME, SCHEMA_NAME, OWNER) VALUES
('PSA', 'METAMORF', 'DATA', 'default'),
('NPSA', 'METAMORF', 'DATA', 'default'),
('RDV', 'METAMORF', 'DATA', 'default');

INSERT INTO ENTRY_DATASET_RELATIONSHIPS (COD_ENTITY_MASTER, COLUMN_NAME_MASTER, COD_ENTITY_DETAIL, COLUMN_NAME_DETAIL, RELATIONSHIP_TYPE, OWNER) VALUES
('ET_AIRCRAFTS', 'CARRIER_IATA', 'ET_CARRIERS', 'IATA', 'MASTER JOIN', 'default'),
('ET_CUSTOMERS', 'FLIGHT_CODE', 'ET_FLIGHTS', 'FLIGHT_CODE', 'MASTER JOIN', 'default'),
('ET_USERS_WEB_TMP', 'ID_CUSTOMER', 'ET_CUSTOMERS', 'ID_CUSTOMER', 'DETAIL JOIN', 'default');

INSERT INTO ENTRY_ORDER (COD_ENTITY_TARGET,COD_ENTITY_SOURCE, COLUMN_NAME,NUM_BRANCH, ORDER_TYPE, OWNER) VALUES
('ET_FLIGHTS_TMP','ET_FLIGHTS', 'UNIQUE_FLIGHT_CODE', 1, 'ASC', 'default'),
('ET_FLIGHTS_TMP','ET_FLIGHTS', 'FLIGHT_CODE', 1, 'DESC', 'default');

INSERT INTO ENTRY_FILTERS (COD_ENTITY_TARGET, VALUE, NUM_BRANCH, OWNER) VALUES
('ET_CUSTOMERS_TMP', 'TIME_ONLINE_SECONDS > 0', 1, 'default');

INSERT INTO ENTRY_AGGREGATORS (COD_ENTITY_TARGET, COD_ENTITY_SOURCE, COLUMN_NAME, NUM_BRANCH, OWNER) VALUES
('ET_USERS_WEB_TMP','ET_USERS_WEB', 'ID_CUSTOMER', 1, 'default');

INSERT INTO ENTRY_DATASET_MAPPINGS (COD_ENTITY_SOURCE,VALUE_SOURCE,COD_ENTITY_TARGET,COLUMN_NAME_TARGET,COLUMN_TYPE_TARGET,ORDINAL_POSITION,"LENGTH","PRECISION",NUM_BRANCH,"KEY_TYPE",SW_DISTINCT,OWNER) VALUES
('ET_USERS_WEB','ID_CUSTOMER','ET_USERS_WEB_TMP','ID_CUSTOMER','INTEGER',1,50,0,1,'PK',0,'default'),
('ET_USERS_WEB','MIN(VISIT_DATE)','ET_USERS_WEB_TMP','FIRST_APPEAR_DATE','VARCHAR',2,50,0,1,NULL,0,'default'),
('ET_USERS_WEB','MAX(VISIT_DATE)','ET_USERS_WEB_TMP','LAST_APPEAR_DATE','VARCHAR',3,50,0,1,NULL,0,'default'),
('ET_USERS_WEB','SUM(TIME_ONLINE_SECONDS)','ET_USERS_WEB_TMP','TIME_ONLINE_SECONDS','INTEGER',4,50,0,1,NULL,0,'default'),
('ET_FLIGHTS','UNIQUE_FLIGHT_CODE','ET_FLIGHTS_TMP','UNIQUE_FLIGHT_CODE','VARCHAR',1,50,0,1,'PK',0,'default'),
('ET_FLIGHTS','SUBSTR(FLIGHT_CODE,1,3)','ET_FLIGHTS_TMP','ICAO_CARRIER_CODE','VARCHAR',2,50,0,1,NULL,0,'default'),
('ET_FLIGHTS','FLIGHT_CODE','ET_FLIGHTS_TMP','FLIGHT_CODE','VARCHAR',3,50,0,1,NULL,0,'default'),
('ET_FLIGHTS','AIRPORT_ORIGIN_CODE','ET_FLIGHTS_TMP','AIRPORT_ORIGIN_CODE','VARCHAR',4,50,0,1,NULL,0,'default'),
('ET_FLIGHTS','AIRPORT_DEST_CODE','ET_FLIGHTS_TMP','AIRPORT_DEST_CODE','VARCHAR',5,50,0,1,NULL,0,'default'),
('ET_FLIGHTS','DEPARTURE_GATE','ET_FLIGHTS_TMP','DEPARTURE_GATE','VARCHAR',6,50,0,1,NULL,0,'default'),
('ET_FLIGHTS','BOARDING_TIME','ET_FLIGHTS_TMP','BOARDING_TIME','VARCHAR',7,50,0,1,NULL,0,'default'),
('ET_FLIGHTS','DEPARTURE_TIME','ET_FLIGHTS_TMP','DEPARTURE_TIME','VARCHAR',8,50,0,1,NULL,0,'default'),
('ET_FLIGHTS','LANDING_TIME','ET_FLIGHTS_TMP','LANDING_TIME','VARCHAR',9,50,0,1,NULL,0,'default'),
('ET_FLIGHTS','ARRIVAL_TIME','ET_FLIGHTS_TMP','ARRIVAL_TIME','VARCHAR',10,50,0,1,NULL,0,'default'),
('ET_FLIGHTS','AIRCRAFT','ET_FLIGHTS_TMP','AIRCRAFT','VARCHAR',11,50,0,1,NULL,0,'default'),
('ET_FLIGHTS','BOARDING_TIME_REAL','ET_FLIGHTS_TMP','BOARDING_TIME_REAL','VARCHAR',12,50,0,1,NULL,0,'default'),
('ET_FLIGHTS','DEPARTURE_TIME_REAL','ET_FLIGHTS_TMP','DEPARTURE_TIME_REAL','VARCHAR',13,50,0,1,NULL,0,'default'),
('ET_FLIGHTS','LANDING_TIME_REAL','ET_FLIGHTS_TMP','LANDING_TIME_REAL','VARCHAR',14,50,0,1,NULL,0,'default'),
('ET_FLIGHTS','ARRIVAL_TIME_REAL','ET_FLIGHTS_TMP','ARRIVAL_TIME_REAL','VARCHAR',15,50,0,1,NULL,0,'default'),
('ET_FLIGHTS','OPERATION','ET_FLIGHTS_TMP','OPERATION','VARCHAR',16,50,0,1,NULL,0,'default'),
('','CURRENT_TIMESTAMP()','ET_FLIGHTS_TMP','DATE_CREATED','VARCHAR',17,50,0,1,NULL,0,'default'),
('','''metamorf_processor''','ET_FLIGHTS_TMP','CREATED_BY','VARCHAR',18,50,0,1,NULL,0,'default'),
('ET_AIRCRAFTS','LICENSE','ET_AIRCRAFTS_TMP','LICENSE','VARCHAR',1,50,0,1,'PK',1,'default'),
('ET_AIRCRAFTS','MODEL_ICAO','ET_AIRCRAFTS_TMP','MODEL_ICAO','VARCHAR',2,50,0,1,NULL,1,'default'),
('ET_AIRCRAFTS','NAME','ET_AIRCRAFTS_TMP','NAME','VARCHAR',3,50,0,1,NULL,1,'default'),
('ET_AIRCRAFTS','AIRCRAFTS_BY','ET_AIRCRAFTS_TMP','AIRCRAFTS_BY','VARCHAR',4,50,0,1,NULL,1,'default'),
('ET_AIRCRAFTS','AIRCRAFTS_TYPE','ET_AIRCRAFTS_TMP','AIRCRAFTS_TYPE','VARCHAR',5,50,0,1,NULL,1,'default'),
('ET_AIRCRAFTS','APC','ET_AIRCRAFTS_TMP','APC','VARCHAR',6,50,0,1,NULL,1,'default'),
('ET_AIRCRAFTS','WTC','ET_AIRCRAFTS_TMP','WTC','VARCHAR',7,50,0,1,NULL,1,'default'),
('ET_AIRCRAFTS','ALTERNATIVE_NAME','ET_AIRCRAFTS_TMP','ALTERNATIVE_NAME','VARCHAR',8,50,0,1,NULL,1,'default'),
('ET_AIRCRAFTS','CARRIER_IATA','ET_AIRCRAFTS_TMP','CARRIER_IATA','VARCHAR',9,50,0,1,NULL,1,'default'),
('ET_CARRIERS','ICAO','ET_AIRCRAFTS_TMP','ICAO','VARCHAR',10,50,0,1,NULL,1,'default'),
('','CURRENT_TIMESTAMP()','ET_AIRCRAFTS_TMP','DATE_CREATED','VARCHAR',11,50,0,1,NULL,1,'default'),
('','''metamorf_processor''','ET_AIRCRAFTS_TMP','CREATED_BY','VARCHAR',12,50,0,1,NULL,1,'default'),
('ET_CUSTOMERS','ID_CUSTOMER','ET_CUSTOMERS_TMP','ID_CUSTOMER','INTEGER',1,50,0,1,'PK',0,'default'),
('ET_CUSTOMERS','CUSTOMER_NAME','ET_CUSTOMERS_TMP','CUSTOMER_NAME','VARCHAR',2,50,0,1,NULL,0,'default'),
('ET_CUSTOMERS','NIE','ET_CUSTOMERS_TMP','NIE','VARCHAR',3,50,0,1,NULL,0,'default'),
('ET_CUSTOMERS','PRICE','ET_CUSTOMERS_TMP','PRICE','INTEGER',4,50,0,1,NULL,0,'default'),
('ET_CUSTOMERS','SELL_DATE','ET_CUSTOMERS_TMP','SELL_DATE','VARCHAR',5,50,0,1,NULL,0,'default'),
('ET_CUSTOMERS','ADDRESS','ET_CUSTOMERS_TMP','ADDRESS','VARCHAR',6,50,0,1,NULL,0,'default'),
('ET_CUSTOMERS','NATIONALITY','ET_CUSTOMERS_TMP','NATIONALITY','VARCHAR',7,50,0,1,NULL,0,'default'),
('ET_FLIGHTS','UNIQUE_FLIGHT_CODE','ET_CUSTOMERS_TMP','UNIQUE_FLIGHT_CODE','VARCHAR',8,50,0,1,NULL,0,'default'),
('ET_USERS_WEB_TMP','TIME_ONLINE_SECONDS','ET_CUSTOMERS_TMP','TIME_ONLINE_SECONDS','INTEGER',9,50,0,1,NULL,0,'default'),
('ET_USERS_WEB_TMP','FIRST_APPEAR_DATE','ET_CUSTOMERS_TMP','FIRST_APPEAR_DATE','VARCHAR',10,50,0,1,NULL,0,'default'),
('ET_USERS_WEB_TMP','LAST_APPEAR_DATE','ET_CUSTOMERS_TMP','LAST_APPEAR_DATE','VARCHAR',11,50,0,1,NULL,0,'default'),
('','CURRENT_TIMESTAMP()','ET_CUSTOMERS_TMP','DATE_CREATED','VARCHAR',12,50,0,1,NULL,0,'default'),
('','''metamorf_processor''','ET_CUSTOMERS_TMP','CREATED_BY','VARCHAR',13,50,0,1,NULL,0,'default');


