alter table meal drop constraint meal_user_fk;
alter table mealrecipe drop constraint mealrecipe_recipe_fk;
alter table mealrecipe drop constraint mealrecipe_course_fk;
alter table mealrecipe drop constraint mealrecipe_meal_fk;
alter table recipe drop constraint recipe_ethnicity_fk;
alter table recipe drop constraint recipe_preptime_fk;
alter table recipe drop constraint recipe_base_fk;
alter table recipe drop constraint recipe_user_fk;
alter table recipe drop constraint recipe_course_fk;
alter table recipe drop constraint recipe_difficulty_fk;
alter table recipe drop constraint recipe_system_fk;
alter table recipecomment drop constraint recipecomment_recipe_fk;
alter table recipeingredient drop constraint recipeingredient_recipe_fk;
alter table recipeingredient drop constraint recipeingredient_unit_fk;
alter table recipeingredient drop constraint recipeingredient_ingredientrecipe_fk;
alter table recipeingredient drop constraint recipeingredient_ingredient_fk;
alter table reciperating drop constraint reciperating_recipe_fk;
alter table recipestep drop constraint recipestep_recipe_fk;
alter table relatedrecipe drop constraint relatedrecipe_recipe_fk;
alter table relatedrecipe drop constraint relatedrecipe_relationkind_fk;
drop table base;
drop table course;
drop table difficulty;
drop table ethnicity;
drop table ingredient;
drop table meal;
drop table mealrecipe;
drop table measurement_system;
drop table preptime;
drop table recipe;
drop table recipecomment;
drop table recipeingredient;
drop table reciperating;
drop table recipestep;
drop table relatedrecipe;
drop table relationkind;
drop table unit;
drop table users;
drop sequence hibernate_integer_seq;
drop sequence hibernate_sequence;
create table base (baseid int4 not null, Value_ varchar(255), primary key (baseid));
create table course (courseid int4 not null, Value_ varchar(255), primary key (courseid));
create table difficulty (difficultyid int4 not null, Value_ varchar(255), primary key (difficultyid));
create table ethnicity (ethnicityid int4 not null, Value_ varchar(255), primary key (ethnicityid));
create table ingredient (ingredientid int4 not null, description varchar(512), ingr_name varchar(128) not null, primary key (ingredientid));
create table meal (mealid int8 not null, ownerid int4, meal_name varchar(128) not null, primary key (mealid));
create table mealrecipe (mealrecipeid int8 not null, recipeid int8, courseid int4, quantity float8, mealid int8, pos int4, primary key (mealrecipeid));
create table measurement_system (systemid int4 not null, Value_ varchar(255), primary key (systemid));
create table preptime (preptimeid int4 not null, Value_ varchar(255), primary key (preptimeid));
create table recipe (recipeid int8 not null, ownerid int4, image varchar(255), excerpt text, source varchar(128), courseid int4, systemid int4, directions text, baseid int4, preptimeid int4, ethnicityid int4, createddate timestamp, servingsize int4 not null, recipe_name varchar(128) not null, modifieddate timestamp, difficultyid int4, primary key (recipeid));
create table recipecomment (commentid int8 not null, Value_ varchar(255), userid int4 not null, createddate timestamp not null, recipeid int8, pos int4, primary key (commentid));
create table recipeingredient (recipeingredientid int8 not null, ingredientid int4, unitid int4, optional bool not null, ingredientrecipeid int8, qualifier varchar(255), quantity float8 not null, recipeid int8, pos int4, primary key (recipeingredientid));
create table reciperating (ratingid int8 not null, userid int4 not null, createddate timestamp not null, rating int2 not null, recipeid int8, pos int4, primary key (ratingid));
create table recipestep (stepid int8 not null, Value_ varchar(255), recipeid int8, pos int4, primary key (stepid));
create table relatedrecipe (relatedrecipeid int8 not null, relationkindid int4, recipeid int8, pos int4, primary key (relatedrecipeid));
create table relationkind (relationkindid int4 not null, Value_ varchar(255), primary key (relationkindid));
create table unit (unitid int4 not null, Value_ varchar(255), abbreviation varchar(8) not null, mass bool not null, tometric float8, tous float8, toimperial float8, systemid int4, primary key (unitid));
create table users (userid int4 not null, password varchar(64) not null, email varchar(128) not null, createddate timestamp not null, country varchar(3) not null, accesslevel int4, lastlogindate timestamp, user_name varchar(64) not null, login varchar(32) not null, language varchar(3) not null, primary key (userid));
alter table meal add constraint meal_user_fk foreign key (ownerid) references users;
alter table mealrecipe add constraint mealrecipe_recipe_fk foreign key (recipeid) references recipe;
alter table mealrecipe add constraint mealrecipe_course_fk foreign key (courseid) references course;
alter table mealrecipe add constraint mealrecipe_meal_fk foreign key (mealid) references meal;
alter table recipe add constraint recipe_ethnicity_fk foreign key (ethnicityid) references ethnicity;
alter table recipe add constraint recipe_preptime_fk foreign key (preptimeid) references preptime;
alter table recipe add constraint recipe_base_fk foreign key (baseid) references base;
alter table recipe add constraint recipe_user_fk foreign key (ownerid) references users;
alter table recipe add constraint recipe_course_fk foreign key (courseid) references course;
alter table recipe add constraint recipe_difficulty_fk foreign key (difficultyid) references difficulty;
alter table recipe add constraint recipe_system_fk foreign key (systemid) references measurement_system;
alter table recipecomment add constraint recipecomment_recipe_fk foreign key (recipeid) references recipe;
alter table recipeingredient add constraint recipeingredient_recipe_fk foreign key (recipeid) references recipe;
alter table recipeingredient add constraint recipeingredient_unit_fk foreign key (unitid) references unit;
alter table recipeingredient add constraint recipeingredient_ingredientrecipe_fk foreign key (ingredientrecipeid) references recipe;
alter table recipeingredient add constraint recipeingredient_ingredient_fk foreign key (ingredientid) references ingredient;
alter table reciperating add constraint reciperating_recipe_fk foreign key (recipeid) references recipe;
alter table recipestep add constraint recipestep_recipe_fk foreign key (recipeid) references recipe;
alter table relatedrecipe add constraint relatedrecipe_recipe_fk foreign key (recipeid) references recipe;
alter table relatedrecipe add constraint relatedrecipe_relationkind_fk foreign key (relationkindid) references relationkind;
create sequence hibernate_integer_seq;
create sequence hibernate_sequence;
