-- eseguire come utente DBCGO

-- creazione sinonimi per i nuovi report di GESTIONE REPORT
CREATE PUBLIC SYNONYM MNP_DELIBERA_DON_VIRT_VIEW FOR MNP_DELIBERA_DON_VIRT_VIEW@DWH;
CREATE PUBLIC SYNONYM MNP_DWH_DON_DATI_RIF_VIRT_VIEW FOR MNP_DWH_DON_DATI_RIF_VIRT_VIEW@DWH;
CREATE PUBLIC SYNONYM MNP_DWH_DON_DATI_VIRT_VIEW FOR MNP_DWH_DON_DATI_VIRT_VIEW@DWH;
CREATE PUBLIC SYNONYM MNP_DWH_REC_DATI_RIF_VIRT_VIEW FOR MNP_DWH_REC_DATI_RIF_VIRT_VIEW@DWH;
CREATE PUBLIC SYNONYM MNP_DWH_REC_DATI_VIRT_VIEW FOR MNP_DWH_REC_DATI_VIRT_VIEW@DWH;
CREATE PUBLIC SYNONYM MNP_RECIPIENT_CANALE_VIRT_VIEW FOR MNP_RECIPIENT_CANALE_VIRT_VIEW@DWH;
CREATE PUBLIC SYNONYM MNP_MOB_INT_VIRT_VIEW FOR MNP_MOB_INT_VIRT_VIEW@DWH;

------------------ per recuperare credito anomalo e nome file ------------------------
CREATE PUBLIC SYNONYM MNP_DWH_XML_IN FOR MNP_DWH_XML_IN@DWH;
CREATE PUBLIC SYNONYM MNP_DWH_TC_ANOMALO FOR MNP_DWH_TC_ANOMALO@DWH;
------------------ per recuperare data cessazione e attivazione ricevuto da MSS
CREATE PUBLIC SYNONYM MNP_DWH_MSS_CESS_IN_VIEW FOR MNP_DWH_MSS_CESS_IN_VIEW@DWH;
CREATE PUBLIC SYNONYM MNP_DWH_MSS_ATT_IN_VIEW FOR MNP_DWH_MSS_ATT_IN_VIEW@DWH;


-----------------------------------------------------------
----- creazione nuove tabelle stato -----------------------

--------------- DBCGO_STATO_TC ----------------------------
CREATE TABLE DBCGO_STATO_TC
(
  ID_STATO     NUMBER(5)                        NOT NULL,
  DESCR_STATO  VARCHAR2(40 BYTE)                NOT NULL
)
TABLESPACE DBCGO_DATA_SMALL
LOGGING 
NOCACHE
NOPARALLEL;

ALTER TABLE DBCGO_STATO_TC ADD (
  CONSTRAINT PK_DBCGO_STATO_TC PRIMARY KEY (ID_STATO ) 
USING INDEX 
TABLESPACE DBCGO_IDX_SMALL);
	
--------------- DBCGO_STATO_MAPPING_DON_RECV -------------

CREATE TABLE DBCGO_STATO_MAPPING_DON_RECV
(
  ID_STATO NUMBER(5)     NOT NULL,
  DESCR VARCHAR2(40) NOT NULL,
  ID_STATO_DONOR NUMBER(5)   ,
  id_stato_rec_virt NUMBER(5)   ,
  id_stato_tc NUMBER(5)
)
TABLESPACE DBCGO_DATA_SMALL
LOGGING 
NOCACHE
NOPARALLEL;

ALTER TABLE DBCGO_STATO_MAPPING_DON_RECV ADD (
  CONSTRAINT PK_DBCGO_STATO_MAPPING_D_RV PRIMARY KEY (ID_STATO ) 
USING INDEX 
TABLESPACE DBCGO_IDX_SMALL);

ALTER TABLE DBCGO_STATO_MAPPING_DON_RECV ADD (
  CONSTRAINT FK_STATO_DONOR FOREIGN KEY (ID_STATO_DONOR) 
    REFERENCES DBCGO_STATO (ID_STATO));
	
ALTER TABLE DBCGO_STATO_MAPPING_DON_RECV ADD (
  CONSTRAINT fk_stato_rec_virt  FOREIGN KEY ( ID_STATO_rec_virt)  REFERENCES DBCGO_STATO_REC_VIRT (ID_STATO));

ALTER TABLE DBCGO_STATO_MAPPING_DON_RECV ADD (
  CONSTRAINT fk_stato_tc  FOREIGN KEY ( ID_STATO_tc)  REFERENCES DBCGO_STATO_TC (ID_STATO));

--------------- DBCGO_STATO_MAPPING_REC_DONV -------------

CREATE TABLE DBCGO_STATO_MAPPING_REC_DONV
(
  ID_STATO NUMBER(5)     NOT NULL,
  DESCR VARCHAR2(40) NOT NULL,
  ID_STATO_RECIPIENT NUMBER(5)   ,
  id_stato_DON_virt NUMBER(5)   ,
  id_stato_tc NUMBER(5)
)
TABLESPACE DBCGO_DATA_SMALL
LOGGING 
NOCACHE
NOPARALLEL;

ALTER TABLE DBCGO_STATO_MAPPING_REC_DONV ADD (
  CONSTRAINT PK_DBCGO_STATO_MAPPING_R_D_V PRIMARY KEY (ID_STATO ) 
USING INDEX 
TABLESPACE DBCGO_IDX_SMALL);

ALTER TABLE DBCGO_STATO_MAPPING_REC_DONV ADD (
  CONSTRAINT FK_STATO_RECIPIENT FOREIGN KEY (ID_STATO_RECIPIENT) 
    REFERENCES DBCGO_STATO_REC (ID_STATO));
	
ALTER TABLE DBCGO_STATO_MAPPING_REC_DONV ADD (
  CONSTRAINT fk_stato_DON_virt  FOREIGN KEY ( id_stato_DON_virt)  REFERENCES DBCGO_STATO_DON_VIRT (ID_STATO));

ALTER TABLE DBCGO_STATO_MAPPING_REC_DONV ADD (
  CONSTRAINT fk_stato_tc1  FOREIGN KEY ( ID_STATO_tc)  REFERENCES DBCGO_STATO_TC (ID_STATO));










------------------------------------------------------------------------
------------------ nuovo rilascio kit luglio 2010 ------------------

------------------ DBCGO_STATO_MAPPING_REC_MVNO ---------------------
CREATE TABLE DBCGO_STATO_MAPPING_REC_MVNO
(
  ID_STATO NUMBER(5)     NOT NULL,
  DESCR VARCHAR2(40) NOT NULL,
  ID_STATO_REC NUMBER(5)   ,
  id_stato_rec_virt_m2m NUMBER(5) 
)
TABLESPACE DBCGO_DATA_SMALL
LOGGING 
NOCACHE
NOPARALLEL;

ALTER TABLE DBCGO_STATO_MAPPING_REC_MVNO ADD (
  CONSTRAINT PK_DBCGO_STATO_MAPPING_R_MVNO PRIMARY KEY (ID_STATO ) 
USING INDEX 
TABLESPACE DBCGO_IDX_SMALL);

ALTER TABLE DBCGO_STATO_MAPPING_REC_MVNO ADD (
  CONSTRAINT FK_STATO_REC FOREIGN KEY (ID_STATO_REC) 
    REFERENCES DBCGO_STATO_REC (ID_STATO));
	
ALTER TABLE DBCGO_STATO_MAPPING_REC_MVNO ADD (
  CONSTRAINT fk_stato_rec_virt_m2m  FOREIGN KEY ( ID_STATO_rec_virt_m2m)  REFERENCES DBCGO_STATO_REC_VIRT_M2M (ID_STATO));


------------------ DBCGO_STATO_MAPPING_DON_MVNO ---------------------
CREATE TABLE DBCGO_STATO_MAPPING_DON_MVNO
(
  ID_STATO NUMBER(5)     NOT NULL,
  DESCR VARCHAR2(40) NOT NULL,
  ID_STATO_DON NUMBER(5)   ,
  id_stato_don_virt NUMBER(5) ,
  id_stato_virt_m2m NUMBER(5) 
)
TABLESPACE DBCGO_DATA_SMALL
LOGGING 
NOCACHE
NOPARALLEL;

ALTER TABLE DBCGO_STATO_MAPPING_DON_MVNO ADD (
  CONSTRAINT PK_DBCGO_STATO_MAPPING_D_MVNO PRIMARY KEY (ID_STATO ) 
USING INDEX 
TABLESPACE DBCGO_IDX_SMALL);

ALTER TABLE DBCGO_STATO_MAPPING_DON_MVNO ADD (
  CONSTRAINT FK_STATO_DON FOREIGN KEY (ID_STATO_DON) 
    REFERENCES DBCGO_STATO (ID_STATO));
	
ALTER TABLE DBCGO_STATO_MAPPING_DON_MVNO ADD (
  CONSTRAINT fk_stato_don_virt1  FOREIGN KEY ( ID_STATO_don_virt)  REFERENCES DBCGO_STATO_DON_VIRT (ID_STATO));
  
ALTER TABLE DBCGO_STATO_MAPPING_DON_MVNO ADD (
  CONSTRAINT fk_stato_virt_m2m  FOREIGN KEY ( ID_STATO_virt_m2m)  REFERENCES DBCGO_STATO_REC_VIRT_M2M (ID_STATO));

------------------ per recuperare data_presa_in_carico e ricevuta_adhoc ----------------------------------
CREATE PUBLIC SYNONYM MNP_DWH_RICH_REC_VIRT_EXT FOR MNP_DWH_RICH_REC_VIRT_EXT@DWH;
CREATE PUBLIC SYNONYM MNP_DWH_RICH_DON_VIRT_EXT FOR MNP_DWH_RICH_DON_VIRT_EXT@DWH;
------------------ per recuperare DATA_VALIDAZIONE_EFF, BUSINESS_ID, FLAG_ESP ----------------------------------
CREATE PUBLIC SYNONYM MNP_DWH_gest_rich_rec_ext FOR MNP_DWH_gest_rich_rec_ext@DWH;
CREATE PUBLIC SYNONYM MNP_DWH_gest_rich_don_ext FOR MNP_DWH_gest_rich_don_ext@DWH;



