--
-- Properly set up C2D UC Dissem
--

-- 1. Create Template table CT_TEMPLTATE_TABLES.C2D_A_UC_DISSEM_METADATA_LOADS

CREATE TABLE CT_ET_TEMPLATES.C2D_A_UC_DISSEM_METADATA_LOADS
   AS SELECT * FROM OU_C2D.A_UC_DISSEM_METADATA_LOADS WHERE 1=2;

-- 2. Create external tables

EXEC CT_MRDS.FILE_MANAGER.CREATE_EXTERNAL_TABLE('C2D_A_UC_DISSEM_METADATA_LOADS_INBOX','CT_ET_TEMPLATES.C2D_A_UC_DISSEM_METADATA_LOADS','INBOX/C2D/UC_DISSEM/A_UC_DISSEM_METADATA_LOADS');
EXEC CT_MRDS.FILE_MANAGER.CREATE_EXTERNAL_TABLE('C2D_A_UC_DISSEM_METADATA_LOADS_ODS','CT_ET_TEMPLATES.C2D_A_UC_DISSEM_METADATA_LOADS','ODS/C2D/UC_DISSEM/A_UC_DISSEM_METADATA_LOADS');
EXEC CT_MRDS.FILE_MANAGER.CREATE_EXTERNAL_TABLE('C2D_A_UC_DISSEM_METADATA_LOADS_ARCHIVE','CT_ET_TEMPLATES.C2D_A_UC_DISSEM_METADATA_LOADS','ARCHIVE/C2D/A_UC_DISSEM_METADATA_LOADS');

-- 3. Export table OU_C2D.A_UC_DISSEM_METADATA_LOADS

EXEC CT_MRDS.FILE_MANAGER.EXPORT_TABLE_DATA_BY_DATE('OU_C2D','A_UC_DISSEM_METADATA_LOADS','A_ETL_LOAD_SET_FK','mrds_inbox_tst','ARCHIVE/C2D/A_UC_DISSEM_METADATA_LOADS');

-- 4. Rename table to legacy table

ALTER TABLE OU_C2D.A_UC_DISSEM_METADATA_LOADS RENAME TO A_UC_DISSEM_METADATA_LOADS_LEGACY;

-- 5. Create OU view on top of ODS table

GRANT SELECT ON ods.C2D_A_UC_DISSEM_METADATA_LOADS_ODS TO OU_C2D;
create or replace view OU_C2D.A_UC_DISSEM_METADATA_LOADS AS SELECT * from ods.C2D_A_UC_DISSEM_METADATA_LOADS_ODS;
show errors
