PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/engine/schema/mysql.sql

https://github.com/masuman/elgg-1
SQL | 370 lines | 242 code | 80 blank | 48 comment | 0 complexity | 73fee4f169226d73eebe92fbc1f50b99 MD5 | raw file
  1. --
  2. -- Main Elgg database
  3. --
  4. -- @link http://elgg.org/
  5. -- @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
  6. -- @author Curverider Ltd
  7. -- @copyright Curverider Ltd 2008-2009
  8. -- @link http://elgg.org/
  9. --
  10. -- --------------------------------------------------------
  11. --
  12. -- *** The main tables ***
  13. --
  14. -- Site configuration.
  15. CREATE TABLE `prefix_config` (
  16. `name` varchar(32) NOT NULL,
  17. `value` text NOT NULL,
  18. `site_guid` int(11) NOT NULL,
  19. PRIMARY KEY (`name`,`site_guid`)
  20. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  21. -- Define entities.
  22. CREATE TABLE `prefix_entities` (
  23. `guid` bigint(20) unsigned NOT NULL auto_increment,
  24. `type` enum ('object', 'user', 'group', 'site') NOT NULL,
  25. `subtype` int(11) NULL,
  26. `owner_guid` bigint(20) unsigned NOT NULL,
  27. `site_guid` bigint(20) unsigned NOT NULL,
  28. `container_guid` bigint(20) unsigned NOT NULL,
  29. `access_id` int(11) NOT NULL,
  30. `time_created` int(11) NOT NULL,
  31. `time_updated` int(11) NOT NULL,
  32. `enabled` enum ('yes', 'no') NOT NULL default 'yes',
  33. primary key (`guid`),
  34. KEY `type` (`type`),
  35. KEY `subtype` (`subtype`),
  36. KEY `owner_guid` (`owner_guid`),
  37. KEY `site_guid` (`site_guid`),
  38. KEY `container_guid` (`container_guid`),
  39. KEY `access_id` (`access_id`),
  40. KEY `time_created` (`time_created`),
  41. KEY `time_updated` (`time_updated`)
  42. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  43. -- Entity subtypes - lets you subtype one of the main objects (sites/objects/etc)
  44. CREATE TABLE `prefix_entity_subtypes` (
  45. `id` int(11) NOT NULL auto_increment,
  46. `type` enum ('object', 'user', 'group', 'site') NOT NULL,
  47. `subtype` varchar(50) NOT NULL,
  48. class varchar(50) NOT NULL default '',
  49. PRIMARY KEY (`id`),
  50. UNIQUE KEY (`type`, `subtype`)
  51. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  52. -- Describe relationships between entities, can describe friendships but also site membership, depending on context
  53. CREATE TABLE `prefix_entity_relationships` (
  54. `id` int(11) NOT NULL auto_increment,
  55. `guid_one` bigint(20) unsigned NOT NULL,
  56. `relationship` varchar(50) NOT NULL,
  57. `guid_two` bigint(20) unsigned NOT NULL,
  58. PRIMARY KEY (`id`),
  59. UNIQUE KEY (`guid_one`,`relationship`,`guid_two`),
  60. KEY `relationship` (`relationship`),
  61. KEY `guid_two` (`guid_two`)
  62. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  63. --
  64. -- *** Access controls ***
  65. --
  66. -- Table structure for table `access_collections`
  67. CREATE TABLE `prefix_access_collections` (
  68. `id` int(11) NOT NULL auto_increment,
  69. `name` text NOT NULL,
  70. `owner_guid` bigint(20) unsigned NOT NULL,
  71. `site_guid` bigint(20) unsigned NOT NULL default '0',
  72. PRIMARY KEY (`id`),
  73. KEY `owner_guid` (`owner_guid`),
  74. KEY `site_guid` (`site_guid`)
  75. ) AUTO_INCREMENT=3 ENGINE=MyISAM DEFAULT CHARSET=utf8;
  76. -- Access containers
  77. CREATE TABLE `prefix_access_collection_membership` (
  78. `user_guid` int(11) NOT NULL,
  79. `access_collection_id` int(11) NOT NULL,
  80. PRIMARY KEY (`user_guid`,`access_collection_id`)
  81. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  82. --
  83. -- *** Entity superclass details ***
  84. -- NB: Aside from GUID, these should now have any field names in common with the entities table.
  85. --
  86. -- Extra information relating to "objects"
  87. CREATE TABLE `prefix_objects_entity` (
  88. `guid` bigint(20) unsigned NOT NULL,
  89. `title` text NOT NULL,
  90. `description` text NOT NULL,
  91. PRIMARY KEY (`guid`),
  92. FULLTEXT KEY (`title`,`description`)
  93. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  94. -- Extra information relating to "sites"
  95. CREATE TABLE `prefix_sites_entity` (
  96. `guid` bigint(20) unsigned NOT NULL,
  97. `name` text NOT NULL,
  98. `description` text NOT NULL,
  99. `url` varchar(255) NOT NULL,
  100. PRIMARY KEY (`guid`),
  101. UNIQUE KEY (`url`),
  102. FULLTEXT KEY (`name`,`description`, `url`)
  103. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  104. -- Extra information relating to "users"
  105. CREATE TABLE `prefix_users_entity` (
  106. `guid` bigint(20) unsigned NOT NULL,
  107. `name` text NOT NULL,
  108. `username` varchar(128) NOT NULL default '',
  109. `password` varchar(32) NOT NULL default '',
  110. `salt` varchar(8) NOT NULL default '',
  111. `email` text NOT NULL,
  112. `language` varchar(6) NOT NULL default '',
  113. `code` varchar(32) NOT NULL default '',
  114. `banned` enum ('yes', 'no') NOT NULL default 'no',
  115. `last_action` int(11) NOT NULL default '0',
  116. `prev_last_action` int(11) NOT NULL default '0',
  117. `last_login` int(11) NOT NULL default '0',
  118. `prev_last_login` int(11) NOT NULL default '0',
  119. PRIMARY KEY (`guid`),
  120. UNIQUE KEY (`username`),
  121. KEY `password` (`password`),
  122. KEY `email` (`email`(50)),
  123. KEY `code` (`code`),
  124. KEY `last_action` (`last_action`),
  125. KEY `last_login` (`last_login`),
  126. FULLTEXT KEY `name` (`name`),
  127. FULLTEXT KEY (`name`,`username`)
  128. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  129. -- Extra information relating to "groups"
  130. CREATE TABLE `prefix_groups_entity` (
  131. `guid` bigint(20) unsigned NOT NULL,
  132. `name` text NOT NULL,
  133. `description` text NOT NULL,
  134. PRIMARY KEY (`guid`),
  135. FULLTEXT KEY (`name`,`description`)
  136. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  137. --
  138. -- *** Annotations and tags ***
  139. --
  140. -- Table structure for annotations
  141. CREATE TABLE `prefix_annotations` (
  142. `id` int(11) NOT NULL auto_increment,
  143. `entity_guid` bigint(20) unsigned NOT NULL,
  144. `name_id` int(11) NOT NULL,
  145. `value_id` int(11) NOT NULL,
  146. `value_type` enum ('integer','text') NOT NULL,
  147. `owner_guid` bigint(20) unsigned NOT NULL,
  148. `access_id` int(11) NOT NULL,
  149. `time_created` int(11) NOT NULL,
  150. `enabled` enum ('yes', 'no') NOT NULL default 'yes',
  151. PRIMARY KEY (`id`),
  152. KEY `entity_guid` (`entity_guid`),
  153. KEY `name_id` (`name_id`),
  154. KEY `value_id` (`value_id`),
  155. KEY `owner_guid` (`owner_guid`),
  156. KEY `access_id` (`access_id`)
  157. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  158. -- Table structure for metadata
  159. CREATE TABLE `prefix_metadata` (
  160. `id` int(11) NOT NULL auto_increment,
  161. `entity_guid` bigint(20) unsigned NOT NULL,
  162. `name_id` int(11) NOT NULL,
  163. `value_id` int(11) NOT NULL,
  164. `value_type` enum ('integer','text') NOT NULL,
  165. `owner_guid` bigint(20) unsigned NOT NULL,
  166. `access_id` int(11) NOT NULL,
  167. `time_created` int(11) NOT NULL,
  168. `enabled` enum ('yes', 'no') NOT NULL default 'yes',
  169. PRIMARY KEY (`id`),
  170. KEY `entity_guid` (`entity_guid`),
  171. KEY `name_id` (`name_id`),
  172. KEY `value_id` (`value_id`),
  173. KEY `owner_guid` (`owner_guid`),
  174. KEY `access_id` (`access_id`)
  175. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  176. -- Meta strings table (avoids storing text strings more than once)
  177. CREATE TABLE `prefix_metastrings` (
  178. `id` int(11) NOT NULL auto_increment,
  179. `string` TEXT NOT NULL,
  180. PRIMARY KEY (`id`),
  181. KEY `string` (`string`(50))
  182. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  183. --
  184. -- *** Misc ***
  185. --
  186. -- API Users
  187. CREATE TABLE `prefix_api_users` (
  188. id int(11) auto_increment,
  189. site_guid bigint(20) unsigned,
  190. api_key varchar(40),
  191. secret varchar(40) NOT NULL,
  192. active int(1) default 1,
  193. unique key (api_key),
  194. primary key (id)
  195. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  196. -- API Sessions
  197. CREATE TABLE `prefix_users_apisessions` (
  198. `id` int(11) NOT NULL auto_increment,
  199. `user_guid` bigint(20) unsigned NOT NULL,
  200. `site_guid` bigint(20) unsigned NOT NULL,
  201. `token` varchar(40),
  202. `expires` int(11) NOT NULL,
  203. PRIMARY KEY (`id`),
  204. UNIQUE KEY (`user_guid`,`site_guid`),
  205. KEY `token` (`token`)
  206. ) ENGINE=MEMORY;
  207. -- HMAC Cache protecting against Replay attacks
  208. CREATE TABLE `prefix_hmac_cache` (
  209. `hmac` varchar(255) NOT NULL,
  210. `ts` int(11) NOT NULL,
  211. PRIMARY KEY (`hmac`),
  212. KEY `ts` (`ts`)
  213. ) ENGINE=MEMORY;
  214. -- Geocode engine cache
  215. CREATE TABLE `prefix_geocode_cache` (
  216. id int(11) auto_increment,
  217. location varchar(128),
  218. `lat` varchar(20),
  219. `long` varchar(20),
  220. PRIMARY KEY (`id`),
  221. KEY `location` (`location`)
  222. ) ENGINE=MEMORY;
  223. -- PHP Session storage
  224. CREATE TABLE `prefix_users_sessions` (
  225. `session` varchar(255) NOT NULL,
  226. `ts` int(11) unsigned NOT NULL default '0',
  227. `data` mediumblob,
  228. PRIMARY KEY `session` (`session`),
  229. KEY `ts` (`ts`)
  230. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  231. -- Datalists for things like db version
  232. CREATE TABLE `prefix_datalists` (
  233. `name` varchar(32) NOT NULL,
  234. `value` text NOT NULL,
  235. PRIMARY KEY `name` (`name`)
  236. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  237. -- Ultra-private system settings for entities
  238. CREATE TABLE `prefix_private_settings` (
  239. `id` INT NOT NULL auto_increment,
  240. `entity_guid` INT NOT NULL ,
  241. `name` varchar(128) NOT NULL ,
  242. `value` TEXT NOT NULL ,
  243. PRIMARY KEY ( `id` ) ,
  244. UNIQUE KEY ( `entity_guid` , `name` ),
  245. KEY `name` (`name`),
  246. KEY `value` (`value` (50))
  247. ) ENGINE = MYISAM DEFAULT CHARSET=utf8;
  248. -- System log
  249. CREATE TABLE `prefix_system_log` (
  250. `id` int(11) NOT NULL auto_increment,
  251. `object_id` int(11) NOT NULL,
  252. `object_class` varchar(50) NOT NULL,
  253. `object_type` varchar(50) NOT NULL,
  254. `object_subtype` varchar(50) NOT NULL,
  255. `event` varchar(50) NOT NULL,
  256. `performed_by_guid` int(11) NOT NULL,
  257. `owner_guid` int(11) NOT NULL,
  258. `access_id` int(11) NOT NULL,
  259. `enabled` enum ('yes', 'no') NOT NULL default 'yes',
  260. `time_created` int(11) NOT NULL,
  261. PRIMARY KEY (`id`),
  262. KEY `object_id` (`object_id`),
  263. KEY `object_class` (`object_class`),
  264. KEY `object_type` (`object_type`),
  265. KEY `object_subtype` (`object_subtype`),
  266. KEY `event` (`event`),
  267. KEY `performed_by_guid` (`performed_by_guid`),
  268. KEY `access_id` (`access_id`),
  269. KEY `time_created` (`time_created`),
  270. KEY `river_key` (`object_type`, `object_subtype`, `event`)
  271. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  272. -- River
  273. CREATE TABLE `prefix_river` (
  274. `id` INT NOT NULL AUTO_INCREMENT ,
  275. `type` VARCHAR( 8 ) NOT NULL ,
  276. `subtype` VARCHAR( 32 ) NOT NULL ,
  277. `action_type` VARCHAR( 32 ) NOT NULL ,
  278. `access_id` INT NOT NULL ,
  279. `view` TEXT NOT NULL ,
  280. `subject_guid` INT NOT NULL ,
  281. `object_guid` INT NOT NULL ,
  282. `posted` INT NOT NULL ,
  283. PRIMARY KEY ( `id` ) ,
  284. KEY `type` (`type`),
  285. KEY `action_type` (`action_type`),
  286. KEY `access_id` (`access_id`),
  287. KEY `subject_guid` (`subject_guid`),
  288. KEY `object_guid` (`object_guid`),
  289. KEY `posted` (`posted`)
  290. ) ENGINE = MYISAM DEFAULT CHARSET=utf8;