/**
  @file
  @brief migration script to move from v6.8.2 to v7.0 of data controller

  BREAKING CHANGE - 1 new column and 4 additional tables for capturing catalogs

  Be sure to run this using the correct system account
  (eg the regular DC account)

  On SAS 9 you may wish to run proc metalib or refresh in DI Studio afterwards
  to see the new tables in the VIEW page

      proc metalib;
        omr (library="&DC_LIBNAME");
        folder="&root/data";
        update_rule=(delete);
      run;

**/

%let dclib=YOURDCLIB;

libname &dclib "/YOUR/DATACONTROLLER/LIBRARY/PATH";

proc sql;
create table work.BACKUP as select * from &dclib..mpe_datastatus_libs;
alter table &dclib..mpe_datastatus_libs add catalog_cnt num;

create table &dclib..mpe_datacatalog_CATS(
    TX_FROM float format=datetime19.,
    TX_TO float format=datetime19.,
    libref char(8) label='Library Name',
    memname char(64) label='Member Name',
  constraint pk_mpe_datacatalog_CATS
      primary key(libref,memname,tx_to));

create table &dclib..mpe_datacatalog_OBJS(
    TX_FROM float format=datetime19.,
    TX_TO float format=datetime19.,
    libref char(8) label='Library Name',
    memname char(64) label='Member Name',
    objname char(32) label='Object Name',
    objtype char(8) label='Object Type',
    objdesc char(256) label='Object Description',
    alias char(32) label='Object Alias',
  constraint pk_mpe_datacatalog_OBJS
      primary key(libref,memname,objname,objtype,tx_to));

create table &dclib..mpe_datastatus_CATS(
    TX_FROM float format=datetime19.,
    TX_TO float format=datetime19.,
    libref char(8) label='Library Name',
    memname char(64) label='Member Name',
    nobjs num label='Number of objects',
    created num format=DATETIME. label='Date Created',
    modified num format=DATETIME. label='Date Modified',
  constraint pk_mpe_datastatus_CATS
      primary key(libref,memname,tx_to));

create table &dclib..mpe_datastatus_OBJS(
    TX_FROM float format=datetime19.,
    TX_TO float format=datetime19.,
    libref char(8) label='Library Name',
    memname char(64) label='Member Name',
    objname char(32) label='Object Name',
    objtype char(8) label='Object Type',
    created num format=DATETIME. label='Date Created',
    modified num format=DATETIME. label='Date Modified',
    level num label='Library Concatenation Level',
  constraint pk_mpe_datastatus_OBJS
      primary key(libref,memname,objname,objtype,tx_to));