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';
DELETE FROM ENTRY_DV_ENTITY where OWNER='default';
DELETE FROM ENTRY_DV_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', 'TRUNCATE AND INSERT', 'default');

INSERT INTO ENTRY_PATH (COD_PATH, DATABASE_NAME, SCHEMA_NAME, OWNER) VALUES
('PSA', 'MAIN', NULL, 'default'),
('NPSA', 'MAIN', NULL, 'default'),
('RDV', 'MAIN', NULL, '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,COLUMN_LENGTH,COLUMN_PRECISION,NUM_BRANCH,KEY_TYPE,SW_DISTINCT,OWNER) VALUES
('ET_USERS_WEB','ID_CUSTOMER','ET_USERS_WEB_TMP','ID_CUSTOMER','int',1,50,0,1,'PK',0,'default'),
('ET_USERS_WEB','MIN(VISIT_DATE)','ET_USERS_WEB_TMP','FIRST_APPEAR_DATE','TEXT',2,50,0,1,NULL,0,'default'),
('ET_USERS_WEB','MAX(VISIT_DATE)','ET_USERS_WEB_TMP','LAST_APPEAR_DATE','TEXT',3,50,0,1,NULL,0,'default'),
('ET_USERS_WEB','SUM(TIME_ONLINE_SECONDS)','ET_USERS_WEB_TMP','TIME_ONLINE_SECONDS','int',4,50,0,1,NULL,0,'default'),
('ET_FLIGHTS','UNIQUE_FLIGHT_CODE','ET_FLIGHTS_TMP','UNIQUE_FLIGHT_CODE','TEXT',1,50,0,1,'PK',0,'default'),
('ET_FLIGHTS','SUBSTR(FLIGHT_CODE,1,3)','ET_FLIGHTS_TMP','ICAO_CARRIER_CODE','TEXT',2,50,0,1,NULL,0,'default'),
('ET_FLIGHTS','FLIGHT_CODE','ET_FLIGHTS_TMP','FLIGHT_CODE','TEXT',3,50,0,1,NULL,0,'default'),
('ET_FLIGHTS','AIRPORT_ORIGIN_CODE','ET_FLIGHTS_TMP','AIRPORT_ORIGIN_CODE','TEXT',4,50,0,1,NULL,0,'default'),
('ET_FLIGHTS','AIRPORT_DEST_CODE','ET_FLIGHTS_TMP','AIRPORT_DEST_CODE','TEXT',5,50,0,1,NULL,0,'default'),
('ET_FLIGHTS','DEPARTURE_GATE','ET_FLIGHTS_TMP','DEPARTURE_GATE','TEXT',6,50,0,1,NULL,0,'default'),
('ET_FLIGHTS','BOARDING_TIME','ET_FLIGHTS_TMP','BOARDING_TIME','TEXT',7,50,0,1,NULL,0,'default'),
('ET_FLIGHTS','DEPARTURE_TIME','ET_FLIGHTS_TMP','DEPARTURE_TIME','TEXT',8,50,0,1,NULL,0,'default'),
('ET_FLIGHTS','LANDING_TIME','ET_FLIGHTS_TMP','LANDING_TIME','TEXT',9,50,0,1,NULL,0,'default'),
('ET_FLIGHTS','ARRIVAL_TIME','ET_FLIGHTS_TMP','ARRIVAL_TIME','TEXT',10,50,0,1,NULL,0,'default'),
('ET_FLIGHTS','AIRCRAFT','ET_FLIGHTS_TMP','AIRCRAFT','TEXT',11,50,0,1,NULL,0,'default'),
('ET_FLIGHTS','BOARDING_TIME_REAL','ET_FLIGHTS_TMP','BOARDING_TIME_REAL','TEXT',12,50,0,1,NULL,0,'default'),
('ET_FLIGHTS','DEPARTURE_TIME_REAL','ET_FLIGHTS_TMP','DEPARTURE_TIME_REAL','TEXT',13,50,0,1,NULL,0,'default'),
('ET_FLIGHTS','LANDING_TIME_REAL','ET_FLIGHTS_TMP','LANDING_TIME_REAL','TEXT',14,50,0,1,NULL,0,'default'),
('ET_FLIGHTS','ARRIVAL_TIME_REAL','ET_FLIGHTS_TMP','ARRIVAL_TIME_REAL','TEXT',15,50,0,1,NULL,0,'default'),
('ET_FLIGHTS','OPERATION','ET_FLIGHTS_TMP','OPERATION','TEXT',16,50,0,1,NULL,0,'default'),
('','DATE(''now'')','ET_FLIGHTS_TMP','DATE_CREATED','TEXT',17,50,0,1,NULL,0,'default'),
('','''metamorf_processor''','ET_FLIGHTS_TMP','CREATED_BY','TEXT',18,50,0,1,NULL,0,'default'),
('ET_AIRCRAFTS','LICENSE','ET_AIRCRAFTS_TMP','LICENSE','TEXT',1,50,0,1,'PK',1,'default'),
('ET_AIRCRAFTS','MODEL_ICAO','ET_AIRCRAFTS_TMP','MODEL_ICAO','TEXT',2,50,0,1,NULL,1,'default'),
('ET_AIRCRAFTS','NAME','ET_AIRCRAFTS_TMP','NAME','TEXT',3,50,0,1,NULL,1,'default'),
('ET_AIRCRAFTS','AIRCRAFTS_BY','ET_AIRCRAFTS_TMP','AIRCRAFTS_BY','TEXT',4,50,0,1,NULL,1,'default'),
('ET_AIRCRAFTS','AIRCRAFTS_TYPE','ET_AIRCRAFTS_TMP','AIRCRAFTS_TYPE','TEXT',5,50,0,1,NULL,1,'default'),
('ET_AIRCRAFTS','APC','ET_AIRCRAFTS_TMP','APC','TEXT',6,50,0,1,NULL,1,'default'),
('ET_AIRCRAFTS','WTC','ET_AIRCRAFTS_TMP','WTC','TEXT',7,50,0,1,NULL,1,'default'),
('ET_AIRCRAFTS','ALTERNATIVE_NAME','ET_AIRCRAFTS_TMP','ALTERNATIVE_NAME','TEXT',8,50,0,1,NULL,1,'default'),
('ET_AIRCRAFTS','CARRIER_IATA','ET_AIRCRAFTS_TMP','CARRIER_IATA','TEXT',9,50,0,1,NULL,1,'default'),
('ET_CARRIERS','ICAO','ET_AIRCRAFTS_TMP','ICAO','TEXT',10,50,0,1,NULL,1,'default'),
('','DATE(''now'')','ET_AIRCRAFTS_TMP','DATE_CREATED','TEXT',11,50,0,1,NULL,1,'default'),
('','''metamorf_processor''','ET_AIRCRAFTS_TMP','CREATED_BY','TEXT',12,50,0,1,NULL,1,'default'),
('ET_CUSTOMERS','ID_CUSTOMER','ET_CUSTOMERS_TMP','ID_CUSTOMER','int',1,50,0,1,'PK',0,'default'),
('ET_CUSTOMERS','NAME','ET_CUSTOMERS_TMP','NAME','TEXT',2,50,0,1,NULL,0,'default'),
('ET_CUSTOMERS','NIE','ET_CUSTOMERS_TMP','NIE','TEXT',3,50,0,1,NULL,0,'default'),
('ET_CUSTOMERS','PRICE','ET_CUSTOMERS_TMP','PRICE','int',4,50,0,1,NULL,0,'default'),
('ET_CUSTOMERS','SELL_DATE','ET_CUSTOMERS_TMP','SELL_DATE','TEXT',5,50,0,1,NULL,0,'default'),
('ET_CUSTOMERS','ADDRESS','ET_CUSTOMERS_TMP','ADDRESS','TEXT',6,50,0,1,NULL,0,'default'),
('ET_CUSTOMERS','NATIONALITY','ET_CUSTOMERS_TMP','NATIONALITY','TEXT',7,50,0,1,NULL,0,'default'),
('ET_FLIGHTS','UNIQUE_FLIGHT_CODE','ET_CUSTOMERS_TMP','UNIQUE_FLIGHT_CODE','TEXT',8,50,0,1,NULL,0,'default'),
('ET_USERS_WEB_TMP','TIME_ONLINE_SECONDS','ET_CUSTOMERS_TMP','TIME_ONLINE_SECONDS','int',9,50,0,1,NULL,0,'default'),
('ET_USERS_WEB_TMP','FIRST_APPEAR_DATE','ET_CUSTOMERS_TMP','FIRST_APPEAR_DATE','TEXT',10,50,0,1,NULL,0,'default'),
('ET_USERS_WEB_TMP','LAST_APPEAR_DATE','ET_CUSTOMERS_TMP','LAST_APPEAR_DATE','TEXT',11,50,0,1,NULL,0,'default'),
('','DATE(''now'')','ET_CUSTOMERS_TMP','DATE_CREATED','TEXT',12,50,0,1,NULL,0,'default'),
('','''metamorf_processor''','ET_CUSTOMERS_TMP','CREATED_BY','TEXT',13,50,0,1,NULL,0,'default');

INSERT INTO ENTRY_DV_ENTITY (COD_ENTITY,ENTITY_NAME,ENTITY_TYPE,COD_PATH,NAME_STATUS_TRACKING_SATELLITE,NAME_RECORD_TRACKING_SATELLITE,NAME_EFFECTIVITY_SATELLITE,OWNER) VALUES
	 ('ET_HUB_CUSTOMERS','HUB_CUSTOMER','HUB','RDV','STS_CUSTOMER','RTS_CUSTOMER','','default'),
	 ('ET_HUB_FLIGHTS','HUB_FLIGHTS','HUB','RDV','','','','default'),
	 ('ET_LINK_SELLS','LINK_SELLS','LINK','RDV','','RTS_SELLS','','default'),
	 ('ET_HUB_AIRPORTS','HUB_AIRPORTS','HUB','RDV','','RTS_AIRPORTS','','default'),
	 ('ET_LINK_AIRPORTS_FLIGHTS','LINK_AIRPORTS_FLIGHTS','LINK','RDV','','','SATE_AIRPORTS_FLIGHTS','default');


INSERT INTO ENTRY_DV_MAPPINGS (COD_ENTITY_SOURCE,COLUMN_NAME_SOURCE,COD_ENTITY_TARGET,COLUMN_NAME_TARGET,COLUMN_TYPE_TARGET,ORDINAL_POSITION,COLUMN_LENGTH,COLUMN_PRECISION,NUM_BRANCH,NUM_CONNECTION,"KEY_TYPE",SATELLITE_NAME,ORIGIN_IS_INCREMENTAL,ORIGIN_IS_TOTAL,ORIGIN_IS_CDC,OWNER) VALUES
	 ('ET_CUSTOMERS_TMP','NIE','ET_HUB_CUSTOMERS','NIE','TEXT','1',50,0,1,0,'BK','',0,1,0,'default'),
	 ('ET_CUSTOMERS_TMP','NAME','ET_HUB_CUSTOMERS','CUSTOMER_NAME','TEXT','2',50,0,1,0,'AT','SAT_CUSTOMER_INFO',0,1,0,'default'),
	 ('ET_CUSTOMERS_TMP','''prueba''','ET_HUB_CUSTOMERS','RECORD_SOURCE','TEXT','3',50,0,1,0,'RS','',0,1,0,'default'),
	 ('ET_CUSTOMERS_TMP','''bcn''','ET_HUB_CUSTOMERS','TENANT_CIUDAD','TEXT','4',50,0,1,0,'TN','',0,1,0,'default'),
	 ('ET_CUSTOMERS_TMP','''sitges''','ET_HUB_CUSTOMERS','TENANT_PUEBLO','TEXT','5',50,0,1,0,'TN','',0,1,0,'default'),
	 ('ET_CUSTOMERS_TMP','NATIONALITY','ET_HUB_CUSTOMERS','NATIONALITY','TEXT','7',50,0,1,0,'AT','SAT_CUSTOMER_LEGAL',0,1,0,'default'),
	 ('ET_CUSTOMERS_TMP','ADDRESS','ET_HUB_CUSTOMERS','ADDRESS','TEXT','8',50,0,1,0,'DCK','SAT_CUSTOMER_LEGAL',0,1,0,'default'),
	 ('ET_FLIGHTS_TMP','UNIQUE_FLIGHT_CODE','ET_HUB_FLIGHTS','UNIQUE_FLIGHT_CODE','TEXT','1',50,0,1,0,'BK','',0,0,1,'default'),
	 ('ET_FLIGHTS_TMP','ICAO_CARRIER_CODE','ET_HUB_FLIGHTS','ICAO_CARRIER_CODE','TEXT','1',50,0,1,0,'AT','SAT_FLIGHTS_ICAO',0,0,1,'default'),
	 ('ET_FLIGHTS_TMP','''vuelos''','ET_HUB_FLIGHTS','RECORD_SOURCE','TEXT','1',50,0,1,0,'RS','',0,0,1,'default'),
	 ('ET_CUSTOMERS_TMP','NIE','ET_LINK_SELLS','NIE','TEXT','1',50,0,1,1,'BK','',0,1,0,'default'),
	 ('ET_CUSTOMERS_TMP','UNIQUE_FLIGHT_CODE','ET_LINK_SELLS','UNIQUE_FLIGHT_CODE','TEXT','4',50,0,1,2,'BK','',0,1,0,'default'),
	 ('ET_CUSTOMERS_TMP','''bcn''','ET_LINK_SELLS','TENANT_CIUDAD','TEXT','2',50,0,1,1,'TN','',0,1,0,'default'),
	 ('ET_CUSTOMERS_TMP','''sitges''','ET_LINK_SELLS','TENANT_PUEBLO','TEXT','3',50,0,1,1,'TN','',0,1,0,'default'),
	 ('ET_CUSTOMERS_TMP','''fichero_1''','ET_LINK_SELLS','RECORD_SOURCE','TEXT','1',50,0,1,0,'RS','',0,1,0,'default'),
	 ('ET_CUSTOMERS_TMP','PRICE','ET_LINK_SELLS','PRICE','TEXT','5',50,0,1,0,'AT','SAT_SELL_PROPERTIES',0,1,0,'default'),
	 ('ET_CUSTOMERS_TMP','SELL_DATE','ET_LINK_SELLS','SELL_DATE','TEXT','6',50,0,1,0,'DCK','SAT_SELL_PROPERTIES',0,1,0,'default'),
	 ('ET_CUSTOMERS_TMP','PRICE','ET_LINK_SELLS','PRICE','TEXT','7',50,0,1,0,'AT','SAT_SELL_EVENT',0,1,0,'default'),
	 ('ET_CUSTOMERS_TMP','''bcn''','ET_LINK_SELLS','TENANT_CIUDAD','TEXT','5',50,0,1,2,'TN','',0,1,0,'default'),
	 ('ET_CUSTOMERS_TMP','''prueba''','ET_LINK_SELLS','TENANT_PUEBLO_SELLS','TEXT','6',50,0,1,2,'TN','',0,1,0,'default'),
	 ('ET_CUSTOMERS_TMP','SELL_DATE','ET_HUB_CUSTOMERS','APPLIED_DATE','TEXT','9',50,0,1,0,'AD','',0,1,0,'default'),
	 ('ET_CUSTOMERS_TMP','ID_CUSTOMER','ET_HUB_CUSTOMERS','NIE','TEXT','1',50,0,2,0,'BK','',0,1,0,'default'),
	 ('ET_CUSTOMERS_TMP','FIRST_APPEAR_DATE','ET_HUB_CUSTOMERS','APPLIED_DATE','TEXT','9',50,0,2,0,'AD','',0,1,0,'default'),
	 ('ET_CUSTOMERS_TMP','''prueba_2''','ET_HUB_CUSTOMERS','RECORD_SOURCE','TEXT','3',50,0,2,0,'RS','',0,1,0,'default'),
	 ('ET_CUSTOMERS_TMP','''bcn''','ET_HUB_CUSTOMERS','TENANT_CIUDAD','TEXT','4',50,0,2,0,'TN','',0,1,0,'default'),
	 ('ET_CUSTOMERS_TMP','''sitges''','ET_HUB_CUSTOMERS','TENANT_PUEBLO','TEXT','5',50,0,2,0,'TN','',0,1,0,'default'),
	 ('ET_CUSTOMERS_TMP','SELL_DATE','ET_LINK_SELLS','APPLIED_DATE','TEXT','1',50,0,1,0,'AD','',0,1,0,'default'),
	 ('ET_CUSTOMERS_TMP','LAST_APPEAR_DATE','ET_HUB_CUSTOMERS','LAST_APPEAR_DATE','TEXT','7',50,0,2,0,'AT','SAT_LAST_APPEAR_DATE',0,1,0,'default'),
	 ('ET_FLIGHTS','AIRPORT_ORIGIN_CODE','ET_HUB_AIRPORTS','AIRPORT_CODE','TEXT','0',50,0,1,0,'BK','',1,0,0,'default'),
	 ('ET_FLIGHTS','''origin airports''','ET_HUB_AIRPORTS','RECORD_SOURCE','TEXT','1',50,0,1,0,'RS','',1,0,0,'default'),
	 ('ET_FLIGHTS','AIRPORT_DEST_CODE','ET_HUB_AIRPORTS','AIRPORT_CODE','TEXT','0',50,0,2,0,'BK','',1,0,0,'default'),
	 ('ET_FLIGHTS','''dest airports''','ET_HUB_AIRPORTS','RECORD_SOURCE','TEXT','1',50,0,2,0,'RS','',1,0,0,'default'),
	 ('ET_FLIGHTS','DEPARTURE_TIME','ET_HUB_AIRPORTS','APPLIED_DATE','TEXT','0',50,0,2,0,'AD','',1,0,0,'default'),
	 ('ET_FLIGHTS','DEPARTURE_TIME','ET_HUB_AIRPORTS','APPLIED_DATE','TEXT','0',50,0,1,0,'AD','',1,0,0,'default'),
	 ('ET_FLIGHTS_TMP','''vuelos origin''','ET_LINK_AIRPORTS_FLIGHTS','RECORD_SOURCE','TEXT','0',50,0,1,0,'RS','',0,1,0,'default'),
	 ('ET_FLIGHTS_TMP','UNIQUE_FLIGHT_CODE','ET_LINK_AIRPORTS_FLIGHTS','UNIQUE_FLIGHT_CODE','TEXT','1',50,0,1,1,'DK','',0,1,0,'default'),
	 ('ET_FLIGHTS_TMP','AIRPORT_ORIGIN_CODE','ET_LINK_AIRPORTS_FLIGHTS','AIRPORT_CODE','TEXT','1',50,0,1,2,'BK','',0,1,0,'default'),
	 ('ET_FLIGHTS_TMP','UNIQUE_FLIGHT_CODE','ET_LINK_AIRPORTS_FLIGHTS','UNIQUE_FLIGHT_CODE','TEXT','1',50,0,2,1,'DK','',0,1,0,'default'),
	 ('ET_FLIGHTS_TMP','AIRPORT_DEST_CODE','ET_LINK_AIRPORTS_FLIGHTS','AIRPORT_CODE','TEXT','1',50,0,2,2,'BK','',0,1,0,'default'),
	 ('ET_FLIGHTS_TMP','''vuelos dest''','ET_LINK_AIRPORTS_FLIGHTS','RECORD_SOURCE','TEXT','0',50,0,2,0,'RS','',0,1,0,'default');

INSERT INTO ENTRY_DV_PROPERTIES (COD_ENTITY,NUM_CONNECTION,HASH_NAME,OWNER) VALUES
	 ('ET_HUB_CUSTOMERS','0','HASH_CUSTOMERS','default'),
	 ('ET_LINK_SELLS','1','HASH_CUSTOMERS','default'),
	 ('ET_LINK_SELLS','0','HASH_SELLS','default'),
	 ('ET_LINK_SELLS','2','HASH_FLIGHTS','default'),
	 ('ET_LINK_AIRPORTS_FLIGHTS','1','HASH_FLIGHTS','default'),
	 ('ET_LINK_AIRPORTS_FLIGHTS','2','HASH_AIRPORTS','default');