create.sql 8.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. alter table meal drop foreign key meal_user_fk;
  2. alter table mealrecipe drop foreign key mealrecipe_recipe_fk;
  3. alter table mealrecipe drop foreign key mealrecipe_course_fk;
  4. alter table mealrecipe drop foreign key mealrecipe_meal_fk;
  5. alter table recipe drop foreign key recipe_ethnicity_fk;
  6. alter table recipe drop foreign key recipe_preptime_fk;
  7. alter table recipe drop foreign key recipe_base_fk;
  8. alter table recipe drop foreign key recipe_user_fk;
  9. alter table recipe drop foreign key recipe_course_fk;
  10. alter table recipe drop foreign key recipe_difficulty_fk;
  11. alter table recipe drop foreign key recipe_system_fk;
  12. alter table recipecomment drop foreign key recipecomment_recipe_fk;
  13. alter table recipeingredient drop foreign key recipeingredient_recipe_fk;
  14. alter table recipeingredient drop foreign key recipeingredient_unit_fk;
  15. alter table recipeingredient drop foreign key recipeingredient_ingredientrecipe_fk;
  16. alter table recipeingredient drop foreign key recipeingredient_ingredient_fk;
  17. alter table reciperating drop foreign key reciperating_recipe_fk;
  18. alter table recipestep drop foreign key recipestep_recipe_fk;
  19. alter table relatedrecipe drop foreign key relatedrecipe_recipe_fk;
  20. alter table relatedrecipe drop foreign key relatedrecipe_relationkind_fk;
  21. drop table if exists base;
  22. drop table if exists course;
  23. drop table if exists difficulty;
  24. drop table if exists ethnicity;
  25. drop table if exists ingredient;
  26. drop table if exists meal;
  27. drop table if exists mealrecipe;
  28. drop table if exists measurement_system;
  29. drop table if exists preptime;
  30. drop table if exists recipe;
  31. drop table if exists recipecomment;
  32. drop table if exists recipeingredient;
  33. drop table if exists reciperating;
  34. drop table if exists recipestep;
  35. drop table if exists relatedrecipe;
  36. drop table if exists relationkind;
  37. drop table if exists unit;
  38. drop table if exists users;
  39. create table base (baseid integer not null auto_increment, Value_ varchar(255), primary key (baseid));
  40. create table course (courseid integer not null auto_increment, Value_ varchar(255), primary key (courseid));
  41. create table difficulty (difficultyid integer not null auto_increment, Value_ varchar(255), primary key (difficultyid));
  42. create table ethnicity (ethnicityid integer not null auto_increment, Value_ varchar(255), primary key (ethnicityid));
  43. create table ingredient (ingredientid integer not null auto_increment, description text, ingr_name varchar(128) not null, primary key (ingredientid));
  44. create table meal (mealid bigint not null auto_increment, ownerid integer, meal_name varchar(128) not null, primary key (mealid));
  45. create table mealrecipe (mealrecipeid bigint not null auto_increment, recipeid bigint, courseid integer, quantity double precision, mealid bigint, pos integer, primary key (mealrecipeid));
  46. create table measurement_system (systemid integer not null auto_increment, Value_ varchar(255), primary key (systemid));
  47. create table preptime (preptimeid integer not null auto_increment, Value_ varchar(255), primary key (preptimeid));
  48. create table recipe (recipeid bigint not null auto_increment, ownerid integer, image varchar(255), excerpt text, source varchar(128), courseid integer, systemid integer, directions text, baseid integer, preptimeid integer, ethnicityid integer, createddate datetime, servingsize integer not null, recipe_name varchar(128) not null, modifieddate datetime, difficultyid integer, primary key (recipeid));
  49. create table recipecomment (commentid bigint not null auto_increment, Value_ varchar(255), userid integer not null, createddate datetime not null, recipeid bigint, pos integer, primary key (commentid));
  50. create table recipeingredient (recipeingredientid bigint not null auto_increment, ingredientid integer, unitid integer, optional bit not null, ingredientrecipeid bigint, qualifier varchar(255), quantity double precision not null, recipeid bigint, pos integer, primary key (recipeingredientid));
  51. create table reciperating (ratingid bigint not null auto_increment, userid integer not null, createddate datetime not null, rating smallint not null, recipeid bigint, pos integer, primary key (ratingid));
  52. create table recipestep (stepid bigint not null auto_increment, Value_ varchar(255), recipeid bigint, pos integer, primary key (stepid));
  53. create table relatedrecipe (relatedrecipeid bigint not null auto_increment, relationkindid integer, recipeid bigint, pos integer, primary key (relatedrecipeid));
  54. create table relationkind (relationkindid integer not null auto_increment, Value_ varchar(255), primary key (relationkindid));
  55. create table unit (unitid integer not null auto_increment, Value_ varchar(255), abbreviation varchar(8) not null, mass bit not null, tometric double precision, tous double precision, toimperial double precision, systemid integer, primary key (unitid));
  56. create table users (userid integer not null auto_increment, password varchar(64) not null, email varchar(128) not null, createddate datetime not null, country varchar(3) not null, accesslevel integer, lastlogindate datetime, user_name varchar(64) not null, login varchar(32) not null, language varchar(3) not null, primary key (userid));
  57. alter table meal add index meal_user_fk (ownerid), add constraint meal_user_fk foreign key (ownerid) references users (userid);
  58. alter table mealrecipe add index mealrecipe_recipe_fk (recipeid), add constraint mealrecipe_recipe_fk foreign key (recipeid) references recipe (recipeid);
  59. alter table mealrecipe add index mealrecipe_course_fk (courseid), add constraint mealrecipe_course_fk foreign key (courseid) references course (courseid);
  60. alter table mealrecipe add index mealrecipe_meal_fk (mealid), add constraint mealrecipe_meal_fk foreign key (mealid) references meal (mealid);
  61. alter table recipe add index recipe_ethnicity_fk (ethnicityid), add constraint recipe_ethnicity_fk foreign key (ethnicityid) references ethnicity (ethnicityid);
  62. alter table recipe add index recipe_preptime_fk (preptimeid), add constraint recipe_preptime_fk foreign key (preptimeid) references preptime (preptimeid);
  63. alter table recipe add index recipe_base_fk (baseid), add constraint recipe_base_fk foreign key (baseid) references base (baseid);
  64. alter table recipe add index recipe_user_fk (ownerid), add constraint recipe_user_fk foreign key (ownerid) references users (userid);
  65. alter table recipe add index recipe_course_fk (courseid), add constraint recipe_course_fk foreign key (courseid) references course (courseid);
  66. alter table recipe add index recipe_difficulty_fk (difficultyid), add constraint recipe_difficulty_fk foreign key (difficultyid) references difficulty (difficultyid);
  67. alter table recipe add index recipe_system_fk (systemid), add constraint recipe_system_fk foreign key (systemid) references measurement_system (systemid);
  68. alter table recipecomment add index recipecomment_recipe_fk (recipeid), add constraint recipecomment_recipe_fk foreign key (recipeid) references recipe (recipeid);
  69. alter table recipeingredient add index recipeingredient_recipe_fk (recipeid), add constraint recipeingredient_recipe_fk foreign key (recipeid) references recipe (recipeid);
  70. alter table recipeingredient add index recipeingredient_unit_fk (unitid), add constraint recipeingredient_unit_fk foreign key (unitid) references unit (unitid);
  71. alter table recipeingredient add index recipeingredient_ingredientrecipe_fk (ingredientrecipeid), add constraint recipeingredient_ingredientrecipe_fk foreign key (ingredientrecipeid) references recipe (recipeid);
  72. alter table recipeingredient add index recipeingredient_ingredient_fk (ingredientid), add constraint recipeingredient_ingredient_fk foreign key (ingredientid) references ingredient (ingredientid);
  73. alter table reciperating add index reciperating_recipe_fk (recipeid), add constraint reciperating_recipe_fk foreign key (recipeid) references recipe (recipeid);
  74. alter table recipestep add index recipestep_recipe_fk (recipeid), add constraint recipestep_recipe_fk foreign key (recipeid) references recipe (recipeid);
  75. alter table relatedrecipe add index relatedrecipe_recipe_fk (recipeid), add constraint relatedrecipe_recipe_fk foreign key (recipeid) references recipe (recipeid);
  76. alter table relatedrecipe add index relatedrecipe_relationkind_fk (relationkindid), add constraint relatedrecipe_relationkind_fk foreign key (relationkindid) references relationkind (relationkindid);