create table j3_canonicalization_method (
    id int8 not null,
    algorithm varchar(255),
    primary key (id)
);

create table j3_key_data_value (
    id int8 not null,
    key_data_name varchar(255),
    key_data_type varchar(255),
    key_data_value oid,
    key_data_value_string text,
    key_data_value_key int8,
    key_info_key int8,
    primary key (id)
);

create table j3_key_info (
    id int8 not null,
    xml_id varchar(255),
    primary key (id)
);

create table j3_object_type (
    id int8 not null,
    encoding varchar(255),
    mime_type varchar(255),
    xml_id varchar(255),
    signature_key int8 not null,
    primary key (id)
);

create table j3_object_type_content (
    id int8 not null,
    content oid,
    object_type_key int8 not null,
    primary key (id)
);

create table j3_reference (
    id int8 not null,
    digest_method varchar(255),
    digest_value oid,
    type varchar(255),
    uri varchar(255),
    xml_id varchar(255),
    signed_info_key int8 not null,
    primary key (id)
);

create table j3_signature (
    id int8 not null,
    xml_id varchar(255),
    binding_template_key varchar(255),
    business_key varchar(255),
    business_service_key varchar(255),
    key_info int8 not null,
    publisher_key varchar(255),
    signature_value int8 not null,
    signed_info int8 not null,
    tmodel_key varchar(255),
    primary key (id)
);

create table j3_signature_method (
    id int8 not null,
    algorithm varchar(255),
    primary key (id)
);

create table j3_signature_transform (
    id int8 not null,
    transform varchar(255),
    reference_key int8 not null,
    primary key (id)
);

create table j3_signature_transform_data (
    id int8 not null,
    content_bytes oid,
    content_type varchar(255),
    signature_transform_key int8 not null,
    primary key (id)
);

create table j3_signature_value (
    id int8 not null,
    value_bytes oid,
    xml_id varchar(255),
    primary key (id)
);

create table j3_signed_info (
    id int8 not null,
    xml_id varchar(255),
    canonicalization_method int8 not null,
    signature_method int8 not null,
    primary key (id)
);

alter table j3_key_data_value 
    add constraint FK74B7E072843143EF 
    foreign key (key_data_value_key) 
    references j3_key_data_value;

alter table j3_key_data_value 
    add constraint FK74B7E07238C90470 
    foreign key (key_info_key) 
    references j3_key_info;

alter table j3_object_type 
    add constraint FK98BBFA04BC6AD65 
    foreign key (signature_key) 
    references j3_signature;

alter table j3_object_type_content 
    add constraint FK987A913E71FA643E 
    foreign key (object_type_key) 
    references j3_object_type;

alter table j3_reference 
    add constraint FK493A4F951E480746 
    foreign key (signed_info_key) 
    references j3_signed_info;

alter table j3_signature 
    add constraint FKC05CA90256E87DED 
    foreign key (publisher_key) 
    references j3_publisher;

alter table j3_signature 
    add constraint FKC05CA90271CD8948 
    foreign key (binding_template_key) 
    references j3_binding_template;

alter table j3_signature 
    add constraint FKC05CA90212F40D40 
    foreign key (business_service_key) 
    references j3_business_service;

alter table j3_signature 
    add constraint FKC05CA9028ACE9A26 
    foreign key (signed_info) 
    references j3_signed_info;

alter table j3_signature 
    add constraint FKC05CA9027CE6418E 
    foreign key (signature_value) 
    references j3_signature_value;

alter table j3_signature 
    add constraint FKC05CA9025793CF55 
    foreign key (tmodel_key) 
    references j3_tmodel;

alter table j3_signature 
    add constraint FKC05CA902DA6C2DD0 
    foreign key (key_info) 
    references j3_key_info;

alter table j3_signature 
    add constraint FKC05CA902EF04CFEE 
    foreign key (business_key) 
    references j3_business_entity;

alter table j3_signature_transform 
    add constraint FK726346F9256790B 
    foreign key (reference_key) 
    references j3_reference;

alter table j3_signature_transform_data 
    add constraint FK3242526C7B88B2A4 
    foreign key (signature_transform_key) 
    references j3_signature_transform;

alter table j3_signed_info 
    add constraint FKD2E7E5BB877110CC 
    foreign key (canonicalization_method) 
    references j3_canonicalization_method;

alter table j3_signed_info 
    add constraint FKD2E7E5BB1A25896 
    foreign key (signature_method) 
    references j3_signature_method;
