alter table DT870 add PORTFOLIO_PICTURE uniqueidentifier;

create table PORTFOLIO_CTG (
    [UUID] uniqueidentifier not null,
    [COST_TYPE_GROUP_ID] varchar(20) not null,
    [PORTFOLIO_ID] varchar(18) not null,
    [OS_CREATED_ON] datetime2,
    [OS_MODIFIED_ON] datetime2,
    [OS_RWDU] numeric(5,0),
    [OS_CREATED_BY] varchar(20),
    [OS_MODIFIED_BY] varchar(20),
    [OS_OWN_LIC] varchar(4),
    [OS_OPC] varchar(8),
    [OS_OWNER] numeric(5,0),
    [OS_GROUP] numeric(5,0),
    [OS_ANY] numeric(5,0),
    [COST_TYPE_GROUP_ACTIVE] numeric(5,0)
);
alter table PORTFOLIO_CTG add constraint PID096DT096 primary key ([COST_TYPE_GROUP_ID], [PORTFOLIO_ID]);

create index IDX_PORTFOLIO_CTGID280 on PORTFOLIO_CTG ([COST_TYPE_GROUP_ID]);

create index IDX_PORTFOLIO_CTGID870 on PORTFOLIO_CTG ([PORTFOLIO_ID]);

alter table PORTFOLIO_CTG
    add constraint DT096UUID_DEFAULT DEFAULT newid() FOR [UUID];

alter table PORTFOLIO_CTG
    add constraint DT096UUID_NOT_NULL check([UUID] is not null);

alter table PORTFOLIO_CTG
    add constraint DT096COST_TYPE_GROUP_ID_NOT check([COST_TYPE_GROUP_ID] is not null);

alter table PORTFOLIO_CTG
    add constraint DT096PORTFOLIO_ID_NOT_NULL check([PORTFOLIO_ID] is not null);

alter table PORTFOLIO_CTG
    add constraint DT096DI064401_DEFAULT DEFAULT CONVERT(datetime2,'01.01.1970',104) FOR [OS_CREATED_ON];

alter table PORTFOLIO_CTG
    add constraint DT096DI064402_DEFAULT DEFAULT CONVERT(datetime2,'01.01.1970',104) FOR [OS_MODIFIED_ON];

alter table PORTFOLIO_CTG
    add constraint DT096DI064403_DEFAULT DEFAULT 0 FOR [OS_RWDU];

alter table PORTFOLIO_CTG
    add constraint DT096DI064408_DEFAULT DEFAULT 0 FOR [OS_OWNER];

alter table PORTFOLIO_CTG
    add constraint DT096DI064409_DEFAULT DEFAULT 0 FOR [OS_GROUP];

alter table PORTFOLIO_CTG
    add constraint DT096DI064410_DEFAULT DEFAULT 0 FOR [OS_ANY];

alter table PORTFOLIO_CTG
    add constraint DT096DI064368_DEFAULT DEFAULT 0 FOR [COST_TYPE_GROUP_ACTIVE];

    create table PF_REPORT_CTG (
        [UUID] uniqueidentifier not null,
        [COST_TYPE_GROUP_ID] varchar(20) not null,
        [STATUSREPORT_ID] varchar(10) not null,
        [PORTFOLIO_ID] varchar(18) not null,
        [OS_CREATED_ON] datetime2,
        [OS_MODIFIED_ON] datetime2,
        [OS_RWDU] numeric(5,0),
        [OS_CREATED_BY] varchar(20),
        [OS_MODIFIED_BY] varchar(20),
        [OS_OWN_LIC] varchar(4),
        [OS_OPC] varchar(8),
        [OS_OWNER] numeric(5,0),
        [OS_GROUP] numeric(5,0),
        [OS_ANY] numeric(5,0),
        [COST_TYPE_GROUP_ACTIVE] numeric(5,0)
    );

alter table PF_REPORT_CTG add constraint PID097DT097 primary key ([COST_TYPE_GROUP_ID], [STATUSREPORT_ID], [PORTFOLIO_ID]);

create index IDX_PF_REPORT_CTGID280 on PF_REPORT_CTG ([COST_TYPE_GROUP_ID]);

create index IDX_PF_REPORT_CTGID090 on PF_REPORT_CTG ([STATUSREPORT_ID], [PORTFOLIO_ID]);

alter table PF_REPORT_CTG
    add constraint UUID_UNIQUE_097  unique ([UUID]);

alter table PF_REPORT_CTG
    add constraint DT097UUID_DEFAULT DEFAULT newid() FOR [UUID];

alter table PF_REPORT_CTG
    add constraint DT097UUID_NOT_NULL check([UUID] is not null);

alter table PF_REPORT_CTG
    add constraint DT097COST_TYPE_GROUP_ID_NOT check([COST_TYPE_GROUP_ID] is not null);

alter table PF_REPORT_CTG
    add constraint DT097STATUSREPORT_ID_NOT_NULL check([STATUSREPORT_ID] is not null);

alter table PF_REPORT_CTG
    add constraint DT097PORTFOLIO_ID_NOT_NULL check([PORTFOLIO_ID] is not null);

alter table PF_REPORT_CTG
    add constraint DT097DI064422_DEFAULT DEFAULT CONVERT(datetime2,'01.01.1970',104) FOR [OS_CREATED_ON];

alter table PF_REPORT_CTG
    add constraint DT097DI064421_DEFAULT DEFAULT CONVERT(datetime2,'01.01.1970',104) FOR [OS_MODIFIED_ON];

alter table PF_REPORT_CTG
    add constraint DT097DI064420_DEFAULT DEFAULT 0 FOR [OS_RWDU];

alter table PF_REPORT_CTG
    add constraint DT097DI064415_DEFAULT DEFAULT 0 FOR [OS_OWNER];

alter table PF_REPORT_CTG
    add constraint DT097DI064414_DEFAULT DEFAULT 0 FOR [OS_GROUP];

alter table PF_REPORT_CTG
    add constraint DT097DI064413_DEFAULT DEFAULT 0 FOR [OS_ANY];

alter table PF_REPORT_CTG
    add constraint DT097DI064412_DEFAULT DEFAULT 0 FOR [COST_TYPE_GROUP_ACTIVE];

create table USERPROJECTPORTFOLIO (
    [UUID] uniqueidentifier not null,
    [PR_ID] varchar(18) not null,
    [PORTFOLIO_ID] varchar(18) not null,
    [USER_ID] varchar(20) not null,
    [OS_CREATED_ON] datetime2,
    [OS_MODIFIED_ON] datetime2,
    [OS_RWDU] numeric(5,0),
    [OS_CREATED_BY] varchar(20),
    [OS_MODIFIED_BY] varchar(20),
    [OS_LICENSE] varchar(4),
    [OS_OPC] varchar(8),
    [OS_OWNER] numeric(5,0),
    [OS_GROUP] numeric(5,0),
    [OS_ANY] numeric(5,0)
);

alter table USERPROJECTPORTFOLIO add constraint PID534DT534 primary key ([PR_ID], [PORTFOLIO_ID], [USER_ID]);

create index IDX_USERPROJECTPORTFOLIOID858 on USERPROJECTPORTFOLIO ([PR_ID], [PORTFOLIO_ID]);

create index IDX_USERPROJECTPORTFOLIOID511 on USERPROJECTPORTFOLIO ([USER_ID]);

alter table USERPROJECTPORTFOLIO
    add constraint UUID_UNIQUE_534  unique ([UUID]);

alter table USERPROJECTPORTFOLIO
    add constraint DT534UUID_DEFAULT DEFAULT newid() FOR [UUID];

alter table USERPROJECTPORTFOLIO
    add constraint DT534UUID_NOT_NULL check([UUID] is not null);

alter table USERPROJECTPORTFOLIO
    add constraint DT534PR_ID_NOT_NULL check([PR_ID] is not null);

alter table USERPROJECTPORTFOLIO
    add constraint DT534PORTFOLIO_ID_NOT_NULL check([PORTFOLIO_ID] is not null);

alter table USERPROJECTPORTFOLIO
    add constraint DT534DI064480_DEFAULT DEFAULT CONVERT(datetime2,'01.01.1970',104) FOR [OS_CREATED_ON];

alter table USERPROJECTPORTFOLIO
    add constraint DT534DI064479_DEFAULT DEFAULT CONVERT(datetime2,'01.01.1970',104) FOR [OS_MODIFIED_ON];

alter table USERPROJECTPORTFOLIO
    add constraint DT534DI064478_DEFAULT DEFAULT 0 FOR [OS_RWDU];

alter table USERPROJECTPORTFOLIO
    add constraint DT534DI064473_DEFAULT DEFAULT 0 FOR [OS_OWNER];

alter table USERPROJECTPORTFOLIO
    add constraint DT534DI064472_DEFAULT DEFAULT 0 FOR [OS_GROUP];

alter table USERPROJECTPORTFOLIO
    add constraint DT534DI064471_DEFAULT DEFAULT 0 FOR [OS_ANY];

alter table DT858 add MANAGER_COMMENT varchar(max);

alter table DT093 add MANAGER_COMMENT varchar(max);

create table PICTURE (
    [UUID] uniqueidentifier not null,
    [OS_CREATED_ON] datetime2,
    [OS_MODIFIED_ON] datetime2,
    [OS_RWDU] numeric(5,0),
    [OS_CREATED_BY] varchar(20),
    [OS_MODIFIED_BY] varchar(20),
    [OS_OWN_LIC] varchar(4),
    [OS_OPC] varchar(8),
    [OS_OWNER] numeric(5,0),
    [OS_GROUP] numeric(5,0),
    [OS_ANY] numeric(5,0),
    [NAME] numeric(10,0),
    [PICTURE] numeric(10,0),
    [PICTURE_TYPE] numeric(5,0),
    [DEFAULT_PICTURE] numeric(5,0)
);

alter table PICTURE add constraint PID098DT098 primary key ([UUID]);

create index IDX_ITEXT_DT098NAME on PICTURE ([NAME]);

alter table PICTURE
    add constraint DT098UUID_DEFAULT DEFAULT newid() FOR [UUID];

alter table PICTURE
    add constraint DT098UUID_NOT_NULL check([UUID] is not null);

alter table PICTURE
    add constraint DT098DI064692_DEFAULT DEFAULT CONVERT(datetime2,'01.01.1970',104) FOR [OS_CREATED_ON];

alter table PICTURE
    add constraint DT098DI064691_DEFAULT DEFAULT CONVERT(datetime2,'01.01.1970',104) FOR [OS_MODIFIED_ON];

alter table PICTURE
    add constraint DT098DI064690_DEFAULT DEFAULT 0 FOR [OS_RWDU];

alter table PICTURE
    add constraint DT098DI064685_DEFAULT DEFAULT 0 FOR [OS_OWNER];

alter table PICTURE
    add constraint DT098DI064684_DEFAULT DEFAULT 0 FOR [OS_GROUP];

alter table PICTURE
    add constraint DT098DI064683_DEFAULT DEFAULT 0 FOR [OS_ANY];

alter table PICTURE
    add constraint DT098DI064695_DEFAULT DEFAULT 0 FOR [PICTURE];

alter table PICTURE
    add constraint DT098DI064723_DEFAULT DEFAULT 0 FOR [PICTURE_TYPE];

alter table PICTURE
    add constraint DT098DI064724_DEFAULT DEFAULT 0 FOR [DEFAULT_PICTURE];
