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

create table j3_key_data_value (
    id bigint not null auto_increment,
    key_data_name varchar(255),
    key_data_type varchar(255),
    key_data_value longblob,
    key_data_value_string longtext,
    key_data_value_key bigint,
    key_info_key bigint,
    primary key (id)
);

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

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

create table j3_object_type_content (
    id bigint not null auto_increment,
    content longblob,
    object_type_key bigint not null,
    primary key (id)
);

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

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

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

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

create table j3_signature_transform_data (
    id bigint not null auto_increment,
    content_bytes longblob,
    content_type varchar(255),
    signature_transform_key bigint not null,
    primary key (id)
);

create table j3_signature_value (
    id bigint not null auto_increment,
    value_bytes longblob,
    xml_id varchar(255),
    primary key (id)
);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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