ddl.sql 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. -- clear out tables
  2. DROP TABLE IF EXISTS Organisation CASCADE;
  3. DROP TABLE IF EXISTS Place CASCADE;
  4. DROP TABLE IF EXISTS Tag CASCADE;
  5. DROP TABLE IF EXISTS TagClass CASCADE;
  6. DROP TABLE IF EXISTS Comment CASCADE;
  7. DROP TABLE IF EXISTS Forum CASCADE;
  8. DROP TABLE IF EXISTS Post CASCADE;
  9. DROP TABLE IF EXISTS Person CASCADE;
  10. DROP TABLE IF EXISTS Comment_hasTag_Tag CASCADE;
  11. DROP TABLE IF EXISTS Post_hasTag_Tag CASCADE;
  12. DROP TABLE IF EXISTS Forum_hasMember_Person CASCADE;
  13. DROP TABLE IF EXISTS Forum_hasTag_Tag CASCADE;
  14. DROP TABLE IF EXISTS Person_hasInterest_Tag CASCADE;
  15. DROP TABLE IF EXISTS Person_likes_Comment CASCADE;
  16. DROP TABLE IF EXISTS Person_likes_Post CASCADE;
  17. DROP TABLE IF EXISTS Person_studyAt_University CASCADE;
  18. DROP TABLE IF EXISTS Person_workAt_Company CASCADE;
  19. DROP TABLE IF EXISTS Person_knows_Person CASCADE;
  20. \! echo OLD TABLES DROPPED
  21. \! date -Iseconds
  22. -- static tables
  23. CREATE TABLE Organisation (
  24. id bigint NOT NULL,
  25. type text NOT NULL,
  26. name text NOT NULL,
  27. url text NOT NULL,
  28. LocationPlaceId bigint NOT NULL
  29. );
  30. CREATE INDEX Organisation_id ON Organisation (id);
  31. CREATE TABLE Place (
  32. id bigint NOT NULL,
  33. name text NOT NULL,
  34. url text NOT NULL,
  35. type text NOT NULL,
  36. PartOfPlaceId bigint -- null for continents
  37. );
  38. CREATE INDEX Place_id ON Place (id);
  39. CREATE TABLE Tag (
  40. id bigint NOT NULL,
  41. name text NOT NULL,
  42. url text NOT NULL,
  43. TypeTagClassId bigint NOT NULL
  44. );
  45. CREATE INDEX Tag_id ON Tag (id);
  46. CREATE INDEX Tag_name ON Tag (name);
  47. CREATE INDEX Tag_TypeTagClassId ON Tag (TypeTagClassId);
  48. CREATE TABLE TagClass (
  49. id bigint NOT NULL,
  50. name text NOT NULL,
  51. url text NOT NULL,
  52. SubclassOfTagClassId bigint -- null for the root TagClass (Thing)
  53. );
  54. CREATE INDEX TagClass_id ON TagClass (id);
  55. CREATE INDEX TagClass_name ON TagClass (name);
  56. -- dynamic tables
  57. CREATE TABLE Comment (
  58. creationDate timestamp with time zone NOT NULL,
  59. id bigint NOT NULL,
  60. locationIP text NOT NULL,
  61. browserUsed text NOT NULL,
  62. content text NOT NULL,
  63. length int NOT NULL,
  64. CreatorPersonId bigint NOT NULL,
  65. LocationCountryId bigint NOT NULL,
  66. ParentPostId bigint,
  67. ParentCommentId bigint
  68. );
  69. CREATE INDEX Comment_id ON Comment (id);
  70. CREATE TABLE Forum (
  71. creationDate timestamp with time zone NOT NULL,
  72. id bigint NOT NULL,
  73. title text NOT NULL,
  74. ModeratorPersonId bigint -- can be null as its cardinality is 0..1
  75. );
  76. CREATE INDEX Forum_id ON Forum (id);
  77. CREATE INDEX Forum_ModeratorPersonId on Forum (ModeratorPersonId);
  78. CREATE TABLE Post (
  79. creationDate timestamp with time zone NOT NULL,
  80. id bigint NOT NULL,
  81. imageFile text,
  82. locationIP text NOT NULL,
  83. browserUsed text NOT NULL,
  84. language text,
  85. content text,
  86. length int NOT NULL,
  87. CreatorPersonId bigint NOT NULL,
  88. ContainerForumId bigint NOT NULL,
  89. LocationCountryId bigint NOT NULL
  90. );
  91. CREATE INDEX Post_id ON Post (id);
  92. CREATE TABLE Person (
  93. creationDate timestamp with time zone NOT NULL,
  94. id bigint NOT NULL,
  95. firstName text NOT NULL,
  96. lastName text NOT NULL,
  97. gender text NOT NULL,
  98. birthday date NOT NULL,
  99. locationIP text NOT NULL,
  100. browserUsed text NOT NULL,
  101. LocationCityId bigint NOT NULL,
  102. speaks text NOT NULL,
  103. email text NOT NULL
  104. );
  105. CREATE INDEX Person_id ON Person (id);
  106. CREATE INDEX Person_LocationCityId ON Person (LocationCityId);
  107. -- edges
  108. CREATE TABLE Comment_hasTag_Tag (
  109. creationDate timestamp with time zone NOT NULL,
  110. CommentId bigint NOT NULL,
  111. TagId bigint NOT NULL
  112. );
  113. CREATE TABLE Post_hasTag_Tag (
  114. creationDate timestamp with time zone NOT NULL,
  115. PostId bigint NOT NULL,
  116. TagId bigint NOT NULL
  117. );
  118. CREATE TABLE Forum_hasMember_Person (
  119. creationDate timestamp with time zone NOT NULL,
  120. ForumId bigint NOT NULL,
  121. PersonId bigint NOT NULL
  122. );
  123. CREATE INDEX Forum_hasMember_Person_ForumId ON Forum_hasMember_Person (ForumId);
  124. CREATE INDEX Forum_hasMember_Person_PersonId ON Forum_hasMember_Person (PersonId);
  125. CREATE TABLE Forum_hasTag_Tag (
  126. creationDate timestamp with time zone NOT NULL,
  127. ForumId bigint NOT NULL,
  128. TagId bigint NOT NULL
  129. );
  130. CREATE TABLE Person_hasInterest_Tag (
  131. creationDate timestamp with time zone NOT NULL,
  132. PersonId bigint NOT NULL,
  133. TagId bigint NOT NULL
  134. );
  135. CREATE INDEX Person_hasInterest_Tag_TagId ON Person_hasInterest_Tag (TagId);
  136. CREATE TABLE Person_likes_Comment (
  137. creationDate timestamp with time zone NOT NULL,
  138. PersonId bigint NOT NULL,
  139. CommentId bigint NOT NULL
  140. );
  141. CREATE TABLE Person_likes_Post (
  142. creationDate timestamp with time zone NOT NULL,
  143. PersonId bigint NOT NULL,
  144. PostId bigint NOT NULL
  145. );
  146. CREATE TABLE Person_studyAt_University (
  147. creationDate timestamp with time zone NOT NULL,
  148. PersonId bigint NOT NULL,
  149. UniversityId bigint NOT NULL,
  150. classYear int NOT NULL
  151. );
  152. CREATE INDEX Person_studyAt_University_PersonId ON Person_studyAt_University (PersonId);
  153. CREATE INDEX Person_studyAt_University_UniversityId ON Person_studyAt_University (UniversityId);
  154. CREATE TABLE Person_workAt_Company (
  155. creationDate timestamp with time zone NOT NULL,
  156. PersonId bigint NOT NULL,
  157. CompanyId bigint NOT NULL,
  158. workFrom int NOT NULL
  159. );
  160. CREATE INDEX Person_workAt_Company_PersonId ON Person_workAt_Company (PersonId);
  161. CREATE INDEX Person_workAt_Company_CompanyId ON Person_workAt_Company (CompanyId);
  162. CREATE TABLE Person_knows_Person (
  163. creationDate timestamp with time zone NOT NULL,
  164. Person1id bigint NOT NULL,
  165. Person2id bigint NOT NULL
  166. );
  167. CREATE INDEX Person_knows_Person_Person1id ON Person_knows_Person (Person1id);
  168. CREATE INDEX Person_knows_Person_Person2id ON person_knows_person (Person2id);
  169. CREATE INDEX Person_knows_Person_Person1id_Person2id ON Person_knows_Person (Person1id, Person2id);