alter table parents drop foreign key FKD0B60D09CCAD08CC;
alter table parents drop foreign key FKD0B60D098D2C51E3;
alter table hier_types_map drop foreign key FKB40BAF05D85CF9F0;
alter table hier_types_map drop foreign key FKB40BAF053679758C;
alter table nodes drop foreign key FK64212B13679758C;
alter table nodes drop foreign key FK64212B1D85CF9F0;
drop table if exists hierarchy;
drop table if exists parents;
drop table if exists node_type;
drop table if exists hier_types_map;
drop table if exists nodes;
create table hierarchy (
   hier_id varchar(32) not null,
   saved datetime not null,
   allow_multiple_parents bit,
   allow_recursion bit,
   description varchar(100),
   display_name varchar(100),
   isrecursive bit,
   primary key (hier_id)
);
create table parents (
   ref_node_id bigint not null,
   parent_node_id bigint not null,
   primary key (ref_node_id, parent_node_id)
);
create table node_type (
   authority varchar(100) not null,
   domain varchar(100) not null,
   keyword varchar(100) not null,
   saved datetime not null,
   description varchar(100),
   primary key (authority, domain, keyword)
);
create table hier_types_map (
   hier_id varchar(32) not null,
   authority varchar(100) not null,
   domain varchar(100) not null,
   keyword varchar(100) not null,
   primary key (hier_id, authority, domain, keyword)
);
create table nodes (
   node_id bigint not null auto_increment,
   saved datetime not null,
   hier_id varchar(32),
   user_node_id varchar(255),
   display_name varchar(100),
   description varchar(100),
   isroot bit,
   authority varchar(100),
   domain varchar(100),
   keyword varchar(100),
   primary key (node_id),
   unique (hier_id, user_node_id)
);
alter table parents add index FKD0B60D09CCAD08CC (ref_node_id), add constraint FKD0B60D09CCAD08CC foreign key (ref_node_id) references nodes (node_id);
alter table parents add index FKD0B60D098D2C51E3 (parent_node_id), add constraint FKD0B60D098D2C51E3 foreign key (parent_node_id) references nodes (node_id);
alter table hier_types_map add index FKB40BAF05D85CF9F0 (authority, domain, keyword), add constraint FKB40BAF05D85CF9F0 foreign key (authority, domain, keyword) references node_type (authority, domain, keyword);
alter table hier_types_map add index FKB40BAF053679758C (hier_id), add constraint FKB40BAF053679758C foreign key (hier_id) references hierarchy (hier_id);
alter table nodes add index FK64212B13679758C (hier_id), add constraint FK64212B13679758C foreign key (hier_id) references hierarchy (hier_id);
alter table nodes add index FK64212B1D85CF9F0 (authority, domain, keyword), add constraint FK64212B1D85CF9F0 foreign key (authority, domain, keyword) references node_type (authority, domain, keyword);
